Gateway app usage

As soon as the setup is complete and reboot is performed, the PiGateway app should already be running, just point your browser to your Pi’s IP address or hostname (ex http://raspberrypi/).

The Gateway app source code is published in this Github Repository – updates and bug fixes will be posted there. Releases are published here. Please use this forum to post any questions or report issues/bugs.

Here are the main application files:

Starting, stopping, autostart

The Gateway app is configured through a systemd service to run automatically when your Pi boots. If the application ever crashes or stops for some reason, systemd should keep trying to restart it. To manually start/stop/restart the app you can use these commands:

sudo service gateway start
sudo service gateway stop
sudo service gateway restart

You can check if the gatweway app is running by running this command, you should see two lines that contain gateway.js:

ps aux | grep gateway

In the UI main menu there are now available options to:

  • restart the application
  • restart the Pi host computer
  • shutdown the Pi host computer

Gateway node & data database

The uses neDB to store node configuration, this is located in ~/gateway/data/db/gateway.db. Node metric data (data points like temperature and motion) are stored in individual binary files in the same directory. For instance  temperature data for node with ID 123 would be stored in 0123_F.bin. Each data point is 9 bytes: 1 reserved byte, 4 bytes store the unix epoch timestamp (in seconds) of the data point, 4 bytes store the decimal value.

Gateway app logs

The gateway.js produces logs that are permanently stored in ~/gateway/logs/gateway.sys.log. As this log grows in size it is rotated/compressed with logrotate into archives in the same directory. In the same directory there are simbolic links to the webserver logs starting with v9.1.

Serial input/output formats from the Gateway Moteino

While this app is completely hardware agnostic and does not require a Moteino to run, it is typically used with a Moteino or equivalent Arduino, which is attached to the Pi either via the GPIO hardware serial port (eg. Moteino on pins 14,15 which are attached to /dev/ttyAMA0 serial port) or via the USB ports (ex. MoteinoUSB, MoteinoMEGA-USB, Moteino M0) which would produce a serial port named like /dev/ttyUSBn). The serial port needs to be identified and saved to the settings page, and app needs a restart to use a new port.

When you buy a genuine Moteino or LowPowerLab hardware, you not only support the development of this free app, but you are sure to receive hardware that will out of the box.

This Moteino acts as the RF gateway to your Internet Of Things. If this is a Moteino+RFM module, then all the rest of your nodes will have compatible radio modules, and they send data to the Gateway Moteino which then hands off that data to this PiGateway app via the serial port. The RFM69 library has many examples which run on LowPowerLab hardware (WeatherNode, MotionMote, SwitchMote etc), all you need is to ensure each node will report a unique node ID, to generate distinct nodes in the UI.

The sketch to load on your Gateway Moteino is the PiGateway sketch, not the general use Gateway sketch. This sketch is ready to work with the other RFM69 examples and is already abiding to the required input/output data formats.

You could also use this app with any other hardware that conforms to the expected data formats. For input to the Gateway app, data packets can contain multiple metrics (pieces of data, ex: Temperature:value). These available predefined metrics are defined in metrics.js as regular expressions. The expected pattern is very simple:

[NodeID] metric1:value metric2:value ... [RSSI:XX]

For data going from the Gateway towards your hardware Gateway (which then gets sent to a specific node) the pattern is the following, node that there is no rule to what the message needs to be as long as your end node can interpret and take action on that message:

[TargetNodeID] message

Gateway app self-signed SSL certificate

The Gateway app runs with an autogenerated self-signed SSL certificate. This means browsers will not recognize this as signed by a known CA authority. This is OK  and you will be greeted with the SSL warning page, just ignore that, you are safe. Then the auth_basic prompt where you need to enter the credentials that you placed in the .htpasswd file. The youtube video at the top of this post shows how all this works.

Gateway access from the internet

To access the Gateway app from the internet, you need port forwarding setup on your router. You should forward ports 80 and 443 to your Pi’s local IP address, you should then be able to access this home automation interface from any internet computer or mobile device when you’re on the road.

Resources that will help with understanding the source code: