Welcome to our new forum
All users of the legacy CODESYS Forums, please create a new account at account.codesys.com. But make sure to use the same E-Mail address as in the old Forum. Then your posts will be matched. Close

Raspberry PI Execution of the Python Script

tomas111
2021-09-30
2021-10-27
  • tomas111 - 2021-09-30

    Hi. Not as I can not figure out with I2C.
    Found another way to obtain data via I2C.
    Performed everything according to the instructions:
    https://github.com/hendrychjan/valt-rpi.
    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?
    Thanks.

     
  • mondinmr

    mondinmr - 2021-10-14

    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))
    
     

    Last edit: mondinmr 2021-10-14
  • tomas111 - 2021-10-15

    Thanks, I'll try!
    But when you start the script somehow you need to call automatically how to do it?

     
  • mondinmr

    mondinmr - 2021-10-15

    You could schedule the script. Take a look to /etc/crontab.

     
  • tomas111 - 2021-10-27

    I do not quite understand, the temperature is visible in the browser or not?
    I launched everything as I wrote, but I did not see the result. What am I doing wrong?

     

Log in to post a comment.