Nasty Alarm is a network-programmable alarm clock that wont stop ringing until you get out of bed. I felt like it was about time to work on a little embedded project again and as I had this idea in mind for quite a while, I decided to build a prototype. This whole project does not aim to create a serious “product” (although I actually use it on a daily base), but was merely started for practicing some low level C programming.
An Arduino is responsible for handling the alarm sound and stopping it upon movement detection. A simple infra-red movement detection module has been used for that purpose, which has to be positioned in the room accordingly. A Rasperry Pi acts as server that handles everything network-related as well as controlling the actual timer behaviour. When a timer is due, a particular GPIO port of the Raspberry is set to “high” which in turn fires an external interrupt of the Arduino. Using a more sophisticated bus, such as I2C, would of course be preferrable in a production system but for a quick prototype this unidirectional “communication strategy” works fairly well. Also the Arduino is not really necessary as the Raspberry Pi’s GPIO pins are sufficient for the given task. However, I wanted to practice low-level microcontroller programming in C, which is why I bought the Arduino in the first place.
The Arduino IDE/library was not used. Instead I have written code targeted towards the Atmel microcontroller on the Arduino board. The code is compiled manually using
avr-gcc and flashed via the command line using
Again, I have made this choice for the sake of learning and understanding “how to do it the hard way”. I do not see any rational reasons against using the more convenient Arduino tools (except maybe additional dependencies).
The server code on the Raspberry Pi has been written in C as well. That being said, the overall environment is fairly different, because it has a full operating system stack (Raspian) underneath. This means that typical POSIX functionality is available, such as system calls for sockets, file persistence and alarm signals. This makes it easier to implement something as complex as a “server” on a Raspberry than it would have been on the Arduino.
The “protocol” is not very sophisticated, as it currently only expects clients to send TCP packets with strings in “HH:MM” (24h) format for setting the alarm. The client is a simple command line application written in C++ using socket system calls for communication.
Potential Future Improvements
In the future it would be good to implement a simple API that allows clients not only to set but also to query the active alarm time in order to display it to the user. Also, the client has to know the server’s IP, which might be considered inconvenient. Using a network service discovery protocol like DNS-SD for that purpose would be an elegant extension.
Another addition would be a smartphone client, because most people do not want to start their computer, fire a up a terminal and type in a command to set the alarm (although it might sound appealing to us geeks :P). I would love to have a smartphone app that automatically synchronises Nasty Alarm with my phone’s alarm times (maybe with an offset of multiple minutes as to give the user a chance to get up before being “forced to do so”).