Gateway setup on Raspberry Pi

To use the gateway, you need to configure it first. This article guides you throught the setup on Raspberry Pi.

Setup

1. Generate registration token

Login with the client mobile app, and add a new gateway. The app generates you a registration token. Use this token to register the gateway.

2. Register the gateway

Registering the gateway will add the gateway to your account. With the token from the previous step, run

meazurem-gateway register -token your_token

3. Scan for sensors

To scan the nearby RuuviTags, run

meazurem-gateway scan

The software will list all tags it finds. To match an address with the physical tag, use the RSSI and temperature to pick the correct one.

4. Add sensors

To add a sensor to the service, run

meazurem-gateway add -address address_of_the_tag -hardware 1 -name "Name of the tag" -period 5

Where address is the address from the previous scan step, hardware is the hardware number from the previous step, name is a given name for the tag, and period defines the update period in minutes [1-60].

Execution

First, to test the setup, run

meazurem-gateway run

This command starts the gateway. It connects to the Meazurem service and starts uploading measurement data in a minute.

Check from the client mobile app that the gateway is detected and that it is online.

You should also get the sensor data in your client app soon. The app will refresh the readings automatically in few minutes. To force an immediate refresh, you can use pull-down-to-refresh in the list views.

When everything is looking good, you can start the gateway as daemon to detach it from your terminal session.

First, stop the running gateway with

ctrl + c

Start the gateway as a daemon

To start the gateway as a daemon, run

meazurem-gateway daemon

You can also stop the gateway when it’s running as deamon.

First, find the PID of the command. Run

ps -e | grep meazurem

Check the PID number. It’s the first number on the row.

Second, send a signal to the process. Run

kill -n 2 1234 where 1234 is the PID number from the previous step.

Or to combine the previous, run

kill -n 2 `ps -e | awk '/meazurem/{print $1}'`

The gateway will now shutdown gracefully. If you kill the gateway otherwise, some resources, such as Bluetooth, stays reserved at least for some time.

Start the daemon automatically at boot

To start the gateway automatically at a boot, open the rc.local file

sudo nano /etc/rc.local

and add line

su pi -c '/usr/bin/meazurem-gateway daemon'

before the exit 0 line. The added command will run meazurem-gateway daemon as a user called pi. If you are using username other than that, change the line accordingly. It’s important to run the gateway with the same user that was used for the configuration.

Troubleshooting

Starting the gateway without any arguments or invalid arguments, will print you a help.

meazurem-gateway

If case something goes wrong, the software should provide an error message. It will also write errors to a log file.

When running the gateway as daemon, the software writes to syslog. To check the log, you can run

cat /var/log/syslog

Otherwise, the logfile used is located at

~/.meazurem/meazurem.log

If the gateway is not shutdown clean, it might cause errors in subsequent launches. For example, the Bluetooth might not be available.

If you need to restart the Bluetooth, run

sudo service bluetooth restart

Extra resources

It is recommended to add a watchdog to monitor the gateway process. In case the process dies for some reason, the watchdog tries to restore the functionality. For watchdog configuration and usage, see Raspberry Pi with a Watchdog.

Get Meazurem on your phone!

Download the app and get started for free.