1. Home
  2. Docs
  3. Documentation
  4. Quick Start
  5. RasbperryPi application with python scripts

RasbperryPi application with python scripts

Remoteme.org allows you to connect Python scripts and send messages from/to them. This is the place where you can expand the program on RasbperryPI, control the motors, receive information from the sensors and forward it,

Python scripts are managed by the remoteme.org application itself launched on RasbperryPi, and also to that application send messages that are later forwarded.

To add such a script from the RasbperryPI menu, select the “Add External script” option

and fill:

what we get

  • runme.sh – a script that starts the remota application on RasbperryPi at startup
  • python.py main script
  • logs.log – logs the program using a defined logger, e.g.

 

Testing

Let’s create a website on the “simpleArduinoMessage” template just like I described here.

Next, because we want to send a message to the python script of id 201 in index.html

variable arduinoDeviceId so that after changing it it looks like this:

It does not matter if the message is sent to arduino or any other device, so we will use the example to send a message to arduino from the quickstart article.

After opening the index.html page in the new tab, we can send bytes to our Python script:

“82 101 109 111 116 101 77 101” is a code in the ASCII RemoteMe code. Let’s check the code

runme.sh

it runs the main python.py program if you want to change the parameters of your program to run it from a different path, add some pther parameters, this is where you should add your own modifications

runme.sh is run as shown

then it runs the python.py file as follows

you can see that runme.sh  passes the received parameters to the python.py program

  • leafDevices / 201 main path – here the python.py file is located, the python script will work in this directory as its workspace. (“Os.chdir (sys.argv [1])”)
  • 200 is the parent id of the python.py script, in our case it is rasbperryPi
  • 201 is the id assigned to the script
  • 2329 – it is a socket port opened by applications on RPi and is used for communication between the program on RPi and the script – it can be changed in the conf.json file in the Rpi device in the device manager.
How it works

thanks to the Python libraries (located in the leafDevices / base directory), the Python program connects to the program on Rpi using sockets, then the messages are forwarded to app.remoteme.org which manages the messages. Receiving of messages is made in similar way.

Initialize the logger and connect to the application on Rpi using the remoteMe library. Also set which functions are to be called when a message is sent to the script.

this function is responsible for sending a message to the website by adding “Hello” to the beginning

the second function is:

It is responsible for synchronous messages we can try it by sending a synchronous message through the device manager:

by completing and clicking “Send” we will get:

With the knowledge provided in this quick start, you will be able to modify your Python scripts. After each modification of the script, the program on Rpi is reset so that the changes are uploaded, you can change it in the configuration at the address https://app.remoteme.org/en/#/app/configuration