Difference between revisions of "Install REST"

From xPL
Jump to: navigation, search
Line 45: Line 45:
 
For Debian and related distributions such as Ubuntu, a dedicated option is to use:
 
For Debian and related distributions such as Ubuntu, a dedicated option is to use:
 
  sudo apt install libmojolicious-perl
 
  sudo apt install libmojolicious-perl
 +
 +
Download the [http://www.dspc.ch/xPL/Downloads/xpl-homeStateRest.pl xPL home state REST interface] script.
  
 
Once installed, one can test the service with:
 
Once installed, one can test the service with:
Line 50: Line 52:
 
  REST_SERVICE_DIRECTORY='/home/control/Documents/Controls'
 
  REST_SERVICE_DIRECTORY='/home/control/Documents/Controls'
 
  morbo -l <nowiki>http://*:$REST_PORT</nowiki> $REST_SERVICE_DIRECTORY/xpl-homeStateRest.pl
 
  morbo -l <nowiki>http://*:$REST_PORT</nowiki> $REST_SERVICE_DIRECTORY/xpl-homeStateRest.pl
This starts an HTTP service, usually on port 3000.
+
This starts an HTTP service.
 
Each time the Perl script is updated, the service is updated too.
 
Each time the Perl script is updated, the service is updated too.
 
Interpretor errors are displayed in the terminal in whick the [https://mojolicious.org/perldoc/morbo morbo] runs.
 
Interpretor errors are displayed in the terminal in whick the [https://mojolicious.org/perldoc/morbo morbo] runs.

Revision as of 15:42, 25 May 2020

Controlling the home from distance can be made via standard web access methods such as the RESTful API.

Different options are available for the implementation of such a service:

  • Installing a web server and writing CGI scipts
  • Writing scripts serving a TCP socket and complying to the HTTP scheme
  • Using a framework such as:

I have chosen Mojolicious Lite for its simplicity and the ease of development.

Before all, make sure you have installed an xPL hub together with the xPL state monitor.


Install Mojolicious Lite

Mojolicious::Lite can be installed with the standard CPAN method. For Debian and related distributions such as Ubuntu, a dedicated option is to use:

sudo apt install libmojolicious-perl

Download the xPL home state REST interface script.

Once installed, one can test the service with:

REST_PORT=33865
REST_SERVICE_DIRECTORY='/home/control/Documents/Controls'
morbo -l http://*:$REST_PORT $REST_SERVICE_DIRECTORY/xpl-homeStateRest.pl

This starts an HTTP service. Each time the Perl script is updated, the service is updated too. Interpretor errors are displayed in the terminal in whick the morbo runs.

Test the service in another terminal window:

REST_PORT=33865
curl -X GET localhost:$REST_PORT/state/study/lights/ceiling && echo

Check the result in:

cat /tmp/xpl-homeStateRest.log