Web Socket - Request status of all devices



  • Is there a way using web sockets to request the status of all devices, similar to the way you can with an HTTP GET request?



  • Is there a way using web sockets to request the status of all devices, similar to the way you can with an HTTP GET request?



  • Once a client is connected to ws, a message is sent for every device configured in evok to the client. Then only a changes are sent to the client. So a hacky way is to reconnect (or connect with new clinet).

    Maybe you could post a request to github?



  • Tomas,

    Thanks for the response. I'm not familiar with Python programming but I tried to follow the path a web socket request takes to get handled by evok. It looks to me that in evok.py, class WsHandler, in the on_message function is where the websocket message gets handled and apparently there is a "cmd" variable. If no "cmd" is sent in the message, it is defaulted to "set". This makes sense because the example usage of the web socket API is used to "set" the state of a relay without having to specifically put in a "cmd".

    I'm thinking that if "cmd" were specifically set to "get", the state of the requested relay could be sent back out the socket. Unfortunately, I wasn't able to figure out how the process gets to the "set" or "get" functions, so that is where I am stuck.

    Maybe you could give me some help understanding how a web socket message is handled from beginning to end? What python modules are involved in evok and tornado?

    Thanks,
    Brett.



  • I solved the issue in another hacky way. Since I am using Node-Red to knock together a prototype, I just set it up to query the http url and then store the resulting JSON in the global context. Then, every time a relay or input is updated, I use the resultant websocket message to update my global context state. This allows me to do things like toggle relays, detect different kinds of inputs such as a click vs press and hold, etc.

    Here is the flow to store the initial state in the global context:

    [{"id":"16044675.e9fbba","type":"http request","z":"12603337.ed9fcd","name":"Initial Status","method":"GET","ret":"txt","url":"http://127.0.0.1/rest/all","x":316,"y":77,"wires":[["9291954d.6d6e68"]]},{"id":"bf8a9779.407568","type":"inject","z":"12603337.ed9fcd","name":"Startup","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":true,"x":175,"y":77,"wires":[["16044675.e9fbba"]]},{"id":"9291954d.6d6e68","type":"function","z":"12603337.ed9fcd","name":"Store Status","func":"context.global.modulestatus = JSON.parse(msg.payload);\nreturn msg;","outputs":1,"noerr":0,"x":472,"y":77,"wires":[["ec3278b5.13cd88"]]},{"id":"ec3278b5.13cd88","type":"debug","z":"12603337.ed9fcd","name":"","active":false,"console":"false","complete":"false","x":630,"y":77,"wires":[]}]
    

    Then that state can be access in any function by including:

    var modulestatus = context.global.modulestatus;
    

    in the function.

    Thanks,
    Brett.