Input change not working
-
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.
-
this is the error message I'm getting.
has anyone seen this?{"status": "fail", "data": "Input is malformed; could not decode JSON object."}
-
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")) -
@TomasKnot
Will this code change an input to an output?
How would I do this?Thanks
-
@Eanna
Changing an input into an output is not possible -
@TomasKnot
Can I send a pulse or anything out?
Or is this only through analogue pins? -
@Eanna
You can use the relays to send a pulse out, or the analog output
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