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

    websocket send command

    Official EVOK API
    1
    2
    1011
    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.
    • J
      juntiedt last edited by

      I am experimenting with websocket send. I want to replace the hard coded command with variables. Unfortunately without success. See code:

      import websocket
      import json
      from time import *
      
      
      #sending messages ------------------------------------
      
      def send_data(CMD,DEV,CIRCUIT,VALUE):
          print("sending data : ",CMD,DEV,CIRCUIT,VALUE)
          x = ("%s" %('"cmd"' + ":" + '"' + CMD + '"' + "," + '"dev"' + ":" + '"' + DEV + '"' + "," + '"circuit"' + ":" + '"' + CIRCUIT + '"' + "," + '"value"' + ":" + '"' + VALUE + '"'))
          print(x)
          ws = websocket.WebSocket()
          ws.connect("ws://localhost/ws")
          #ws.send('{"cmd":"all"}')
          #ws.send('{"cmd":"set","dev":"relay","circuit":"3","value":"0"}')
          ws.send('{("%s" %('"cmd"' + ":" + '"' + CMD + '"' + "," + '"dev"' + ":" + '"' + DEV + '"' + "," + '"circuit"' + ":" + '"' + CIRCUIT + '"' + "," + '"value"' + ":" + '"' + VALUE + '"'))}')    
          #ws.send('{"%s" %(x)}')
          ws.close()
      
      #main program -----------------------------------------
      #
      send_data("set","relay","5","1")
      sleep(10)
      

      Any idea what I am doing wrong here?
      Also command "cmd":"all" is not working.

      I am running evok on Stretch. Are there still problems with the new os?
      I find it difficult to find the needed libraries for stretch and Python3. It would be helpfull to have some tested links for download.

      appriciate your help.

      1 Reply Last reply Reply Quote 0
      • J
        juntiedt last edited by

        I found it:

        #sending messages
        def ws_send(CMD, DEV, CIRCUIT, VALUE):
            ws = websocket.WebSocket()
            ws.connect(url)
            ws.send('{"cmd":"%s","dev":"%s","circuit":"%s","value":"%s"}' %(CMD,DEV,CIRCUIT,VALUE))    
            ws.close()
        1 Reply Last reply Reply Quote 0
        • First post
          Last post