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

    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:
    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?

  • mondinmr

    mondinmr - 2021-10-14

    You could use a udp datagram.
    $ Python3 Sensor.py >/dev/udp/

    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, ("", 9187))

    Last edit: mondinmr 2021-10-14
  • tomas111

    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.


Log in to post a comment.