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

    Curl works, Python http.client.request not fully

    Official EVOK API
    2
    3
    169
    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.
    • M
      Maxiba last edited by

      Hello!

      I'm new to the Unipi. I have Python and general coding/programming experience.

      I have the Unipi 1.1 and a RaspberryPi 3B+. I want to create an application to monitor the rpm of a machine, and if the rpm is ok, i output a signal on a relay.

      For this, i need to read analog and digital inputs and write relay states. I started to play a bit with the Evok API and i ran into following problem:

      1: command line: curl http://localhost:8080/json/input/{1,2} - works
      2: command line: curl http://localhost:8080/json/{input,ai}/{{1,2},1} - works
      3: python: conn.request("GET", "/json/input/1", payload) - works
      4: python: conn.request("GET", "/json/input/{1}", payload) - does not work
      5: python: conn.request("GET", "/json/input/{1,2}", payload) - does not work
      6: python: conn.request("GET", "/json/input/%7B1%7D", payload) - does not work

      Output of #2:

      {"status": "success", "data": {"bitvalue": 0, "glob_dev_id": 0, "value": 0, "circuit": "1", "time": 0, "debounce": 0, "counter_mode": false, "dev": "input"}}{"status": "success", "data": {"bitvalue": 0, "glob_dev_id": 0, "value": 0, "circuit": "2", "time": 0, "debounce": 0, "counter_mode": false, "dev": "input"}}{"status": "success", "data": {"bitvalue": 0, "glob_dev_id": 0, "value": 0, "circuit": "1", "time": 0, "debounce": 0, "counter_mode": false, "dev": "input"}}{"status": "success", "data": {"glob_dev_id": 0, "modes": ["Simple"], "value": 0.0011303831752485904, "circuit": "1", "time": null, "mode": "Simple", "interval": 2.0, "bits": 18, "dev": "ai", "gain": 1}}{"status": "success", "data": {"glob_dev_id": 0, "modes": ["Simple"], "value": 0.0011303831752485904, "circuit": "2", "time": null, "mode": "Simple", "interval": 1.0, "bits": 18, "dev": "ai", "gain": 1}}{"status": "success", "data": {"glob_dev_id": 0, "modes": ["Simple"], "value": 0.0011303831752485904, "circuit": "1", "time": null, "mode": "Simple", "interval": 2.0, "bits": 18, "dev": "ai", "gain": 1}}
      

      Output of #4-#6:

      b'{"status": "error", "message": "Internal Server Error", "code": 500}'
      

      Python-code:

      import http.client
      
      conn = http.client.HTTPConnection("localhost:8080")
      
      payload = "{}"
      
      conn.request("GET", "/json/input/%7B1%7D", payload)
      
      res = conn.getresponse()
      data = res.read()
      
      print(data)
      

      maybe the problem is, how the http.client.request method handles the URL. but i already tried to Encode the URL, and it didnt help...

      What can i try now?

      Best Regards
      Max

      1 Reply Last reply Reply Quote 0
      • M
        martin_triska administrators last edited by

        Hello @Maxiba,

        the issue described occurs because the curl command sends two separate requests in fact (one for each input).

        Opposite, the Python script does not have intelligence and sends exactly what you pass to it while Evok does not support this request syntax.

        In your case, you can consider using JSON Bulk request to read/write more I/Os at once.

        https://evok-14.api-docs.io/1.11/bulk/bulk-json-request

        1 Reply Last reply Reply Quote 0
        • M
          Maxiba last edited by

          Thank you for the answer!

          I am using the websocket API now, as this suits my requirements the most.

          Have a nice day!

          1 Reply Last reply Reply Quote 0
          • First post
            Last post