Alarms based on an Online Calendar
This project will create a real-world alarm clock that can be setup from an online calendar of your choice. Just create a calendar event with a specific word in it, and your Omega will act as an alarm based on the event’s time and date.
Skill Level: Intermediate
Time Required: 30 minutes
This project requires an online calendar source in addition to the ingredients below. We’ll be using Google calendar in our Step-By-Step, but you can pick any compatible iCalendar source.
The complete project code can be found in Onion’s
iot-gcal-alarm repo on GitHub.
- Onion Omega2 or Omega2+
- Any Onion Dock that exposes the Omega’s GPIOs: Expansion Dock, Power Dock, Arduino Dock 2, Breadboard Dock
- A breadboard (optional, but recommended)
- 1x 100Ω Resistor
- 2x Jumper wires (M-M)
Follow these instructions to setup your very own alarm!
You’ll have to have an Omega2 ready to go, complete the First Time Setup Guide to connect your Omega to WiFi and update to the latest firmware.
2. Install Required Software on the Omega
Connect to the Omega’s Command line and install Python as well as some of the packages we need:
opkg update opkg install python python-pip git git-http ca-bundle
pip to install some additional Python module:
pip install --upgrade setuptools pip install urllib3 python-crontab icalendar
urllib3 module will help make HTTP requests to connect to our calendar source.
icalendar will help parse the calendar data, and
crontab will allow us to create and remove cron jobs for our alarm.
3. Build the Buzzer Circuit
To keep it straightforward, the buzzer will be powered directly by a GPIO. We’ll build it on our breadboard for ease of setup. Feel free to do some soldering or electrical tape if you’d like a more compact alarm.
- Plug the Buzzer across the channel of your breadboard.
- Using a jumper, connect the negative end of the buzzer (the pin WITHOUT a plus sign) to a
GNDpin on the expansion headers
- Plug in a 100Ω current limiting resistor across the (+) row of the buzzer and an empty row.
- Finally, connect the resistor to GPIO1 on the Dock’s Expansion Headers
Once we’re done, it should look a little like this:
4. Download the Project Code
cd /root git clone https://github.com/OnionIoT/iot-gcal-alarm.git
wget to download the three files directly to your Omega:
mkdir /root/iot-gcal-alarm cd /root/iot-gcal-alarm wget https://raw.githubusercontent.com/OnionIoT/iot-gcal-alarm/master/iotGcalAlarm.py https://raw.githubusercontent.com/OnionIoT/iot-gcal-alarm/master/config.json https://raw.githubusercontent.com/OnionIoT/iot-gcal-alarm/master/config.json
Now all of the code will be in the new
/root/iot-gcal-alarm/ directory on your Omega.
5. Setting Up Your Calendar
The calendar can be any calendar you wish, but for the events to be recognized, they have to include
SET_BUZZER string in the event’s title. More specifically, the ‘SUMMARY’ field of the iCalendar event.
We’ll use a Google calendar as an example.
First, go to the settings page of your calendar:
Then navigate to the ‘Calendars’ tab in the settings page. Here, click which calendar your event will be in:
The green ‘ICAL’ button next to ‘Private Address’ will be a direct link to your up-to-date calendar in the
.ics format - this is it! To get the link, right click, and hit the ‘Copy Link Location’ button.
config.json from the repo, and paste the link as the value to the “icalAddr” key - replacing
6. Run the Code
Let’s run the code!
The script will read the calendar data from your source, and add a cron job for every event in the future with the keyword
SET_BUZZER. It will also clear any cron jobs that have already been run - only for up to a year, since cron does not keep track of year data.
7. Schedule the Code to Run Once a Day
Now we’ll use the trusty
cron Linux utility to schedule the script to run once a day at midnight to update our other cron jobs.
crontab -e to add the task, it will open the crontab file in vi, add the following lines:
0 0 * * * python /root/iot-gcal-alarm/iotGcalAlarm.py #
cron daemon for the changes to take effect:
iotGcalAlarm script will run every day at midnight, updating your alarms based on calendar events that have the
Check out the Omega documentation for more info on using
You’re all set, your Omega will now automatically set off alarms based on your calendar events!