Home - SmartMilk/SmartMilk GitHub Wiki
Overview
The Problem
When sharing a house with lazy flatmates or family members, there are often times when they will leave the milk out of the fridge and forget to put it back in (e.g before going out or going to bed), which can lead to the milk being unnecessarily spoiled long before its expiry date. According to the Food and Drug Administration (FDA), the proliferation of the harmful bacteria that cause this is most enhanced when pasteurised milk has been left out at room temperature for more than 2 hours [1].
The Solution
SmartMilk is a simple, but effective embedded programming system that monitors the temperature of the milk in real time, alerting the user's smartphone when the milk has been left out of the fridge for too long.
How it works
The temperature sensor's probe is placed inside the user's milk container (ideally this would be a re-usable bottle/container) and monitors the temperature of the milk. The sensor communicates with the RPi (located externally) using Dallas 1-wire communication protocol. When certain milk temperature measurements are recorded, the RPi will alert the user by sending specific notifications to their smartphone on the condition of their milk via the Prowl app. This all starts when the user leaves their milk out of the fridge.
Three messages will be communicated to the user's phone:
- After 15 minutes, a message will be sent to warn the user that they have left their milk out of the fridge, and prompt them to put it back. This message is for those still at home who have merely forgotten about the milk.
- When the milk has reached room temperature [2], the user will receive another notification warning them that they now have two hours to return it to the fridge. This message is sent after the milk temperature has remained around room temperature for 20 seconds.
- The final message will inform the user that their milk has been at room temperature for two hours, and that they should throw it out and buy more (as its highly recommended not to drink such milk!).
Additional graphical output will be sent to a PC monitor which uses Qt5 to display the temperature of the milk (Tmilk) in real time, with buttons for displaying temperature in Celsius or Farenheit. The overall system can be viewed in the diagram below.
Figure 1: Schematic of SmartMilk
Hardware
The hardware listed below are the essentials needed to get the program up and running, but in order gain full utility of the program, we recommend you check out the "Getting the most out of SmartMilk" page which will show you how you can use our program the way we intended it!
- Raspberry Pi (we used Model B Rev 2)
- DS18B20 Waterproof Temperature Sensor
- 4.7k Ohm pullup resistor
- Breadboard/PCB configuration
- iPhone
- Milk, although if you're worried about the condition of other consumable liquids you can adapt the program
To set up the electrical connections, check the 'Circuit and PCB' page for reference.
Configuring the RPi
The following libraries and packages need to be installed on to your Pi:
- Qt5:
sudo apt-get install qtdeclarative5-dev-tools libqwt-qt5-dev
- Prowl dependencies:
sudo apt-get install libwww-perl
Getting the RPi-iPhone communication working
Command-line test
For this project the 'Prowl' app was used, which sends messages to the iPhone automatically upon certain temperature measurements. To get this up and running, you need to do a quick command-line test run first to make sure it's all working.
Phone (iPhone only)
First you'll need to get Prowl on your smartphone:
- go to https://www.prowlapp.com and create a prowl account (username and password).
- generate an API key (for linking the RPi and phone). This makes sure you send notifications to the right phone!
- download Prowl from app store (price: £2.99) onto your iOS device.
- open the app and log in using credentials.
RPi
We utilise the perl script written for the Prowl application (written and developed by Zachary West: see description in the perl script), and have edited the original script to send three distinctive messages.
From your pi's home directory:
- Make sure the perl scripts are authorised and executable (see README.md).
- Take a note of the API key (from https://www.prowlapp.com/api_settings.php) and copy and paste it into the prowlApiKey.txt file.
- The last thing is now to send a test message to your phone from the RPi command-line. For the first message, run the first perl script using:
./prowl1.pl
After a few seconds you should get a message on the RPi command line:
Notification successfully posted.
closely followed by a notification on your iPhone. If this works, then the communication protocol is sorted and you'll know that the automatic transmission/receiving of messages will work too (see Software page).
Specify options
You can access the prowl.pl
scripts to specify the message contents from the nano
editor. We have defined these within three separate scripts (prowl1, prowl2 and prowl3) for each of the three messages, but you're free to change them as you see fit. Do this from the $options
commands from line 51 onwards.
Team Roles
Alexander Jamieson - Data Acquisition, Hardware, GUI, Debugging
Calum MacLellan - Communication, GUI, Wiki handling, Debugging
References
[1] Cold food storage advice by the Food and Drug Administration (FDA). Accessed Feb. 21 2018. URL: https://www.fda.gov/Food/ResourcesForYou/Consumers/ucm253954.htm
[2] Room temperature values according to the World Health Organisation (WHO). Accessed March 10 2018. URL: http://www.bbc.co.uk/news/magazine-12606943
[3] Munsch-Alatossava P, Ghafar A, and Alatossava T: Potential of Nitrogen Gas (N2) Flushing to Extend the Shelf Life of Cold Stored Pasteurised Milk. Int. J. Mol. Sci.: 14; pp. 5668-85, 2013. doi:10.3390/ijms14035668