Raspberry Pi: Connect to STA

This is a simple tutorial of connecting Raspberry Pi to OGC SensorThings API. We will show you how to use Raspberry Pi to upload temperature readings to the SensorThings API server.

Start Tutorial

Raspberry Pi:

Connect to SensorUp SensorThings

This is a simple tutorial to demonstrate how to connect a Raspberry Pi with GrovePi to a SensorThings API server.

Hardware and software you will need:

  • Raspberry Pi
  • GrovePi
  • Grove DHT Sensor
  • Grove Connection wires

GrovePi is an open source platform for connecting Grove Sensors to the Raspberry Pi. All the parts used in this tutorial are available in the GrovePi Starter Kit.

Prerequisites

A fully set up Raspberry Pi board with Internet access

For information about setting up your Raspberry Pi, see Raspberry Pi Quickstart Guide.

Install GrovePi+ on the Raspberry Pi, please refer to Setting Up The Software.

Set the SensorThing API (STA) Request Parameters

Those information come from the STA 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 STA Playground, please refer to the Tutorial: Create SensorThings Datastream in SensorUp SensorThings API Playground.

  • DATASTREAM_ID_TEMP
  • ACCESS_TOKEN
  • SERVER_URL

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

Connecting the Raspberry Pi temperature sensor

Connect the DHT sensor to Port 8. Now power on the Raspberry Pi.

Connecting the Raspberry Pi temperature sensor

Running the Program

In the Raspberry Pi terminal, run the sta_sensor.py in python program in root (sudo):

sudo python sta_sensor.py

The program will start sending the live temperature data from the DHT sensor to a SensorThings API server every 30 seconds.

Note the dht_sensor_type below may need to be changed depending on which DHT sensor you have:

  • 0 - DHT11 - blue one - comes with the GrovePi+ Starter Kit
  • 1 - DHT22 - white one, aka DHT Pro or AM2302
  • 2 - DHT21 - black one, aka AM2301