High Level Code Overview:
Variable initialization then check for weather alerts the first time followed by starting the fetch timer(default set at 10 min) and then set up and register the interrupts.
Next enter the while loop forever and check for button presses to toggle visual alerts, fetch todays weather and weather alerts or fetch tomorrow’s weather. If any alerts exist then display them if enabled. All of this is done in parallel with the main while loop which checks for button presses.
Lower Level Code Overview:
Initialize variables, check WeatherAlerts the first time the code is run, start the fetch_timer function, setup_and_register_interrupts then loop forever while checking for button presses, modifying the LED state as needed and spawning a thread to display_events of the RGB LEDs. Exit the while loop if a keyboard interrupt is generated(only used when running the script from the command line) and run the shutdown function.
Removes unnecessary files, turns off the LED, stops the fetch timer thread from running. Future functionality will be to power the system down by pressing and holding a button. Currently you need to remotely login and type ‘sudo shutdown -h now’ to safely power off the AlertTube
Check alert state, if True then adds the LED sequence to the to-do list else if False then remove the RGB LED sequence from the to-do list. Then cycle through the to-do list and display the RGB LED sequence. LED options are solid|snooze|blink|die RRR GGG BBB intensity(0-100) RRR|GGG|BBB take values between 0-255
Determine if the aplay command is currently running. Returns a True if no wav file is playing else returns a false. This function makes sure we don’t try to play a sound, when one is already being played.
Play a short beep for the user indicating that the button has been pushed to fetch today’s weather forecast from the Nation Weather Service(USA weather only) and strip out any color escape codes. The color escape codes are used when this script is run from a command line prompt. Next, send today’s weather forecast text to a text to speech engine on the web, which converts the text to speech in the form of a .wav file. Lastly play the wave file with today’s weather forecast.
Play a short beep for the user indicating that the button has been pushed to fetch tomorrow’s weather forecast from the Nation Weather Service(USA weather only). Next, send tomorrow’s weather forecast text to a text to speech engine on the web, which converts the text to speech in the form of a .wav file. Lastly play the wave file with tomorrow’s weather forecast.
Expand certain abbreviations; remove certain words that weren’t useful to say and rephrase certain things to sound better when the were converted from text to speech.
If sunny or clear in the forecast then return True, else False
If cloudy or overcast in the forecast then return True ,else False
If snow tomorrow and a greater than X% chance of precipitation then return True, else false
If rain tomorrow and a greater than X% chance of precipitation then return True, else false
Call fetch_weather and fetch_mail every CHECK_DELAY minutes. Currently set to 600 sec = 10 minutes.
Try to fetch the temp, current conditions and today’s weather forecast from the web, if not then wait 30 seconds and try again. If there’s a new weather alert then play the alert sound. If it’s before 18:00 hours then save the forecast for today, otherwise if it’s after 18:00 hours then save the forecast for tonight.
Try to check emails X(currently set to 1) number of days back(i.e. today) and from firstname.lastname@example.org. If the email matches a Personal Recipe number then find the interesting part of the email alert and save it. Once that has been done delete the email, so we don’t have to worry about processing it ever again. As the code is currently written Personal Recipe 3430936 is matched, which means that we know this alert is a Stock Alert, so we save the interesting part of the email and convert it from text to speech and then play it. The same goes for Personal Recipe 3439586, if we match that Personal Recipe number then we know that the email is a calendar alert, so we set calendar_alert to True, which will result in a blue flashing RGB LED alert until the next time the mail is fetched again, which is 10 minutes by default. If we aren’t able to check emails then wait 30 seconds and try again.
Try to fetch alerts from the National Weather Service (USA only). If we’re not able to then try again in 30 seconds. If the alert is severe then return true else false, or if the alert is major then return true else false, or if the alert is moderate then return true else false, or if the alert is minor then return true else false.
Turn off all LEDs via the ws2801 module of pigredients, which controls the SPI bus.
Display a growing and shrinking RGB LED sequence via the ws2801 module of pigredients, which controls the SPI bus. This is similar to the LED effect on Apple laptops when they’re sleeping.
Display a blinking RGB LED sequence via the ws2801 module of pigredients, which controls the SPI bus.
Display a random flickering RGB LED sequence via the ws2801 module of pigredients, which controls the SPI bus.
Display a solid RGB LED sequence via the ws2801 module of pigredients, which controls the SPI bus.
Try to read the state of GPIO4, GPIO23, and GPIO24. If we get an error, wait a quarter second and try again.
GPIO export Raspberry Pi P1 pins 7, 16, 18, and 22 for GPIO. Setup GPIO pins by setting the direction to in with a rising edge. Lastly create a polling object and register GPIO pins.