Hi. Not as I can not figure out with I2C.
Found another way to obtain data via I2C.
Performed everything according to the instructions:
Now I see in the console:
PI @ Raspberrypi: ~ $ Python3 Sensor.py
Temperature: 27.42578125 ° C
How can I see this line from the console in Codesys?
You could use a udp datagram.
$ Python3 Sensor.py >/dev/udp/127.0.0.1/9187
Read datagrams on port 9187 localhost from CODESYS.
Datagram should contain "Temperature: 27.42578125 °C"
It require permission to write datagram.
Another solution could be modify Sensor.py to send directly a datagram.
If "27.42578125" is on a string named valueString you can add this to script:
byte_message = bytes(valueString, "utf-8")
opened_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
opened_socket.sendto(byte_message, ("127.0.0.1", 9187))
Thanks, I'll try!
But when you start the script somehow you need to call automatically how to do it?
You could schedule the script. Take a look to /etc/crontab.
Log in to post a comment.