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