Announcing Pytomation remote Raspberry Pi ineterface - RpiGpioRemote

11 views
Skip to first unread message

George Farris

unread,
Feb 27, 2018, 8:14:51 PM2/27/18
to pytomation
Greetings all,

Today I pushed the remote support for Raspberry Pi's to the Python3 branch of Pytomation.

The RpiGpioRemote is configured similar to the RpiGpio interface except it includes a few parameters to start
a server on a specific IP address and IP port.  It also supports ssl encryption and shared secret support.
All configuration options for the GPIO support is done as per normal, in your Instance file.  The client will run, connect
to Pytomation and get all it's configuration options from the server.


The Instance file configuration is:

1) Include RpiGpioRemote in your import like so.
from pytomation.interfaces import Serial, InsteonPLM, PhilipsHue, \
                                StateInterface, Command, PytoWebSocketServer, RpiGpioRemote

2) Define an instance of the interface.
rpi = RpiGpioRemote(address='0.0.0.0', port=8088, pin_layout='BCM', secret='my shared secret')

The ip address of 0.0.0.0 should ideally be the address of the interface you are serving from, but 0.0.0.0 will work as well.
You can check the documentation for complete details.

3) Set the direction and options of the GPIO pins
rpi.setPin(17, 'IN', pud='PULL_UP', invert=True)
rpi.setPin(23, 'IN', pud='PULL_DOWN', invert=False)
rpi.setPin(26, 'OUT', init='LOW')

Here is and input and output example:
d_mt = Door(17,rpi,name='testy')

l_mtl = Light(address=26, devices=(rpi,), name='me test')


The remote client is configured as follows:

The rpi_remote_client.py client will only run on versions of Python 3.4
or higher.

Setting GPIO pins
--------------------------
Please see above.

Running on the Pi
--------------------------
You can choose to run the client manually or automatically on boot.

First make sure the rpi_remote_client.py file is executable. 
"sudo chmod +x rpi_remote_client.py"  will do the trick or use your favourite
file manager.

For manual use, run from the current directory, ./rpi_remote_client.py

For automatically running at boot, first make sure /etc/rc.local file executable so it
runs at boot.  Now add this line to your /etc/rc.local file:
  su pyto -c "sleep 20;/home/pyto/rpi_remote_client.py 1>/dev/null" &

This assumes you have a user "pyto" and the rpi_remote_client.py file
is in the pyto user $HOME directory.  To run as the default "pi" user, change
the line like this.
  su pi -c "sleep 20;/home/pi/rpi_remote_client.py 1>/dev/null" &


Settable parameters:
--------------------------
You must edit the "rpi_remote_client.py" file and change the following
parameters before execution.

host=<string>    Host name or IP address of your Pytomation server.
port=<int>       IP port of your Pytomation server.
secret=<string>  Shared secret contained both here and in your instance file
                 on your server. This is a string that should be between 8 and 32 characters
                 in length and contains ascii printable characters.

sslcert=<string> OPTIONAL: Path to an openssl cert for encrypting the link.
                 You do not require encryption.

If you want to use encryption you must generate a certificate|key pair for your
Pytomation server.  You can use the following command and I have provided an
example run as well.

  openssl req -x509 -newkey rsa:2048 -keyout selfsigned.key -nodes \
          -out selfsigned.cert -sha256 -days 1000

Your Pytomation server must have both the cert and key, the client only
requires the cert file.

When generating a cert|key pair you should use the host name of your Pytomation
server.  Here is an example:

    $ openssl req -x509 -newkey rsa:2048 -keyout selfsigned.key -nodes \
           -out selfsigned.cert -sha256 -days 1000
    Generating a 2048 bit RSA private key
    ......................................................+++
    ......+++
    writing new private key to 'selfsigned.key'
    -----
    You are about to be asked to enter information that will be incorporated
    into your certificate request.
    What you are about to enter is what is called a Distinguished Name or a DN.
    There are quite a few fields but you can leave some blank
    For some fields there will be a default value,
    If you enter '.', the field will be left blank.
    -----
    Country Name (2 letter code) [AU]:CA
    State or Province Name (full name) [Some-State]:British Columbia
    Locality Name (eg, city) []:Victoria
    Organization Name (eg, company) [Internet Widgits Pty Ltd]:Personal
    Organizational Unit Name (eg, section) []:
    Common Name (e.g. server FQDN or YOUR name) []:pytomation    <---your server host name or ip
    Email Address []:

    Store your cert file in the same location as this file.

That's all, enjoy.

George

David

unread,
Feb 28, 2018, 2:31:01 AM2/28/18
to pytomation
From the looks of it you should also be able to use the same cert/key pair from your Pytomation web server SSL, or visa versa.

If you use the SSL instructions from the Readme.md though, you should use your CA cert on the remote client.

Would it be possible run the pi client, without specifying the cert, if the CA cert was copied to /usr/local/share/ca-certificates and update-ca-certificates was run, or if you used an already trusted CA to generate your cert/key pair?

George Farris

unread,
Feb 28, 2018, 10:54:06 AM2/28/18
to pytom...@googlegroups.com
On Tue, 2018-02-27 at 23:31 -0800, David wrote:
> From the looks of it you should also be able to use the same cert/key
> pair from your Pytomation web server SSL, or visa versa.
>

Yup it's true you could.

> If you use the SSL instructions from the Readme.md though, you should
> use your CA cert on the remote client.
>
You most certainly could, I made the instructions simple enough to get
anyone running as quickly as possible.

> Would it be possible run the pi client, without specifying the cert,
> if the CA cert was copied to /usr/local/share/ca-certificates and
> update-ca-certificates was run, or if you used an already trusted CA
> to generate your cert/key pair?
>

Yes that support should be added.
> --
> You received this message because you are subscribed to the Google
> Groups "pytomation" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to pytomation+...@googlegroups.com.
> To post to this group, send email to pytom...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages