During the first week of 2018, the entire east coast of the US experienced an unusually cold strong snowstorm. The news coverage was full of exciting terms: bombogenesis, explosive cyclogenesis, and bomb cyclone to name a few. It turns out that bombogenesis is precisely defined in meteorology as a drop in barometric pressure of more than 24 * sin(f)/sin(60) where f is the latitude. This equals 24 millibars at 60 degrees N latitude, and 18.5 millibars in Boston (42 degrees N) where the winter storm hit hardest.
I thought it would be fun to use the Renesas/Medium One Analytics Library together with the S5D9 board to monitor the barometric pressure and use the FCM (Firebase Cloud Messaging) library to send push notifications to the mobile app when bombogenesis conditions have been measured. Of course, the pressure drops necessary for bombogenesis are rare, and the tutorial is easily modified to measure smaller pressure drops that could indicate impending rain. A quick survey of meteorology information on the web reveals that a drop of 3 millibars in 3 hours is considered serious For this tutorial, 3mbar/3hours is the threshold for a bombogenesis alert. By reducing the threshold to perhaps 1 millibar/3 hours this could become an impending rain alert.
This tutorial builds on the earlier tutorial, “Using the Mobile App with the S5D9 Board.” It introduces some of the functionality available in both the Analytics Library and the FCM Library. We also add an extra button to the mobile app which transmits a ‘pressure_request’ that triggers a push notification with the latest pressure measurement.
IoT Controller by Medium One – installed on your mobile device
App available for Android in Google Play Store or the App Store for iPhone
Complete the “Using the Mobile App with the S5D9 Board” tutorial available here:
Using the Mobile App with the S5D9 Board
S5D9 IoT Fast Prototyping Kit
Step 1: Complete “Using the Mobile App with the S5D9 Board”
Your S5D9 board should be online and connected to the project you used in the tutorial. You also need to have created the API user ‘Mobile’. If you completed the tutorial this will all be done.
Also, make sure that you completed the section connecting and setting up the mobile app.
The app on your mobile device should look like this:
Step 2: Configure the Pressure Request Button on the Mobile App
For transmitting pressure data requests to the project, we’ll use a JSON widget. Every time the ‘post’ button on the widget is pressed, a raw:pressure_request is transmitted. This will trigger a workflow which sends a push notification containing the latest pressure measurement.
Click on the ‘+’ button and add a JSON widget. Swipe it to the side to reveal the configuration options. Set the stream to: ‘raw.’
Now, set the tag to ‘pressure_request’ and save it.
The app should now have the 3 widgets configured and ready to use. Make sure the drop down box in the JSON widget screen is set to ‘String.’ There is a field above it which doesn’t display properly due to a bug in the mobile app. I typed ‘hello’ up there, but it can be left blank. The value doesn’t matter because the tag triggers a workflow that doesn’t need a value.
Step 3: Create and Enable the raw:pressure_request Tag
The tag, raw:pressure_request doesn’t exist in your project yet. Press the ‘post’ button to transmit the tag which will be auto-detected by the system. After a minute, navigate to Config:Data Streams:raw in the IoT Sandbox and find the new pressure_request tag. By default it is not enabled, so you have to check the box to its right in order to start using it. Don’t forget to scroll down to the bottom and click save.
Step 4: Create and Activate the ‘Process Mobile Pressure Request’ Workflow
In the Workflow Studio, create a new workflow and name it, ‘Process Mobile Pressure Request.’ Drag a ‘Base Python’ module into the work space and double click on it in order to add a third input. Drag a raw:pressure_request tag into the work space and connect it to ‘in1.’ Drag a raw:FCM_token tag into the work space and connect it to ‘in2’. Finally, drag a raw:pressure_avg tag into the work space and connect it to ‘in3’. The final workflow should look like this:
The raw:FCM_token trigger occurs once when the mobile app first connects to the project. When FCM_token is the trigger, the workflow pushes a message to the mobile app that says ‘Connected to S5D9 Board.’
Every time the mobile user presses the ‘post’ button, the raw:pressure_request triggers the workflow. In this case, the workflow uses the Analytics Library to access the most recently received pressure measurement and pushes it to the mobile app.
By default the S5D9 transmits sensor data to the cloud every 15 minutes. This triggers the workflow with the raw:pressure.avg data. pressure.avg is the average pressure recorded over the previous interval (default 15 minutes). When this occurs, the workflow uses the Analytics Library to look at the current pressure value as well as the previous 12 in order to go back 3 hours (12 * 15 minutes). If 3 hours of continuous data are available, the workflow looks at the pressure difference over the 3 hour period and pushes a ‘Bombogenesis Alert’ to the mobile app if the 3 millibar threshold has been exceeded.
Here is the code to paste into the Base Python module:
''' This workflow handles mobile requests for the latest pressure measurement. It also monitors the barometric pressure for drops of more than 3 millibars in 3 hours. If the mobile app requests the current barometric pressure, the workflow sends a push notification to the requesting mobile device with the current pressure. The S5D9 measures and reports the barometric pressure every 15 minutes. Every time the pressure is updated, the workflow looks at the pressure 3 hours ago and determines if the the pressure has dropped 3 millibars or more during that time. If so, a 'Bombogenesis Alert' is pushed to the mobile device. Created: January 4, 2018 by DK ''' import FCM import Analytics import datetime import DateRange ALERT_THRESHOLD = 3.0 # Change in millibars over 3 hours that triggers the bombogenesis alert #Read the FCM_token as soon as the mobile app connects FCM_token = IONode.get_input('in2')['event_data']['value'] data_sufficient = False # Flag to indicate that we have 13 continuous readings over the last 3 hours #Determine trigger source pressure_request = IONode.is_trigger('in1') mobile_connected = IONode.is_trigger('in2') #Creates a DateRange for the past 185 minutes #Added 5 extra minutes to make sure we don't miss the first reading exactly 180 minutes ago start = datetime.datetime.utcnow() - datetime.timedelta(minutes=185) end = datetime.datetime.utcnow() last_three_hours = DateRange.date_range(start, end) #Get the most recent 13 pressure readings using the Analytics library #Note that this project defaults to a reading interval of 15 minutes #This can be changed if desired, although it is suitable for this application. #13 readings including the current reading stretches back 3 hours pressure_measurements = Analytics.last_n_values('raw.pressure.avg', 13, date_range=last_three_hours, user='Mobile') # list of last 13 pressure measurements pressure = pressure_measurements['raw.pressure.avg'] # current pressure reading pressure_three_hours_ago = pressure #default initialization delta_pressure = 0 #default initialization length = len(pressure_measurements) log ("Length = "+str(length)) #debug if (mobile_connected): FCM.send_fcm_notification_to_m1_application([FCM_token], "Connected to S5D9 Board", sound='chime') elif (pressure_request): # Mobile pressure request FCM.send_fcm_notification_to_m1_application([FCM_token], "Barometric Pressure: "+str(round(pressure,2))+" mb",sound='chime') else: #New incoming pressure measurement if (length == 13): # Only proceed if we have 13 continuous data readings up to the present pressure_three_hours_ago = pressure_measurements['raw.pressure.avg'] delta_pressure = pressure_three_hours_ago - pressure #measurement 3 hours ago minus measurement now data_sufficient = True if ((data_sufficient) and (delta_pressure>=ALERT_THRESHOLD)): FCM.send_fcm_notification_to_m1_application([FCM_token], "Bombogenesis Alert!!!",sound='chime')
Click ‘Save and Activate’. You are now ready to try it out.
Step 5: Test the System
First, press the ‘post’ button to request a pressure reading. You should almost instantly receive a notification through the mobile app that looks something like this:
Testing the bombogenesis alert is a little tricky because you have to wait 3 hours. Also, drops of 3mbar in 3 hours are very rare. We can temporarily change this to 12 minutes by changing the data interval from 15 minutes to 1 minute. You can do this in the ‘Update Sample Periods and Thresholds’ workflow. After you make this change, you must power cycle the S5D9 board.
Also, in our workflow, change the ALERT_THRESHOLD to -10.0 (guaranteed to trigger) and the datetime range to 15 minutes rather than 3 hours so we’re only looking in the last 15 minutes for 13 pressure measurements. See below:
ALERT_THRESHOLD = -10.0 # Change in millibars over 3 hours that triggers the bombogenesis alert #Read the FCM_token as soon as the mobile app connects FCM_token = IONode.get_input('in2')['event_data']['value'] data_sufficient = False # Flag to indicate that we have 13 continuous readings over the last 3 hours #Determine trigger source pressure_request = IONode.is_trigger('in1') mobile_connected = IONode.is_trigger('in2') #Creates a DateRange for the past 185 minutes #Added 5 extra minutes to make sure we don't miss the first reading exactly 180 minutes ago start = datetime.datetime.utcnow() - datetime.timedelta(minutes=15)
After 12-13 minutes you should receive the ‘Bombogenesis Alert.’
Congratulations! You now have the beginnings of a remotely monitored weather station.
Pressure drops large enough to be called bombogenesis are rare. I chose to write this tutorial as a bombogenesis warning because the phenomenon was recently all over the news and many people on the east coast experienced it. I also like using the word bombogenesis!
This would be of more practical value if you reduced the ALERT_THRESHOLD from 3 millibars to perhaps 1 millibar or even ½ millibar. Somewhere in that range you’d have a more helpful ‘poor weather’ alert or perhaps a thunder storm alert.
The main goal of this tutorial was to demonstrate how to use push notifications and how to use the Analytics Library. However, by adding humidity and temperature, you could build out a simple little remotely accessible weather station.
I should also note that as this simple script was written, the bombogenesis alerts keep coming every 15 minutes as long as the pressure continues to drop. A few small modifications would limit the number of push notifications so that after you receive one or two, they stop.