<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>http://www.elab.tecnico.ulisboa.pt/wwwelab/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ist14028</id>
	<title>wwwelab - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="http://www.elab.tecnico.ulisboa.pt/wwwelab/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Ist14028"/>
	<link rel="alternate" type="text/html" href="http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=Special:Contributions/Ist14028"/>
	<updated>2026-05-09T09:55:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.34.2</generator>
	<entry>
		<id>http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4617</id>
		<title>WPA FREE 0.6.0 Instalation</title>
		<link rel="alternate" type="text/html" href="http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4617"/>
		<updated>2022-10-10T21:52:31Z</updated>

		<summary type="html">&lt;p&gt;Ist14028: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Janus Server=&lt;br /&gt;
&lt;br /&gt;
== Update ==&lt;br /&gt;
If the Janus server is already running with the FREE 0.3.0 version it is only necessary to guarantee that  the admin secret is defined.&lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg ''' file in the '''/var/snap/janus-gateway/common/etc ​''' directory and guarantee that the '''admin_key ''' is defined:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;elab1&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
To install the Janus stream server you will need to run the following commands on your Debian 11 machine:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snap​&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snapd&lt;br /&gt;
&lt;br /&gt;
 sudo snap install janus-gateway​&lt;br /&gt;
&lt;br /&gt;
===Configuration===&lt;br /&gt;
&lt;br /&gt;
The configuration of Janus is done editing a file in the '''/var/snap/janus-gateway/common/etc​''' directory &lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg''' file&lt;br /&gt;
&lt;br /&gt;
Define an administration secret​ by uncommenting the line 104) or the one that contains the '''admin_key''' string= and changing the string to a suitable value.&lt;br /&gt;
&lt;br /&gt;
Define the possible ports that Janus will use to ​receive the video stream from the pendulum by uncomment line 106​) or the one containing the string '''rtp_port_range'''= and define the available ports (for example to 6000-7000​).&lt;br /&gt;
&lt;br /&gt;
Delete the sample pre-configure endpoints by deleting all lines from line 124. &lt;br /&gt;
&lt;br /&gt;
Restart Janus  by running the command:&lt;br /&gt;
 &lt;br /&gt;
 sudo snap restart janus-gateway​&lt;br /&gt;
&lt;br /&gt;
=== Example of Janus Configuration ===&lt;br /&gt;
After the configuration of a newly installed Janus Server the '''janus.plugin.streaming.jcfg''' should only containg the following`&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;super_pass&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== HTTPS cfigurations ==&lt;br /&gt;
TODO!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= FREE Server=&lt;br /&gt;
&lt;br /&gt;
== New instalation == &lt;br /&gt;
&lt;br /&gt;
=== Installation of Source Code ===&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of FREE.&lt;br /&gt;
* For example '''mkdir wpa_free_060 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/FREE_Web_0_6_0.zip&lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip FREE_Web_0_6_0.zip -d wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Create a new python virtual environment, it should be called '''free-env''':&lt;br /&gt;
 virtualenv -p python3 free-env&lt;br /&gt;
&lt;br /&gt;
Activate the virtual environment:&lt;br /&gt;
 source free-env/bin/activate&lt;br /&gt;
&lt;br /&gt;
You should now see a prefix of (free-env) in your command line. &lt;br /&gt;
&lt;br /&gt;
After that, install the dependent packages:&lt;br /&gt;
 pip install -r REQUIREMENTS.txt&lt;br /&gt;
&lt;br /&gt;
=== Installation of New Database ===&lt;br /&gt;
Since the data model was change it is necessary to download and install a new empty database.&lt;br /&gt;
&lt;br /&gt;
This database is configured with two users and the WPA pendulum apparatus types and protocols.&lt;br /&gt;
&lt;br /&gt;
Download the database and put it into the project root:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/db_template_0_5_1.sqlite3 -O db.sqlite3&lt;br /&gt;
&lt;br /&gt;
This database contains a Pendulum experiment, as well as two example user accounts.&lt;br /&gt;
* wp-admin - superuser account with access to admin interface&lt;br /&gt;
* wp-guest - guest account&lt;br /&gt;
Both users have a '''temporary123 ''' password. &lt;br /&gt;
&lt;br /&gt;
This password should be changed through admin interface.&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
The application is configured using environment variables. &lt;br /&gt;
&lt;br /&gt;
You can set them using the '''/freeweb/.env ''' file. &lt;br /&gt;
&lt;br /&gt;
There is a '''.env-template ''' file in the '''~freeweb ''' folder, that can be renamed to '''.env ''' :&lt;br /&gt;
 mv freeweb/.env-template freeweb/.env&lt;br /&gt;
&lt;br /&gt;
It is necessary to define correct values for the following variables. Some of these values can be copied form the previous version .env file.&lt;br /&gt;
* PROJECT_NAME, PROJECT_ACRONYMUM, SITE_NAME - Texts that will appear in the page header&lt;br /&gt;
* TIME_ZONE - Time zone setting for that app in '''TZ database name''' from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List.&lt;br /&gt;
* FREE_PRODUCTION - set to '''on ''' to enable production mode (disables sensitive error messages etc.)&lt;br /&gt;
* FREE_REVERSE_PROXY - set to '''on ''' to be able to run the FREE behind a reverse proxy&lt;br /&gt;
* FREE_SECRET - String used in hashing function. Set either to a random string of your choice, or generate one here: https://djecrety.ir&lt;br /&gt;
* FREE_ALLOWED_HOSTS - comma separated list of domain names/addresses; only requests to these hosts will be processed by the application. This is necessary to prevent HTTP Host header attacks.&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== FREE server execution ===&lt;br /&gt;
to start the FREE server run the following command:&lt;br /&gt;
 daphne freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
By default, the webserver will be available at port 8000. To change the port, pass -p &amp;lt;portnumber&amp;gt; parameter to the daphne command. &lt;br /&gt;
You can also force binding to specific address by -b &amp;lt;address&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Copy of Pendulum Information ===&lt;br /&gt;
Since a new database is now being used, it is necessary to copy the various apparatus into the new database.&lt;br /&gt;
&lt;br /&gt;
If running both version at the same time, one of them, should be executed on a different port&lt;br /&gt;
&lt;br /&gt;
On the administration page of the you should copy some of the information from the old database to the new.&lt;br /&gt;
&lt;br /&gt;
here is the list and description of the various fields:&lt;br /&gt;
* Apparatus Type : Pendulum&lt;br /&gt;
* Location - description of the physical place of the pendulum&lt;br /&gt;
* Description - specific characteristics of the pendulum&lt;br /&gt;
* Secret - a random string specific to each pendulum&lt;br /&gt;
* Owner - Name of the person responsible for the operation and maintenance of the pendulum&lt;br /&gt;
* Timeout - leave 60 &lt;br /&gt;
* Configuration - copy the following json and modify accordingly the '''id ''' and '''ports_restrict ''' to suitable values:&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;WP_LIS_IST&amp;quot;, &lt;br /&gt;
    &amp;quot;serial_port&amp;quot;: {&lt;br /&gt;
       &amp;quot;ports_restrict&amp;quot;: [&amp;quot;/dev/ttyS0&amp;quot;], &lt;br /&gt;
       &amp;quot;baud&amp;quot;: &amp;quot;115200&amp;quot;, &amp;quot;numbits&amp;quot;: &amp;quot;8&amp;quot;, &amp;quot;stopbits&amp;quot;: &amp;quot;1&amp;quot;, &amp;quot;partitybits&amp;quot;: &amp;quot;0&amp;quot;, &lt;br /&gt;
       &amp;quot;listening_timeout&amp;quot;: &amp;quot;100000&amp;quot;, &amp;quot;death_timeout&amp;quot;: &amp;quot;10000000&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
* video configuration - either copy the value from the old database or leave empty&lt;br /&gt;
&lt;br /&gt;
=== Configuration of Video ===&lt;br /&gt;
In order to have video stream from the Raspberry Pi to the server and then to the browser it is necessary to  verify the following data on the '''.env ''' file:&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
After this configuration is correct it is necessary to assign each pendulum one video stream so that video can go from the pendulum to the server and to the browser.&lt;br /&gt;
&lt;br /&gt;
Open the '''Video Config ''' menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Video-config-menu.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page, a table will contain all the configured pendulums and the associated video configuration:&lt;br /&gt;
&lt;br /&gt;
[[File:Video_Config_table.png]]&lt;br /&gt;
&lt;br /&gt;
In the previous example the first apparatus was automatically configure from the previous identifier copied from the old database.&lt;br /&gt;
&lt;br /&gt;
The second apparatus does not have the video stream configure. To create a video stream and update the database click '''Configure Video '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config assign stream.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page it is necessary to click on the '''Assign Stream ''' button.&lt;br /&gt;
&lt;br /&gt;
If the Janus server is well configure the new page will show the Video Stream Configuration and the data to be copied to the Raspberry Pi:&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config RP data.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Upgrade of previous instalation == &lt;br /&gt;
&lt;br /&gt;
{{Background color|red|FAZER backup as BD e codigo!}}&lt;br /&gt;
&lt;br /&gt;
Follow the first two steps of the installation guide. The commands already contain overwrite switches so that the old version will be overwritten, while '''.env ''' and '''.sqlite''' files won't be touched.&lt;br /&gt;
&lt;br /&gt;
A new release might contain changes to the database structure. If you are preserving your database from a previous version, run&lt;br /&gt;
&lt;br /&gt;
 python manage.py migrate&lt;br /&gt;
&lt;br /&gt;
== HTTPS configuration ==&lt;br /&gt;
IN order to allow remote OAuth authentication (Google or Microsoft) it is necessary to activate HTTPS.&lt;br /&gt;
this requires the installation of SSL certificates and the execution of daphne in a with a different configuration:&lt;br /&gt;
&lt;br /&gt;
=== Cerificates ===&lt;br /&gt;
FREE should execute with certificates produced by the organization, can use self-signed cerificates temporarly.&lt;br /&gt;
Certificates cshould be generated by the network administrator and installed with the suitable names (free_private.key and free_public.crt) in the '''freeweb/certificates/''' directory&lt;br /&gt;
For testing purposed it is also possible to create a self signed certificate by running the following command on the FREE server:&lt;br /&gt;
&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout freeweb/certificates/free_private.key -out freeweb/certificates/free_public.crt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Server execution ===&lt;br /&gt;
After the creation or installation of the certificate the server should be executed as follows&lt;br /&gt;
&lt;br /&gt;
 daphne -e ssl:8000:privateKey=freeweb/certificates/free_private.key:certKey=freeweb/certificates/free_public.crt freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
If running with this configuration, users should use the following url to access FREE:&lt;br /&gt;
&lt;br /&gt;
 https://hostname.some_domain:8000/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Apparatus proxy configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also configure all apparatus proxies to use HTTPS.&lt;br /&gt;
the version of the proxy should the the most recent change the '''server_info.ini''' file:&lt;br /&gt;
 HTTPS = True&lt;br /&gt;
&lt;br /&gt;
=== janus configuration ===&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also further configure janus to also use HTTPS.&lt;br /&gt;
It is necessary to create the certificate similar rto the one used in daphne. Unfortunetly the certificate can not be created in the host (self-signed certificate), '''it must be created by the network administrator of the domain'''.&lt;br /&gt;
&lt;br /&gt;
This certificate should be placed in a system directory before editing the '''janus.transport.http.jcfg''' configuration file:&lt;br /&gt;
*Disable HTTP: http = false&lt;br /&gt;
*Enable HTTPS: https = true&lt;br /&gt;
*define the HTTPS port: secure_port = 8088 - Set the certificate directory:&lt;br /&gt;
**cert_pem = &amp;quot;/some_system_directory/janus_public.crt&amp;quot;&lt;br /&gt;
**cert_key = &amp;quot;/some_system_directory/janus_private.key&amp;quot; In the .env file it is also necessary to update the protocolo of janu from http to https:&lt;br /&gt;
*JANUS_SERVER_ADDRESS=&amp;quot;https://janus-server-address:8088/janus&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== External Authentication ==&lt;br /&gt;
FREE now allows the use of external services from Google and Microsoft for user authentication.&lt;br /&gt;
To configure these services it is necessary to have HTTPS working and have a fixed public numeric address (or DNS name) for the FREE installation (for instance https://free.some-university.edu:8000/) and follow the next instructions.&lt;br /&gt;
=== GOOGLE ===&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/google.html#google-oauth2 / https://developers.google.com/identity/protocols/oauth2?csw=1#Registering:&lt;br /&gt;
&lt;br /&gt;
*access the Google API Console: https://console.developers.google.com/&lt;br /&gt;
*Create a new project&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create Credentials -&amp;gt; OAuth client ID&lt;br /&gt;
*Configure Consent Screen&lt;br /&gt;
**Select External User Type&lt;br /&gt;
**Fill The App information screen (app name, User support email, Developer contact information)&lt;br /&gt;
**Select scopes (may be empty)&lt;br /&gt;
**Add a test user&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create credentials -&amp;gt; OAuth client ID&lt;br /&gt;
**Application Type - Web application&lt;br /&gt;
**Define name &lt;br /&gt;
**Add Authorized redirect URIs&lt;br /&gt;
***append '''/complete/google-oauth2/''' to the installation URL (example: `https://free.some-university.edu:8000/complete/google-oauth2/`)&lt;br /&gt;
**Create&lt;br /&gt;
*Download json or save the Client ID and Client Secret&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_GOOGLE_OAUTH''':&lt;br /&gt;
***FREE_GOOGLE_OAUTH=true&lt;br /&gt;
**copy the value of '''Your Client ID''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'''&lt;br /&gt;
**copy '''Client Secret''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
=== Microsoft ===&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/microsoftgraph.html.html#google-oauth2 / https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app:&lt;br /&gt;
&lt;br /&gt;
*Sign in to the Azure portal: https://portal.azure.com/&lt;br /&gt;
*Manage Azure Active Directory - View&lt;br /&gt;
*Select  App registrations on the menu&lt;br /&gt;
*New registration&lt;br /&gt;
**Define the name of teh application&lt;br /&gt;
**Select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)&lt;br /&gt;
**Define the redirect URI&lt;br /&gt;
***Select a platform - Web&lt;br /&gt;
***to create the URI, append '''/complete/microsoft-graph/''' to the installation URL (exampe: `https://free.some-university.edu:8000/complete/microsoft-graph/`)&lt;br /&gt;
**Register&lt;br /&gt;
**Save the '''Application (client) ID'''&lt;br /&gt;
***this value should be put in the .env file&lt;br /&gt;
**Select Certificates and secrets on the menu&lt;br /&gt;
***New client secret&lt;br /&gt;
***Add&lt;br /&gt;
**Save the '''Value'''&lt;br /&gt;
***this value should be put in the .env file &amp;lt;span style=&amp;quot;color:#FFFFFF; background:#F50000&amp;quot;&amp;gt;'''The secret Value dissapears after closing this page '''&amp;lt;/span&amp;gt;&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_MS_OAUTH''':&lt;br /&gt;
***FREE_MS_OAUTH=true&lt;br /&gt;
**copy  the value of '''Application (client) ID''' to '''SSOCIAL_AUTH_MICROSOFT_GRAPH_KEY'''&lt;br /&gt;
**copy the value of '''Secret ID''' to '''SOCIAL_AUTH_MICROSOFT_GRAPH_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Raspberry Pi Proxy =&lt;br /&gt;
&lt;br /&gt;
Due to changes on the API and the database you will need to make a upgrade to this version of the Proxy.&lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of Proxy (compatible to the Version of the FREE server).&lt;br /&gt;
* For example '''mkdir Proxy_051 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/RPi_Proxy/releases/latest/download/RPi_Proxy_0_5_1.zip &lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip RPi_Proxy_0_5_1.zip -d Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
After that, install the dependent package:&lt;br /&gt;
&lt;br /&gt;
For the Proxy:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3-pip&lt;br /&gt;
&lt;br /&gt;
 pip3 install pyserial&lt;br /&gt;
&lt;br /&gt;
And for streaming the video (for '''gstreamer '''):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-tools&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-good&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-bad&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-ugly&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-base&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For '''ffmpeg ''':&lt;br /&gt;
 sudo apt-get install ffmpeg&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Video Streaming Configuration ===&lt;br /&gt;
&lt;br /&gt;
In order to configure the video streaming process on the Raspberry pi edit the '''video-stream.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
* video_server video_port apparatus_location apparatus_name apparatus_id&lt;br /&gt;
** copy this information from the Video Conf administration page on the FREE server&lt;br /&gt;
&lt;br /&gt;
* usb_camera video_width video_height video_frame&lt;br /&gt;
** find the suitable values depending on the network resources and the information provided by the following commands:&lt;br /&gt;
 v4l2-ctl --list-devices&lt;br /&gt;
 v4l2-ctl -d /dev/videoXXXXX --list-formats-ext&lt;br /&gt;
&lt;br /&gt;
In order to debug and verify the video configuration it is possible to execute the '''video-stream.sh ''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Configuration ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to configure the Proxy on Raspberry pi edit the '''server_info.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
 &lt;br /&gt;
*SERVER : The IP address or domain of your FREE_Web server;&lt;br /&gt;
*PORT : The port of the server by default is the 8000;&lt;br /&gt;
*DEBUG: This can be change to off, after this installation is correctly done;&lt;br /&gt;
*APPARATUS_ID, SECRET: This parameters can be seen on the admin of the FREE_Web server;&lt;br /&gt;
On the apparatus configure page, you will be able to see the APPARATUS_ID on the URL of the page (indicated with the arrow) and the SECRET on the page it self:&lt;br /&gt;
&lt;br /&gt;
[[File:Info for Proxy.png|1220px]]&lt;br /&gt;
&lt;br /&gt;
== Proxy execution ==&lt;br /&gt;
&lt;br /&gt;
In order to debug the various video and apparatus control configuration, the two scripts (video-stream.sh and main.py) can be executed independently on the command line.&lt;br /&gt;
&lt;br /&gt;
After all the parameters are correct, both programs can be executed simultaneously  using the following command:&lt;br /&gt;
&lt;br /&gt;
 nohup sh start-wp.sh &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This command runs until the raspberry pi is rebooted.&lt;br /&gt;
&lt;br /&gt;
To make the Proxy run when the Raspberry pi reboots it is necessary to edit the '''/etc/rc.local ''' and add the following lines before the '''exit 0 ''':&lt;br /&gt;
 sleep 60&lt;br /&gt;
 cd /INSTALLATION_FOLDER/PATH&lt;br /&gt;
 su USER -c &amp;quot;sh start-wp.sh &amp;amp;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace /INSTALLATION_FOLDER/PATH with the output of the following command:&lt;br /&gt;
 readlink -f Proxy_051/&lt;br /&gt;
&lt;br /&gt;
Replace USER the the actual user owner of the proxy.&lt;/div&gt;</summary>
		<author><name>Ist14028</name></author>
		
	</entry>
	<entry>
		<id>http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4616</id>
		<title>WPA FREE 0.6.0 Instalation</title>
		<link rel="alternate" type="text/html" href="http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4616"/>
		<updated>2022-10-10T21:45:15Z</updated>

		<summary type="html">&lt;p&gt;Ist14028: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Janus Server=&lt;br /&gt;
&lt;br /&gt;
== Update ==&lt;br /&gt;
If the Janus server is already running with the FREE 0.3.0 version it is only necessary to guarantee that  the admin secret is defined.&lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg ''' file in the '''/var/snap/janus-gateway/common/etc ​''' directory and guarantee that the '''admin_key ''' is defined:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;elab1&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
To install the Janus stream server you will need to run the following commands on your Debian 11 machine:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snap​&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snapd&lt;br /&gt;
&lt;br /&gt;
 sudo snap install janus-gateway​&lt;br /&gt;
&lt;br /&gt;
===Configuration===&lt;br /&gt;
&lt;br /&gt;
The configuration of Janus is done editing a file in the '''/var/snap/janus-gateway/common/etc​''' directory &lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg''' file&lt;br /&gt;
&lt;br /&gt;
Define an administration secret​ by uncommenting the line 104) or the one that contains the '''admin_key''' string= and changing the string to a suitable value.&lt;br /&gt;
&lt;br /&gt;
Define the possible ports that Janus will use to ​receive the video stream from the pendulum by uncomment line 106​) or the one containing the string '''rtp_port_range'''= and define the available ports (for example to 6000-7000​).&lt;br /&gt;
&lt;br /&gt;
Delete the sample pre-configure endpoints by deleting all lines from line 124. &lt;br /&gt;
&lt;br /&gt;
Restart Janus  by running the command:&lt;br /&gt;
 &lt;br /&gt;
 sudo snap restart janus-gateway​&lt;br /&gt;
&lt;br /&gt;
=== Example of Janus Configuration ===&lt;br /&gt;
After the configuration of a newly installed Janus Server the '''janus.plugin.streaming.jcfg''' should only containg the following`&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;super_pass&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== HTTPS cfigurations ==&lt;br /&gt;
TODO!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= FREE Server=&lt;br /&gt;
&lt;br /&gt;
== New instalation == &lt;br /&gt;
&lt;br /&gt;
=== Installation of Source Code ===&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of FREE.&lt;br /&gt;
* For example '''mkdir wpa_free_060 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/FREE_Web_0_6_0.zip&lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip FREE_Web_0_6_0.zip -d wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Create a new python virtual environment, it should be called '''free-env''':&lt;br /&gt;
 virtualenv -p python3 free-env&lt;br /&gt;
&lt;br /&gt;
Activate the virtual environment:&lt;br /&gt;
 source free-env/bin/activate&lt;br /&gt;
&lt;br /&gt;
You should now see a prefix of (free-env) in your command line. &lt;br /&gt;
&lt;br /&gt;
After that, install the dependent packages:&lt;br /&gt;
 pip install -r REQUIREMENTS.txt&lt;br /&gt;
&lt;br /&gt;
=== Installation of New Database ===&lt;br /&gt;
Since the data model was change it is necessary to download and install a new empty database.&lt;br /&gt;
&lt;br /&gt;
This database is configured with two users and the WPA pendulum apparatus types and protocols.&lt;br /&gt;
&lt;br /&gt;
Download the database and put it into the project root:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/db_template_0_5_1.sqlite3 -O db.sqlite3&lt;br /&gt;
&lt;br /&gt;
This database contains a Pendulum experiment, as well as two example user accounts.&lt;br /&gt;
* wp-admin - superuser account with access to admin interface&lt;br /&gt;
* wp-guest - guest account&lt;br /&gt;
Both users have a '''temporary123 ''' password. &lt;br /&gt;
&lt;br /&gt;
This password should be changed through admin interface.&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
The application is configured using environment variables. &lt;br /&gt;
&lt;br /&gt;
You can set them using the '''/freeweb/.env ''' file. &lt;br /&gt;
&lt;br /&gt;
There is a '''.env-template ''' file in the '''~freeweb ''' folder, that can be renamed to '''.env ''' :&lt;br /&gt;
 mv freeweb/.env-template freeweb/.env&lt;br /&gt;
&lt;br /&gt;
It is necessary to define correct values for the following variables. Some of these values can be copied form the previous version .env file.&lt;br /&gt;
* PROJECT_NAME, PROJECT_ACRONYMUM, SITE_NAME - Texts that will appear in the page header&lt;br /&gt;
* TIME_ZONE - Time zone setting for that app in '''TZ database name''' from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List.&lt;br /&gt;
* FREE_PRODUCTION - set to '''on ''' to enable production mode (disables sensitive error messages etc.)&lt;br /&gt;
* FREE_REVERSE_PROXY - set to '''on ''' to be able to run the FREE behind a reverse proxy&lt;br /&gt;
* FREE_SECRET - String used in hashing function. Set either to a random string of your choice, or generate one here: https://djecrety.ir&lt;br /&gt;
* FREE_ALLOWED_HOSTS - comma separated list of domain names/addresses; only requests to these hosts will be processed by the application. This is necessary to prevent HTTP Host header attacks.&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== FREE server execution ===&lt;br /&gt;
to start the FREE server run the following command:&lt;br /&gt;
 daphne freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
By default, the webserver will be available at port 8000. To change the port, pass -p &amp;lt;portnumber&amp;gt; parameter to the daphne command. &lt;br /&gt;
You can also force binding to specific address by -b &amp;lt;address&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Copy of Pendulum Information ===&lt;br /&gt;
Since a new database is now being used, it is necessary to copy the various apparatus into the new database.&lt;br /&gt;
&lt;br /&gt;
If running both version at the same time, one of them, should be executed on a different port&lt;br /&gt;
&lt;br /&gt;
On the administration page of the you should copy some of the information from the old database to the new.&lt;br /&gt;
&lt;br /&gt;
here is the list and description of the various fields:&lt;br /&gt;
* Apparatus Type : Pendulum&lt;br /&gt;
* Location - description of the physical place of the pendulum&lt;br /&gt;
* Description - specific characteristics of the pendulum&lt;br /&gt;
* Secret - a random string specific to each pendulum&lt;br /&gt;
* Owner - Name of the person responsible for the operation and maintenance of the pendulum&lt;br /&gt;
* Timeout - leave 60 &lt;br /&gt;
* Configuration - copy the following json and modify accordingly the '''id ''' and '''ports_restrict ''' to suitable values:&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;WP_LIS_IST&amp;quot;, &lt;br /&gt;
    &amp;quot;serial_port&amp;quot;: {&lt;br /&gt;
       &amp;quot;ports_restrict&amp;quot;: [&amp;quot;/dev/ttyS0&amp;quot;], &lt;br /&gt;
       &amp;quot;baud&amp;quot;: &amp;quot;115200&amp;quot;, &amp;quot;numbits&amp;quot;: &amp;quot;8&amp;quot;, &amp;quot;stopbits&amp;quot;: &amp;quot;1&amp;quot;, &amp;quot;partitybits&amp;quot;: &amp;quot;0&amp;quot;, &lt;br /&gt;
       &amp;quot;listening_timeout&amp;quot;: &amp;quot;100000&amp;quot;, &amp;quot;death_timeout&amp;quot;: &amp;quot;10000000&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
* video configuration - either copy the value from the old database or leave empty&lt;br /&gt;
&lt;br /&gt;
=== Configuration of Video ===&lt;br /&gt;
In order to have video stream from the Raspberry Pi to the server and then to the browser it is necessary to  verify the following data on the '''.env ''' file:&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
After this configuration is correct it is necessary to assign each pendulum one video stream so that video can go from the pendulum to the server and to the browser.&lt;br /&gt;
&lt;br /&gt;
Open the '''Video Config ''' menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Video-config-menu.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page, a table will contain all the configured pendulums and the associated video configuration:&lt;br /&gt;
&lt;br /&gt;
[[File:Video_Config_table.png]]&lt;br /&gt;
&lt;br /&gt;
In the previous example the first apparatus was automatically configure from the previous identifier copied from the old database.&lt;br /&gt;
&lt;br /&gt;
The second apparatus does not have the video stream configure. To create a video stream and update the database click '''Configure Video '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config assign stream.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page it is necessary to click on the '''Assign Stream ''' button.&lt;br /&gt;
&lt;br /&gt;
If the Janus server is well configure the new page will show the Video Stream Configuration and the data to be copied to the Raspberry Pi:&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config RP data.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Upgrade of previous instalation == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Follow the first two steps of the installation guide. The commands already contain overwrite switches so that the old version will be overwritten, while '''.env ''' and '''.sqlite''' files won't be touched.&lt;br /&gt;
&lt;br /&gt;
A new release might contain changes to the database structure. If you are preserving your database from a previous version, run&lt;br /&gt;
&lt;br /&gt;
 python manage.py migrate&lt;br /&gt;
&lt;br /&gt;
== HTTPS configuration ==&lt;br /&gt;
IN order to allow remote OAuth authentication (Google or Microsoft) it is necessary to activate HTTPS.&lt;br /&gt;
this requires the installation of SSL certificates and the execution of daphne in a with a different configuration:&lt;br /&gt;
&lt;br /&gt;
=== Cerificates ===&lt;br /&gt;
FREE should execute with certificates produced by the organization, can use self-signed cerificates temporarly.&lt;br /&gt;
Certificates cshould be generated by the network administrator and installed with the suitable names (free_private.key and free_public.crt) in the '''freeweb/certificates/''' directory&lt;br /&gt;
For testing purposed it is also possible to create a self signed certificate by running the following command on the FREE server:&lt;br /&gt;
&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout freeweb/certificates/free_private.key -out freeweb/certificates/free_public.crt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Server execution ===&lt;br /&gt;
After the creation or installation of the certificate the server should be executed as follows&lt;br /&gt;
&lt;br /&gt;
 daphne -e ssl:8000:privateKey=freeweb/certificates/free_private.key:certKey=freeweb/certificates/free_public.crt freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
If running with this configuration, users should use the following url to access FREE:&lt;br /&gt;
&lt;br /&gt;
 https://hostname.some_domain:8000/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Apparatus proxy configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also configure all apparatus proxies to use HTTPS.&lt;br /&gt;
the version of the proxy should the the most recent change the '''server_info.ini''' file:&lt;br /&gt;
 HTTPS = True&lt;br /&gt;
&lt;br /&gt;
=== janus configuration ===&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also further configure janus to also use HTTPS.&lt;br /&gt;
It is necessary to create the certificate similar rto the one used in daphne. Unfortunetly the certificate can not be created in the host (self-signed certificate), '''it must be created by the network administrator of the domain'''.&lt;br /&gt;
&lt;br /&gt;
This certificate should be placed in a system directory before editing the '''janus.transport.http.jcfg''' configuration file:&lt;br /&gt;
*Disable HTTP: http = false&lt;br /&gt;
*Enable HTTPS: https = true&lt;br /&gt;
*define the HTTPS port: secure_port = 8088 - Set the certificate directory:&lt;br /&gt;
**cert_pem = &amp;quot;/some_system_directory/janus_public.crt&amp;quot;&lt;br /&gt;
**cert_key = &amp;quot;/some_system_directory/janus_private.key&amp;quot; In the .env file it is also necessary to update the protocolo of janu from http to https:&lt;br /&gt;
*JANUS_SERVER_ADDRESS=&amp;quot;https://janus-server-address:8088/janus&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== External Authentication ==&lt;br /&gt;
FREE now allows the use of external services from Google and Microsoft for user authentication.&lt;br /&gt;
To configure these services it is necessary to have HTTPS working and have a fixed public numeric address (or DNS name) for the FREE installation (for instance https://free.some-university.edu:8000/) and follow the next instructions.&lt;br /&gt;
=== GOOGLE ===&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/google.html#google-oauth2 / https://developers.google.com/identity/protocols/oauth2?csw=1#Registering:&lt;br /&gt;
&lt;br /&gt;
*access the Google API Console: https://console.developers.google.com/&lt;br /&gt;
*Create a new project&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create Credentials -&amp;gt; OAuth client ID&lt;br /&gt;
*Configure Consent Screen&lt;br /&gt;
**Select External User Type&lt;br /&gt;
**Fill The App information screen (app name, User support email, Developer contact information)&lt;br /&gt;
**Select scopes (may be empty)&lt;br /&gt;
**Add a test user&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create credentials -&amp;gt; OAuth client ID&lt;br /&gt;
**Application Type - Web application&lt;br /&gt;
**Define name &lt;br /&gt;
**Add Authorized redirect URIs&lt;br /&gt;
***append '''/complete/google-oauth2/''' to the installation URL (example: `https://free.some-university.edu:8000/complete/google-oauth2/`)&lt;br /&gt;
**Create&lt;br /&gt;
*Download json or save the Client ID and Client Secret&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_GOOGLE_OAUTH''':&lt;br /&gt;
***FREE_GOOGLE_OAUTH=true&lt;br /&gt;
**copy the value of '''Your Client ID''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'''&lt;br /&gt;
**copy '''Client Secret''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
=== Microsoft ===&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/microsoftgraph.html.html#google-oauth2 / https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app:&lt;br /&gt;
&lt;br /&gt;
*Sign in to the Azure portal: https://portal.azure.com/&lt;br /&gt;
*Manage Azure Active Directory - View&lt;br /&gt;
*Select  App registrations on the menu&lt;br /&gt;
*New registration&lt;br /&gt;
**Define the name of teh application&lt;br /&gt;
**Select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)&lt;br /&gt;
**Define the redirect URI&lt;br /&gt;
***Select a platform - Web&lt;br /&gt;
***to create the URI, append '''/complete/microsoft-graph/''' to the installation URL (exampe: `https://free.some-university.edu:8000/complete/microsoft-graph/`)&lt;br /&gt;
**Register&lt;br /&gt;
**Save the '''Application (client) ID'''&lt;br /&gt;
***this value should be put in the .env file&lt;br /&gt;
**Select Certificates and secrets on the menu&lt;br /&gt;
***New client secret&lt;br /&gt;
***Add&lt;br /&gt;
**Save the '''Value'''&lt;br /&gt;
***this value should be put in the .env file &amp;lt;span style=&amp;quot;color:#FFFFFF; background:#F50000&amp;quot;&amp;gt;'''The secret Value dissapears after closing this page '''&amp;lt;/span&amp;gt;&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_MS_OAUTH''':&lt;br /&gt;
***FREE_MS_OAUTH=true&lt;br /&gt;
**copy  the value of '''Application (client) ID''' to '''SSOCIAL_AUTH_MICROSOFT_GRAPH_KEY'''&lt;br /&gt;
**copy the value of '''Secret ID''' to '''SOCIAL_AUTH_MICROSOFT_GRAPH_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Raspberry Pi Proxy =&lt;br /&gt;
&lt;br /&gt;
Due to changes on the API and the database you will need to make a upgrade to this version of the Proxy.&lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of Proxy (compatible to the Version of the FREE server).&lt;br /&gt;
* For example '''mkdir Proxy_051 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/RPi_Proxy/releases/latest/download/RPi_Proxy_0_5_1.zip &lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip RPi_Proxy_0_5_1.zip -d Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
After that, install the dependent package:&lt;br /&gt;
&lt;br /&gt;
For the Proxy:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3-pip&lt;br /&gt;
&lt;br /&gt;
 pip3 install pyserial&lt;br /&gt;
&lt;br /&gt;
And for streaming the video (for '''gstreamer '''):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-tools&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-good&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-bad&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-ugly&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-base&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For '''ffmpeg ''':&lt;br /&gt;
 sudo apt-get install ffmpeg&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Video Streaming Configuration ===&lt;br /&gt;
&lt;br /&gt;
In order to configure the video streaming process on the Raspberry pi edit the '''video-stream.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
* video_server video_port apparatus_location apparatus_name apparatus_id&lt;br /&gt;
** copy this information from the Video Conf administration page on the FREE server&lt;br /&gt;
&lt;br /&gt;
* usb_camera video_width video_height video_frame&lt;br /&gt;
** find the suitable values depending on the network resources and the information provided by the following commands:&lt;br /&gt;
 v4l2-ctl --list-devices&lt;br /&gt;
 v4l2-ctl -d /dev/videoXXXXX --list-formats-ext&lt;br /&gt;
&lt;br /&gt;
In order to debug and verify the video configuration it is possible to execute the '''video-stream.sh ''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Configuration ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to configure the Proxy on Raspberry pi edit the '''server_info.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
 &lt;br /&gt;
*SERVER : The IP address or domain of your FREE_Web server;&lt;br /&gt;
*PORT : The port of the server by default is the 8000;&lt;br /&gt;
*DEBUG: This can be change to off, after this installation is correctly done;&lt;br /&gt;
*APPARATUS_ID, SECRET: This parameters can be seen on the admin of the FREE_Web server;&lt;br /&gt;
On the apparatus configure page, you will be able to see the APPARATUS_ID on the URL of the page (indicated with the arrow) and the SECRET on the page it self:&lt;br /&gt;
&lt;br /&gt;
[[File:Info for Proxy.png|1220px]]&lt;br /&gt;
&lt;br /&gt;
== Proxy execution ==&lt;br /&gt;
&lt;br /&gt;
In order to debug the various video and apparatus control configuration, the two scripts (video-stream.sh and main.py) can be executed independently on the command line.&lt;br /&gt;
&lt;br /&gt;
After all the parameters are correct, both programs can be executed simultaneously  using the following command:&lt;br /&gt;
&lt;br /&gt;
 nohup sh start-wp.sh &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This command runs until the raspberry pi is rebooted.&lt;br /&gt;
&lt;br /&gt;
To make the Proxy run when the Raspberry pi reboots it is necessary to edit the '''/etc/rc.local ''' and add the following lines before the '''exit 0 ''':&lt;br /&gt;
 sleep 60&lt;br /&gt;
 cd /INSTALLATION_FOLDER/PATH&lt;br /&gt;
 su USER -c &amp;quot;sh start-wp.sh &amp;amp;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace /INSTALLATION_FOLDER/PATH with the output of the following command:&lt;br /&gt;
 readlink -f Proxy_051/&lt;br /&gt;
&lt;br /&gt;
Replace USER the the actual user owner of the proxy.&lt;/div&gt;</summary>
		<author><name>Ist14028</name></author>
		
	</entry>
	<entry>
		<id>http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4615</id>
		<title>WPA FREE 0.6.0 Instalation</title>
		<link rel="alternate" type="text/html" href="http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4615"/>
		<updated>2022-10-10T21:44:38Z</updated>

		<summary type="html">&lt;p&gt;Ist14028: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Janus Server=&lt;br /&gt;
&lt;br /&gt;
== Update ==&lt;br /&gt;
If the Janus server is already running with the FREE 0.3.0 version it is only necessary to guarantee that  the admin secret is defined.&lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg ''' file in the '''/var/snap/janus-gateway/common/etc ​''' directory and guarantee that the '''admin_key ''' is defined:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;elab1&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
To install the Janus stream server you will need to run the following commands on your Debian 11 machine:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snap​&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snapd&lt;br /&gt;
&lt;br /&gt;
 sudo snap install janus-gateway​&lt;br /&gt;
&lt;br /&gt;
===Configuration===&lt;br /&gt;
&lt;br /&gt;
The configuration of Janus is done editing a file in the '''/var/snap/janus-gateway/common/etc​''' directory &lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg''' file&lt;br /&gt;
&lt;br /&gt;
Define an administration secret​ by uncommenting the line 104) or the one that contains the '''admin_key''' string= and changing the string to a suitable value.&lt;br /&gt;
&lt;br /&gt;
Define the possible ports that Janus will use to ​receive the video stream from the pendulum by uncomment line 106​) or the one containing the string '''rtp_port_range'''= and define the available ports (for example to 6000-7000​).&lt;br /&gt;
&lt;br /&gt;
Delete the sample pre-configure endpoints by deleting all lines from line 124. &lt;br /&gt;
&lt;br /&gt;
Restart Janus  by running the command:&lt;br /&gt;
 &lt;br /&gt;
 sudo snap restart janus-gateway​&lt;br /&gt;
&lt;br /&gt;
=== Example of Janus Configuration ===&lt;br /&gt;
After the configuration of a newly installed Janus Server the '''janus.plugin.streaming.jcfg''' should only containg the following`&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;super_pass&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== HTTPS cfigurations ==&lt;br /&gt;
TODO!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= FREE Server=&lt;br /&gt;
&lt;br /&gt;
== New instalation == &lt;br /&gt;
&lt;br /&gt;
=== Installation of Source Code ===&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of FREE.&lt;br /&gt;
* For example '''mkdir wpa_free_060 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/FREE_Web_0_6_0.zip&lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip FREE_Web_0_6_0.zip -d wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Create a new python virtual environment, it should be called '''free-env''':&lt;br /&gt;
 virtualenv -p python3 free-env&lt;br /&gt;
&lt;br /&gt;
Activate the virtual environment:&lt;br /&gt;
 source free-env/bin/activate&lt;br /&gt;
&lt;br /&gt;
You should now see a prefix of (free-env) in your command line. &lt;br /&gt;
&lt;br /&gt;
After that, install the dependent packages:&lt;br /&gt;
 pip install -r REQUIREMENTS.txt&lt;br /&gt;
&lt;br /&gt;
=== Installation of New Database ===&lt;br /&gt;
Since the data model was change it is necessary to download and install a new empty database.&lt;br /&gt;
&lt;br /&gt;
This database is configured with two users and the WPA pendulum apparatus types and protocols.&lt;br /&gt;
&lt;br /&gt;
Download the database and put it into the project root:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/db_template_0_5_1.sqlite3 -O db.sqlite3&lt;br /&gt;
&lt;br /&gt;
This database contains a Pendulum experiment, as well as two example user accounts.&lt;br /&gt;
* wp-admin - superuser account with access to admin interface&lt;br /&gt;
* wp-guest - guest account&lt;br /&gt;
Both users have a '''temporary123 ''' password. &lt;br /&gt;
&lt;br /&gt;
This password should be changed through admin interface.&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
The application is configured using environment variables. &lt;br /&gt;
&lt;br /&gt;
You can set them using the '''/freeweb/.env ''' file. &lt;br /&gt;
&lt;br /&gt;
There is a '''.env-template ''' file in the '''~freeweb ''' folder, that can be renamed to '''.env ''' :&lt;br /&gt;
 mv freeweb/.env-template freeweb/.env&lt;br /&gt;
&lt;br /&gt;
It is necessary to define correct values for the following variables. Some of these values can be copied form the previous version .env file.&lt;br /&gt;
* PROJECT_NAME, PROJECT_ACRONYMUM, SITE_NAME - Texts that will appear in the page header&lt;br /&gt;
* TIME_ZONE - Time zone setting for that app in '''TZ database name''' from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List.&lt;br /&gt;
* FREE_PRODUCTION - set to '''on ''' to enable production mode (disables sensitive error messages etc.)&lt;br /&gt;
* FREE_REVERSE_PROXY - set to '''on ''' to be able to run the FREE behind a reverse proxy&lt;br /&gt;
* FREE_SECRET - String used in hashing function. Set either to a random string of your choice, or generate one here: https://djecrety.ir&lt;br /&gt;
* FREE_ALLOWED_HOSTS - comma separated list of domain names/addresses; only requests to these hosts will be processed by the application. This is necessary to prevent HTTP Host header attacks.&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== FREE server execution ==&lt;br /&gt;
to start the FREE server run the following command:&lt;br /&gt;
 daphne freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
By default, the webserver will be available at port 8000. To change the port, pass -p &amp;lt;portnumber&amp;gt; parameter to the daphne command. &lt;br /&gt;
You can also force binding to specific address by -b &amp;lt;address&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copy of Pendulum Information ==&lt;br /&gt;
Since a new database is now being used, it is necessary to copy the various apparatus into the new database.&lt;br /&gt;
&lt;br /&gt;
If running both version at the same time, one of them, should be executed on a different port&lt;br /&gt;
&lt;br /&gt;
On the administration page of the you should copy some of the information from the old database to the new.&lt;br /&gt;
&lt;br /&gt;
here is the list and description of the various fields:&lt;br /&gt;
* Apparatus Type : Pendulum&lt;br /&gt;
* Location - description of the physical place of the pendulum&lt;br /&gt;
* Description - specific characteristics of the pendulum&lt;br /&gt;
* Secret - a random string specific to each pendulum&lt;br /&gt;
* Owner - Name of the person responsible for the operation and maintenance of the pendulum&lt;br /&gt;
* Timeout - leave 60 &lt;br /&gt;
* Configuration - copy the following json and modify accordingly the '''id ''' and '''ports_restrict ''' to suitable values:&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;WP_LIS_IST&amp;quot;, &lt;br /&gt;
    &amp;quot;serial_port&amp;quot;: {&lt;br /&gt;
       &amp;quot;ports_restrict&amp;quot;: [&amp;quot;/dev/ttyS0&amp;quot;], &lt;br /&gt;
       &amp;quot;baud&amp;quot;: &amp;quot;115200&amp;quot;, &amp;quot;numbits&amp;quot;: &amp;quot;8&amp;quot;, &amp;quot;stopbits&amp;quot;: &amp;quot;1&amp;quot;, &amp;quot;partitybits&amp;quot;: &amp;quot;0&amp;quot;, &lt;br /&gt;
       &amp;quot;listening_timeout&amp;quot;: &amp;quot;100000&amp;quot;, &amp;quot;death_timeout&amp;quot;: &amp;quot;10000000&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
* video configuration - either copy the value from the old database or leave empty&lt;br /&gt;
&lt;br /&gt;
== Configuration of Video ==&lt;br /&gt;
In order to have video stream from the Raspberry Pi to the server and then to the browser it is necessary to  verify the following data on the '''.env ''' file:&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
After this configuration is correct it is necessary to assign each pendulum one video stream so that video can go from the pendulum to the server and to the browser.&lt;br /&gt;
&lt;br /&gt;
Open the '''Video Config ''' menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Video-config-menu.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page, a table will contain all the configured pendulums and the associated video configuration:&lt;br /&gt;
&lt;br /&gt;
[[File:Video_Config_table.png]]&lt;br /&gt;
&lt;br /&gt;
In the previous example the first apparatus was automatically configure from the previous identifier copied from the old database.&lt;br /&gt;
&lt;br /&gt;
The second apparatus does not have the video stream configure. To create a video stream and update the database click '''Configure Video '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config assign stream.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page it is necessary to click on the '''Assign Stream ''' button.&lt;br /&gt;
&lt;br /&gt;
If the Janus server is well configure the new page will show the Video Stream Configuration and the data to be copied to the Raspberry Pi:&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config RP data.png]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Upgrade of previous instalation == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Follow the first two steps of the installation guide. The commands already contain overwrite switches so that the old version will be overwritten, while '''.env ''' and '''.sqlite''' files won't be touched.&lt;br /&gt;
&lt;br /&gt;
A new release might contain changes to the database structure. If you are preserving your database from a previous version, run&lt;br /&gt;
&lt;br /&gt;
 python manage.py migrate&lt;br /&gt;
&lt;br /&gt;
== HTTPS configuration ==&lt;br /&gt;
IN order to allow remote OAuth authentication (Google or Microsoft) it is necessary to activate HTTPS.&lt;br /&gt;
this requires the installation of SSL certificates and the execution of daphne in a with a different configuration:&lt;br /&gt;
&lt;br /&gt;
=== Cerificates ===&lt;br /&gt;
FREE should execute with certificates produced by the organization, can use self-signed cerificates temporarly.&lt;br /&gt;
Certificates cshould be generated by the network administrator and installed with the suitable names (free_private.key and free_public.crt) in the '''freeweb/certificates/''' directory&lt;br /&gt;
For testing purposed it is also possible to create a self signed certificate by running the following command on the FREE server:&lt;br /&gt;
&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout freeweb/certificates/free_private.key -out freeweb/certificates/free_public.crt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Server execution ===&lt;br /&gt;
After the creation or installation of the certificate the server should be executed as follows&lt;br /&gt;
&lt;br /&gt;
 daphne -e ssl:8000:privateKey=freeweb/certificates/free_private.key:certKey=freeweb/certificates/free_public.crt freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
If running with this configuration, users should use the following url to access FREE:&lt;br /&gt;
&lt;br /&gt;
 https://hostname.some_domain:8000/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Apparatus proxy configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also configure all apparatus proxies to use HTTPS.&lt;br /&gt;
the version of the proxy should the the most recent change the '''server_info.ini''' file:&lt;br /&gt;
 HTTPS = True&lt;br /&gt;
&lt;br /&gt;
=== janus configuration ===&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also further configure janus to also use HTTPS.&lt;br /&gt;
It is necessary to create the certificate similar rto the one used in daphne. Unfortunetly the certificate can not be created in the host (self-signed certificate), '''it must be created by the network administrator of the domain'''.&lt;br /&gt;
&lt;br /&gt;
This certificate should be placed in a system directory before editing the '''janus.transport.http.jcfg''' configuration file:&lt;br /&gt;
*Disable HTTP: http = false&lt;br /&gt;
*Enable HTTPS: https = true&lt;br /&gt;
*define the HTTPS port: secure_port = 8088 - Set the certificate directory:&lt;br /&gt;
**cert_pem = &amp;quot;/some_system_directory/janus_public.crt&amp;quot;&lt;br /&gt;
**cert_key = &amp;quot;/some_system_directory/janus_private.key&amp;quot; In the .env file it is also necessary to update the protocolo of janu from http to https:&lt;br /&gt;
*JANUS_SERVER_ADDRESS=&amp;quot;https://janus-server-address:8088/janus&amp;quot;&lt;br /&gt;
&lt;br /&gt;
== External Authentication ==&lt;br /&gt;
FREE now allows the use of external services from Google and Microsoft for user authentication.&lt;br /&gt;
To configure these services it is necessary to have HTTPS working and have a fixed public numeric address (or DNS name) for the FREE installation (for instance https://free.some-university.edu:8000/) and follow the next instructions.&lt;br /&gt;
=== GOOGLE ===&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/google.html#google-oauth2 / https://developers.google.com/identity/protocols/oauth2?csw=1#Registering:&lt;br /&gt;
&lt;br /&gt;
*access the Google API Console: https://console.developers.google.com/&lt;br /&gt;
*Create a new project&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create Credentials -&amp;gt; OAuth client ID&lt;br /&gt;
*Configure Consent Screen&lt;br /&gt;
**Select External User Type&lt;br /&gt;
**Fill The App information screen (app name, User support email, Developer contact information)&lt;br /&gt;
**Select scopes (may be empty)&lt;br /&gt;
**Add a test user&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create credentials -&amp;gt; OAuth client ID&lt;br /&gt;
**Application Type - Web application&lt;br /&gt;
**Define name &lt;br /&gt;
**Add Authorized redirect URIs&lt;br /&gt;
***append '''/complete/google-oauth2/''' to the installation URL (example: `https://free.some-university.edu:8000/complete/google-oauth2/`)&lt;br /&gt;
**Create&lt;br /&gt;
*Download json or save the Client ID and Client Secret&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_GOOGLE_OAUTH''':&lt;br /&gt;
***FREE_GOOGLE_OAUTH=true&lt;br /&gt;
**copy the value of '''Your Client ID''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'''&lt;br /&gt;
**copy '''Client Secret''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
=== Microsoft ===&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/microsoftgraph.html.html#google-oauth2 / https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app:&lt;br /&gt;
&lt;br /&gt;
*Sign in to the Azure portal: https://portal.azure.com/&lt;br /&gt;
*Manage Azure Active Directory - View&lt;br /&gt;
*Select  App registrations on the menu&lt;br /&gt;
*New registration&lt;br /&gt;
**Define the name of teh application&lt;br /&gt;
**Select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)&lt;br /&gt;
**Define the redirect URI&lt;br /&gt;
***Select a platform - Web&lt;br /&gt;
***to create the URI, append '''/complete/microsoft-graph/''' to the installation URL (exampe: `https://free.some-university.edu:8000/complete/microsoft-graph/`)&lt;br /&gt;
**Register&lt;br /&gt;
**Save the '''Application (client) ID'''&lt;br /&gt;
***this value should be put in the .env file&lt;br /&gt;
**Select Certificates and secrets on the menu&lt;br /&gt;
***New client secret&lt;br /&gt;
***Add&lt;br /&gt;
**Save the '''Value'''&lt;br /&gt;
***this value should be put in the .env file &amp;lt;span style=&amp;quot;color:#FFFFFF; background:#F50000&amp;quot;&amp;gt;'''The secret Value dissapears after closing this page '''&amp;lt;/span&amp;gt;&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_MS_OAUTH''':&lt;br /&gt;
***FREE_MS_OAUTH=true&lt;br /&gt;
**copy  the value of '''Application (client) ID''' to '''SSOCIAL_AUTH_MICROSOFT_GRAPH_KEY'''&lt;br /&gt;
**copy the value of '''Secret ID''' to '''SOCIAL_AUTH_MICROSOFT_GRAPH_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= Raspberry Pi Proxy =&lt;br /&gt;
&lt;br /&gt;
Due to changes on the API and the database you will need to make a upgrade to this version of the Proxy.&lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of Proxy (compatible to the Version of the FREE server).&lt;br /&gt;
* For example '''mkdir Proxy_051 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/RPi_Proxy/releases/latest/download/RPi_Proxy_0_5_1.zip &lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip RPi_Proxy_0_5_1.zip -d Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
After that, install the dependent package:&lt;br /&gt;
&lt;br /&gt;
For the Proxy:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3-pip&lt;br /&gt;
&lt;br /&gt;
 pip3 install pyserial&lt;br /&gt;
&lt;br /&gt;
And for streaming the video (for '''gstreamer '''):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-tools&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-good&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-bad&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-ugly&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-base&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For '''ffmpeg ''':&lt;br /&gt;
 sudo apt-get install ffmpeg&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Video Streaming Configuration ===&lt;br /&gt;
&lt;br /&gt;
In order to configure the video streaming process on the Raspberry pi edit the '''video-stream.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
* video_server video_port apparatus_location apparatus_name apparatus_id&lt;br /&gt;
** copy this information from the Video Conf administration page on the FREE server&lt;br /&gt;
&lt;br /&gt;
* usb_camera video_width video_height video_frame&lt;br /&gt;
** find the suitable values depending on the network resources and the information provided by the following commands:&lt;br /&gt;
 v4l2-ctl --list-devices&lt;br /&gt;
 v4l2-ctl -d /dev/videoXXXXX --list-formats-ext&lt;br /&gt;
&lt;br /&gt;
In order to debug and verify the video configuration it is possible to execute the '''video-stream.sh ''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Configuration ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to configure the Proxy on Raspberry pi edit the '''server_info.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
 &lt;br /&gt;
*SERVER : The IP address or domain of your FREE_Web server;&lt;br /&gt;
*PORT : The port of the server by default is the 8000;&lt;br /&gt;
*DEBUG: This can be change to off, after this installation is correctly done;&lt;br /&gt;
*APPARATUS_ID, SECRET: This parameters can be seen on the admin of the FREE_Web server;&lt;br /&gt;
On the apparatus configure page, you will be able to see the APPARATUS_ID on the URL of the page (indicated with the arrow) and the SECRET on the page it self:&lt;br /&gt;
&lt;br /&gt;
[[File:Info for Proxy.png|1220px]]&lt;br /&gt;
&lt;br /&gt;
== Proxy execution ==&lt;br /&gt;
&lt;br /&gt;
In order to debug the various video and apparatus control configuration, the two scripts (video-stream.sh and main.py) can be executed independently on the command line.&lt;br /&gt;
&lt;br /&gt;
After all the parameters are correct, both programs can be executed simultaneously  using the following command:&lt;br /&gt;
&lt;br /&gt;
 nohup sh start-wp.sh &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This command runs until the raspberry pi is rebooted.&lt;br /&gt;
&lt;br /&gt;
To make the Proxy run when the Raspberry pi reboots it is necessary to edit the '''/etc/rc.local ''' and add the following lines before the '''exit 0 ''':&lt;br /&gt;
 sleep 60&lt;br /&gt;
 cd /INSTALLATION_FOLDER/PATH&lt;br /&gt;
 su USER -c &amp;quot;sh start-wp.sh &amp;amp;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace /INSTALLATION_FOLDER/PATH with the output of the following command:&lt;br /&gt;
 readlink -f Proxy_051/&lt;br /&gt;
&lt;br /&gt;
Replace USER the the actual user owner of the proxy.&lt;/div&gt;</summary>
		<author><name>Ist14028</name></author>
		
	</entry>
	<entry>
		<id>http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4614</id>
		<title>WPA FREE 0.6.0 Instalation</title>
		<link rel="alternate" type="text/html" href="http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4614"/>
		<updated>2022-10-10T21:42:26Z</updated>

		<summary type="html">&lt;p&gt;Ist14028: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Janus Server=&lt;br /&gt;
&lt;br /&gt;
== Update ==&lt;br /&gt;
If the Janus server is already running with the FREE 0.3.0 version it is only necessary to guarantee that  the admin secret is defined.&lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg ''' file in the '''/var/snap/janus-gateway/common/etc ​''' directory and guarantee that the '''admin_key ''' is defined:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;elab1&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
To install the Janus stream server you will need to run the following commands on your Debian 11 machine:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snap​&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snapd&lt;br /&gt;
&lt;br /&gt;
 sudo snap install janus-gateway​&lt;br /&gt;
&lt;br /&gt;
===Configuration===&lt;br /&gt;
&lt;br /&gt;
The configuration of Janus is done editing a file in the '''/var/snap/janus-gateway/common/etc​''' directory &lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg''' file&lt;br /&gt;
&lt;br /&gt;
Define an administration secret​ by uncommenting the line 104) or the one that contains the '''admin_key''' string= and changing the string to a suitable value.&lt;br /&gt;
&lt;br /&gt;
Define the possible ports that Janus will use to ​receive the video stream from the pendulum by uncomment line 106​) or the one containing the string '''rtp_port_range'''= and define the available ports (for example to 6000-7000​).&lt;br /&gt;
&lt;br /&gt;
Delete the sample pre-configure endpoints by deleting all lines from line 124. &lt;br /&gt;
&lt;br /&gt;
Restart Janus  by running the command:&lt;br /&gt;
 &lt;br /&gt;
 sudo snap restart janus-gateway​&lt;br /&gt;
&lt;br /&gt;
=== Example of Janus Configuration ===&lt;br /&gt;
After the configuration of a newly installed Janus Server the '''janus.plugin.streaming.jcfg''' should only containg the following`&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;super_pass&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== HTTPS cfigurations ==&lt;br /&gt;
TODO!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= FREE Server=&lt;br /&gt;
&lt;br /&gt;
== New instalation == &lt;br /&gt;
&lt;br /&gt;
=== Installation of Source Code ===&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of FREE.&lt;br /&gt;
* For example '''mkdir wpa_free_060 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/FREE_Web_0_6_0.zip&lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip FREE_Web_0_6_0.zip -d wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Create a new python virtual environment, it should be called '''free-env''':&lt;br /&gt;
 virtualenv -p python3 free-env&lt;br /&gt;
&lt;br /&gt;
Activate the virtual environment:&lt;br /&gt;
 source free-env/bin/activate&lt;br /&gt;
&lt;br /&gt;
You should now see a prefix of (free-env) in your command line. &lt;br /&gt;
&lt;br /&gt;
After that, install the dependent packages:&lt;br /&gt;
 pip install -r REQUIREMENTS.txt&lt;br /&gt;
&lt;br /&gt;
=== Installation of New Database ===&lt;br /&gt;
Since the data model was change it is necessary to download and install a new empty database.&lt;br /&gt;
&lt;br /&gt;
This database is configured with two users and the WPA pendulum apparatus types and protocols.&lt;br /&gt;
&lt;br /&gt;
Download the database and put it into the project root:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/db_template_0_5_1.sqlite3 -O db.sqlite3&lt;br /&gt;
&lt;br /&gt;
This database contains a Pendulum experiment, as well as two example user accounts.&lt;br /&gt;
* wp-admin - superuser account with access to admin interface&lt;br /&gt;
* wp-guest - guest account&lt;br /&gt;
Both users have a '''temporary123 ''' password. &lt;br /&gt;
&lt;br /&gt;
This password should be changed through admin interface.&lt;br /&gt;
&lt;br /&gt;
=== Configuration ===&lt;br /&gt;
&lt;br /&gt;
The application is configured using environment variables. &lt;br /&gt;
&lt;br /&gt;
You can set them using the '''/freeweb/.env ''' file. &lt;br /&gt;
&lt;br /&gt;
There is a '''.env-template ''' file in the '''~freeweb ''' folder, that can be renamed to '''.env ''' :&lt;br /&gt;
 mv freeweb/.env-template freeweb/.env&lt;br /&gt;
&lt;br /&gt;
It is necessary to define correct values for the following variables. Some of these values can be copied form the previous version .env file.&lt;br /&gt;
* PROJECT_NAME, PROJECT_ACRONYMUM, SITE_NAME - Texts that will appear in the page header&lt;br /&gt;
* TIME_ZONE - Time zone setting for that app in '''TZ database name''' from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List.&lt;br /&gt;
* FREE_PRODUCTION - set to '''on ''' to enable production mode (disables sensitive error messages etc.)&lt;br /&gt;
* FREE_REVERSE_PROXY - set to '''on ''' to be able to run the FREE behind a reverse proxy&lt;br /&gt;
* FREE_SECRET - String used in hashing function. Set either to a random string of your choice, or generate one here: https://djecrety.ir&lt;br /&gt;
* FREE_ALLOWED_HOSTS - comma separated list of domain names/addresses; only requests to these hosts will be processed by the application. This is necessary to prevent HTTP Host header attacks.&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Upgrade of previous instalation == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Follow the first two steps of the installation guide. The commands already contain overwrite switches so that the old version will be overwritten, while '''.env ''' and '''.sqlite''' files won't be touched.&lt;br /&gt;
&lt;br /&gt;
A new release might contain changes to the database structure. If you are preserving your database from a previous version, run&lt;br /&gt;
&lt;br /&gt;
 python manage.py migrate&lt;br /&gt;
&lt;br /&gt;
=== HTTPS configuration ===&lt;br /&gt;
IN order to allow remote OAuth authentication (Google or Microsoft) it is necessary to activate HTTPS.&lt;br /&gt;
this requires the installation of SSL certificates and the execution of daphne in a with a different configuration:&lt;br /&gt;
&lt;br /&gt;
==== Cerificates ====&lt;br /&gt;
FREE should execute with certificates produced by the organization, can use self-signed cerificates temporarly.&lt;br /&gt;
Certificates cshould be generated by the network administrator and installed with the suitable names (free_private.key and free_public.crt) in the '''freeweb/certificates/''' directory&lt;br /&gt;
For testing purposed it is also possible to create a self signed certificate by running the following command on the FREE server:&lt;br /&gt;
&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout freeweb/certificates/free_private.key -out freeweb/certificates/free_public.crt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Server execution ====&lt;br /&gt;
After the creation or installation of the certificate the server should be executed as follows&lt;br /&gt;
&lt;br /&gt;
 daphne -e ssl:8000:privateKey=freeweb/certificates/free_private.key:certKey=freeweb/certificates/free_public.crt freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
If running with this configuration, users should use the following url to access FREE:&lt;br /&gt;
&lt;br /&gt;
 https://hostname.some_domain:8000/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Apparatus proxy configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also configure all apparatus proxies to use HTTPS.&lt;br /&gt;
the version of the proxy should the the most recent change the '''server_info.ini''' file:&lt;br /&gt;
 HTTPS = True&lt;br /&gt;
&lt;br /&gt;
==== janus configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also further configure janus to also use HTTPS.&lt;br /&gt;
It is necessary to create the certificate similar rto the one used in daphne. Unfortunetly the certificate can not be created in the host (self-signed certificate), '''it must be created by the network administrator of the domain'''.&lt;br /&gt;
&lt;br /&gt;
This certificate should be placed in a system directory before editing the '''janus.transport.http.jcfg''' configuration file:&lt;br /&gt;
*Disable HTTP: http = false&lt;br /&gt;
*Enable HTTPS: https = true&lt;br /&gt;
*define the HTTPS port: secure_port = 8088 - Set the certificate directory:&lt;br /&gt;
**cert_pem = &amp;quot;/some_system_directory/janus_public.crt&amp;quot;&lt;br /&gt;
**cert_key = &amp;quot;/some_system_directory/janus_private.key&amp;quot; In the .env file it is also necessary to update the protocolo of janu from http to https:&lt;br /&gt;
*JANUS_SERVER_ADDRESS=&amp;quot;https://janus-server-address:8088/janus&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== External Authentication ===&lt;br /&gt;
FREE now allows the use of external services from Google and Microsoft for user authentication.&lt;br /&gt;
To configure these services it is necessary to have HTTPS working and have a fixed public numeric address (or DNS name) for the FREE installation (for instance https://free.some-university.edu:8000/) and follow the next instructions.&lt;br /&gt;
==== GOOGLE ====&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/google.html#google-oauth2 / https://developers.google.com/identity/protocols/oauth2?csw=1#Registering:&lt;br /&gt;
&lt;br /&gt;
*access the Google API Console: https://console.developers.google.com/&lt;br /&gt;
*Create a new project&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create Credentials -&amp;gt; OAuth client ID&lt;br /&gt;
*Configure Consent Screen&lt;br /&gt;
**Select External User Type&lt;br /&gt;
**Fill The App information screen (app name, User support email, Developer contact information)&lt;br /&gt;
**Select scopes (may be empty)&lt;br /&gt;
**Add a test user&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create credentials -&amp;gt; OAuth client ID&lt;br /&gt;
**Application Type - Web application&lt;br /&gt;
**Define name &lt;br /&gt;
**Add Authorized redirect URIs&lt;br /&gt;
***append '''/complete/google-oauth2/''' to the installation URL (example: `https://free.some-university.edu:8000/complete/google-oauth2/`)&lt;br /&gt;
**Create&lt;br /&gt;
*Download json or save the Client ID and Client Secret&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_GOOGLE_OAUTH''':&lt;br /&gt;
***FREE_GOOGLE_OAUTH=true&lt;br /&gt;
**copy the value of '''Your Client ID''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'''&lt;br /&gt;
**copy '''Client Secret''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
==== Microsoft ====&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/microsoftgraph.html.html#google-oauth2 / https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app:&lt;br /&gt;
&lt;br /&gt;
*Sign in to the Azure portal: https://portal.azure.com/&lt;br /&gt;
*Manage Azure Active Directory - View&lt;br /&gt;
*Select  App registrations on the menu&lt;br /&gt;
*New registration&lt;br /&gt;
**Define the name of teh application&lt;br /&gt;
**Select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)&lt;br /&gt;
**Define the redirect URI&lt;br /&gt;
***Select a platform - Web&lt;br /&gt;
***to create the URI, append '''/complete/microsoft-graph/''' to the installation URL (exampe: `https://free.some-university.edu:8000/complete/microsoft-graph/`)&lt;br /&gt;
**Register&lt;br /&gt;
**Save the '''Application (client) ID'''&lt;br /&gt;
***this value should be put in the .env file&lt;br /&gt;
**Select Certificates and secrets on the menu&lt;br /&gt;
***New client secret&lt;br /&gt;
***Add&lt;br /&gt;
**Save the '''Value'''&lt;br /&gt;
***this value should be put in the .env file &amp;lt;span style=&amp;quot;color:#FFFFFF; background:#F50000&amp;quot;&amp;gt;'''The secret Value dissapears after closing this page '''&amp;lt;/span&amp;gt;&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_MS_OAUTH''':&lt;br /&gt;
***FREE_MS_OAUTH=true&lt;br /&gt;
**copy  the value of '''Application (client) ID''' to '''SSOCIAL_AUTH_MICROSOFT_GRAPH_KEY'''&lt;br /&gt;
**copy the value of '''Secret ID''' to '''SOCIAL_AUTH_MICROSOFT_GRAPH_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
&lt;br /&gt;
== FREE server execution ==&lt;br /&gt;
to start the FREE server run the following command:&lt;br /&gt;
 daphne freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
By default, the webserver will be available at port 8000. To change the port, pass -p &amp;lt;portnumber&amp;gt; parameter to the daphne command. &lt;br /&gt;
You can also force binding to specific address by -b &amp;lt;address&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copy of Pendulum Information ==&lt;br /&gt;
Since a new database is now being used, it is necessary to copy the various apparatus into the new database.&lt;br /&gt;
&lt;br /&gt;
If running both version at the same time, one of them, should be executed on a different port&lt;br /&gt;
&lt;br /&gt;
On the administration page of the you should copy some of the information from the old database to the new.&lt;br /&gt;
&lt;br /&gt;
here is the list and description of the various fields:&lt;br /&gt;
* Apparatus Type : Pendulum&lt;br /&gt;
* Location - description of the physical place of the pendulum&lt;br /&gt;
* Description - specific characteristics of the pendulum&lt;br /&gt;
* Secret - a random string specific to each pendulum&lt;br /&gt;
* Owner - Name of the person responsible for the operation and maintenance of the pendulum&lt;br /&gt;
* Timeout - leave 60 &lt;br /&gt;
* Configuration - copy the following json and modify accordingly the '''id ''' and '''ports_restrict ''' to suitable values:&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;WP_LIS_IST&amp;quot;, &lt;br /&gt;
    &amp;quot;serial_port&amp;quot;: {&lt;br /&gt;
       &amp;quot;ports_restrict&amp;quot;: [&amp;quot;/dev/ttyS0&amp;quot;], &lt;br /&gt;
       &amp;quot;baud&amp;quot;: &amp;quot;115200&amp;quot;, &amp;quot;numbits&amp;quot;: &amp;quot;8&amp;quot;, &amp;quot;stopbits&amp;quot;: &amp;quot;1&amp;quot;, &amp;quot;partitybits&amp;quot;: &amp;quot;0&amp;quot;, &lt;br /&gt;
       &amp;quot;listening_timeout&amp;quot;: &amp;quot;100000&amp;quot;, &amp;quot;death_timeout&amp;quot;: &amp;quot;10000000&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
* video configuration - either copy the value from the old database or leave empty&lt;br /&gt;
&lt;br /&gt;
== Configuration of Video ==&lt;br /&gt;
In order to have video stream from the Raspberry Pi to the server and then to the browser it is necessary to  verify the following data on the '''.env ''' file:&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
After this configuration is correct it is necessary to assign each pendulum one video stream so that video can go from the pendulum to the server and to the browser.&lt;br /&gt;
&lt;br /&gt;
Open the '''Video Config ''' menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Video-config-menu.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page, a table will contain all the configured pendulums and the associated video configuration:&lt;br /&gt;
&lt;br /&gt;
[[File:Video_Config_table.png]]&lt;br /&gt;
&lt;br /&gt;
In the previous example the first apparatus was automatically configure from the previous identifier copied from the old database.&lt;br /&gt;
&lt;br /&gt;
The second apparatus does not have the video stream configure. To create a video stream and update the database click '''Configure Video '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config assign stream.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page it is necessary to click on the '''Assign Stream ''' button.&lt;br /&gt;
&lt;br /&gt;
If the Janus server is well configure the new page will show the Video Stream Configuration and the data to be copied to the Raspberry Pi:&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config RP data.png]]&lt;br /&gt;
&lt;br /&gt;
= Raspberry Pi Proxy =&lt;br /&gt;
&lt;br /&gt;
Due to changes on the API and the database you will need to make a upgrade to this version of the Proxy.&lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of Proxy (compatible to the Version of the FREE server).&lt;br /&gt;
* For example '''mkdir Proxy_051 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/RPi_Proxy/releases/latest/download/RPi_Proxy_0_5_1.zip &lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip RPi_Proxy_0_5_1.zip -d Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
After that, install the dependent package:&lt;br /&gt;
&lt;br /&gt;
For the Proxy:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3-pip&lt;br /&gt;
&lt;br /&gt;
 pip3 install pyserial&lt;br /&gt;
&lt;br /&gt;
And for streaming the video (for '''gstreamer '''):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-tools&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-good&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-bad&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-ugly&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-base&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For '''ffmpeg ''':&lt;br /&gt;
 sudo apt-get install ffmpeg&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Video Streaming Configuration ===&lt;br /&gt;
&lt;br /&gt;
In order to configure the video streaming process on the Raspberry pi edit the '''video-stream.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
* video_server video_port apparatus_location apparatus_name apparatus_id&lt;br /&gt;
** copy this information from the Video Conf administration page on the FREE server&lt;br /&gt;
&lt;br /&gt;
* usb_camera video_width video_height video_frame&lt;br /&gt;
** find the suitable values depending on the network resources and the information provided by the following commands:&lt;br /&gt;
 v4l2-ctl --list-devices&lt;br /&gt;
 v4l2-ctl -d /dev/videoXXXXX --list-formats-ext&lt;br /&gt;
&lt;br /&gt;
In order to debug and verify the video configuration it is possible to execute the '''video-stream.sh ''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Configuration ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to configure the Proxy on Raspberry pi edit the '''server_info.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
 &lt;br /&gt;
*SERVER : The IP address or domain of your FREE_Web server;&lt;br /&gt;
*PORT : The port of the server by default is the 8000;&lt;br /&gt;
*DEBUG: This can be change to off, after this installation is correctly done;&lt;br /&gt;
*APPARATUS_ID, SECRET: This parameters can be seen on the admin of the FREE_Web server;&lt;br /&gt;
On the apparatus configure page, you will be able to see the APPARATUS_ID on the URL of the page (indicated with the arrow) and the SECRET on the page it self:&lt;br /&gt;
&lt;br /&gt;
[[File:Info for Proxy.png|1220px]]&lt;br /&gt;
&lt;br /&gt;
== Proxy execution ==&lt;br /&gt;
&lt;br /&gt;
In order to debug the various video and apparatus control configuration, the two scripts (video-stream.sh and main.py) can be executed independently on the command line.&lt;br /&gt;
&lt;br /&gt;
After all the parameters are correct, both programs can be executed simultaneously  using the following command:&lt;br /&gt;
&lt;br /&gt;
 nohup sh start-wp.sh &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This command runs until the raspberry pi is rebooted.&lt;br /&gt;
&lt;br /&gt;
To make the Proxy run when the Raspberry pi reboots it is necessary to edit the '''/etc/rc.local ''' and add the following lines before the '''exit 0 ''':&lt;br /&gt;
 sleep 60&lt;br /&gt;
 cd /INSTALLATION_FOLDER/PATH&lt;br /&gt;
 su USER -c &amp;quot;sh start-wp.sh &amp;amp;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace /INSTALLATION_FOLDER/PATH with the output of the following command:&lt;br /&gt;
 readlink -f Proxy_051/&lt;br /&gt;
&lt;br /&gt;
Replace USER the the actual user owner of the proxy.&lt;/div&gt;</summary>
		<author><name>Ist14028</name></author>
		
	</entry>
	<entry>
		<id>http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4613</id>
		<title>WPA FREE 0.6.0 Instalation</title>
		<link rel="alternate" type="text/html" href="http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4613"/>
		<updated>2022-10-10T21:41:55Z</updated>

		<summary type="html">&lt;p&gt;Ist14028: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Janus Server=&lt;br /&gt;
&lt;br /&gt;
== Update ==&lt;br /&gt;
If the Janus server is already running with the FREE 0.3.0 version it is only necessary to guarantee that  the admin secret is defined.&lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg ''' file in the '''/var/snap/janus-gateway/common/etc ​''' directory and guarantee that the '''admin_key ''' is defined:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;elab1&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
To install the Janus stream server you will need to run the following commands on your Debian 11 machine:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snap​&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snapd&lt;br /&gt;
&lt;br /&gt;
 sudo snap install janus-gateway​&lt;br /&gt;
&lt;br /&gt;
===Configuration===&lt;br /&gt;
&lt;br /&gt;
The configuration of Janus is done editing a file in the '''/var/snap/janus-gateway/common/etc​''' directory &lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg''' file&lt;br /&gt;
&lt;br /&gt;
Define an administration secret​ by uncommenting the line 104) or the one that contains the '''admin_key''' string= and changing the string to a suitable value.&lt;br /&gt;
&lt;br /&gt;
Define the possible ports that Janus will use to ​receive the video stream from the pendulum by uncomment line 106​) or the one containing the string '''rtp_port_range'''= and define the available ports (for example to 6000-7000​).&lt;br /&gt;
&lt;br /&gt;
Delete the sample pre-configure endpoints by deleting all lines from line 124. &lt;br /&gt;
&lt;br /&gt;
Restart Janus  by running the command:&lt;br /&gt;
 &lt;br /&gt;
 sudo snap restart janus-gateway​&lt;br /&gt;
&lt;br /&gt;
=== Example of Janus Configuration ===&lt;br /&gt;
After the configuration of a newly installed Janus Server the '''janus.plugin.streaming.jcfg''' should only containg the following`&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;super_pass&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== HTTPS cfigurations ==&lt;br /&gt;
TODO!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= FREE Server=&lt;br /&gt;
&lt;br /&gt;
== New instalation == &lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of FREE.&lt;br /&gt;
* For example '''mkdir wpa_free_060 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/FREE_Web_0_6_0.zip&lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip FREE_Web_0_6_0.zip -d wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Create a new python virtual environment, it should be called '''free-env''':&lt;br /&gt;
 virtualenv -p python3 free-env&lt;br /&gt;
&lt;br /&gt;
Activate the virtual environment:&lt;br /&gt;
 source free-env/bin/activate&lt;br /&gt;
&lt;br /&gt;
You should now see a prefix of (free-env) in your command line. &lt;br /&gt;
&lt;br /&gt;
After that, install the dependent packages:&lt;br /&gt;
 pip install -r REQUIREMENTS.txt&lt;br /&gt;
&lt;br /&gt;
== Installation of New Database ==&lt;br /&gt;
Since the data model was change it is necessary to download and install a new empty database.&lt;br /&gt;
&lt;br /&gt;
This database is configured with two users and the WPA pendulum apparatus types and protocols.&lt;br /&gt;
&lt;br /&gt;
Download the database and put it into the project root:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/db_template_0_5_1.sqlite3 -O db.sqlite3&lt;br /&gt;
&lt;br /&gt;
This database contains a Pendulum experiment, as well as two example user accounts.&lt;br /&gt;
* wp-admin - superuser account with access to admin interface&lt;br /&gt;
* wp-guest - guest account&lt;br /&gt;
Both users have a '''temporary123 ''' password. &lt;br /&gt;
&lt;br /&gt;
This password should be changed through admin interface.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The application is configured using environment variables. &lt;br /&gt;
&lt;br /&gt;
You can set them using the '''/freeweb/.env ''' file. &lt;br /&gt;
&lt;br /&gt;
There is a '''.env-template ''' file in the '''~freeweb ''' folder, that can be renamed to '''.env ''' :&lt;br /&gt;
 mv freeweb/.env-template freeweb/.env&lt;br /&gt;
&lt;br /&gt;
It is necessary to define correct values for the following variables. Some of these values can be copied form the previous version .env file.&lt;br /&gt;
* PROJECT_NAME, PROJECT_ACRONYMUM, SITE_NAME - Texts that will appear in the page header&lt;br /&gt;
* TIME_ZONE - Time zone setting for that app in '''TZ database name''' from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List.&lt;br /&gt;
* FREE_PRODUCTION - set to '''on ''' to enable production mode (disables sensitive error messages etc.)&lt;br /&gt;
* FREE_REVERSE_PROXY - set to '''on ''' to be able to run the FREE behind a reverse proxy&lt;br /&gt;
* FREE_SECRET - String used in hashing function. Set either to a random string of your choice, or generate one here: https://djecrety.ir&lt;br /&gt;
* FREE_ALLOWED_HOSTS - comma separated list of domain names/addresses; only requests to these hosts will be processed by the application. This is necessary to prevent HTTP Host header attacks.&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Upgrade of previous instalation == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Follow the first two steps of the installation guide. The commands already contain overwrite switches so that the old version will be overwritten, while '''.env ''' and '''.sqlite''' files won't be touched.&lt;br /&gt;
&lt;br /&gt;
A new release might contain changes to the database structure. If you are preserving your database from a previous version, run&lt;br /&gt;
&lt;br /&gt;
 python manage.py migrate&lt;br /&gt;
&lt;br /&gt;
=== HTTPS configuration ===&lt;br /&gt;
IN order to allow remote OAuth authentication (Google or Microsoft) it is necessary to activate HTTPS.&lt;br /&gt;
this requires the installation of SSL certificates and the execution of daphne in a with a different configuration:&lt;br /&gt;
&lt;br /&gt;
==== Cerificates ====&lt;br /&gt;
FREE should execute with certificates produced by the organization, can use self-signed cerificates temporarly.&lt;br /&gt;
Certificates cshould be generated by the network administrator and installed with the suitable names (free_private.key and free_public.crt) in the '''freeweb/certificates/''' directory&lt;br /&gt;
For testing purposed it is also possible to create a self signed certificate by running the following command on the FREE server:&lt;br /&gt;
&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout freeweb/certificates/free_private.key -out freeweb/certificates/free_public.crt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Server execution ====&lt;br /&gt;
After the creation or installation of the certificate the server should be executed as follows&lt;br /&gt;
&lt;br /&gt;
 daphne -e ssl:8000:privateKey=freeweb/certificates/free_private.key:certKey=freeweb/certificates/free_public.crt freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
If running with this configuration, users should use the following url to access FREE:&lt;br /&gt;
&lt;br /&gt;
 https://hostname.some_domain:8000/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Apparatus proxy configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also configure all apparatus proxies to use HTTPS.&lt;br /&gt;
the version of the proxy should the the most recent change the '''server_info.ini''' file:&lt;br /&gt;
 HTTPS = True&lt;br /&gt;
&lt;br /&gt;
==== janus configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also further configure janus to also use HTTPS.&lt;br /&gt;
It is necessary to create the certificate similar rto the one used in daphne. Unfortunetly the certificate can not be created in the host (self-signed certificate), '''it must be created by the network administrator of the domain'''.&lt;br /&gt;
&lt;br /&gt;
This certificate should be placed in a system directory before editing the '''janus.transport.http.jcfg''' configuration file:&lt;br /&gt;
*Disable HTTP: http = false&lt;br /&gt;
*Enable HTTPS: https = true&lt;br /&gt;
*define the HTTPS port: secure_port = 8088 - Set the certificate directory:&lt;br /&gt;
**cert_pem = &amp;quot;/some_system_directory/janus_public.crt&amp;quot;&lt;br /&gt;
**cert_key = &amp;quot;/some_system_directory/janus_private.key&amp;quot; In the .env file it is also necessary to update the protocolo of janu from http to https:&lt;br /&gt;
*JANUS_SERVER_ADDRESS=&amp;quot;https://janus-server-address:8088/janus&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== External Authentication ===&lt;br /&gt;
FREE now allows the use of external services from Google and Microsoft for user authentication.&lt;br /&gt;
To configure these services it is necessary to have HTTPS working and have a fixed public numeric address (or DNS name) for the FREE installation (for instance https://free.some-university.edu:8000/) and follow the next instructions.&lt;br /&gt;
==== GOOGLE ====&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/google.html#google-oauth2 / https://developers.google.com/identity/protocols/oauth2?csw=1#Registering:&lt;br /&gt;
&lt;br /&gt;
*access the Google API Console: https://console.developers.google.com/&lt;br /&gt;
*Create a new project&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create Credentials -&amp;gt; OAuth client ID&lt;br /&gt;
*Configure Consent Screen&lt;br /&gt;
**Select External User Type&lt;br /&gt;
**Fill The App information screen (app name, User support email, Developer contact information)&lt;br /&gt;
**Select scopes (may be empty)&lt;br /&gt;
**Add a test user&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create credentials -&amp;gt; OAuth client ID&lt;br /&gt;
**Application Type - Web application&lt;br /&gt;
**Define name &lt;br /&gt;
**Add Authorized redirect URIs&lt;br /&gt;
***append '''/complete/google-oauth2/''' to the installation URL (example: `https://free.some-university.edu:8000/complete/google-oauth2/`)&lt;br /&gt;
**Create&lt;br /&gt;
*Download json or save the Client ID and Client Secret&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_GOOGLE_OAUTH''':&lt;br /&gt;
***FREE_GOOGLE_OAUTH=true&lt;br /&gt;
**copy the value of '''Your Client ID''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'''&lt;br /&gt;
**copy '''Client Secret''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
==== Microsoft ====&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/microsoftgraph.html.html#google-oauth2 / https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app:&lt;br /&gt;
&lt;br /&gt;
*Sign in to the Azure portal: https://portal.azure.com/&lt;br /&gt;
*Manage Azure Active Directory - View&lt;br /&gt;
*Select  App registrations on the menu&lt;br /&gt;
*New registration&lt;br /&gt;
**Define the name of teh application&lt;br /&gt;
**Select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)&lt;br /&gt;
**Define the redirect URI&lt;br /&gt;
***Select a platform - Web&lt;br /&gt;
***to create the URI, append '''/complete/microsoft-graph/''' to the installation URL (exampe: `https://free.some-university.edu:8000/complete/microsoft-graph/`)&lt;br /&gt;
**Register&lt;br /&gt;
**Save the '''Application (client) ID'''&lt;br /&gt;
***this value should be put in the .env file&lt;br /&gt;
**Select Certificates and secrets on the menu&lt;br /&gt;
***New client secret&lt;br /&gt;
***Add&lt;br /&gt;
**Save the '''Value'''&lt;br /&gt;
***this value should be put in the .env file &amp;lt;span style=&amp;quot;color:#FFFFFF; background:#F50000&amp;quot;&amp;gt;'''The secret Value dissapears after closing this page '''&amp;lt;/span&amp;gt;&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_MS_OAUTH''':&lt;br /&gt;
***FREE_MS_OAUTH=true&lt;br /&gt;
**copy  the value of '''Application (client) ID''' to '''SSOCIAL_AUTH_MICROSOFT_GRAPH_KEY'''&lt;br /&gt;
**copy the value of '''Secret ID''' to '''SOCIAL_AUTH_MICROSOFT_GRAPH_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
&lt;br /&gt;
== FREE server execution ==&lt;br /&gt;
to start the FREE server run the following command:&lt;br /&gt;
 daphne freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
By default, the webserver will be available at port 8000. To change the port, pass -p &amp;lt;portnumber&amp;gt; parameter to the daphne command. &lt;br /&gt;
You can also force binding to specific address by -b &amp;lt;address&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copy of Pendulum Information ==&lt;br /&gt;
Since a new database is now being used, it is necessary to copy the various apparatus into the new database.&lt;br /&gt;
&lt;br /&gt;
If running both version at the same time, one of them, should be executed on a different port&lt;br /&gt;
&lt;br /&gt;
On the administration page of the you should copy some of the information from the old database to the new.&lt;br /&gt;
&lt;br /&gt;
here is the list and description of the various fields:&lt;br /&gt;
* Apparatus Type : Pendulum&lt;br /&gt;
* Location - description of the physical place of the pendulum&lt;br /&gt;
* Description - specific characteristics of the pendulum&lt;br /&gt;
* Secret - a random string specific to each pendulum&lt;br /&gt;
* Owner - Name of the person responsible for the operation and maintenance of the pendulum&lt;br /&gt;
* Timeout - leave 60 &lt;br /&gt;
* Configuration - copy the following json and modify accordingly the '''id ''' and '''ports_restrict ''' to suitable values:&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;WP_LIS_IST&amp;quot;, &lt;br /&gt;
    &amp;quot;serial_port&amp;quot;: {&lt;br /&gt;
       &amp;quot;ports_restrict&amp;quot;: [&amp;quot;/dev/ttyS0&amp;quot;], &lt;br /&gt;
       &amp;quot;baud&amp;quot;: &amp;quot;115200&amp;quot;, &amp;quot;numbits&amp;quot;: &amp;quot;8&amp;quot;, &amp;quot;stopbits&amp;quot;: &amp;quot;1&amp;quot;, &amp;quot;partitybits&amp;quot;: &amp;quot;0&amp;quot;, &lt;br /&gt;
       &amp;quot;listening_timeout&amp;quot;: &amp;quot;100000&amp;quot;, &amp;quot;death_timeout&amp;quot;: &amp;quot;10000000&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
* video configuration - either copy the value from the old database or leave empty&lt;br /&gt;
&lt;br /&gt;
== Configuration of Video ==&lt;br /&gt;
In order to have video stream from the Raspberry Pi to the server and then to the browser it is necessary to  verify the following data on the '''.env ''' file:&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
After this configuration is correct it is necessary to assign each pendulum one video stream so that video can go from the pendulum to the server and to the browser.&lt;br /&gt;
&lt;br /&gt;
Open the '''Video Config ''' menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Video-config-menu.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page, a table will contain all the configured pendulums and the associated video configuration:&lt;br /&gt;
&lt;br /&gt;
[[File:Video_Config_table.png]]&lt;br /&gt;
&lt;br /&gt;
In the previous example the first apparatus was automatically configure from the previous identifier copied from the old database.&lt;br /&gt;
&lt;br /&gt;
The second apparatus does not have the video stream configure. To create a video stream and update the database click '''Configure Video '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config assign stream.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page it is necessary to click on the '''Assign Stream ''' button.&lt;br /&gt;
&lt;br /&gt;
If the Janus server is well configure the new page will show the Video Stream Configuration and the data to be copied to the Raspberry Pi:&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config RP data.png]]&lt;br /&gt;
&lt;br /&gt;
= Raspberry Pi Proxy =&lt;br /&gt;
&lt;br /&gt;
Due to changes on the API and the database you will need to make a upgrade to this version of the Proxy.&lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of Proxy (compatible to the Version of the FREE server).&lt;br /&gt;
* For example '''mkdir Proxy_051 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/RPi_Proxy/releases/latest/download/RPi_Proxy_0_5_1.zip &lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip RPi_Proxy_0_5_1.zip -d Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
After that, install the dependent package:&lt;br /&gt;
&lt;br /&gt;
For the Proxy:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3-pip&lt;br /&gt;
&lt;br /&gt;
 pip3 install pyserial&lt;br /&gt;
&lt;br /&gt;
And for streaming the video (for '''gstreamer '''):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-tools&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-good&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-bad&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-ugly&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-base&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For '''ffmpeg ''':&lt;br /&gt;
 sudo apt-get install ffmpeg&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Video Streaming Configuration ===&lt;br /&gt;
&lt;br /&gt;
In order to configure the video streaming process on the Raspberry pi edit the '''video-stream.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
* video_server video_port apparatus_location apparatus_name apparatus_id&lt;br /&gt;
** copy this information from the Video Conf administration page on the FREE server&lt;br /&gt;
&lt;br /&gt;
* usb_camera video_width video_height video_frame&lt;br /&gt;
** find the suitable values depending on the network resources and the information provided by the following commands:&lt;br /&gt;
 v4l2-ctl --list-devices&lt;br /&gt;
 v4l2-ctl -d /dev/videoXXXXX --list-formats-ext&lt;br /&gt;
&lt;br /&gt;
In order to debug and verify the video configuration it is possible to execute the '''video-stream.sh ''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Configuration ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to configure the Proxy on Raspberry pi edit the '''server_info.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
 &lt;br /&gt;
*SERVER : The IP address or domain of your FREE_Web server;&lt;br /&gt;
*PORT : The port of the server by default is the 8000;&lt;br /&gt;
*DEBUG: This can be change to off, after this installation is correctly done;&lt;br /&gt;
*APPARATUS_ID, SECRET: This parameters can be seen on the admin of the FREE_Web server;&lt;br /&gt;
On the apparatus configure page, you will be able to see the APPARATUS_ID on the URL of the page (indicated with the arrow) and the SECRET on the page it self:&lt;br /&gt;
&lt;br /&gt;
[[File:Info for Proxy.png|1220px]]&lt;br /&gt;
&lt;br /&gt;
== Proxy execution ==&lt;br /&gt;
&lt;br /&gt;
In order to debug the various video and apparatus control configuration, the two scripts (video-stream.sh and main.py) can be executed independently on the command line.&lt;br /&gt;
&lt;br /&gt;
After all the parameters are correct, both programs can be executed simultaneously  using the following command:&lt;br /&gt;
&lt;br /&gt;
 nohup sh start-wp.sh &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This command runs until the raspberry pi is rebooted.&lt;br /&gt;
&lt;br /&gt;
To make the Proxy run when the Raspberry pi reboots it is necessary to edit the '''/etc/rc.local ''' and add the following lines before the '''exit 0 ''':&lt;br /&gt;
 sleep 60&lt;br /&gt;
 cd /INSTALLATION_FOLDER/PATH&lt;br /&gt;
 su USER -c &amp;quot;sh start-wp.sh &amp;amp;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace /INSTALLATION_FOLDER/PATH with the output of the following command:&lt;br /&gt;
 readlink -f Proxy_051/&lt;br /&gt;
&lt;br /&gt;
Replace USER the the actual user owner of the proxy.&lt;/div&gt;</summary>
		<author><name>Ist14028</name></author>
		
	</entry>
	<entry>
		<id>http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4612</id>
		<title>WPA FREE 0.6.0 Instalation</title>
		<link rel="alternate" type="text/html" href="http://www.elab.tecnico.ulisboa.pt/wiki/index.php?title=WPA_FREE_0.6.0_Instalation&amp;diff=4612"/>
		<updated>2022-10-10T21:39:56Z</updated>

		<summary type="html">&lt;p&gt;Ist14028: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;= Janus Server=&lt;br /&gt;
&lt;br /&gt;
== Update ==&lt;br /&gt;
If the Janus server is already running with the FREE 0.3.0 version it is only necessary to guarantee that  the admin secret is defined.&lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg ''' file in the '''/var/snap/janus-gateway/common/etc ​''' directory and guarantee that the '''admin_key ''' is defined:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;elab1&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
To install the Janus stream server you will need to run the following commands on your Debian 11 machine:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snap​&lt;br /&gt;
&lt;br /&gt;
 sudo apt install snapd&lt;br /&gt;
&lt;br /&gt;
 sudo snap install janus-gateway​&lt;br /&gt;
&lt;br /&gt;
===Configuration===&lt;br /&gt;
&lt;br /&gt;
The configuration of Janus is done editing a file in the '''/var/snap/janus-gateway/common/etc​''' directory &lt;br /&gt;
&lt;br /&gt;
Edit the '''janus.plugin.streaming.jcfg''' file&lt;br /&gt;
&lt;br /&gt;
Define an administration secret​ by uncommenting the line 104) or the one that contains the '''admin_key''' string= and changing the string to a suitable value.&lt;br /&gt;
&lt;br /&gt;
Define the possible ports that Janus will use to ​receive the video stream from the pendulum by uncomment line 106​) or the one containing the string '''rtp_port_range'''= and define the available ports (for example to 6000-7000​).&lt;br /&gt;
&lt;br /&gt;
Delete the sample pre-configure endpoints by deleting all lines from line 124. &lt;br /&gt;
&lt;br /&gt;
Restart Janus  by running the command:&lt;br /&gt;
 &lt;br /&gt;
 sudo snap restart janus-gateway​&lt;br /&gt;
&lt;br /&gt;
=== Example of Janus Configuration ===&lt;br /&gt;
After the configuration of a newly installed Janus Server the '''janus.plugin.streaming.jcfg''' should only containg the following`&lt;br /&gt;
&lt;br /&gt;
 general :&lt;br /&gt;
 {&lt;br /&gt;
   admin_key = &amp;quot;super_pass&amp;quot;;&lt;br /&gt;
   rtp_port_range = &amp;quot;6000-7000&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
== HTTPS cfigurations ==&lt;br /&gt;
TODO!!!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
= FREE Server=&lt;br /&gt;
&lt;br /&gt;
== New instalation == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Upgrade of previous instalation == &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Follow the first two steps of the installation guide. The commands already contain overwrite switches so that the old version will be overwritten, while '''.env ''' and '''.sqlite''' files won't be touched.&lt;br /&gt;
&lt;br /&gt;
A new release might contain changes to the database structure. If you are preserving your database from a previous version, run&lt;br /&gt;
&lt;br /&gt;
 python manage.py migrate&lt;br /&gt;
&lt;br /&gt;
=== HTTPS configuration ===&lt;br /&gt;
IN order to allow remote OAuth authentication (Google or Microsoft) it is necessary to activate HTTPS.&lt;br /&gt;
this requires the installation of SSL certificates and the execution of daphne in a with a different configuration:&lt;br /&gt;
&lt;br /&gt;
==== Cerificates ====&lt;br /&gt;
FREE should execute with certificates produced by the organization, can use self-signed cerificates temporarly.&lt;br /&gt;
Certificates cshould be generated by the network administrator and installed with the suitable names (free_private.key and free_public.crt) in the '''freeweb/certificates/''' directory&lt;br /&gt;
For testing purposed it is also possible to create a self signed certificate by running the following command on the FREE server:&lt;br /&gt;
&lt;br /&gt;
 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout freeweb/certificates/free_private.key -out freeweb/certificates/free_public.crt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Server execution ====&lt;br /&gt;
After the creation or installation of the certificate the server should be executed as follows&lt;br /&gt;
&lt;br /&gt;
 daphne -e ssl:8000:privateKey=freeweb/certificates/free_private.key:certKey=freeweb/certificates/free_public.crt freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
If running with this configuration, users should use the following url to access FREE:&lt;br /&gt;
&lt;br /&gt;
 https://hostname.some_domain:8000/&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== Apparatus proxy configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also configure all apparatus proxies to use HTTPS.&lt;br /&gt;
the version of the proxy should the the most recent change the '''server_info.ini''' file:&lt;br /&gt;
 HTTPS = True&lt;br /&gt;
&lt;br /&gt;
==== janus configuration ====&lt;br /&gt;
If the FREE server is configured to use HTTPS it is necessary to also further configure janus to also use HTTPS.&lt;br /&gt;
It is necessary to create the certificate similar rto the one used in daphne. Unfortunetly the certificate can not be created in the host (self-signed certificate), '''it must be created by the network administrator of the domain'''.&lt;br /&gt;
&lt;br /&gt;
This certificate should be placed in a system directory before editing the '''janus.transport.http.jcfg''' configuration file:&lt;br /&gt;
*Disable HTTP: http = false&lt;br /&gt;
*Enable HTTPS: https = true&lt;br /&gt;
*define the HTTPS port: secure_port = 8088 - Set the certificate directory:&lt;br /&gt;
**cert_pem = &amp;quot;/some_system_directory/janus_public.crt&amp;quot;&lt;br /&gt;
**cert_key = &amp;quot;/some_system_directory/janus_private.key&amp;quot; In the .env file it is also necessary to update the protocolo of janu from http to https:&lt;br /&gt;
*JANUS_SERVER_ADDRESS=&amp;quot;https://janus-server-address:8088/janus&amp;quot;&lt;br /&gt;
&lt;br /&gt;
=== External Authentication ===&lt;br /&gt;
FREE now allows the use of external services from Google and Microsoft for user authentication.&lt;br /&gt;
To configure these services it is necessary to have HTTPS working and have a fixed public numeric address (or DNS name) for the FREE installation (for instance https://free.some-university.edu:8000/) and follow the next instructions.&lt;br /&gt;
==== GOOGLE ====&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/google.html#google-oauth2 / https://developers.google.com/identity/protocols/oauth2?csw=1#Registering:&lt;br /&gt;
&lt;br /&gt;
*access the Google API Console: https://console.developers.google.com/&lt;br /&gt;
*Create a new project&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create Credentials -&amp;gt; OAuth client ID&lt;br /&gt;
*Configure Consent Screen&lt;br /&gt;
**Select External User Type&lt;br /&gt;
**Fill The App information screen (app name, User support email, Developer contact information)&lt;br /&gt;
**Select scopes (may be empty)&lt;br /&gt;
**Add a test user&lt;br /&gt;
*Credentials&lt;br /&gt;
**Create credentials -&amp;gt; OAuth client ID&lt;br /&gt;
**Application Type - Web application&lt;br /&gt;
**Define name &lt;br /&gt;
**Add Authorized redirect URIs&lt;br /&gt;
***append '''/complete/google-oauth2/''' to the installation URL (example: `https://free.some-university.edu:8000/complete/google-oauth2/`)&lt;br /&gt;
**Create&lt;br /&gt;
*Download json or save the Client ID and Client Secret&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_GOOGLE_OAUTH''':&lt;br /&gt;
***FREE_GOOGLE_OAUTH=true&lt;br /&gt;
**copy the value of '''Your Client ID''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_KEY'''&lt;br /&gt;
**copy '''Client Secret''' to '''SOCIAL_AUTH_GOOGLE_OAUTH2_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
==== Microsoft ====&lt;br /&gt;
Follow the instructions in https://python-social-auth.readthedocs.io/en/latest/backends/microsoftgraph.html.html#google-oauth2 / https://learn.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app:&lt;br /&gt;
&lt;br /&gt;
*Sign in to the Azure portal: https://portal.azure.com/&lt;br /&gt;
*Manage Azure Active Directory - View&lt;br /&gt;
*Select  App registrations on the menu&lt;br /&gt;
*New registration&lt;br /&gt;
**Define the name of teh application&lt;br /&gt;
**Select Accounts in any organizational directory (Any Azure AD directory - Multitenant) and personal Microsoft accounts (e.g. Skype, Xbox)&lt;br /&gt;
**Define the redirect URI&lt;br /&gt;
***Select a platform - Web&lt;br /&gt;
***to create the URI, append '''/complete/microsoft-graph/''' to the installation URL (exampe: `https://free.some-university.edu:8000/complete/microsoft-graph/`)&lt;br /&gt;
**Register&lt;br /&gt;
**Save the '''Application (client) ID'''&lt;br /&gt;
***this value should be put in the .env file&lt;br /&gt;
**Select Certificates and secrets on the menu&lt;br /&gt;
***New client secret&lt;br /&gt;
***Add&lt;br /&gt;
**Save the '''Value'''&lt;br /&gt;
***this value should be put in the .env file &amp;lt;span style=&amp;quot;color:#FFFFFF; background:#F50000&amp;quot;&amp;gt;'''The secret Value dissapears after closing this page '''&amp;lt;/span&amp;gt;&lt;br /&gt;
*Edit .env file:&lt;br /&gt;
**activate '''FREE_MS_OAUTH''':&lt;br /&gt;
***FREE_MS_OAUTH=true&lt;br /&gt;
**copy  the value of '''Application (client) ID''' to '''SSOCIAL_AUTH_MICROSOFT_GRAPH_KEY'''&lt;br /&gt;
**copy the value of '''Secret ID''' to '''SOCIAL_AUTH_MICROSOFT_GRAPH_SECRET'''&lt;br /&gt;
**restart the FREE installation&lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of FREE.&lt;br /&gt;
* For example '''mkdir wpa_free_060 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/FREE_Web_0_6_0.zip&lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip FREE_Web_0_6_0.zip -d wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd wpa_free_060/ '''&lt;br /&gt;
&lt;br /&gt;
Create a new python virtual environment, it should be called '''free-env''':&lt;br /&gt;
 virtualenv -p python3 free-env&lt;br /&gt;
&lt;br /&gt;
Activate the virtual environment:&lt;br /&gt;
 source free-env/bin/activate&lt;br /&gt;
&lt;br /&gt;
You should now see a prefix of (free-env) in your command line. &lt;br /&gt;
&lt;br /&gt;
After that, install the dependent packages:&lt;br /&gt;
 pip install -r REQUIREMENTS.txt&lt;br /&gt;
&lt;br /&gt;
== Installation of New Database ==&lt;br /&gt;
Since the data model was change it is necessary to download and install a new empty database.&lt;br /&gt;
&lt;br /&gt;
This database is configured with two users and the WPA pendulum apparatus types and protocols.&lt;br /&gt;
&lt;br /&gt;
Download the database and put it into the project root:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
wget https://github.com/e-lab-FREE/FREE_Web/releases/latest/download/db_template_0_5_1.sqlite3 -O db.sqlite3&lt;br /&gt;
&lt;br /&gt;
This database contains a Pendulum experiment, as well as two example user accounts.&lt;br /&gt;
* wp-admin - superuser account with access to admin interface&lt;br /&gt;
* wp-guest - guest account&lt;br /&gt;
Both users have a '''temporary123 ''' password. &lt;br /&gt;
&lt;br /&gt;
This password should be changed through admin interface.&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
The application is configured using environment variables. &lt;br /&gt;
&lt;br /&gt;
You can set them using the '''/freeweb/.env ''' file. &lt;br /&gt;
&lt;br /&gt;
There is a '''.env-template ''' file in the '''~freeweb ''' folder, that can be renamed to '''.env ''' :&lt;br /&gt;
 mv freeweb/.env-template freeweb/.env&lt;br /&gt;
&lt;br /&gt;
It is necessary to define correct values for the following variables. Some of these values can be copied form the previous version .env file.&lt;br /&gt;
* PROJECT_NAME, PROJECT_ACRONYMUM, SITE_NAME - Texts that will appear in the page header&lt;br /&gt;
* TIME_ZONE - Time zone setting for that app in '''TZ database name''' from https://en.wikipedia.org/wiki/List_of_tz_database_time_zones#List.&lt;br /&gt;
* FREE_PRODUCTION - set to '''on ''' to enable production mode (disables sensitive error messages etc.)&lt;br /&gt;
* FREE_REVERSE_PROXY - set to '''on ''' to be able to run the FREE behind a reverse proxy&lt;br /&gt;
* FREE_SECRET - String used in hashing function. Set either to a random string of your choice, or generate one here: https://djecrety.ir&lt;br /&gt;
* FREE_ALLOWED_HOSTS - comma separated list of domain names/addresses; only requests to these hosts will be processed by the application. This is necessary to prevent HTTP Host header attacks.&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
== FREE server execution ==&lt;br /&gt;
to start the FREE server run the following command:&lt;br /&gt;
 daphne freeweb.asgi:application&lt;br /&gt;
&lt;br /&gt;
By default, the webserver will be available at port 8000. To change the port, pass -p &amp;lt;portnumber&amp;gt; parameter to the daphne command. &lt;br /&gt;
You can also force binding to specific address by -b &amp;lt;address&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Copy of Pendulum Information ==&lt;br /&gt;
Since a new database is now being used, it is necessary to copy the various apparatus into the new database.&lt;br /&gt;
&lt;br /&gt;
If running both version at the same time, one of them, should be executed on a different port&lt;br /&gt;
&lt;br /&gt;
On the administration page of the you should copy some of the information from the old database to the new.&lt;br /&gt;
&lt;br /&gt;
here is the list and description of the various fields:&lt;br /&gt;
* Apparatus Type : Pendulum&lt;br /&gt;
* Location - description of the physical place of the pendulum&lt;br /&gt;
* Description - specific characteristics of the pendulum&lt;br /&gt;
* Secret - a random string specific to each pendulum&lt;br /&gt;
* Owner - Name of the person responsible for the operation and maintenance of the pendulum&lt;br /&gt;
* Timeout - leave 60 &lt;br /&gt;
* Configuration - copy the following json and modify accordingly the '''id ''' and '''ports_restrict ''' to suitable values:&lt;br /&gt;
 {&lt;br /&gt;
    &amp;quot;id&amp;quot;: &amp;quot;WP_LIS_IST&amp;quot;, &lt;br /&gt;
    &amp;quot;serial_port&amp;quot;: {&lt;br /&gt;
       &amp;quot;ports_restrict&amp;quot;: [&amp;quot;/dev/ttyS0&amp;quot;], &lt;br /&gt;
       &amp;quot;baud&amp;quot;: &amp;quot;115200&amp;quot;, &amp;quot;numbits&amp;quot;: &amp;quot;8&amp;quot;, &amp;quot;stopbits&amp;quot;: &amp;quot;1&amp;quot;, &amp;quot;partitybits&amp;quot;: &amp;quot;0&amp;quot;, &lt;br /&gt;
       &amp;quot;listening_timeout&amp;quot;: &amp;quot;100000&amp;quot;, &amp;quot;death_timeout&amp;quot;: &amp;quot;10000000&amp;quot;&lt;br /&gt;
    }&lt;br /&gt;
 }&lt;br /&gt;
* video configuration - either copy the value from the old database or leave empty&lt;br /&gt;
&lt;br /&gt;
== Configuration of Video ==&lt;br /&gt;
In order to have video stream from the Raspberry Pi to the server and then to the browser it is necessary to  verify the following data on the '''.env ''' file:&lt;br /&gt;
* JANUS_SERVER_ADDRESS, JANUS_STREAM_KEY - Configuration of Janus video streaming server.&lt;br /&gt;
&lt;br /&gt;
After this configuration is correct it is necessary to assign each pendulum one video stream so that video can go from the pendulum to the server and to the browser.&lt;br /&gt;
&lt;br /&gt;
Open the '''Video Config ''' menu:&lt;br /&gt;
&lt;br /&gt;
[[File:Video-config-menu.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page, a table will contain all the configured pendulums and the associated video configuration:&lt;br /&gt;
&lt;br /&gt;
[[File:Video_Config_table.png]]&lt;br /&gt;
&lt;br /&gt;
In the previous example the first apparatus was automatically configure from the previous identifier copied from the old database.&lt;br /&gt;
&lt;br /&gt;
The second apparatus does not have the video stream configure. To create a video stream and update the database click '''Configure Video '''&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config assign stream.png]]&lt;br /&gt;
&lt;br /&gt;
On the new page it is necessary to click on the '''Assign Stream ''' button.&lt;br /&gt;
&lt;br /&gt;
If the Janus server is well configure the new page will show the Video Stream Configuration and the data to be copied to the Raspberry Pi:&lt;br /&gt;
&lt;br /&gt;
[[File:Video Config RP data.png]]&lt;br /&gt;
&lt;br /&gt;
= Raspberry Pi Proxy =&lt;br /&gt;
&lt;br /&gt;
Due to changes on the API and the database you will need to make a upgrade to this version of the Proxy.&lt;br /&gt;
&lt;br /&gt;
== Installation of Source Code ==&lt;br /&gt;
&lt;br /&gt;
Create a new folder for the new version of Proxy (compatible to the Version of the FREE server).&lt;br /&gt;
* For example '''mkdir Proxy_051 '''&lt;br /&gt;
&lt;br /&gt;
Download the Zip file containing the code&lt;br /&gt;
 wget https://github.com/e-lab-FREE/RPi_Proxy/releases/latest/download/RPi_Proxy_0_5_1.zip &lt;br /&gt;
&lt;br /&gt;
Unzip the downloaded file into the new directory.&lt;br /&gt;
* For example '''unzip RPi_Proxy_0_5_1.zip -d Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
Enter the directory containing the code.&lt;br /&gt;
* For example '''cd Proxy_051/ '''&lt;br /&gt;
&lt;br /&gt;
After that, install the dependent package:&lt;br /&gt;
&lt;br /&gt;
For the Proxy:&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3&lt;br /&gt;
&lt;br /&gt;
 sudo apt install python3-pip&lt;br /&gt;
&lt;br /&gt;
 pip3 install pyserial&lt;br /&gt;
&lt;br /&gt;
And for streaming the video (for '''gstreamer '''):&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-tools&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-good&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-bad&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-ugly&lt;br /&gt;
&lt;br /&gt;
 sudo apt-get install gstreamer1.0-plugins-base&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
For '''ffmpeg ''':&lt;br /&gt;
 sudo apt-get install ffmpeg&lt;br /&gt;
&lt;br /&gt;
== Configuration ==&lt;br /&gt;
&lt;br /&gt;
=== Video Streaming Configuration ===&lt;br /&gt;
&lt;br /&gt;
In order to configure the video streaming process on the Raspberry pi edit the '''video-stream.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
* video_server video_port apparatus_location apparatus_name apparatus_id&lt;br /&gt;
** copy this information from the Video Conf administration page on the FREE server&lt;br /&gt;
&lt;br /&gt;
* usb_camera video_width video_height video_frame&lt;br /&gt;
** find the suitable values depending on the network resources and the information provided by the following commands:&lt;br /&gt;
 v4l2-ctl --list-devices&lt;br /&gt;
 v4l2-ctl -d /dev/videoXXXXX --list-formats-ext&lt;br /&gt;
&lt;br /&gt;
In order to debug and verify the video configuration it is possible to execute the '''video-stream.sh ''' command.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Proxy Configuration ===&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In order to configure the Proxy on Raspberry pi edit the '''server_info.ini ''' file.&lt;br /&gt;
&lt;br /&gt;
The following values should be correctly set:&lt;br /&gt;
 &lt;br /&gt;
*SERVER : The IP address or domain of your FREE_Web server;&lt;br /&gt;
*PORT : The port of the server by default is the 8000;&lt;br /&gt;
*DEBUG: This can be change to off, after this installation is correctly done;&lt;br /&gt;
*APPARATUS_ID, SECRET: This parameters can be seen on the admin of the FREE_Web server;&lt;br /&gt;
On the apparatus configure page, you will be able to see the APPARATUS_ID on the URL of the page (indicated with the arrow) and the SECRET on the page it self:&lt;br /&gt;
&lt;br /&gt;
[[File:Info for Proxy.png|1220px]]&lt;br /&gt;
&lt;br /&gt;
== Proxy execution ==&lt;br /&gt;
&lt;br /&gt;
In order to debug the various video and apparatus control configuration, the two scripts (video-stream.sh and main.py) can be executed independently on the command line.&lt;br /&gt;
&lt;br /&gt;
After all the parameters are correct, both programs can be executed simultaneously  using the following command:&lt;br /&gt;
&lt;br /&gt;
 nohup sh start-wp.sh &amp;gt; /dev/null 2&amp;gt;&amp;amp;1 &amp;amp;&lt;br /&gt;
&lt;br /&gt;
This command runs until the raspberry pi is rebooted.&lt;br /&gt;
&lt;br /&gt;
To make the Proxy run when the Raspberry pi reboots it is necessary to edit the '''/etc/rc.local ''' and add the following lines before the '''exit 0 ''':&lt;br /&gt;
 sleep 60&lt;br /&gt;
 cd /INSTALLATION_FOLDER/PATH&lt;br /&gt;
 su USER -c &amp;quot;sh start-wp.sh &amp;amp;&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Replace /INSTALLATION_FOLDER/PATH with the output of the following command:&lt;br /&gt;
 readlink -f Proxy_051/&lt;br /&gt;
&lt;br /&gt;
Replace USER the the actual user owner of the proxy.&lt;/div&gt;</summary>
		<author><name>Ist14028</name></author>
		
	</entry>
</feed>