How-tos

IoT application that monitors your food pantry – Part 2

Share this post:

This is the second and concluding part of the earlier post where we presented a “Internet of Things” project idea around tracking kitchen food inventory. We discussed the benefits and use cases of this application from a restaurant’s point of view and presented a gist of the the project setup and components. Now it’s time to discuss the detailed hardware, software setup and the complete functionality of the system.

Project Setup

The reference architecture is shown below.

If you would like to build this application yourself, then you can access the complete source code at this shyampurk/kitchen-tracker project on GitHub. All the steps for setting up and building the project’s components are listed in the README file.

Before building, you need to sign up with IBM Bluemix and PubNub. Visit the Bluemix registration page and PubNub service page to create your respective accounts. Both services offer a free tier account to play around with their offerings.

Server Setup

The Inventory Tracking Server (ITS) is written in Python and can be installed as a IBM Bluemix hosted app. IBM Bluemix provides the computing horsepower for the ITS to monitor hardware devices and manage automatic inventory tracking. Additionally you will need to associate the PubNub service with your Bluemix account for the ITS to work with PubNub. Refer to these deployment steps to understand how to setup and host a Python application under Bluemix with PubNub. As noted earlier, the source code for ITS is located under the kitchen_tracker directory in the GitHub repository.

Hardware Setup

The hardware has two parts:

  • Sensor Controller – Driven by Arduino UNO, the sensor controller acts as a localized aggregator of all storage containers which are under this inventory tracking system. It interfaces with the load cells to sense their weight and is connected to a HM-10 BLE module to transmit the weight data over bluetooth. By using this arrangement of local aggregation and BLE, there is an added advantage of bringing in new storage containers under this inventory tracking system with minimal additional wiring.
  • Master Controller – Master controller acts as a gateway for the sensor controller. This is powered by Linkit ONE board. It has a inbuilt BLE module that probes the sensor controller every few seconds to get the current weight sensed by the load cells. It also has inbuilt WiFI interface for connecting with ITS over internet to send the weight readings.

The master controller plays a crucial role in stabilizing the weight value of the containers. This is to avoid sending transient or spurious weight values while, for example, the container is being refilled.

The schematic diagram of the sensor controller hardware is shown below:

Refer to these build and install steps for configuring the hardware. The source code for hardware setup is available under the hardware directory (for the sensor controller) and the linkitble/pubnub_linkit directory (for the master controller), under the GitHub repository.

Calibrate the load cells to avoid errors is weight measurement.

Mobile App Setup

The mobile app is a standard Apache Cordova based Android app. Cordova is an open source, cross platform, mobile development framework based on standard web technologies, such as HTML5, CSS3 and JavaScript. Among other features, this app provides the user with a visual indication of the current container level.

Look at all that bacon!

The source code for the mobile app is under the mobileApp/kitchen directory in the GitHub repository. Steps for building the app are available here.

PubNub

PubNub acts as the communication middleware for the entire system. It provides a cloud-based realtime Data Stream Network that supports over 70 SDKs, such that it can enable any device to communicate with any other device on the Internet. This application uses three of PubNub’s SDKs for all components to seamlessly communicate with each other. They are:

PubNub uses the ubiquitous publish/subscribe mechanism to stream data in realtime, from one device to another. This is achieved by the use of channels which provide a secure bidirectional messaging layer between the devices. This application uses several PubNub channels for enabling communication between the hardware, ITS and mobile app. Refer to this tutorial to learn more about how to build a small publish / subscribe demo using PubNub.

Application Use Cases

There are three main use cases of this application:

  • Track the current status of inventory
  • Expiration Notification
  • Access historical inventory usage data

Before we can start using the mobile app for tracking inventory, we need to perform some container specific settings and register them with the server. Those setting are:

  • Label – A user defined identifier for the container for easy identification.
  • Threshold Value – A threshold value (in kilograms) to indicate a critical level for container weight.
  • Expiry – Since most of the kitchen inventory is consumable food items which have an expiry date, we can set an expiration value (in months) for the container. This way, the server can track the expiration date and send a notification to the app when those contents have expired.

These parameters can be set for every container.

Once submitted, these settings are sent to the ITS application server via a PubNub channel.

Use Case 1: Track current status of inventory

Once the container settings are registered with the ITS, the app can receive current weight measurements of the containers. Every time a container weight changes, either due to consumption or replenishment, the application performs the following steps:

  • Step 1: The hardware detects change in weight and publishes a new weight value on PubNub channel ‘kitchenDevice-resp.’
  • Step 2: ITS receives the new weight and daily consumption for the current day.
  • Step 3: ITS updates the database to record the daily consumption data.
  • Step 4: ITS publishes the new weight on PubNub channel ‘kitchenApp-resp.’
  • Step 5: The app receives the new weight value and updates the screen display to reflect the new weight value and updates the visual level indicator for the container.

Alternate Flow

Step 2 – If the server detects that there has been an increase in the weight, then this means that the inventory has been replenished on the container. In this case the ITS performs the following steps

  • Step 2a: ITS resets the expiry calculation to start from the current date.
  • Step 2b : ITS stores the start of expiry date in its internal memory.
  • Step 2c : Use case continues from step 3.

Use Case 2: Expiration Notifications

This use case is also an alternative flow of the previous use case. If a container has not been refilled before the expiry date, then the ITS can sense this during step 2 and alert the user whenever it detects a consumption to warn against expired food.

In this case the sequence of steps from step 2 will be as follows:

  • Step 2a: ITS receives the new weight and calculates the expiry validity of the container and finds that the expiry period has been crossed.
  • Step 2b: ITS updates the database to record of the daily consumption data.
  • Step 2c: ITS publishes the new weight on PubNub channel kitchenApp-resp and sets the expiry parameter as zero.
  • Step 2d: Use case jumps to step 5.

When the mobile app receives the notification for consumption with the expiry set to zero, it updates the container icon in a way to alert the user that the inventory being consumed has expired.

Use Case 3: Access historical inventory usage data

The ITS is supported by a backend data warehousing service powered by IBM DashDB. Daily inventory data for consumption and replenishment is updated on dashDB database which can provide some basic analytics on historical inventory usage for the last 7 days.

To display the historical inventory usage, the user has the option to either display a graph or a table by tapping on the “Graph” or “History” button.

The request is honored by ITS by sending the consumption and replenishment data in two separate PubNub channels. The flow of information is as follows:

The mobile analytics look something like this:

Conclusion

This application demonstrates how easily one can leverage IoT to eliminate human intervention and automate manual processes. For a restaurant or large hotel, this can make a big difference.

A further enhancement of this app would be to automatically place an order with suppliers when inventory falls below a critical level. The possibilities are endless, and with IBM Bluemix’s state of the art data warehousing and the 99.999% reliable messaging infrastructure of PubNub, building such solutions is fast, secure, and highly scalable.

Stay tuned for more demos and application use cases using IBM Bluemix & PubNub Data Stream Network!

Add Comment
One Comment

Leave a Reply

Your email address will not be published.Required fields are marked *


ASISH RANJAN

CAN U PROVIDE ME THE ARDUINO CODE USED FOR SETTING UP THRESHOLD VALUE FOR LOAD CELL
THANK YOU sir

Reply
More Internet of Things Stories

Monitoring & logging for IBM Bluemix Container Service with Sematext

In this blog post we discuss how Sematext integrates with IBM Bluemix Container Service to provide monitoring and logging visibility of your containerized applications, as they run in production. In the sections below, we demonstrate how to set up a Kubernetes cluster in Bluemix and how to set up Sematext in this cluster. IBM Cloud has monitoring and logging capabilities in the platform, but we know our customers operate in a multi-cloud or hybrid cloud environment and we are very excited to partner with Sematext, enabling operational consistency across those environments. We worked with Alen Komljen, an Automation Engineer from Sematext, to create the following content and perform the technology validation.

Continue reading

99.95% availability. Balancing release velocity and reliability

Availability and reliability are rarely at the front of developers minds when delivering new applications on Bluemix. The ease and speed of creating and deploying new features is very seductive.

Continue reading

Deploying to IBM Cloud private with IBM Cloud Developer Tools CLI

IBM Cloud private is an application platform for developing and managing on-premises, containerized applications. It is an integrated environment for managing containers that includes the container orchestrator Kubernetes, a private image repository, a management console, and monitoring frameworks.

Continue reading