This is a simple tutorial for connecting an Arduino Ethernet board to OGC SensorThings API.
Start TutorialThis is a simple tutorial of connecting an Arduino Ethernet board to OGC SensorThings API.
Please register an account in OGC SensorThings Playground and follow the steps to create SensorThings entities for your Arduino. When it is finished, make note of the following variable values:
Now, let's begin by walking through the code, how to read the temperature and send the value to the SensorUp SensorThings Playgound.
This part shows you how to initialize the Ethernet client library with the IP address and port of the server that you want to connect to (port 80 is the default for HTTP):
Please enter a MAC address for your controller. Newer Ethernet shields have a MAC address printed on a sticker on the shield byte, like mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }. For older shields, choose your own.
Set the static IP address to use if the DHCP fails to assign IPAddress ip(127, 0, 0, 1).
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, and SERVER_URL with your information.
This part shows how to use DHCP mode with Ethernet Shield.
Start serial communication with a baud rate of 9600 followed by initiating Ethernet connection.
Wait for voltages to become stable and then read the output. The returned temperature is in degrees Celcius.
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 for debugging purposes.
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 2.5 seconds.