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

    UniPi changing relay state

    UniPi 1 - First Generation
    2
    10
    2520
    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.
    • E
      Eanna last edited by

      Hi

      Sorry I'm new to this and trying to set up the UniPi with my raspberry Pi but i cant get the relays to change state. I cant see what im doing wrong I've followed all instructions.
      Any help greatly appreciated

      Thanks.

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

        Could you describe what exactly are you using to change the relay state, i.e. which software and image?

        You may find it easiest to use Mervis, at least to try things out.

        1 Reply Last reply Reply Quote 0
        • E
          Eanna last edited by tomas_hora

          Hi Tomas

          Im using Python to programme it.

          this is my code:

          payload = "{1}"
          
          conn.request("GET", "/json/relay/%7Bcircuit%7D", payload)
          
          res = conn.getresponse()
          data = res.read()
          
          print(data.decode("utf-8"))
          
          ##payload = "{\"1\":\"0\",\"timeout\":\"0\",\"mode\":\"string (optional)\",\"pwm_freq\":\"2000",\"pwm_duty\":\"50\",\"alias\":\"string (optional)\"}"
          ##headers = { 'content-type': "application/json" }
          ##
          ##conn.request("POST", "/json/relay/%7Bcircuit%7D", payload, headers)
          ##
          ##res = conn.getresponse()
          ##data = res.read()
          ##
          ##print(data.decode("utf-8"))
          
          payload = "{2}"
          
          conn.request("GET", "/json/relay/%7Bcircuit%7D", payload)
          
          res = conn.getresponse()
          data = res.read()
          
          print(data.decode("utf-8"))
          
          ##payload = "{\"2\":\"0\",\"timeout\":\"0\",\"mode\":\"string (optional)\",\"pwm_freq\":\"2000",\"pwm_duty\":\"50\",\"alias\":\"string (optional)\"}"
          ##headers = { 'content-type': "application/json" }
          ##
          ##conn.request("POST", "/json/relay/%7Bcircuit%7D", payload, headers)
          ##
          ##res = conn.getresponse()
          ##data = res.read()
          ##
          ##print(data.decode("utf-8"))
          

          I have the changing state code commented out because its giving me errors.

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

            You need to replace "%7Bcircuit%7D" with e.g. 1_01, or whichever circuit you wish to use. The %7B%7D is caused by the api-docs interface escaping characters '{' and '}', which is meant as a hint for the implementation, to be replaced by the user.

            You can get a list of circuits and device types present by calling/visiting "YOUR-NEURON-IP:PORT/rest/all", sans the quotes and substituting the IP and port for proper values.

            I hope this helps, please do write if you have further issues.

            E 2 Replies Last reply Reply Quote 0
            • E
              Eanna @TomasKnot last edited by

              @TomasKnot have you any examples of the code? I cant find any online that I can understand.
              Thanks

              1 Reply Last reply Reply Quote 0
              • E
                Eanna last edited by

                How do I know which circuit is numbered in which way?
                Is there examples online?

                1 Reply Last reply Reply Quote 0
                • E
                  Eanna @TomasKnot last edited by

                  @TomasKnot said in UniPi changing relay state:

                  "YOUR-NEURON-IP:PORT/rest/all"

                  Hi Tomas

                  Im using the unipi 1.1. does that still work with the
                  "YOUR-NEURON-IP:PORT/rest/all" ?

                  thanks again

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

                    Yes, it should work for the UniPi 1.1 as well. You can simply go to e.g. 192.168.1.146:80/rest/all via a standard browser, to see the available devices.

                    You can look into the source code for the website GUI if you want to see an example of using the rest/json API in practice.

                    E 1 Reply Last reply Reply Quote 0
                    • E
                      Eanna @TomasKnot last edited by

                      @TomasKnot
                      Should that ip address work for all or should i use the pi's ip address?

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

                        You'll have to use your own ip address of course, hence the e.g.

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