Difference between revisions of "FREE - Framework for Remote Experiments in Education"

From wwwelab
Jump to navigation Jump to search
Line 75: Line 75:
  
 
To start the connection between the RPi_Server and the Main_Server, when the RPi_Server is turned on, it tries to connect to the Exp_Server server. If not successful, it should wait 10 seconds and try again until it manages to make the connection.  
 
To start the connection between the RPi_Server and the Main_Server, when the RPi_Server is turned on, it tries to connect to the Exp_Server server. If not successful, it should wait 10 seconds and try again until it manages to make the connection.  
 
(TODO: figure)
 
  
 
<div style="display: flex;align-items: center;justify-content: center;"><ul>
 
<div style="display: flex;align-items: center;justify-content: center;"><ul>
Line 84: Line 82:
 
</div>
 
</div>
  
 +
When the connection is successfully established, the server RPi_Server sends to Main_Servero its ID and Secret. These two variables are then checked on the Main_Server server side as a simple way to authenticate that the connection is coming from an authorized machine. In case of successful verification, the Main_Server responds to the RPi_Server with a message encoded in JSON format that describes the experience to be served by the RPi_Server. This configuration message allows the same RPi_Server program to be adaptable to different experiences with, for example, different numbers of actuators and sensors without changes to the source code. Based on the information contained in this message, the name of the config_file, the RPi_Server looks for the experiment at the indicated address and tries to establish communication with the controller of the experimental apparatus. In order to decouple the RPi_Server from the different communication protocols that each experimental controller may implement, the RPi_Server must communicate with the devices calling a set of standard methods whose implementation must be adapted to suit the target controller.
  
  
When the connection is successfully established, the server RPi_Server sends to Main_Servero its ID and Secret. These two variables are then checked on the Main_Server server side as a simple way to authenticate that the connection is coming from an authorized machine. In case of successful verification, the Main_Server responds to the RPi_Server with a message encoded in JSON format that describes the experience to be served by the RPi_Server. This configuration message allows the same RPi_Server program to be adaptable to different experiences with, for example, different numbers of actuators and sensors without changes to the source code. Based on the information contained in this message, the name of the config_file, the RPi_Server looks for the experiment at the indicated address and tries to establish communication with the controller of the experimental apparatus. In order to decouple the RPi_Server from the different communication protocols that each experimental controller may implement, the RPi_Server must communicate with the devices calling a set of standard methods whose implementation must be adapted to suit the target controller.
 
 
(TODO)
 
(TODO)
 +
 +
 +
After this initial configuration, the connection of the RPi_Serverao Exp_Serverand the RPi_Serverto the controller of the experiment, the system is ready for the exchange of messages between the components. The messages exchanged between components were defined following an everything is a string philosophy. Thus, the messages exchanged are JSON-formatted strings in which the JSON fields encode the message to be transmitted. The type of each message is identified by the msg_id field of the message JSON, and for the message sent, the reply, if any, must have reply_id with the same value. In order to be adaptable to various types of experimental apparatus, the system does not store apparatus status information so it is possible to send any of the defined messages at any time. The correct sequencing of messages for the successful operation of the apparatus is the responsibility of other user-controlled software layers.

Revision as of 05:16, 21 August 2021

Pre-requisites

Build environment

  • Git (2.30.2+)
  • Python (3.7.0+)

Install

Raspberry PI Server (RPI_Server)

Setup python3 environment variable pointing to run the version installed (in this exemple is for python3.7) by:

   $ sudo nano ~/.bashrc

edit it adding to the end:

   $ alias python3="python3.7"

First checkout the project from github:

   $ git clone https://github.com/e-lab-tecnico-ulisboa-pt/RPi_Server-PG

then edit the "main.py" file and change the following global variables:

   SERVER = "main_server_IP"
   MY_IP = "RPi_IP"
   SEGREDO = "password"
   PORT = Port_to_comunication
   BINARY_DATA_PORT = Port_to_transfer_Binary_data

After this changes the RPi_Server is ready to run by typing:

   $ pyhton3 main.py

This will try to connect to the IP defined as SERVER every 10 sec.

Main Server (Main_Server)

This software is the dispatcher of the information. By allowing the communications form the frontend and each RPi_Server responsable for a experience. To install this you need to install at least Python 3.7 and the lib Flask (https://pypi.org/project/Flask/).

Then go to the project from github:

   $ git clone https://github.com/e-lab-tecnico-ulisboa-pt/Main_Server-RexC

Edit the "main.py" file and change the following global variables:

   SERVER = "main_server_IP"
   MY_IP = "RPi_IP"
   SEGREDO = "password"
   PORT = Port_to_comunication
   BINARY_DATA_PORT = Port_to_transfer_Binary_data

After that you need to change or edit this last one variable "segredos",

ADD the new experiment.jpg

the struct of it's the following: {"RPi_IP":{"segredo":"password","nome":"Name_of_the_exp"},...}

Config File (JSON)

In the project of the Main_Server there is a folder called Configs, in there are all the configuration files of the experience linked to the Main_Server. To add a new experiment you just have to copy one of the existing files and change its name to the experiment's and change the parameters in the config file:

Config JSON.jpg

After this changes done you can run the Main_Server, typing the cmd:

   $ start.bat

System architecture

Architecture of the new system. It is possible to observe the different layers of software that separate the users, on the left side of the image, from the experimental apparatus, on the right side of the image.


Communication protocol

(TODO)

To start the connection between the RPi_Server and the Main_Server, when the RPi_Server is turned on, it tries to connect to the Exp_Server server. If not successful, it should wait 10 seconds and try again until it manages to make the connection.

  • Label
  • Label

When the connection is successfully established, the server RPi_Server sends to Main_Servero its ID and Secret. These two variables are then checked on the Main_Server server side as a simple way to authenticate that the connection is coming from an authorized machine. In case of successful verification, the Main_Server responds to the RPi_Server with a message encoded in JSON format that describes the experience to be served by the RPi_Server. This configuration message allows the same RPi_Server program to be adaptable to different experiences with, for example, different numbers of actuators and sensors without changes to the source code. Based on the information contained in this message, the name of the config_file, the RPi_Server looks for the experiment at the indicated address and tries to establish communication with the controller of the experimental apparatus. In order to decouple the RPi_Server from the different communication protocols that each experimental controller may implement, the RPi_Server must communicate with the devices calling a set of standard methods whose implementation must be adapted to suit the target controller.


(TODO)


After this initial configuration, the connection of the RPi_Serverao Exp_Serverand the RPi_Serverto the controller of the experiment, the system is ready for the exchange of messages between the components. The messages exchanged between components were defined following an everything is a string philosophy. Thus, the messages exchanged are JSON-formatted strings in which the JSON fields encode the message to be transmitted. The type of each message is identified by the msg_id field of the message JSON, and for the message sent, the reply, if any, must have reply_id with the same value. In order to be adaptable to various types of experimental apparatus, the system does not store apparatus status information so it is possible to send any of the defined messages at any time. The correct sequencing of messages for the successful operation of the apparatus is the responsibility of other user-controlled software layers.