You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

4.9 KiB

:description: IoT Example
:keywords: iot, swarmlab
:data-uri:
:toc: right
:toc-title: Table of contents
:toclevels: 4
:source-highlighter: highlight
:icons: font
:sectnums:

{empty} +


== Connect to socket Server

Does something asynchronously and executes the EventBus on completion.

[source,javascript]
----
this.SwarmabAsciiLabTemplate = {
"iot5": {
"id": 5,
"name": "auto5",
"img": "rinse.png",
"Servicios": [
{
"model":"Sentra",
"doors":4
},
{
"model":"Maxima",
"doors":4
},
{
"model":"Skyline",
"doors":2
}
]
}
this.$root.$emit('iot_add', this.SwarmabAsciiLabTemplate) // <1>
----
<1> EventBus is used for parent/child component communication.



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/App.vue
- *Line:* 131
- *Code:* async connect_to_iot(iot) {
====

== socketclose()

[source,javascript]
----
this.$socket.client.close();
----



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 101
- *Code:* async socketclose () {
====

== Socket subscribe

[source,javascript]
----
this.$root.$on('iot_add', (v) => { // <1>
...
})
sdfsf
den to perni sdfsf
----
<1> EventBus is used for parent/child component communication.



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 123
- *Code:* mounted() {
====

== Destroy EventBus

See
https://www.digitalocean.com/community/tutorials/vuejs-component-lifecycle[Vue.js Lifecycle Hooks^].

*beforeDestroy*

- beforeDestroy is fired right before teardown. Your component will still be fully present and functional.

[source,javascript]
----
this.$root.$off('iot_add') // <1>
----
<1> EventBus is used for parent/child component communication.



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 157
- *Code:* beforeDestroy () {
====

== Open a socket

See
https://www.digitalocean.com/community/tutorials/vuejs-component-lifecycle[ Vue.js Lifecycle Hooks^]

*Created*

- You are able to access reactive data and events that are active with the created hook. Templates and Virtual DOM have not yet been mounted or rendered:

[source,javascript]
----
this.socketopen()
----



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 179
- *Code:* created () {
====

== Socket events

[source,javascript]
----
this.$socket.client.emit('authenticate', 'logintoken');
----



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 192
- *Code:* sockets: {
====

=== onError



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 205
- *Code:* error(error) {
====

=== connect_error



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 214
- *Code:* connect_error(error) {
====

=== connect_error



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 223
- *Code:* disconnect(reason) {
====

=== Socket connect_timeout



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 232
- *Code:* connect_timeout(reason) {
====

=== Socket reconnect



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 241
- *Code:* reconnect(attemptNumber) {
====

=== connect_attempt



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 249
- *Code:* reconnect_attempt(attemptNumber) {
====

=== Socket reconnecting



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 257
- *Code:* reconnecting(attemptNumber) {
====

=== reconnect_error



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 265
- *Code:* reconnect_error(error) {
====

=== unauthorized



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 274
- *Code:* unauthorized(val) {
====

=== connected



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 283
- *Code:* socket_id_emit(val) {
====

=== Socket onMessage



[TIP]
====
- *File:* /data/appl/ok/swarmlab-iot-example/browser-client/src/components/doclive/runLlo.vue
- *Line:* 293
- *Code:* async adhocEmit(val) {
====