👉🏼 Please also refer to the accompanying Github Repository.
Node-RED is a low-code tool for working with IoT data. It natively works with the JSON format which the OpenEEW sensor outputs, making it fast and easy to use. It also provides plugins, called
nodes, that can take data from an MQTT broker, output to email, write to a database, and much more.
This tool allows you to make
flows which are visual representations of data being processed. We encourage you to use the flows we create, and share flows that you have made.
Whilst most of what you may want to do requires simply connecting and configuring the
nodes, for advanced work such as creating new
Node-RED can be installed on many systems, from a Raspberry Pi to a virtual machine in the cloud. You can find instructions here.
For local deployment you can simply run an instance on a laptop, and when you are ready you can re-use your flows in a production environment.
Reading OpenEEW sensor data
The very first task should be reading real-time data from your sensors. To do this you will need an MQTT node and the credentials for connecting to the MQTT broker. If you are reading directly from an OpenEEW cluster, then you can access the credentials here. If you are hosting your own MQTT broker, then you will use the credentials you have created.
Simply connect your
MQTT node with a
debug node, and in the debug panel you will see your data live!
Each sensors sends a single message per second, with the following structure:
The timestamp from the moment each array of 32 readings is received by the accelerometer is denoted by
t. The sensor rate, typically 32hz or 125hz, is denoted by
sr. The individual accelerations are found in their respective axis,
z. The accelerations are in gal units, where 1 gal equals 1 cm/s2.
Detecting peak accelerations (PGAs)
As a simple trigger, you can simply set a threshold that alerts on high accelerations from the sensors. The following code can be inserted into a
This node will declare an earthquake when it detects values above 3 gals. Of course this will not filter out accelerations from other events, such as passing vehicles or slamming doors.
Running the traces through an STA/LTA (Short-Term Average/Long-Term Average) node before the PGA node will help filter out non-earthquake accelerations.
To create an STA/LTA function node, you will need to do the following:
- Take the first 10 messages of data for each sensor (approximately 10s) and for each axis take the average of the absolute values.
- Take the final 1 message worth of data for each sensor (approximately 1s) from this same 10 message window and again take an average reading of the absolute values for each axis.
- The average value taken from the 1 message window should be divided by the value for the 10 message window.
Repeat this every second to obtain a new STA/LTA value. Experiment with OpenEEW historic data to establish a good threshold for this value, based on the typical earthquake magnitudes in your region.