Hello everyone.
In trying to use an Exec Node to run a program that will connect to a car wich works by the way, but when I create another Exec Node to collect this information of connection, and using this collect information in real time of the car, the first Exec Node doesn’t keep the function about connection alive.
How can I keep this information (connection) alive to use in another Exec Node?
I thought about another possibility, to use this function in a python3 function node to collect information, but I don’t know how is the better way.
I want to keep the connection function alive to use in another Exec Node or Python3 function node because if I put all the code in just one Exec, every time that the Exec Node will collect information about the car, it will reconnect to the car, and I want to connect just once.
Here is my Node RED flow:
[{"id":"c5e74fd0.252b9","type":"inject","z":"9a892fd1.020dc","name":"","topic":"","payload":"","payloadType":"flow","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":170,"y":120,"wires":[["b88c48d0.e9a8d8"]]},{"id":"b88c48d0.e9a8d8","type":"exec","z":"9a892fd1.020dc","command":"sudo python3 /home/workdb/Desktop/conecta.py","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Connection","x":450,"y":120,"wires":[["a45bd8a7.440b28"],["a45bd8a7.440b28"],["a45bd8a7.440b28"]]},{"id":"a45bd8a7.440b28","type":"exec","z":"9a892fd1.020dc","command":"sudo python3 /home/workdb/Desktop/OBD.py","addpay":true,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Information","x":460,"y":260,"wires":[["5961ced3.fb2a8"],["5961ced3.fb2a8"],["5961ced3.fb2a8"]]},{"id":"5961ced3.fb2a8","type":"debug","z":"9a892fd1.020dc","name":"","active":true,"tosidebar":true,"console":true,"tostatus":false,"complete":"true","x":670,"y":260,"wires":[]},{"id":"73ca5b85.4d0b34","type":"inject","z":"9a892fd1.020dc","name":"","topic":"","payload":"","payloadType":"date","repeat":"15","crontab":"","once":true,"onceDelay":0.1,"x":190,"y":260,"wires":[["a45bd8a7.440b28"]]}]
Here is my code to connect to the car:
import obd
try:
ports = obd.scan_serial() # return list of valid USB or RF ports
connection = obd.OBD(str(ports[-1]))
print(ports)
except Exception as e:
connection = obd.OBD(’/dev/rfcomm0’)
print(connection)