How to retrieve real-time readings from SensorUp SensorThings?
Quicklink
Objective
This is a short tutorial explaining how to retrieve the metadata datastreams of a live video camera. The static information can be retrieved with OGC SensorThings API via HTTP. The dynamic information can be retrieved with OGC SensorThings API MQTT.
Background
OGC SensorThings has the following key concepts:
Thing
- a
Thing
can be a sensor system or a person who wear multiple sensors. AThing
can have multipleDatastreams
, such as speed, heart rate, live video, bearing, etc.
- a
Datastream
Datastream
groups multipleObservations
. You can get the metadata ofObservations
from here.
Observation
- where you can find the "readings", and we call it
result
.
- where you can find the "readings", and we call it
There are more details, but I guess these are enough for now.
A Video Cam System as a Thing
- A Garmin XE Virb is a Thing, and it can have multiple Datastreams, such as live video feed, bearing, speed, body temperature, etc.
- As a result, in order to retrieve the "metadata", in fact you are retrieving Observations from another Datastream.
Retrieve Readings (Observations) via SensorThings API
- It is very easy to retrieve Observations from another Datastream. Let's use the following example.
- SensorUp set up a Garmin XE Virb as a Thing on PS-Cloud, and the detail of the Thing can be retrieve with the following URL.
- And the
Datastreams
of theThing
can be retrieved with the following link (basically add "Datastreams" after the above URL)- http://ogc-pilot.sensorup.com:8080/OGCSensorThings/v1.0/Things(70570)/Datastreams
- and the above link gives you a list of the available Datastreams. One of the Datastreams is a live video feed (id 70590), and the rest of the Datastreams are so-called "metadata" (id 78731).
- Let's say we want to get a speed Datastream (id 78731), and you can use the following link (
Datastreams(id)/Observations
)- http://ogc-pilot.sensorup.com:8080/OGCSensorThings/v1.0/Datastreams(78731)/Observations?$select=result,phenomenonTime
- If you keep requesting the above link, it gives you the readings from the speed
Datastream
. It is great for retrieve historical readings. But it's quite boring, as the latest data are not "pushed" to you.
Pushing and streaming new reading whenever they are available (Observations) via SensorThings API MQTT
- SensorUp PS-Cloud has the MQTT feature, and it can push readings to you in real-time.
- Simply use the same URL path described above, you can received new readings via MQTT.
- e.g., the URL for the speed
Observations
isv1.0/Datastreams(78731)/Observations
- note: as the camera is not moving most of the time, most likely you will not receive new speed readings.
- But let's use a different
Datastream
, we do have a live sensor uploading data every 10 seconds.- The
Datastream
id is69665
, so the URL path (or the MQTT Topic) isv1.0/Datastreams(69665)/Observations
- Click the following link to see the sample code and sample application to receive the real-time readings
- http://jsfiddle.net/d7406kw9/2/
- FYI, from the code you will find the MQTT Broker URL is
ogcpilot.sensorup.com
, and the port number is9001
.
- You can also click the following link to see a live chart
- The
Summary
This is a very brief tutorial of how to get the live data stream from "metadata". In fact, these metadata are also Observations
. SensorUp is the editor of the OGC SensorThings API and provides the most complete and comprehensive OGC SensorThings API solution. Please feel free to contact us if you need to learn more about our offerings.