Weather Station tutorial

Introduction

Weather Station is an example IoT prototype that utilizes the LinkIt ONE development board to acquire temperature, humidity and pressure data from sensors. The data is then visualized on the MediaTek Cloud Sandbox (MCS).

By the end of this tutorial you’ll have a fully functioning IoT prototype, which gathers data from the sensors attached to the LinkIt ONE development board, transmits the data through a wireless communication channel, and provides control and visualization using cloud services on any Wi-Fi enabled device.

This tutorial guides you through:

  • Building the prototype, with details of the hardware requirements and how to put them together to create the Weather Station.
  • Adding your Weather Station to the MCS, creating the data channels to collect the sensor data and obtaining the information to use in the software to send data to MCS.
  • Creating the software to provide the interfaces with the sensors to collect their data and implement data communications to send that data to the MCS.
  • Using the MCS to view that data collected on the Weather Station, including using the MCS app on a Wi-Fi enabled Android smartphone or tablet (running Android v. 4.0 or above) to view data while away from your PC.

At the end of the tutorial there are details on where to go for additional information on the LinkIt ONE development board and how to create software for it.

You can complete this project on a Microsoft Windows or Apple Mac.

Before you start

If you haven’t built a LinkIt ONE project before, this section describes the steps you need to follow before commencing this project.

Arduino software

Download and install Arduino software version supported by the LinkIt ONE development board as described in the LinkIt ONE get started guide. In addition to providing your coding environment, the software is used for monitoring the development board.

LinkIt ONE SDK installation and configuration

Follow the instructions in the LinkIt ONE get started guide to install and configure the SDK. In addition to providing the API and tools to use Arduino, the SDK provides a tool to upgrade the development board firmware and reset it to the factory default settings.

Create your MediaTek Cloud Sandbox account

Register on MediaTek Labs and activate a MCS account to prototype your own devices and applications. Your MediaTek Labs registration also provides access to the hardware reference designs and the ability to interact in the developer support forum with other members of the Labs community.

A Wi-Fi enabled Android device

The MCS app supports Wi-Fi enabled Android smartphones and tablets. In this particular scenario Android (v. 4.0 or above) smartphone is used with a Wi-Fi hotspot enabled (preferred method for network connectivity).

Building the Weather Station hardware

This section describes the hardware and electronics needed to build Weather Station and provides details on how to put them together.

What you need

To build the Weather Station hardware, in addition to a LinkIt ONE development board, you need the following components:

ComponentDescriptionSource
DisplaySerial LCDGrove – LCD RGB backlight
SensorsTemperature, pressure, and humidity (TPH) sensor board.Grove Starter Kit for LinkIt ONE
RelayRelay v1.2 jump-wired with a USB socket.Grove Starter Kit for LinkIt ONE
AntennaBasic Wi-Fi antenna supporting 802.11 b/g/n standards. 
GSM antenna is optional for this tutorial.
LinkIt ONE development board kit
Connector CablesGrove Universal four pin buckled cable (2). 
Grove four pin male jumper to Grove four pin conversion cable. 
Basic micro-USB cable.
Grove Starter Kit for LinkIt ONE
Fan (optional)USB–powered fan 

Schematics

The components of the Weather Station are assembled according to the following schematic diagram:

Schematic diagram of the Weather Station hardware

The components used in the Weather Station are as follows:

  1. Wi-Fi/Bluetooth antenna connected to Wi-Fi + BT Antenna Port. The antenna is provided in the LinkIt ONE development board’s kit and supports 802.11 b/g/n Wi-Fi standards.
  2. TPH board connected to the voltage (3v3), ground (GND), A4/SDA and A5/SCL pins. The TPH board measures temperature, humidity and pressure. This board includes the Sensirion SHT21 digital humidity sensor and the Bosch Sensortec BMP180 pressure sensor (both capable of measuring temperature). Note that the board is only compatible with 3.3 volt sensors and peripheral.
  3. The Grove LCD Backlight v 2.0 connected to the SCL, SDA, VCC and GND pins of the LinkIt ONE development board. The temperature unit provides Celsius data and has an operating range of -40ºC to +85 ºC. Humidity is measured in percentage and the relative humidity (RH) with an operating range of 0 to 100% RH. The pressure unit measures in Pascals, with a range from 300 to 1100 hectopascal (hPa).
  4. The Weather Station has an optional USB–powered fan control, which could be connected to the LinkIt ONE development board using a relay with a hardwired USB socket. In this tutorial Grove Relay v1.2 is used attached to the RX, TX and voltage (5V and ground (GND)) pins, as shown in the schematic above.

Putting the components together

This section provides step-by-step instructions on putting the Weather Station hardware together. At the end you’ll have a Weather Station similar to the one shown below:

Weather station hardware setup

Step 1 — Antennas

Attach the dual purpose Wi-Fi/Bluetooth (1) and GSM (2) (optional) antennas to their corresponding pins on the LinkIt ONE development board as follows:

Front view of the antenna connection

Back view of the antenna connection

Step 2 — TPH board

Attach the TPH board to the LinkIt ONE development board using a Grove connector cable (Grove four pin male jumper to Grove four pin conversion cable) as shown below. Take care to connect the sensor to the 3.3V supply pin.

TPH board connected to the LinkIt ONE development board

The next steps use the Grove sockets on the LinkIt ONE development board.

Step 3 — Relay

Attach a relay hardwired with a USB socket to LinkIt ONE development board, using one of the Grove universal four pin buckled cables.

Relay connected to the LinkIt ONE development board

Step 4 — Grove-LCD RGB backlight

Attach the Grove – LCD RGB backlight v 2.0 to the second Grove socket on the LinkIt ONE development board using the second Grove universal four pin buckled cable, as shown below:

Grove-LCD RGB backlight connected to the LinkIt ONE development board

Note: Refer to the LinkIt ONE development board’s pin-out diagram for more details.

Setup the MCS

In this project you’ll be using MCS to collect and visualize the data recorded by the Weather Station hardware. The setup is described in two parts:

  1. Creating a prototype, with data channels to control and monitor data.
  2. Creating a test device to support the hardware connectivity and data transfer.

If you haven’t done so already, sign in or register on MediaTek Labs. From the main navigation toolbar select Dev Tools & Resources, then Cloud Sandbox and Open the Sandbox. Authorization request page is opened where you can sign into MCS with your Labs@mediatek.com account credentials as shown below.

Login to the MCS

Create a new prototype for Weather Station

Setting up your device in MCS requires the creation of a prototype that serves as a blueprint for the actual hardware interface configuration. A prototype consists of one or more data channels of type display, controller and hybrid. The data channels are defined with a Data channel name, Data channel id and data type. The variety of data types and overall structure of the prototype in general is shown below.

General prototype content in MCS

Create data channels

You can now create and configure a Weather Station prototype with data channels as follows:

  1. Click Development in the navigation toolbar, and then under Prototype list click Create to create a new prototype.
    Create a new prototype
  2. Provide the information, as shown below to define the Weather Station prototype.
    Create a prototype profile
  3. Save the information and proceed to the next step. 

    Note: Fields marked by a red asterisk ( ) are required fields.

  4. Click  Detail  to view the prototype information, as shown below. 

    Accessing the Weather Station prototype details


  5. Click Exit  to bypass initiation instructions.Bypassing the data channel initiation instructions
  6. On the  Data channel  toolbar click Add, to provide data channels for the Weather Station prototype. Controller and Display are data channel types available to use. Create a Display data channel for temperature data visualization on MCS by clicking Add.
    Add a data channel to the Weather Station prototype
  7. Controller  and  Display  are data channel types available to use. Create a  Display  data channel for temperature data visualization on MCS by clicking  Add .

    Data channel types

  8. Enter the information for  Data channel name ,  Data channel id Description ,  Data type  and  unitTypes  for temperature data channel and click  Save . The  Data channel name  and  Data Channel id  are a name and an identifier that define the data channel and will be used in an Arduino sketch to communicate with the corresponding sensor. The temperature  unitTypes  is degree Celsius and the  Data type  is a floating point number that has a range determined by the output range of the connected device. For more details on the information you need to provide when setting up a data channel, please refer to  Key concept  in the MCS documentation.

    Temperature data channel details

Repeat steps 6 to 8 to create data channels for humidity and pressure. The humidity is measured in percent and pressure in Pascals, thus the unitTypes should be defined according to these measurement units. The Data type for humidity and pressure data channels is float. For the unique identifier and name use humidity and pressure respectively.

Create a controller channel

To add the optional USB-powered fan or similar device to the Weather Station prototype, define a  Controller  data channel as follows:

  1. Add a  Controller  Data channel.
  2. Click Add under the Controller data channel, as shown below:
    Add a controller to the Weather Station interface
  3. Fill in the details, as indicated in the figure below, to create a fan_control controller.
    Create a switch for a fan controller

You should now have a complete definition of the Weather Station prototype, as shown below:

Weather Station prototype definition

Create a new device from the Weather Station prototype

Each prototype on MCS is defined on a specific hardware platform. The hardware platform used in this tutorial is the LinkIt ONE development board. The Weather Station prototype is mapped to the physical device as follows.

  1. Click Development from the MCS toolbar, and then click the Weather Station’s Prototype detail.

  2. Click Create test device to configure a new device, as shown below.
    Creating a test device for Weather Station prototype
  3. Provide  Device name , an example device name shown below, click OK to continue.
    Weather Station test device configuration
  4. Click Go to detail, as shown below to view the device information.
    Confirmation that a test device for the Weather Station prototype has been created
  5. It’s essential to store the DeviceID and DeviceKey values to enable API calls in the Arduino sketch for device connectivity. Store the values in the device.txt file on the LinkIt ONE development board’s memory. See Configure Wi-Fi settings for details on creating and loading this file to your board.
    Device details for the Weather Station prototype

You’ve now created a test device in MCS matching the Weather Station prototype with three display data channels for temperature, humidity and pressure and a controller data channel for the USB-powered fan. The next section describes the Weather Station’s software implementation.

Create your Weather Station’s software

Your Weather Station needs an Arduino Sketch to share data from the sensors with MCS. This section describes the software required as follows:

  • Overview of the Arduino sketch.
  • Configuring device and Wi-Fi settings.
  • Transmitting sensor data to the MCS.
  • Integrating with MediaTek Cloud Sandbox on a PC and a mobile device.

Overview of the Arduino Sketch

The Arduino project source code is provided in a GitHub repository. The following driver support is required for its successful operation:

The HTTP communication is supported by an HTTPClient driver.

An Arduino sketch is implemented, verified and uploaded to the LinkIt ONE development board. A sketch is a source code file representing the core controlling logic for the LinkIt ONE development board. It consists of two main structures: setup and loop.

  • setup() structure initializes resources, such as the Wi-Fi module.
  • loop() structure continuously listens to and processes events from hardware sensors and software modules. The loop() structure runs forever — until the device is shutdown.

The setup() structure is called only once at the beginning of the program and provides for initialization of the functions, as shown below.

setup() structure call hierarchy

The key functions with their descriptions are given below.

FunctionDescription
void setup()Main program to provide TCP connection and sensor data communication. Executes only once when the device first starts and MCS communication is initiated.
void bmp085Calibration()Initialize sensor pins to specific memory locations.
void readDeviceSetting()Read the content of a device.txt file to determine the device ID connected to Wi-Fi network.
void readWiFiSetting()Read the content of a wifi.txt file to determine the SSID and key values of Wi-Fi connection.
void getconnectInfo()Call RESTful API to get TCP socket connection.
void connectTCP()TCP socket connection.

The loop() structure executes continuously and provides continuous updates of the sensor data on the LCD display and on MCS by calling senddata() function. Functionfatal_error() is called to output an error message and reset the Weather Station device.

FunctionDescription
void loop()Continuous communication with an Access Point (AP) to send the sensor data and check the status of the fan.
void senddata()Sends sensor data.
void fatal_error(const char* str)Determines the source of errors, clears the device state and outputs an error message.

The following sections step through some of the functions to identify the process of device connectivity, Wi-Fi configuration and the sensor data communication.

Configure the device settings

The function readDeviceSetting() extracts device ID and device key information from the device.txt file stored in the flash memory of the LinkIt ONE development board, see Configure Wi-Fi settings for details on creating and loading this file to your board. The device ID and device key were generated when the test device for Weather station prototype was created, see Create a new device from the Weather Station prototype. The device ID and device key are used to identify the Weather Station hardware.

  1. Initialize flash memory
    In function  readDeviceSetting()  initialize the flash memory communication by calling the  begin()  method of  LFlash  class using the  Drv.begin()  statement where Drv is defined as an LFlash object. 

    void readDeviceSetting()
    {
     Drv.begin();
  2. Opening the file to read
    Declare an object f of type LFile to read the content of a file device.txt located on the flash memory of the LinkIt ONE development board. Use Drv.open("device.txt",FILE_READ), which defines the file path and operation mode, to open the device.txt file and prepare to read its content. If the file doesn’t exist printout a message to the serial output calling fatal_error() function. 

     LFile f = Drv.open("device.txt", FILE_READ);
     if(!f)
      fatal_error("Fail to open device.txt");
  3. Reading the data into a character array
    Declare a character array and read the information from the file into the array. Close the file to reallocate the resources and assign the character array length to 0. 

     char buf[100];
     int len = f.size();
    
     f.read(buf, len);
     f.close();
     buf[len] = '\0';
  4. Extract device ID and device key information from an array
    Declare two loops to extract device ID and device key information from buf array and store the information in deviceid and devicekey arrays, respectively. The device ID and device key should be comma “,” separated. The bytes before “,” are allocated for device ID and the bytes after are for the device key. The while loop iterates from the beginning of the array and reads the bytes until it reaches “,” sign, if the “,” isn’t found in the buf character array an error message is sent to the serial output using the fatal_error() function. 

     int i = 0, j = 0;
    
     while(buf[i] && buf[i] != ',')
     {
      deviceid[j++]=buf[i++];
     }
     deviceid[j] = 0;
     if(buf[i] != ',')
      fatal_error("Fail to parse wifi.txt");
     i++;
     j=0;
     while(buf[i])
     {
     devicekey[j++]=buf[i++];
     }
     devicekey[j]=0;
    }
  5. Handling errors
    When an error occurs, details are passed to the function fatal_error() to print error messages on the serial output, clear the display and set the cursor and LED to default settings.

    The full code for the readDeviceSetting() function is given below. 

    void readDeviceSetting()
    {
     Drv.begin();
    
     LFile f = Drv.open("device.txt", FILE_READ);
     if(!f)
      fatal_error("Fail to open device.txt");
    
     char buf[100];
     int len = f.size();
    
     f.read(buf, len);
     f.close();
     buf[len] = '\0';
    
     int i = 0, j = 0;
    
     while(buf[i] && buf[i] != ',')
     {
      deviceid[j++]=buf[i++];
     }
     deviceid[j] = 0;
     if(buf[i] != ',')
      fatal_error("Fail to parse wifi.txt");
     i++;
     j=0;
     while(buf[i])
     {
      devicekey[j++]=buf[i++];
     }
     devicekey[j]=0;
    }

Configure Wi-Fi settings

The function  readWiFiSetting()  is similar to the  readDeviceSetting()  function. Here the  ssid  and key for Wi-Fi configuration are extracted from  wifi.txt  file located on the flash memory of the LinkIt ONE development board.

Sending sensor data to the MCS

The setup() function is called only once to initialize the Wi-Fi and device settings, LCD display, fan control and sensors. The loop() function runs continuously and communicates the sensor data from the Weather Station hardware to the MCS. The details of the loop function are described below:

  1. Connecting to an AP.
    Check the status of the Wi-Fi connectivity by calling the status() function of the LWiFiclass. If the Wi-Fi is disconnected (LWIFI_STATUS_DISCONNECTED) then a warning message is printed to the serial output. If Wi-Fi is available the device ssid and key information are used to connect to the AP using LWiFi.connect(ssid, LWiFiLoginInfo(WIFI_AUTH, key). There is a delay of one second (1000 ms) to wait for the connection to be established.

    void loop() {
     if (LWiFi.status() == LWIFI_STATUS_DISCONNECTED) {
      Serial.println("Disconnected from AP");
      while (0 == LWiFi.connect(ssid, LWiFiLoginInfo(WIFI_AUTH, key))){
       Serial.println("Connecting to AP");
       delay(1000);
      }
     }
  2. Sending the sensor data.
    Sending the sensor data is synchronized with the real time clock of the LinkIt ONE development board. The data from the TPH sensor board is sent periodically. The current and last timestamps are compared to the value of per variable, which is initialized to five seconds, to indicate the time interval at which the sensor data is uploaded to the MCS.

     LDateTime.getRtc(&rtc);
     if ((rtc - lrtc) >= per) {
      Serial.println("Senddata");
       senddata();
      lrtc = rtc;
    }

    Let’s explore the  senddata()  function for temperature sensor data communication only.

    1. Reading the data from the temperature sensor.
      A variable temp of data type float is first declared and assigned to the output of the readsht1temp() function. readsht1temp() function initiates a wire transfer using Wire library and its functionality and converts the received bytes into floating point number. The Wire library supports inter integrated circuit (I2C) or two wire interface (TWI) device communication from a specified memory address. 

      void senddata() {
       Serial.println("Begin of senddata");
       float temp = readsht21temp();
    2. Displaying the converted temperature on the Grove LCD Backlight.
      Send the formatted floating point number to a string pointed to, by buffert using function sprintf()lcd.print(buffert) function then send the value of buffert to the LCD display of the Weather Station. 

       Serial.println("1");
       char buffert[5];
       sprintf(buffert, "%.2f", temp);
       Serial.println("2");
       // display status
       lcd.clear();
       lcd.setCursor(0, 0);
       lcd.print("T:");
       lcd.print(buffert);
    3. Prepare the data for POST request.
      Combine a header with the data recorded from the Weather Station’s temperature sensor and package them into a string to send it in your POST request. The string is also sent to the serial output by calling println() method of the Serial class. 

       String data = "temperature,," + String(buffert);
       Serial.println(data);
    4. Sending the temperature sensor data to the MCS server.
      Establish a successful connection with MCS server and send the HTTP POST request to transfer data. length() function returns the length of the data string which is stored in variable thisLength. An object c2 of class LWiFiClient is then declared. A timer is initialized using millis() function which returns the number of milliseconds since the LinkIt ONE development board began running the program. The while loop checks the connectivity to the site URL calling the connect(SITE_URL, 80) method of c2 Wi-Fi client object providing one second waiting time to reconnect to the website using delay(1000)function. connect(SITE_URL, 80) method makes an HTTP connection to the server and POSTs data. 

       int thisLength = data.length();
       LWiFiClient c2;
       while (0 == c2.connect(SITE_URL, 80))
       {
        Serial.println("Re-Connecting to WebSite");
        delay(1000);
       }
    5. Edit the POST URL.
      Update the POST URL to the location of your datapoints.csv on your web-host using the statements below: 

       delay(500);
       Serial.println("send POST request");
      
       c2.print("POST /mcs/v2/devices/");
       c2.print(deviceid);
       c2.println("/datapoints.csv HTTP/1.1");
    6. Edit the Host information.
      Update the Host to match your domain and send the data using c2.println(data) statement

       c2.print("Host: ");
       c2.println(SITE_URL);
       c2.print("deviceKey: ");
       c2.println(devicekey);
       c2.print("Content-Length: ");
       c2.println(thisLength);
       c2.println("Content-Type: text/csv");
       c2.println("Connection: close");
       c2.println();
       c2.println(data);
    7. Handling errors.
      Allow data to fully upload to the MCS server and disconnect after successful completion. If there is an error during the transmission a variable errorcount is incremented and the Wi-Fi client is disconnected if the value of errorcount is greater than ten. 

       String dataget = "";
       Serial.println("waiting HTTP response:");
       int errorcount = 0;
       while (!c2.available())
       {
        Serial.println("waiting HTTP response:");
        errorcount += 1;
        if (errorcount > 10) {
         c2.stop();
         return;
        }
        delay(100);
       }
       while (c2)
       {
        int v = c2.read();
        if (v != -1)
        {
         Serial.print(char(v));
      
         delay(1);
        }
        else
        {
         Serial.println("no more content, disconnect");
         c2.stop();
        }
      }
    8. Upload the data to MCS
      The display and cursor values are cleared and reinitialized. A message on successful data upload is printed on the LCD display and a new timer is set to the output of the  millis() function. 

       lcd.clear();
       lcd.setCursor(0, 0);
       lcd.print("Data uploaded");
       lcd.setCursor(0, 1);
       lcd.print("to MCS");
       delay(300);
      }

      The full code for the  senddata()  function is provided below. 

      void senddata() {
       Serial.println("Begin of senddata");
       float temp = readsht21temp();
      
       Serial.println("1");
       char buffert[5];
       sprintf(buffert, "%.2f", temp);
       Serial.println("2");
       // display status
       lcd.clear();
       lcd.setCursor(0, 0);
       lcd.print("T:");
       lcd.print(buffert);
      
      
       String data = "temperature,," + String(buffert);
       Serial.println(data);
      
       int thisLength = data.length();
       LWiFiClient c2;
      
       while (0 == c2.connect(SITE_URL, 80))
       {
        Serial.println("Re-Connecting to WebSite");
        delay(1000);
       }
      
       delay(500);
       Serial.println("send POST request");
      
       c2.print("POST /mcs/v2/devices/");
       c2.print(deviceid);
       c2.println("/datapoints.csv HTTP/1.1");
       c2.print("Host: ");
       c2.println(SITE_URL);
       c2.print("deviceKey: ");
       c2.println(devicekey);
       c2.print("Content-Length: ");
       c2.println(thisLength);
       c2.println("Content-Type: text/csv");
       c2.println("Connection: close");
       c2.println();
       c2.println(data);
      
       String dataget = "";
       Serial.println("waiting HTTP response:");
      
       int errorcount = 0;
       while (!c2.available())
       {
        Serial.println("waiting HTTP response:");
        errorcount += 1;
        if (errorcount > 10) {
         c2.stop();
         return;
        }
        delay(100);
       }
       while (c2)
       {
        int v = c2.read();
        if (v != -1)
        {
         Serial.print(char(v));
      
         delay(1);
        }
        else
        {
         Serial.println("no more content, disconnect");
         c2.stop();
        }
       }
       lcd.clear();
       lcd.setCursor(0, 0);
       lcd.print("Data uploaded");
       lcd.setCursor(0, 1);
       lcd.print("to MCS");
       delay(300);
      }
  3. Turning the fan ON or OFF.
    An optional USB-powered fan can be turned on or off using a TCP socket command from the MCS server. The while loop checks if the object c of LWiFiClient class is available and then an if statement compares its value to either 0 or 1. If the value equals to one then the voltage is turned to High on the fan output pin and the fan turns on, otherwise it turns off. A message is printed on the LCD display indicating the status of the fan. 

    //Check for TCP socket command from MCS Server 
    String tcpcmd="";
    while (c.available())
     {
      int v = c.read();
      if (v != -1)
      {
       Serial.print((char)v);
       tcpcmd += (char)v;
       if (tcpcmd.substring(52).equals("1")){
        digitalWrite(FAN_PIN, HIGH);
        lcd.clear();
        lcd.print("Switch FAN ON ");
        tcpcmd="";
       }else if(tcpcmd.substring(52).equals("0")){
        digitalWrite(FAN_PIN, LOW);
        lcd.clear();
        lcd.print("Switch FAN OFF");
        tcpcmd="";
       }
      }
     }
  4. Keeping track of time.
    As the sensor data is sent to the MCS periodically the time is also updated periodically in order to synchronize message transmission through the TCP socket communication. 

    //Check for heartbeat interval 
     LDateTime.getRtc(&rtc2);
     if ((rtc2 - lrtc2) >= per1) {
      heartBeat();
      lrtc2 = rtc2;
     } 
    }

    The full implementation of the  loop()  function is provided below: 

    void loop() {
     if (LWiFi.status() == LWIFI_STATUS_DISCONNECTED) {
      Serial.println("Disconnected from AP");
      while (0 == LWiFi.connect(ssid, LWiFiLoginInfo(WIFI_AUTH, key))){
       Serial.println("Connecting to AP");
       delay(1000);
      }
     }
    
     LDateTime.getRtc(&rtc);
     if ((rtc - lrtc) >= per) {
      Serial.println("Senddata");
       senddata();
      lrtc = rtc;
     }
    
     //Check for TCP socket command from MCS Server 
     String tcpcmd="";
     while (c.available())
     {
      int v = c.read();
      if (v != -1)
      {
       Serial.print((char)v);
       tcpcmd += (char)v;
       if (tcpcmd.substring(52).equals("1")){
        digitalWrite(FAN_PIN, HIGH);
        lcd.clear();
        lcd.print("Switch FAN ON ");
        tcpcmd="";
       }else if(tcpcmd.substring(52).equals("0")){ 
        digitalWrite(FAN_PIN, LOW);
        lcd.clear();
        lcd.print("Switch FAN OFF");
        tcpcmd="";
       }
      }
     }
     //Check for hearbeat interval
     LDateTime.getRtc(&rtc2);
     if ((rtc2 - lrtc2) >= per1) {
      heartBeat();
      lrtc2 = rtc2;
     } 
    }

    The humidity and pressure sensor data are communicated similarly. Next section describes the Wi-Fi configuration on the LinkIt ONE development board.

Configure Wi-Fi settings on the LinkIt ONE development board

The Weather Station application utilizes wireless communication between a LinkIt ONE development board and MCS. The method of communication used in this tutorial is through a Wi-Fi hotspot. The following steps will enable IP configuration on the LinkIt ONE development board. For more details on switches on the LinkIt ONE development board refer to the pin-out diagram.

  1. Connect LinkIt ONE development board to your computer using Micro-USB port.
  2. Turn the USB Power Source/Li Battery Power Source switch to USB Power Source mode.
  3. Set the Mass Storage Bootup/Normal Bootup switch to Mass Storage Bootup mode.
  4. Press the reset button.
    Ports and modes on the LinkIt ONE development board
  5. Once the LinkIt ONE development board is connected to your computer an external device drive will be detected, as shown in the figure below.
    LinkIt ONE development board in a Mass Storage Bootup mode
  6. Open the  Removable Disk  drive and observe the content of  wifi.txt , as shown below. The Arduino sketch will read the content of wifi.txt file to detect the SSID and key values for Wi-Fi hotspot in order to enable Weather Station application’s wireless connectivity. Replace and save the content of this file with actual SSID and key values of your Wi-Fi hotspot. 

    Note: WEP and WPA are currently supported.

      Wi-Fi configuration settings Once the Wi-Fi hotspot is available follow these steps to provide wireless connectivity to LinkIt ONE development board. Refer to the figure in step 4  for the switch names and options.

  7. Disconnect the Micro-USB cable.
  8. Set the Mass Storage Bootup/Normal Bootup switch to Normal Bootup mode.
  9. Set the USB Power Source/Li Battery Power Source switch to Li Battery Power Source mode.
  10. Connect the battery pack to the power jack.
  11. Reset the LinkIt ONE development board.

After successful connection the LCD panel on the Weather Station will display the following messages:

Confirmation on connecting to the MediaTek Cloud Sandbox

Temperature, Humidity and Pressure values obtained from sensors Congratulations, the Weather Station is now connected to the MCS using Wi-Fi hotspot and LinkIt ONE development board equipped with sensors.

Remote access to the Weather Station prototype

Once the device and the prototype are defined click  My Devices  on the MCS toolbar to view existing devices or add one.

View available devices on MCS

Accessing Weather Station device details


Click  Detail  on Weather Station test device from the  Device list  menu. The values of temperature, humidity and pressure will be on the display along with the fan control option.

Real-time sensor data on MCS

Each of those controls has a shortcut menu. Open the shortcut menu for data channel to view the available options.

  Card menu History and API Hint options

The History option provides all the past and present values of the data channel, in this case temperature.

Temperature values over time

The fan control has two options – ON and OFF. The Weather Station demo kit has a micro – USB port to attach a small fan and view it running when the switch is ON.

Congratulations, you have now completed the Weather Station prototype setup.

MCS provides mobile app to remotely control the existing prototypes connected to the LinkIt ONE development board. Download and install the app on an Android Wi-Fi hotspot enabled smartphone or tablet device to get started with the Weather Station tutorial on a mobile device.

Conclusion

In this tutorial you have implemented a remote controlled Weather Station application using LinkIt ONE development board, TPH sensors, MediaTek Cloud Sandbox and Arduino programming environment.

For more information on MediaTek LinkIt ONE development and prototyping board and cloud services refer to LinkIt ONE developer’s guide and MediaTek Cloud Sandbox.