This project won the Southern California Azure IOT Hackathon 2017. It is a remote monitoring IOT solution for a Shared Laundry service.
A common problem in apartments with Shared Laundry room is not knowing if enough number of machines are free to use at any given point of time. This project aims to bridge the knowledge gap by an IOT solution and Mobile app so the tenants can better plan their laundry activities.
This remote monitoring solution when implemented will save time and free tenants from frustration. The apartment manager will also be able to analyze machine activity and can plan to increase the total number of machines in his building if required.
This solution can be implemented in public Laundrymats as well.
The solution consists of 4 main components
- Sensor Data collection: Vibration sensors connected to RaspberryPi for determining machine state.
- Data storage: Microsoft Azure IOT Hub, DocumentDB to receive, analyze and store data from Raspberry Pi.
- Data retrieval: HTTP triggered Azure Function to act as a server less application to retrieve latest machine state from Document DB.
- Mobile App: App to retrieve latest machine state by triggering Azure function and visually presenting its availability to the user.
The solution architecture looks like this
Sensor Data Collection
Vibration sensors attached to each machine are used to detect if a machine is running or not. Hardware Wiring documentation can be found here. A Node.JS program running on Raspberry Pi receives data from sensors every 2 seconds. When a state change is discovered, it sends a message to the Azure IOT hub. The program is available to download from Github.
Data storage
Azure IOT Hub is used securely to collect messages from the Raspberry Pi. Azure Stream analytics is used to process the data and store in DocumentDB.
Input for the stream analytics job is Azure IOT hub. Output is DocumentDB. The query used is
SELECT
machine,
CAST(Status AS BIGINT) AS machinestatus,
EventProcessedUtcTime
INTO
dbout
FROM slrawin
Data retrieval
A HTTP triggered Azure function was used to query the documentdb database to retrieve the latest machine state of the desired machine. Here is the main Node.js script. The entire package can be downloaded from Github
module.exports = function (context, req)
{
var DocumentDBClient = require('documentdb').DocumentClient
, config = require('./config')
, host = config.host
, masterKey = config.authKey
, query = `SELECT TOP 1 c.machine, c.machinestatus FROM c WHERE c.machine = "${req.body.machine}" ORDER BY c.eventprocessedutctime DESC`
, databaseId = config.databaseId
, databaseUrl = `dbs/${config.databaseId}`
, collectionUrl = `${databaseUrl}/colls/${config.collectionId}`;
// Establish a new instance of the DocumentDBClient to be used throughout this demo
var client = new DocumentDBClient(host, { masterKey: masterKey });
var results = client.queryDocuments(collectionUrl, query).toArray((err, results) =>
{
if (err) context.log(err)
else {
var r = results[0];
context.res = { status: 200, body: r };
context.done();
}
});
}
Note:
- CORS configuration should be set to allow all origins for the the API request to get response
- Github has been configured as a source to the Azure function under 'Code Deploy'
Mobile App
End result is the Mobile app that can be used by the Tenant users to check the machine state.
Mobile App was created using IONIC framework. It sends an API request to the Azure function URL every 5 seconds to check the machine state. The machine name is sent in the request body as below.
{
"machine": "Dryer001"
}
The entire Mobile app solution can be downloaded from Github.
Comments