[Tutorial] SensorThings API 101 - How to upload observation data to SensorThings API
This is a step-by-step tutorial regarding creating a Thing
instance, the related entities with SensorThings API, and eventually upload sensor readings.
You can also download the Postman script here (download). (Note: Postman is a great tool for sharing and sending RESTful requests.)
If you haven't seen the OGC SensorThings UML diagram, it might be a very good idea to look at it first (link to UML).
Step-by-step guide
Step 1: CREATE a Thing entity instance as well as the Thing's Location.
In this case, a weather station is modelled as a Thing
in the SensorThings API data model. The Icelandic Weather Office (example station) provides excellent data description and we can easily convert the table into the following SensorThings API JSON.
POST: URL_to_the_Server
(You can use SensorUp's sandbox server: http://chashuhotpot.sensorup.com/OGCSensorThings/v1.0)
Header: Content Type: application/json
Step 2.a: CREATE an ObservedProperty
instance (when the observed property doesn't existing in the system)
If no existing ObservedProperty
, create an ObservedProperty
entity instance by POST
the following JSON to the server. An ObservedProperty
describes what is the phenomenon a datastream is measuring. And once an ObservedProperty
is created, it SHALL be reused by other Datastreams
that measuring the same phenomenon. In this example, we use the definition from DBPedia. Note that different domain application might have different definition though.
Step 2.b: When the observed property already exists in the system.
When the ObservedProperty
already exists in the system, Go To Step 3.
Is the ObservedProperty already in the system?
You can simply issue a request to URL/ObervedProperties
to list all the existing ObservedProperties in the system (e.g., click here), and find the one you can use. Only create new ones if you cannot find an existing one.
Step 3.a: If no existing Sensor
, CREATE a new Sensor
.
Similar to the previous step, if the Sensor
doesn't already exist in the system, create a new instance by POST
the following JSON request. However, if the Sensor
already exists, it should be re-used.
Differences between Sensor and Thing?
How a Thing
different from a Sensor
??
A Sensor
is "an entity capable of observing a phenomenon and returning an observed value. Type of observation procedure that provides the estimated value of an observed property at its output. [OGC 12-000] ". For example, a Campbell weather station (e.g., road weather information station) can be modelled as a Thing
, and multiple Sensors
(examples) can be mounted on the station.
Step 3.b: If the Sensor
already exists.
Go to Step 4.
Step 4: CREATE a new Datastream by linking to the newly created (or existing) Sensor and ObservedProperty
Step 5: If the FeatureOfInterest is different from the Thing
Location, then either CREATE a new FeatureOfInterest or LINK to an existing one.
In this example, the FoI and the Thing's Location are the same, so we don't need to do anything. Server will create the FoI automatically.
Step 6: CREATE new Observations
Finally, we have established all the required "metadata" for the observations. Now we can upload many many observations to the system.
Step 7: Retrieve the uploaded Observations
Finally, you can retrieve the Observations you just created by issuing a GET request to the server URL, like this: http://chashuhotpot.sensorup.com/OGCSensorThings/v1.0/Datastreams(453609)/Observations
BTW, feel free to ask questions by leaving comments below.
Related articles