With the increasing adoption of IoT in agriculture, we thought we’d bring you this Smart Farming application which you can set up with a Nebula 2.0, an SHT click and scriptr.io. The application on the Nebula board reads the ambient humidity and temperature from the SHT click, and sends the readings to IBM Watson IoT. Through its MQTT connector, scriptr.io picks up this data from Watson IoT, runs its through the business rules defined in your application and displays it on the app’s dashboard.

In this tutorial, you will learn how to configure your Nebula and your scriptr.io app so you can have your PoC (Proof of Concept) up and running in under an hour.

Start by going through the prerequisites section to make sure you have what’s needed to build this PoC, then move to the step by step instructions to put all the pieces together.

Prerequisites

Hardware

  • Nebula 2.0: make sure you connect your Nebula board to your PC using the USB cable before you start. This is needed to install the nebula20-shtclick-watson app on it using WICED Studio.
  • SHT click: plug in the SHT click into your Nebula board. The SHT click from MikroElektronika is used in this tutorial to read temperature and humidity data (if you decide to use a different sensor board, you will need to install its corresponding libraries using WICED Studio and make a few tweaks to the Nebula app).

Software

  • WICED Studio: you need to download and install the WICED Studio IDE by Cypress  (this example has been tested with versions 6.2 and 6.4), and use the 43xxx_WiFi project to build the Nebula 2.0 application as described later in this guide.
  • Terminal Tool: you need to install a terminal tool such as Tera Term or CuteCom (baud rate 115,200, data 8 bit, parity none, stop 1 bit, flow control none) so you can see the output of your Nebula device.
  • Preconfigured scriptr.io account, loaded with the Nebula 2.0 Smart Farming app, created using the following registration link: https://www.scriptr.io/register?promocode=nebula-2.0

Step by Step Instructions

  1. Registering for a free scriptr.io account with the nebula-2.0 promo code

    Navigate to https://www.scriptr.io/register?promocode=nebula-2.0 and follow the registration instructions to register to scriptr.io using the nebula-2.0 promotion code. This will automatically install the Nebula Smart Farming app on your account.

  2. Installing the Nebula 2.0 Smart Farming app using WICED Studio

    In this step, you will install the nebula20-shtclick-watson app on your Nebula board so that it can send the SHT click sensor data to IBM Watson IoT.

    1. Clone the nebula20-shtclick-watson repository.
    2. Copy the cloned repository code into your 43xxx_Wi-Fi WICED Studio project so that the files from the repository would replace the existing files. This repository already contains the NEB1DX_02 platform and the sensor libraries, which means that you don’t have to worry about importing them into your project.
    3. Open WICED Studio.
    4. Configure your Nebula board to connect to your local WiFi network as follows:
      1. Open the apps/nebula/bluemix_iot_sensors/wifi_config_dct.h file
      2. Set the CLIENT_AP_SSID constant (line #61) to your WiFi SSID
      3. Set the CLIENT_AP_PASSPHRASE constant (line #62) to your WiFi Network Security Key
      4. Save
    5. Now you need to set the MQTT topic and Client ID to be used with IBM Watson IoT Quickstart. For that, follow the below steps:
      1. Log in to your scriptr.io Workspace using the credentials you used to register in step #1 above
      2. Copy the Token provided to you in your landing page
      3. Go back to WICED Studio, and open the file apps/nebula/bluemix_iot_sensors/bluemix_dct.c
      4. Replace <TOKEN> in the dev_id constant value (line #69) with the Token you copied from your scriptr.io Workspace
      5. Replace <TOKEN> in the pub_topic constant value (line #71) with the Token you copied from your scriptr.io Workspace
      6. Save – the code section that you edited should look similar to the below:
    6. Generate a new build target as follows:
      1. Right-click the 43xxx_Wif-Fi project folder
      2. Select Make Targets > Create…
      3. Set the Target name to nebula.bluemix_iot_sensors-NEB1DX_02 download download_apps run
      4. Click OK
    7. In the Make Target window, double-click the new make target you created in the previous step in order to build it. This will install the app on your Nebula board.

    Check your terminal program (baud rate 115,200, data 8 bit, parity none, stop 1 bit, flow control none) to see the results.

  3. Sending data to IBM Watson IoT

    Now that you’re all set, let’s start sending the data to IBM Watson IoT:

    1. Once connected, the Nebula board will send a message to IBM Watson IoT every minute. The message will have a payload similar to the one below:
      {"d":{"thermistor_temp":25.1,"t":24.6,"h":57.5,"id":"myShtClick"}}
    2. If you would like to check the data on IBM Watson IoT Quickstart, follow the below steps:
      1. Navigate to the IBM Watson IoT Platform Quickstart page: https://quickstart.internetofthings.ibmcloud.com
      2. In the Device ID, enter the Token as retrieved from your scriptr.io Workspace above, prefixed by the word device
      3. Click Go

    You should now be able to see the data packets on Watson IoT Quickstart.

  4. Running your IoT application in scriptr.io

    To run your application, all you need to do is:

    1. Go to your scriptr.io Workspace
    2. From the tree on the left, navigate to smartfarming/index.html and double-click it open it in the editor
    3. Click View to view it in your browser
    4. Log in using the credentials demo / demo

    You should now see your device on the map (it will be shown in a predefined location since the device doesn’t send a GPS location). You can either zoom in on the device and click its marker/pin to see the sensors’ readings, or select the device (myShtClick) from the drop down list on top of the map. This data is updated in near-real-time, i.e. every time the device sends a new message to scriptr.io, you can see it on the terminal window if you’re connected to the device, and you will also see the new values reflected in the app as well.

     

    If you click View Dashboard button, it will open a dashboard showing several charts, including time series charts showing the variations over time. This view is updated in near-real-time as well:

    You can also click View Alerts in order to see the warnings logged whenever a value exceeds the thresholds that you define in the Rules Designer screen.

    You can access the Rules Designer from the left side bar and define the rules that should be met for an alert to be logged and/or sent to you by email. For instance, as you can see in Rule 3 below, if the temperature drops below 2 degrees (Celsius), it will log a LOW_TEMPERATURE record and trigger an alert:

    rules

    In order to set the recipients of the alerts, click on the user icon on the top right corner of the screen and select Notification Settings. This will open a form allowing you to enter a comma-separated list of email addresses to receive the email alerts:

    notification-settings

  5. Going Forward

    Scriptr.io allows you to reduce the time to market of your IoT applications by accelerating your development pace, thanks to a plethora of API and visual development tools, such as our dashboard builder, our business rules editor, and the multitude of tools at your disposal in the Workspace. You can also find a long list of demo applications / modules / connectors under our GitHub account.

    This app’s code can be found in your Workspace under the app folder, so you can modify it as you see fit. You can check out the Readme file under the app folder to learn more about it.

    For a deeper dive in scriptr.io, we suggest to check our one-page documentation and our how-to guides.

    Finally, if you have any questions or feedback, we’d love to hear from you at support@scriptr.io.