RPi: Streaming raspberry shake data to node-red

Goal:

Learn how to send seismology data from a raspberry shake into a separate raspberry pi with node-red. And how to use the data once it arrives.

 

Resources:

Raspberry shake, setup following this guide: https://t3alliance.org/rpi-setting-up-a-raspberry-shake/

A separate raspberry pi with node-red, running on the same network

Introduction:

Raspberry shake usually processes its own data, and publishes it to it’s own public databases. However it is possible to configure raspberry shake to send a raw data-stream from itself to any device your network can reach. Raspberry shake uses a UDP stream to send data from itself to any list of ip addresses and ports that happen to be listening. Using this raw data stream you can create your own graphs, or set up alerts and triggers in node-red.

This means that the raspberry shake could be physically located anywhere in a building, or using the proper networking setup anywhere in the world and you can still comfortably receive the data in node-red on your own computer.  Imagine an email alert being sent-out by your RPi at home, because your RPi shake at school detected some unusual vibrations.  Or you could trigger a camera to go off, and email you a picture whenever footsteps were detected in your room, the possibilities are endless!

 

What is UDP?

When stuff is sent over the internet it is sent using a protocol, which is a way of organizing data so that both parties know what’s going on. If you made an agreement with a friend to always use red envelopes when a message was urgent, that would be an example of a protocol. Most of the time when you download a file, or send an email it is sent using TCP protocol; which is rather strict. For example, if something messes up and the TCP packets (analogous to envelopes with letters inside) arrive out of order, they will be reorganized and only sent to the destination when everything is sorted out. UDP is much less strict, and is more like a raw flow of data vs an orderly sequence of letters. If UDP packets arrive out of order, or have some missing, or even if the data inside is messed up they’ll usually be sent straight along to the destination.  This is useful in projects like our seismometer because it is more lightweight with less latency, also it comes with a feature called multicast which allows a data stream to be sent to multiple destinations at the same time; which is exactly what is possible with the raspberry shake.

Getting Started:

The first thing you’ll need is the IP address of the pi that will listen for the data, this can be found just by hovering over the network applet here. The easiest way to ensure the listening pi and the shake-pi are on the same network is to plug them both into the same router using ethernet cables. Otherwise setting up a WiFi connection on the shake can be tricky and even interfere with the measurements.

Connecting to the rs.local  or raspberryshake.local or even the ip_address:80 of the shake,

From the settings page, come to the UDP streams tab

Here is where you’ll need the ip address of your listening pi, it’s also important to make sure it’s connected to the same network as the shake. If the shake is using LAN this means you’ll probably have to plug your pi into LAN to.

Here I’ve entered the IP of my listening pi, and used the default port 8888

Click the plus button and don’t forget to hit save.

 

Reading the stream on raspberry pi:

Starting with a fresh flow, we’ll drag the UDP IN node in.

 

For the configuration chose the same port as we used in the rs.local config, that would be 8888, and make sure to set output to ‘a String’ instead of ‘Buffer’.
If you hook your UDP RECIEVER up to a debug node you should already be able to see a stream of data coming in, if not something is wrong with your connection (probably raspi isn’t on the same network as raspberry shake).

Next we need the raspberry shake parser node, made by the guys who build the SHAKE.
This can be installed by going into the palette manager, as of now it’s the only result when you search ‘shake’.
The installation will take a few minutes, and then you can chain it with the UDP node like so.

All the rshake parser node does is take the raw thing outputted by the UDP node, and turn it into an object with various data sorted into properties. Using a a debug node we can examine the output. For example, the ‘channel’ property allows you to discriminate between different sensors on the shake. We are using a raspberry-shake ‘1D’  so we only get one channel ‘EHZ’.

 

Now that we have received the data through the UDP ports, we can start to use the data. The data can be used as any other variable data sensor data, and to practice using the data follow the links below.

To make a real-time, Dashboard Seismogram: https://t3alliance.org/rpi-building-a-raspberry-shake-applausemeter-in-node-red/

To make a Shakemeter: https://t3alliance.org/rpi-building-a-raspberry-shake-seismogram-in-node-red