The “I’m Fine” project is about monitoring the well being of especially lonely elderly people, who may not have daily contact to the family.
Things used in this project
Story
I have a complete description of this project on my GitHub repository. You can also go there to read about my project.
Project Overview
The “I’m Fine” project is about monitoring the wellbeing of especially lonely elderly people, who may not have daily contact to the family or other people. In this project I have chosen to represent the typical user as “Grandma“.
This project provides a simple solution to help monitor people in a non intrusive way. By pressing a simple button a few times a day it can be signaled that I’m Fine and no help is needed. If the regular signalling stops, the system detects this and sends out email alerts to the family members, who can then take proper response. This ensures that in case of a personal problem preventing the person from pressing the button, help can come in hours instead of days or maybe even longer..
System concept drawing
Future options
The implementation on the Arduino/Genuino MKR1000 device side is intentionally kept simple, with very few features, but the system can easily be expanded with other types of sensors. Sensors like movement detection using a PIR sensor, a smoke detector to detect fire, a temperature sensor to detect abnormal temperatures in the house and so on.
This project actually already implements a DHT22 sensor to measure temperature and humidity, mainly as a proof of concept and for testing the communication between the MKR1000 device and the Microsoft Azure IoTHub (data it is not monitored in the main application as of now).
“Grandma” lives alone
This section tells a story about Grandma.
Grandma lives alone in her house and she doesn’t talk to her family every day.
Her children lives far away from her, so she only gets a visit every week or two. Her children are often busy with their own stuff, so they don’t call her on the phone as often as they would like.
Grandma is fine with this, as she is still able to take care of herself, but as she is getting older she would like the safety of someone checking up on her every day, making sure she is alright. She has heard scary stories about older people getting ill and not getting any help in time – she doesn’t like that thought!
Grandma is an independent person and don’t want to bother her children to call her on the phone every day, even though she knows that they would be happy to.
Problem solved: The “I’m Fine” system
Next week, Grandma is getting the new safety system, called “I’m Fine”, for elderly people who may be at risk of suddenly getting ill and not being able to call for help.
With this system she only has to press the big button a couple of times a day when it starts to blink and makes a beeping sound. When she press the button, the light stops blinking and the beeping goes away. After a few seconds she hear a new sound signal from the device. This is the way of the safety system to tell her that she has sent a message letting her children know she is OK.
The system monitors all the button push messages from Grandma and if she does not push the button in time, the system will detect this and send out SMS and/or email messages to her children and to the neighbor. Then they will know that something may be wrong with Grandma and they must call her to hear if she is alright. If she doesn’t answer the phone they maybe also need to visit her to help.
As long as Grandma push the button within a configurable set time, to report that she is fine, the system will not notify her children.
When the children receives an alert message from the “I’m Fine” system, on their phone, they know that they must call Grandma to check up on her – maybe she just forgot to press the button!
With the new system, Grandma knows that if she does not push the “I’m Fine” button regularly, it will only be a short time, before her help is on the way.
System Description
The I’m Fine project is an IoT system, based on cheap but advanced device hardware sending and receiving messages over the Internet to a cloud based backend system. The backend system takes care of all business logic including storage and processing of device messages and sending out alerts in form of emails.
The project consists of 4 parts.
- The “I’m Fine” button device
- A Cloud based backend monitor and communication system.
- Azure Device Explorer for IoT Hub devices Tool
- A Windows 10 Universal Windows Platform (UWP) application for system configuration
This part is built using the Arduino MKR1000 device, which has builtin wifi communication and security features to make a secure SSL connection to the cloud. Provided with a simple button, an LED for visual indication and a buzzer for audible indication, the extra hardware needed can hardly be more simple.
The MKR1000 device can be powered by a 3.7V LiPo battery, which can be charged from the device USB connector.
A Cloud based backend monitor and communication system.
Microsoft Azure cloud services is the heart of the system business logic, utilizing features like IoTHub, WebJob and SQL Server database.
The business logic application is programmed in C# and implemented as a traditional console application. This console application is then configured to run as a WebJob in the Azure cloud system. This makes it easy to develop, test and deploy.
Running the console application as a Azure WebJob, is almost as running a traditional Windows Service application in the background. For this to work, you must have at least a “Basic App Service Plan” and activate the “Always On” option in Azure.
Visual Studio 2015 makes it extremely easy to deploy your console application to Azure and set it up to run as a WebJob. You can also do it manually from Azure, if you prefer this – all you need is to make a ZIP compressed file containing all your application files.
Using a standard email account from Google Gmail, Emails can be sent out easily.
Azure Device Explorer for IoT Hub devices Tool
This is an application provided by Microsoft and is a great demo- and test tool for configuring your devices and test that your device can actually send and receive messages to/from your IoTHub.
The Microsoft Device Explorer Tool can be found here and this article describes in detail how to use the tool and how to configure your device. You also use this tool to get a device specific authorization token to use in your Arduino code. This is a very important feature of the system in order to POST data to your IoTHub and prevent unauthorized devices to send data to your system.
This tool is available from GitHub and you can download the source code as well as a compiled version.
In a more finished product than this competition project, your own configuration application should contain similar functionality as found in this tool as you need some way to provision and maintain devices in your Azure IoTHub. Also this tool only contains the minimum set of properties defining your device.
Using this tool instead of making my own, does not make any differences to the “ImFine” concept, as I could use this tool to get up and running (thanks Microsoft).
A Windows 10 Universal Windows Platform (UWP) application for system configuration
This application has been rescheduled and is now planned for version 2!
Comments: When I started on making this project I thought I would also have time to make my own UWP application to define and configure the devices, but alas I ran out of time!
Other functionality I should also have implemented in this UWP application, was setup/configuration of names and address data for the users of the “ImFine device”. The database should hold information regarding how often the user should press the device button to report back to the backend in order to prevent sending alert emails to other people.
There is a set of features missing to make this look like a finished product which is flexible and easy to use for setting up new devices and defining the business rules on how the system must handle messages (both existing and missing).
Arduino MKR1000 device
Go to the Arduino website to get the best and authoritative description of the Arduino/Genuino MKR1000 device. At the time of writing this article, the official documentation is kind of non-existent, because the board has not yet been released to the public.
The MKR1000 device seems to be combination of some other existing documented Arduino hardware, like the Arduino Zero board + a WiFi101 shield. To get to know the MKR1000 device better at the time of writing, a good idea is to look at these two boards.
Arduino programming
Go to the Getting Started with Arduino page on the Arduino website to read about Arduino programming and download the Arduino development software.
Install the MKR1000 board in Arduino
Before you can use the MKR1000 board from the Arduino IDE, you must first install it using the “Boards Manager” menu item.
Although the Boards Manager shows that a newer version than the 1.6.3 I have used is available, I have not been successful in using the version 1.6.4. If I choose that, I don’t see the MKR1000 board in my boards list. Using version 1.6.3 has been working fine.
Install the Arduino WiFi101 library
To use the MKR1000 board to connect to a WiFi network, Arduino has provided a wifi library to use. This library is named “WiFi101”. It is also used for the WiFi101 shield. Go to the Arduino WiFi101 Library page to read all about it.
Installing support for the DHT22 sensor
To use the DHT22 temperature and humidity sensor, you need to install and use the supporting library. Adafruit has made this library named “DHT Sensor Library”.
MKR1000 SSL configuration
In order to connect your device to the Azure IoTHub in a secure way, you will need to use the HTTPS protocol. This requires a SSL certificate, which must be installed in the device. You will use the WiFi101 library, which contains a class to use for secure SSL connections. Read about the WiFiSSLClient here.
You get the SSL certificate from your Azure IoTHub, when you have that configured and running. To get the SSL certificate and configure your device to use the SSL certificate, you need to use a tool, which is provided by Arduino on GitHub here Firmware/Certificates updater for the WiFi 101 and MKR1000. You should read the explanation on how to use it there.
The tool to use is called “WiFi101 FirmwareUpdater”, and in use it looks like this:
I have erased the part of my Azure IotHub name. You must of course provide the name of your own IoTHub, when you have it configured and running.
Arduino Code Structure
For a detailed look at the code, please have a look at this in my Github source repository.
Code description
As all other Arduino programs, this one starts with definitions and initializations.
The setup() function initializes all used I/O pins, connects to the wifi network and to Azure. It also indicates to the user by sound and light, that the device is started and connected. It sends a “WakeUp” message to the cloud backend.
The main loop() function basically does 3 things:
- Check if the button is pressed. If yes, then send a message to the cloud backend.
- Check if a command has been sent from the cloud backend to the device. If yes, then process the command
- Periodically send temperature and humidity data to the cloud backend.
Azure and IoT Hub
For this project I use a few of the many possibilities which the whole Azure eco system provides.
- IotHub
- WebJob
- SQL Server database
Azure IoTHub
For running this project, you will need to first configure your own Azure IoTHub. You can get started for free, but to be able to run a WebJob continously, you will as minimum need a payed plan, starting with the Basic App Plan. For testing you can start completely free, but your WebJob will automatically terminate after 20 minutes. Then you will have to manually start it again from the Azure Portal.
Microsoft has a lot of online documentation for all the Azure stuff and you can read more about the IoTHub here.
There is a lot of stuff you need to know about and this takes time. You will notbe able to get through it in a few hours.
I can only encourage you to read through the documentation, it will save you time in the end. Go get some coffee and get started…
Azure IotHub REST Api
To communicate with the Azure IoTHub, Microsoft has provided a set of programming APIs. You can Get an overview of the REST api here.
This is really essential reading like most of the other Azure IotHub Documentation – and there is a lot to read and digest!
For the device to talk to IoTHub, the Device Messaging REST APIs is something you must understand.
There are other options to use than REST, but I have used the REST apis.
I’m Fine C# Application
IoTHub backend console app.
The main application basically configures the IoTHub and then start to monitor incoming messages. When receiving a new message, this is logged in the database and depending on the contents of the message received, a reply may be sent back to the device. This is currently used to activate the piezo beeper on the device as a response to the user pressing the button on the device in order to inform the user that the message is acknowledged.
When sending data to the device, the application monitors if the messages is delivered to the device or not. The response from the IoTHub feedback system updates the status of the message data in the database.
The console application prints all messages in colors depending on the source. Light blue/Cyan colored lines are incoming messages received from the Arduino device. White colored lines are outgoing messages sent from the backend application to the device. The green lines are status responses from the IoTHub feedback system, monitoring the outgoing messages to the device.
Visual Studio 2015 Solution
The backend solution which connects to the service side of the IoTHub is implemented in 3 projects:
- ImFineBackendConsole
- ImFineDatamodel
- IoTHubServiceBackend
ImFineBackendConsole
The main application is implemented as a C# console application.
ImFineDatamodel
A datamodel using Entity Framework 6 is made on top of a SQL Server database. I have used the “database first” approach and built the model from the database.
Database table
Entity Framework model
Currently the database only contains one table to hold all incoming and outgoing messages through the IoTHub.
IoTHubServiceBackend
This project contains 3 classes which implement functionality to receive data from a device, to send data to a device and monitor the feedback status and last a class to handle sending emails.
Diagram and Materials
Diagram
The resistor named “R” has a value of 220Ohm.
The buzzer is a piezo type buzzer.
The button is a big arcade game console type of button with a built in LED light.
The LiPo battery I have used is a 3.7V – 1100mAh type.
Prototype
Materials
Arduino MKR1000 This has not been released for sale yet, so th eonly way to get one was to participate in this contest.
Button with builtin LED
Many different usefull types available on Ebay. Try this search and see what pops up.
Piezo Buzzer
Any piezo buzzer will do. I just picked one laying around.
DHT22 temperature and Humidity sensor
Also available on Ebay. Try this search.
LiPo Battery
Read the MKR1000 documentation about the battery. Then pick any.
Source Code
All source code for this project is on GitHub in my GitHub ImFine repository.
The project contains a subfolder named src, which has 3 subfolders – one for Arduino code, one for Windows C# code and one for a SQL script file.
Although several files contains usernames and passwords or SAS tokens, you will not be able to use the code on my Azure backend. All information has been changed.
Before setting up your own system, you will have to change these to match your own setup.
Arduino code
The MKR1000 code can be found in Arduino code here.
Windows C# code
The Windows application code for Visual Studio 2015, can be found in C# code here.
SQL Server database script
The SQL Server database can be recreated in your own server by using SQL Server script found here.
Schematics
Code
Source : I’m Fine