(Example)
 
(Example)
Line 3: Line 3:
  
 
== Example ==
 
== Example ==
<syntaxhighlight lang="python">
+
```
from socketIO_client import SocketIO
+
import socketio
import json
+
  
def on_connect():
+
sio = socketio.Client()
    print('connect')
+
  
def on_disconnect():
+
@sio.event
     print('disconnect')
+
def connect():
 +
     print('connected to server')
  
def on_reconnect():
+
@sio.event
    print('reconnect')
+
def disconnect():
def on_mqtt(*args):
+
     print('disconnected from server')
     #print('on_mqtt', args)
+
    call = json.loads(args[0]['payload'])
+
    print json.dumps(call,separators=(',',':'),sort_keys=True,indent=4)
+
  
socket = SocketIO('https://api.brandmeister.network/lh')
+
@sio.on("mqtt")
socket.on('connect', on_connect)
+
def on_mqtt(data):
socket.on('disconnect', on_disconnect)
+
    print (data)
socket.on('reconnect', on_reconnect)
+
    return
socket.on('mqtt', on_mqtt)
+
 
socket.wait()
+
sio.connect(url='https://api.brandmeister.network', socketio_path="/lh/socket.io", transports="websocket")
</syntaxhighlight>
+
sio.wait()
 +
```

Revision as of 10:39, 16 March 2022

Requirements

pip install socketIO-client

Example

``` import socketio

sio = socketio.Client()

@sio.event def connect():

   print('connected to server')

@sio.event def disconnect():

   print('disconnected from server')

@sio.on("mqtt") def on_mqtt(data):

   print (data)
   return

sio.connect(url='https://api.brandmeister.network', socketio_path="/lh/socket.io", transports="websocket") sio.wait() ```

Requirements[edit]

pip install socketIO-client

Example[edit]

<syntaxhighlight lang="python"> from socketIO_client import SocketIO import json

def on_connect():

   print('connect')

def on_disconnect():

   print('disconnect')

def on_reconnect():

   print('reconnect')

def on_mqtt(*args):

   #print('on_mqtt', args)
   call = json.loads(args[0]['payload'])
   print json.dumps(call,separators=(',',':'),sort_keys=True,indent=4)

socket = SocketIO('https://api.brandmeister.network/lh') socket.on('connect', on_connect) socket.on('disconnect', on_disconnect) socket.on('reconnect', on_reconnect) socket.on('mqtt', on_mqtt) socket.wait() </syntaxhighlight>