ARM mbed LPC1768: Connect to SensorThings API

This is a simple tutorial of connecting ARM mbed LPC1768 to OGC SensorThings API. We will show you how to use mbed to upload temperature readings to the SensorUp SensorThings Playground.

Start Tutorial

ARM mbed LPC1768:

Connect to SensorUp SensorThings

This is a simple tutorial of connecting ARM mbed LPC1768 to OGC SensorThings API. This tutorial will show you how to use mbed to upload temperature readings to the SensorUp SensorThings Playground.

Please refer to this Tutorial: Connect mbed to OGC SensorThings API - Part II to prepare the development environment. Visit ARM mbed OS developer site now

Then, simply register an account in OGC SensorThings Playground and follow the steps to create SensorThings entities for your mbed. When it is finished, make note of the following variable values:

  • DATASTREAM_ID_TEMP
  • ACCESS_TOKEN

Now, let's begin by walking through the code, how to read the input from temperature sensor and send the value to the SensorUp SensorThings Playgound.

Hardware you will need:

Example code:

Set the SensorThing API Request Parameters

Those information come from the SensorUp SensorThings Playground. If you didn't have one, please go to OGC SensorThings Playground and get the following variable values. If you don't know how to use SensorUp SensorThings Playground, please refer to the Tutorial: Create SensorThings Datastream in SensorUp SensorThings API Playground.

  * DATASTREAM_ID_TEMP
  * ACCESS_TOKEN

Make sure you edit the fields where it says DATASTREAM_ID_TEMP and network ACCESS_TOKEN with your information.

Initialize Ethernet

In this tutorial, our mbed is connected to the internet through an Ethernet network.

So that we have to import these packages in the compiler as libraries using those links:

Send HTTP request

In the previous step, we import the TinyHTTP. In this case, we prefer TinyHTTP to official HttpClient to send http request, because it is easier to change the parameters of the request based on our requirements.

But you can also try the HTTPClient if you want.

Get temperature sensor data

Get data from the LM75B temperature sensor and display on the 128x32 LCD.

mbed-example-photo

Please remember to import packages for the sensor and the LCD in the compiler as libraries using those links:

Post temperature data to SensorThings server

1.Prepare the data for POST request. Package the sensor reading into a JSON string to send it in an HTTP POST request. The string is also sent to the serial output by calling println() method of the Serial class.

2.Sending the temperature sensor data to the SensorThings server. Establish a successful connection with SensorThings server and send the HTTP POST request to transfer data every Interval second(s).