(→Example) |
(→Requirements) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
== Requirements == | == Requirements == | ||
− | pip install | + | pip install "python-socketio[client]" |
== Example == | == Example == | ||
− | < | + | <pre> |
− | + | import socketio | |
− | + | ||
− | + | sio = socketio.Client() | |
− | + | ||
− | def | + | @sio.event |
− | print(' | + | def connect(): |
+ | print('connected to server') | ||
− | + | @sio.event | |
− | + | def disconnect(): | |
− | def | + | print('disconnected from server') |
− | + | ||
− | + | ||
− | + | ||
− | + | @sio.on("mqtt") | |
− | + | def on_mqtt(data): | |
− | + | print (data) | |
− | + | return | |
− | socket. | + | |
− | + | sio.connect(url='https://api.brandmeister.network', socketio_path="/lh/socket.io", transports="websocket") | |
− | </ | + | sio.wait() |
+ | </pre> |
- pip install "python-socketio[client]"
- 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()
- pip install socketIO-client
<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>