i cant read the event messages from the evok client. All i get is always that error message
ERROR:websocket:error from callback <function on_message at 0xb67882b0>: string indices must be integers
import websocket
import json
import logging
#import time
logging.basicConfig()
# Replace this with your Neuron IP Address
url = "ws://127.0.0.1:8080/ws"
def on_message(ws, message):
obj = json.loads(message)
for single_obj in obj:
dev = single_obj['dev']
circuit = single_obj['circuit']
value = single_obj['value']
print "Value: " + str(value) + " Device: " + str(dev) + " Circuit: " + str(circuit)
print message
def on_error(ws, error):
print error
def on_close(ws):
print "Connection closed"
def on_open(ws):
# Turn on filtering
#ws.send('{"cmd":"filter", "devices":["ai","input",output]}')
#ws.send(json.dumps({"cmd":"filter", "devices":["ai", "output"]}))
# Turn on DO 1.01
ws.send(json.dumps({"cmd":"set", "dev":"relay", "circuit": "1", "value":0}))
ws.send(json.dumps({"cmd":"set", "dev":"relay", "circuit": "2", "value":0}))
# Query for complete status
ws.send(json.dumps({"cmd":"all"}))
#receiving messages
ws = websocket.WebSocketApp(url, on_open = on_open, on_message = on_message, on_error = on_error, on_close = on_close)
ws.run_forever()
The "cmd" "all" works fine at the first start
Value: 0 Device: input Circuit: 11
Value: 0 Device: input Circuit: 10
Value: 0 Device: input Circuit: 12
Value: 0 Device: input Circuit: 1
Value: 0 Device: input Circuit: 3
Value: 0 Device: input Circuit: 2
Value: 0 Device: input Circuit: 5
Value: 0 Device: input Circuit: 4
Value: 0 Device: input Circuit: 7
Value: 0 Device: input Circuit: 6
Value: 0 Device: input Circuit: 9
Value: 0 Device: input Circuit: 8
Value: 0 Device: relay Circuit: 1
Value: 0 Device: relay Circuit: 3
Value: 0 Device: relay Circuit: 2
Value: 1 Device: relay Circuit: 5
Value: 0 Device: relay Circuit: 4
Value: 1 Device: relay Circuit: 7
Value: 1 Device: relay Circuit: 6
Value: 0 Device: relay Circuit: 8
Value: 0.000695620415538 Device: ai Circuit: 1
Value: 0.000956478071364 Device: ai Circuit: 2
Can someone help me please ?