Hello,
I try to connect to a ADAX Neo heater with NodeRed. I have a working code in python:
(snippet)
url = 'https://' + HEATER_IP + '/api'
payload = { 'command': 'set_target', 'time': int(time.time()), 'value': target_temperature }
headers = { 'Authorization': 'Basic ' + HEATER_TOKEN }
return requests.get(url, params = payload, headers = headers, timeout = 15, verify = False)
that I try to recreate with a function and httprequest-node in NodeRed.
This is what i have in the function-node:
var d = Math.floor(new Date().getTime() / 1000);
var token = 12345678;
msg.url = "https://172.16.x.y/api";
msg.rejectUnauthorized = false;
msg.headers = { 'Authorization': 'Basic ' + token };
//msg.headers = {};
//msg.headers['Authorization'] = 'Basic 12345678';
msg.timeout = 15;
msg.payload = {
"command":"set_target",
"time": d,
"value": "1800"
};
return msg;
But I cant get the heater to respond other than 404, and that I read it as authentification error.
How can I duplicate the function from python to nodered?
Any help is appreciated!
Regards
HĆ„kan
PS.
File upload was disabled for me (new users), so I paste in my full nodered code here:
[{"id":"89fb703cf6594aac","type":"http request","z":"e961ad82.557ed","name":"","method":"GET","ret":"obj","paytoqs":"body","url":"https://172.16.6.2/api","tls":"604655aceaad0408","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"basic","senderr":false,"headers":[],"x":510,"y":860,"wires":[["59eaed8789db5ee7"]]},{"id":"59eaed8789db5ee7","type":"debug","z":"e961ad82.557ed","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":740,"y":860,"wires":[]},{"id":"7b7a69fa8e099eed","type":"inject","z":"e961ad82.557ed","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":120,"y":860,"wires":[["0a03c04733728ae0"]]},{"id":"0a03c04733728ae0","type":"function","z":"e961ad82.557ed","name":"function 1","func":"var d = Math.floor(new Date().getTime() / 1000);\nvar token = 12345678;\n\nmsg.url = \"https://172.16.6.2/api\";\nmsg.rejectUnauthorized = false;\n\nmsg.headers = { 'Authorization': 'Basic' + token };\n//msg.headers = {}; \n//msg.headers['Authorization'] = 'Basic 12345678';\n\nmsg.timeout = 15;\n\nmsg.payload = {\n \"command\":\"set_target\",\n \"time\": d,\n \"value\": \"1800\"\n};\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":280,"y":860,"wires":[["89fb703cf6594aac","8b2d9ea2bbaf71ce"]]},{"id":"8b2d9ea2bbaf71ce","type":"debug","z":"e961ad82.557ed","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":520,"y":940,"wires":[]},{"id":"604655aceaad0408","type":"tls-config","name":"","cert":"","key":"","ca":"","certname":"","keyname":"","caname":"","servername":"","verifyservercert":false,"alpnprotocol":""}]
ADMIN EDIT: Wrapped flow JSON in triple backticks