Proper way to set websocket filter ?



  • I'm wondering what is the proper way to set websocket response filters ? I have tried to set them with command "filter", parameters "devices" as "ai,input" as I read from /opt/evok/evok.py but still I'm not getting input values as websocket messages on every message.

      1 import websocket
      2 import time
      3 import json
      4
      5 url = "ws://127.0.0.1/ws"
      6
      7 def on_message(ws, message):
      8     print(message)
      9     print("---")
     10
     11 def on_error(ws, error):
     12     print error
     13
     14 def on_close(ws):
     15     print "Connection closed"
     16
     17 def on_open(ws):
     19         ws.send('{"cmd":"filter","devices":"ai,input"}')
     20         #ws.send('{"cmd":"all"}')
     21
     22 ws = websocket.WebSocketApp(url, on_message = on_message, on_error = on_error, on_close = on_close)
     23 ws.on_open = on_open
     24 ws.run_forever()
    

    Reason I'm asking is because I have an button connected to one input and I would like to see it's counter value on every message. I have a certain point in my program that waits for user to press button. Now it seems that I'm missing some button presses since sometimes button press is not noticed, eg. no websocket message is ever received with increased button count. However if I press button long enough, then I get a valid websocket message with an increased counter. Usually this counter is then advanced by more than 1, say from 50 to 52 and thus I'm missing button press 51.

    --
    Henkka


  • administrators

    @Henkka You might need to set the scan_frequency to higher value (eg 5) to be able to read such short presses.

    @tomas_knot will tell you how to configure the filter


  • administrators

    The filter is a JSON array rather than a comma-separated list, so it should be sent as:

     ws.send('{"cmd":"filter","devices":["ai","input"]}')
    

    That being said though, this will not have any impact on your problems. From what you've described it sounds like it might be worth playing with the debounce settings; the counter should certainly not increase by 2 if you press the button once. The counters are handled internally via an embedded 48Mhz SoC, so it's unlikely that they will make a mistake in any input under circa 200KHz.



  • @tomas_knot

    Thanks, I will try that.

    How could I ask for input states through websocket, without using "all" query message? For example ideally I would like to ask about the state of one spesific input ? Or perhaps state of all inputs.

    --
    Henkka