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

    Input change not working

    Scheduled Pinned Locked Moved Evok API
    7 Posts 2 Posters 3.2k Views 1 Watching
    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

      im getting the hang of the UniPi 1.1
      But i'm having difficulty changing the input state.
      Could anyone give a hand?

      #!/usr/bin/python3
      import http.client
      conn = http.client.HTTPConnection("192.168.173.209:8080")

      payload = "{"input":"1","circuit":5","bitvalue":"1",:"rising","rising":["string"],"counter":"0","mode":"Simple","modes":["Simple"],"ds_mode":"string (optional)","ds_modes":["string"],"glob_dev_id":"number (required)","alias":"string (optional)"}"

      payload = "{"input":"5"""bitvalue: 1""}"

      headers = { 'content-type': "application/json" }

      conn.request("POST", "/json/input/circuit: 1", payload, headers)

      res = conn.getresponse()
      data = res.read()

      print(data.decode("utf-8"))

      this is my code.

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

        this is the error message I'm getting.
        has anyone seen this?

        {"status": "fail", "data": "Input is malformed; could not decode JSON object."}

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

          Hi @Eanna!

          The error indicates that your message is not valid JSON. But first - inputs do not have an "input" state which could be changed; they are purely used for reading signals. Only outputs have an output state which can be set.

          Second of all: you should either delete or comment out (with ##) your fourth line, though this will not by itself fix your problems

          Third of all: you should be able to set the output with the following:

          import http.client
          
          conn = http.client.HTTPConnection("192.168.173.209:8080")
          
          payload = "{\"value\":1}"
          
          headers = { 'content-type': "application/json" }
          
          conn.request("POST", "/json/relay/1", payload, headers)
          
          res = conn.getresponse()
          data = res.read()
          
          print(data.decode("utf-8"))
          
          E 1 Reply Last reply
          Reply Quote 0
          • E
            Eanna @TomasKnot
            last edited by

            @TomasKnot
            Will this code change an input to an output?
            How would I do this?

            Thanks

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

              @Eanna
              Changing an input into an output is not possible

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

                @TomasKnot
                Can I send a pulse or anything out?
                Or is this only through analogue pins?

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

                  @Eanna
                  You can use the relays to send a pulse out, or the analog output

                  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