Smart green house with Intel Edison and Microsoft Azure

I have attended the Intel IoT Roadshow here in Silicon Valley during last weekend, and made this cool project – Smart Green House. Intel provided a bunch of sensors, and I thought of doing something with green house. We had done similar hack earlier during AT&T Developer summit hackathon at Las Vegas, but that was for industrial farming.

Project description :- I have placed various sensors inside the green house, and the system will monitor current condition (soil Smart Green Housetemperature, moisture, light, ph level, ultra violet, water et ), and report to the back end cloud.  Backend knows the current profile of the green house(I have used radish plant for demo), and if there is anything abnormal, green house system will adjust the settings. For example, if the temperature is high then the system will turn on the fan. If the water level is low, then the system will automatically turn on water pump. I have placed the LCD display unit outside to see the current health level, and if anything unusual with green house then the display will be red, and notification will be send as SMS.  Let us dive into more technical details. Following diagram shows the hardware pieces used in this project.Smart Green House components

Implementation details:- Core of this project is the Intel IoT developer kit which they have provided to the first 150 attendees, and I was lucky enough to get one. In addition to the default kit, I have managed to get the mini water pump, water flow control, fan, light etc.  I have used Intel XDK IoT edition for the development and used the Node.JS / Java script to read/write to hardware/sensors.  Intel SDK team did pretty decent job in documenting everything, and enough sample codes, and I could set up the first sensor up and running in couple of hours including the XDK and drivers installation.  Here comes the code sample to read the temperature value from the sensor connected to the analog pin.

Similarly, I have read values from all the sensors, and sent the same to Azure Event hub. I couldn’t find any AMQP 1.0 node package to connect to the Azure event hub, hence I used the REST api to post the reading in every second.    During the start of the app, green house system will connect the Azure backend to retrieve the profile for the current plant, and in this case it got the profile for radish plant.  Since the green house system already got the plant profile at the start, any reactive action (eg:- turn on water pump, turn on fan etc) don’t require network/backend connectivity. Hence we don’t put the plants on risk incase if there is any network outage.

Once I get the sensor values at Azure event hub, data gets forwarded to Stream Analytics service, and then the output of the stream is directed to the Power BI for dashboard. dashboardHere is a dashboard from my demo.

Even though I am an electronics engineer by degree, I didn’t seriously worked with the electronics components after the course. IoT hackathons are really helping me to do some amazing things, and I am enjoying it. Hope to write some more articles pretty soon on IoT.

 

Send events from Android app to Microsoft Azure Event Hubs

Event Hubs is a highly scalable publish-subscribe ingestion system that can process millions of events per second. This article will explain how to publish event from an Android application to Azure event hub.

Create an Event Hub

  1. Log on to the Azure management portal, and click NEW at the bottom of the screen.
  2. Click App Services, then Service Bus, then Event Hub, then Quick Create.create_eventhub
  3. Enter the event hub name (eg:- AndroidHub) , select the region and namespace, and create the event hub.
  4. Select the newly created event hub, and select the Configure tab
  5. Create the shared access policy (eg:- android). We will require the policy name, key, namespace and event hub name at later stage to create the signature.shared_access_policy

Create Android application

Let us create anew_project simple android application using Android Studio. Select the minimum SDK (eg:- API 19), Blank Activity template, and  default activity (eg:- MainActivity), and then click “finish”to create the project.

Now add a button to the main layout to send sample event to Azure event hub.  Updated layout is given below.

We need to update the manifest file to support the network operation by including the following permission.

Connecting to EventHub:- Sending events to an Event Hub is accomplished either using HTTP POST or via an AMQP 1.0 connection. The choice of which to use when depends on the specific scenario being addressed. AMQP 1.0 connections are metered as brokered connections in Service Bus and are more appropriate in scenarios with frequent higher message volumes and lower latency requirements as they provide a persistent messaging channel. I will be using the HTTP post to publish the events.  I have been using the Android AsyncHttpClient library for a while to do asynchronous operation, and thought of using the same here as well. Let us update the build.gradle file with the following to add the AsyncHttpClient package.

Now update the button click handler with the following code.

Replace the namespace and eventhub name with the actual values from the Azure portal, and ClientId can be anything to identify the publisher. In real life scenario there will be multiple devices/apps publishing events to same event hub.   I have created another Azure website to generate the SAS signature, and let us use this site to create signature for this demo application.  In production application, it is better to generate the signature in Android app itself (or get it from a secure cloud service).

Once we update all the placeholders, it is time to execute the application, and eventhub_dashboardclick the button to send events. We should see the updates in Event hub dashboard as shown here. If not, check out the AsyncHttpClient callback handler and see the response from the server after the POST request.

Hope, many more Android apps will start publishing events to Azure Event hubs 🙂