OpenSensors.io
Published © CC BY-SA

How to monitor earthquakes with Node-RED

Did you feel that?? Use OpenSensors together with Node-RED to receive email alerts whenever there’s a major quake in a region of interest!

IntermediateFull instructions provided2,989
How to monitor earthquakes with Node-RED

Things used in this project

Software apps and online services

OpenSensors Data Exchange

Story

Read more

Code

The flow JSON:

JSON
[{"id":"e9024ae0.16fdb8","type":"mqtt-broker","broker":"opensensors.io","port":"1883","clientid":"1646"},{"id":"2952b879.d6ad48","type":"mqtt in","name":"EMSC","topic":"/orgs/EMSC/+","broker":"e9024ae0.16fdb8","x":127,"y":104,"z":"82a1c632.7d5e38","wires":[["490a140f.b6f5ec","163677af.e9c988"]]},{"id":"54239d6.fabdc64","type":"mqtt in","name":"USGS","topic":"/orgs/USGS/+","broker":"e9024ae0.16fdb8","x":128,"y":159,"z":"82a1c632.7d5e38","wires":[["490a140f.b6f5ec","163677af.e9c988"]]},{"id":"490a140f.b6f5ec","type":"debug","name":"","active":true,"console":"false","complete":"false","x":538,"y":86,"z":"82a1c632.7d5e38","wires":[]},{"id":"163677af.e9c988","type":"function","name":"parse","func":"// uppercase the payload (different centres report in mixed formats)\nmsg.payload = msg.payload.toUpperCase();\n\n// extracting interesting fields with regular expressions,\n// instead of using JSON.parse which fails with null fields\nvar places_with_ia_regex = new RegExp(\"REGION\\\":\\\"(.*IA.*)\\\",\\\"UPDATED\");\nvar result1 = places_with_ia_regex.exec(msg.payload);\n\nvar magnitude_regex = new RegExp(\"MAGNITUDE\\\":([0-9].[0-9]+)\");\nvar result2 = magnitude_regex.exec(msg.payload);\n\n// if successful, sets topic to the region and payload to the magnitude\nif (result1 && result2) {\n msg.topic = 'EVENT in '+result1[1];\n msg.payload = result2[1];\n return msg;\n}","outputs":1,"noerr":0,"x":296,"y":251,"z":"82a1c632.7d5e38","wires":[["64f4f2ea.9b0b0c"]]},{"id":"64f4f2ea.9b0b0c","type":"switch","name":"at least magnitude 2","property":"payload","rules":[{"t":"gte","v":"2"}],"checkall":"true","outputs":1,"x":428,"y":179,"z":"82a1c632.7d5e38","wires":[["490a140f.b6f5ec","f7bcc59c.084338"]]},{"id":"f7bcc59c.084338","type":"e-mail","server":"smtp.gmail.com","port":"465","name":"ohmygodithappened@gmail.com","dname":"","x":581,"y":256,"z":"82a1c632.7d5e38","wires":[]}]

Published by Google DriveReport AbuseUpdated automatically every 5 minutes

Credits

OpenSensors.io

OpenSensors.io

11 projects • 128 followers
OpenSensors is a real time Internet of Things data exchange.

Comments