• Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Proper way to set websocket filter ?

    Scheduled Pinned Locked Moved Evok API
    4 Posts 3 Posters 2.9k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H
      Henkka
      last edited by

      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

      T 1 Reply Last reply
      Reply Quote 0
      • T
        tomas_hora administrators @Henkka
        last edited by

        @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

        1 Reply Last reply
        Reply Quote 0
        • T
          TomasKnot
          last edited by TomasKnot

          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.

          H 1 Reply Last reply
          Reply Quote 0
          • H
            Henkka @TomasKnot
            last edited by

            @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

            1 Reply Last reply
            Reply Quote 0

            Hello! It looks like you're interested in this conversation, but you don't have an account yet.

            Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

            With your input, this post could be even better 💗

            Register Login
            • First post
              Last post