MKR NB 1500 Software flow

The Mini Farm environment for this project includes three plots of garden beds, a worm farm and a chicken house. The main goal is for the IoT solution to monitor the environment and control the water and feeding systems for the plants and animals.

This is the third instalment of my IoT Garden Project.

The first introductory instalment is found here.

The second hardware description instalment is found here.

In my first post, I described the context of the IoT Project that focused on the solution overview of the garden environment. In my second post, I described the hardware and sensors used in this project. This blog will overview the messaging and information flow between the Azure IoT services and the Arduino device. I will describe the common environmental sensor readings, how telemetric data is sent to Azure and how I can control external systems to support the environment in the form of fertilizer, chicken feed and water delivery systems.

IoT Hub and Device message flow

The diagram describes the two main types of messages in this IoT environment. Telemetric data is JSON data that is sent from the IoT device to the IoT HUB for processing and storage. It contains environmental sensor readings and status information. This data is one way. action commands will be alerts and instructions to activate or deactivate relays and solenoids. The commands can be cloud to device or device to cloud. The actions can be triggered through events, alerts, logic apps and voice commands.


Arduino Data Processing Logic

The MKR NB 1500 is a micro-controller that is configured with the Arduino IDE. The code I have written sets up the micro-controller network connectivity to Telstra IOT Mobile network and configures routines to monitor sensor readings and commands to activate solenoid and devices. The IoT device will continuously scan for control messages from Azure. The control messages use the direct connect method that sends a JSON data file to the MKR NB 1500 and receives an acknowledgement. The commands will activate the fertilizer, chicken feed auger and sprinklers. The format of the JSON file that Azure send is {“MethodName”,”Payload”}.

The MKR NB 1500 will continuously scan for following commands:

{“action” ,”watermainon”} Turns on Main water relay
{“action” ,”watermainoff”} Turns Off main water relay
{“action” ,”waterplotaon”} Turns on plot a water relay
{“action” ,”waterplotaoff”} Turns off plot a water relay
{“action” ,”waterwormon”} Turns on Worm Farm water
{“action” ,”waterwormoff”} Turns Off Worm Farm water
{“action” ,”chookfeedon”} Turns On Chicken feed Auger

The commands can be activated through Azure Machine Learning, Azure events and manually through voice or browser commands.

Telemetric messages

The MKR NB 1500 scans its sensors every minute and builds a JSON data file that is sent to Azure for storage and processing. The Format of the JSON string is as follows.

{"deviceid": 55223, "temp": 25, "humid": 57, "Pre": 1020,"UVIndex": 0, "Light": 69, "Fertlvl": 14.47,"Chookfdlvl": 0.00, "wplotA": 42, "wplotB": 4,"wplotC": 18, "wflow": 0, "wormfarmtemp": 21,"wflowt": 0.00, "waterflowon": 0, "sig": 24}]
Data:[ Data Block begin
{ Begin JSONdata string
“deviceid”: 55223, Device ID, I assigned number to each MKR NB1500
“temp”: 25, Temperature is 25C
“humid”: 57 Humidity is 57%
“Pre”: 102,
Atmospheric Pressure is 1020 hpa
“UVIndex”: 0, UV Index
“Light”: 69, Light in
“Fertlvl”: 14.47, Fertiliser container level is 14.47% full
“Chookfdlvl”: 0.00,
Chicken feed level is 0% and empty
“wplotA”: 42, Moisture reading plot a top surface between 0-100    ( Medium)
 “wplotB”: 4,
Moisture reading plot a below surface between 0-100,   ( Wet)
 “wplotC”: 18,
Moisture reading plot C top surface between 0-100
 “wflow”: 0, Water flow in liters  
 “wormfarmtemp”: 21, Worm Farm Temperature is 21C
 “wflowt”: 0.00, Water flow Total per day in liters
 “waterflowon”: 0, Current Water Flow 0= Off 1 =On
 “sig”: 24 Mobile Data Signal strength    24 %
}] End Json String and data

Azure Services



IoT Hub is a managed service, hosted in the cloud, that acts as a central message hub for bi-directional communication between the IoT Garden application and the MKR NB 1500 device. The IoT Hub manages secure communications between  IoT devices and a cloud-hosted solution backend.  IoT Hub supports communications both from the device to the cloud and from the cloud to the device. IoT Hub supports multiple messaging patterns such as device-to-cloud telemetry, file upload from devices, and request-reply methods to control the devices from the cloud. The IoT Hub monitoring maintains the health and tracks events such as device creation, device failures, and device connections.


Stream Analytics

Telemetric data from the IoT garden device is sent via the Azure IoT Hub and is routed to Azure stream analytics engine.  The Azure Stream Analytics service will analyse and process data from multiple sources simultaneously. The JSON data from multiple garden IoT devices are used to trigger actions and initiate workflows such as creating alerts and feeding information to the Power BI reporting tool.

The JSON data for the project is stored in Azure Tables, Blobs and reporting Power BI tools.

An Azure Stream Analytics job consists of an input, query, and an output. Stream Analytics ingests data from my Azure IoT Hub for the input data. The query, which is based on SQL query language, selects and filters the JSON data. The output for the JSON data is redirected to the four output streams i have created as in the diagram above.


Telemetric Output Destination

Send data to a Power BI dashboard for real-time dashboarding.
Send data to Azure Table storage
Store data in other Azure Blob storage for machine learning based on historical data.


Azure Functions and commands

The Azure function is a serverless compute service that I have used to control communications and commands from the external processes like google voice commands.

The Function is a web services URL that listens for Http: POST messages that contain JSON commands to water the garden or feed the chickens. The function activates when it receives a posted message from google for example and interprets the payload. The function will translate and forward the command to the IoT HUB as a cloud to device message.



Google Home assistant is used to provide voice-activated commands to the garden devices. Google web service If This Then That (IFTTT) will monitor my google home assist device for certain phrases. I can say HEY GOOGLE, turn on garden water. It will look at matching the phrase with a Google App  I have created in the IFTTT portal and post an action command to my Azure Function. The Function will then forward the command message to the IoT device.

As above the IFTTT web service will send a JSON POST with the message body {“name”,”watermainon”} to my Azure Function URL.

Next week I will drill down on how to set up Microsoft Azure for the IoT garden project.