As soon as the setup step is complete, assuming everything went well, the Gateway 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 restart it. To manually start/stop/restart the app you can use these commands:
sudo systemctl start gateway
sudo systemctl stop gateway
sudo systemctl restart gateway
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
You can also restart the application from the UI (the app simply stops itself via an exit call, then systemd restarts it). This self-restart option is available on the main menu. This can be useful if you make code changes in the user metrics or main source code. Note that if you change back-end nodeJS source code (in any of the .js files) and there is a bug, the app will crash upon restart, and you will see the errors in the logs/gateway.sys.log file.
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
All stdout and stderror and console output from the gateway.js app will be logged in /home/pi/gateway/logs/gateway.sys.log. As this log grows in size it is rotated/compressed with logrotate into archives in the same directory.
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 or MoteinoMEGA on pins 14,15 which produce a serial port named /dev/ttyAMA0) or via the USB ports (eg. MoteinoUSB, MoteinoMEGA-USB, Moteino M0 which would produce a serial port named like /dev/ttyUSBx). The serial port needs to be identified and saved to the settings page, and app needs a restart to use a new port. By default the app comes with a /dev/ttyAMA0 setting (GPIO serial port).
When you buy a genuine Moteino or LowPowerLab hardware, you support the development of this nice app and other research by LowPowerLab, and it’s a nice way to give back for the free stuff you get here 😉
This Moteino acts as the hardware 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 Gateway 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:
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: