Okay so here are the steps for it.
- Download the py script with this command " sudo wget https://gist.githubusercontent.com/arevindh/b24bf626c0d55cd5afd0aa5fecd1e875/raw/1f4fbcb40a2f30bf976edaccd12b107d1db460c4/toggle.py" also install the dependency with command “pip install tinxy”
- Modify the script as below.
pip install tinxy
Python 3
import time
import base64
import requests
from tinxy import tinxy
import time
def encrypts(arg1, mqttpass):
en_arg1 = tinxy.strToLongs(arg1.encode(‘utf-8’).decode())
en_mqttpass = tinxy.strToLongs(mqttpass.encode(‘utf-8’).decode())
ed = tinxy.encodes(en_arg1, en_mqttpass)
ciphertext = tinxy.longsToStr(ed)
cipherutf2 = ciphertext.encode(‘latin-1’)
cipherbase64 = base64.b64encode(cipherutf2)
return base64.b64decode(cipherbase64).hex()
tm = str(int(time.time()))
data = encrypts(tm, “your mqtt pass here”)
print(data)
- import the following json in node red flow.
[{“id”:“c0b0665caa6cfd7f”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 0 in relay 2”,“props”:[{“p”:“relaynumber”,“v”:“2”,“vt”:“num”},{“p”:“action”,“v”:“0”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:400,“y”:60,“wires”:[[“7a9bcbdef2764716”]]},{“id”:“7a9bcbdef2764716”,“type”:“exec”,“z”:“600597defeb9b915”,“command”:“python3 toggle.py”,“addpay”:"",“append”:"",“useSpawn”:“false”,“timer”:"",“winHide”:false,“oldrc”:false,“name”:"",“x”:590,“y”:60,“wires”:[[“57068fc962c583c4”,“333f898707d87936”],[“f594cdedcf472beb”],[“b99b6fe5df99dd2d”]]},{“id”:“f594cdedcf472beb”,“type”:“debug”,“z”:“600597defeb9b915”,“name”:"",“active”:false,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:770,“y”:160,“wires”:[]},{“id”:“b99b6fe5df99dd2d”,“type”:“debug”,“z”:“600597defeb9b915”,“name”:"",“active”:false,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:770,“y”:200,“wires”:[]},{“id”:“57068fc962c583c4”,“type”:“debug”,“z”:“600597defeb9b915”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:790,“y”:120,“wires”:[]},{“id”:“73f172d3ec41f7af”,“type”:“http request”,“z”:“600597defeb9b915”,“name”:"",“method”:“POST”,“ret”:“txt”,“paytoqs”:“ignore”,“url”:"",“tls”:"",“persist”:false,“proxy”:"",“authType”:"",“senderr”:false,“credentials”:{},“x”:650,“y”:360,“wires”:[[“700c8acff3d68bcc”]]},{“id”:“333f898707d87936”,“type”:“function”,“z”:“600597defeb9b915”,“name”:"",“func”:“var passkey = msg.payload.replace(”\n","");\nvar json={\n “password”: passkey,\n “action”: msg.action,\n “relayNumber”: msg.relaynumber\n};\nvar out = {\n “url”:“http://YOURTINXYIPHERE/toggle”,\n “payload”:JSON.stringify(json)\n}\nreturn out;",“outputs”:1,“noerr”:0,“initialize”:"",“finalize”:"",“libs”:[],“x”:520,“y”:320,“wires”:[[“73f172d3ec41f7af”,“700c8acff3d68bcc”]]},{“id”:“700c8acff3d68bcc”,“type”:“debug”,“z”:“600597defeb9b915”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“true”,“targetType”:“full”,“statusVal”:"",“statusType”:“auto”,“x”:730,“y”:420,“wires”:[]},{“id”:“9e32e0ac1aefd5ee”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 1 in relay 2”,“props”:[{“p”:“relaynumber”,“v”:“2”,“vt”:“num”},{“p”:“action”,“v”:“1”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:400,“y”:100,“wires”:[[“7a9bcbdef2764716”]]},{“id”:“435dfe37a4cebd2c”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 0 in relay 1”,“props”:[{“p”:“relaynumber”,“v”:“1”,“vt”:“num”},{“p”:“action”,“v”:“0”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:180,“y”:60,“wires”:[[“7a9bcbdef2764716”]]},{“id”:“5b3741883c366066”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 1 in relay 1”,“props”:[{“p”:“relaynumber”,“v”:“1”,“vt”:“num”},{“p”:“action”,“v”:“1”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:180,“y”:100,“wires”:[[“7a9bcbdef2764716”]]},{“id”:“61cd223d0295953c”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 0 in relay 4”,“props”:[{“p”:“relaynumber”,“v”:“4”,“vt”:“num”},{“p”:“action”,“v”:“0”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:400,“y”:160,“wires”:[[“7a9bcbdef2764716”]]},{“id”:“87a9d90bb47eecff”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 1 in relay 4”,“props”:[{“p”:“relaynumber”,“v”:“4”,“vt”:“num”},{“p”:“action”,“v”:“1”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:400,“y”:200,“wires”:[[“7a9bcbdef2764716”]]},{“id”:“c448257230a537c9”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 0 in relay 3”,“props”:[{“p”:“relaynumber”,“v”:“3”,“vt”:“num”},{“p”:“action”,“v”:“0”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:180,“y”:160,“wires”:[[“7a9bcbdef2764716”]]},{“id”:“a0e1782428caf93e”,“type”:“inject”,“z”:“600597defeb9b915”,“name”:“inject 1 in relay 3”,“props”:[{“p”:“relaynumber”,“v”:“3”,“vt”:“num”},{“p”:“action”,“v”:“1”,“vt”:“str”}],“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“topic”:"",“x”:180,“y”:200,“wires”:[[“7a9bcbdef2764716”]]}] - After importing the flow assign a local IP to your tinxy device with mac reservation in your router.
- set the same IP in the function of node red.
Deploy and it will start working.
This is just the start, I am trying to get the dynamic IP so that the function wont need any kind of static IP.
Also make sure to change the py command location as per your saved location.