2.5. Sensor Fields¶
Sensor fields are the fields of data saved in a sensor stream. Together they make up the sensor schema.
Each sensor has the following default fields:
Field Name | Information |
---|---|
value | The numerical data for the sensor. Required. |
lat | The latitude of the sensor. Required. |
lng | The longitude of the sensor. Required. |
message | The string message for the sensor. Not Required. |
Each sensor field consists of the following:
Field Name | Information |
---|---|
name | The unique name for the sensor field. It is required when creating/updating/deleting a field and cannot be changed. |
longName | The display name for the field. |
type | Can be “NUMBER” or “STRING”. It is required when creating/updating a field. |
required | Is a boolean field. If true, data sent to a sensor must include this field or an error will result. Optional. |
units | Is a string. Optional. |
index | The numerical index of the field used to maintain ordering. This field is automatically generated by the system and is read only. |
value | The last value of this sensor field received by the sensor when sending data. This is a read only field set when the sensor receives data for this field. |
lastUpdate | The time stamp of the last value sent to the field. This is a read only field set when the sensor receives data for this field. |
2.5.1. Querying Sensor Fields¶
To retrieve the sensor fields for a specific sensor:
URL | http://wotkit.sensetecnic.com/api/sensors/{sensorname}/fields |
Privacy | Public or Private |
Format | json |
Method | GET |
Returns | Appropriate HTTP status code; OK 200 - if successful |
To query a single sensor field for a specific sensor:
URL | http://wotkit.sensetecnic.com/api/sensors/{sensorname}/fields/{fieldName} |
Privacy | Public or Private |
Format | json |
Method | GET |
Returns | Appropriate HTTP status code; OK 200 - if successful |
2.5.2. Updating a Sensor Field¶
You can update or add a sensor field by performing a PUT operation to the specified field. The field information is supplied in a JSON format.
If the sensor already has a field with the given name, it will be updated with new information. Otherwise, a new field with that name will be created.
Notes:
- When inputting field data, the sub-fields “name” and “type” are required-both for adding a new field or updating an existing one.
- Read only sub-fields such as index, value and lastUpdate should not be supplied.
- The “name” sub-field of an existing field cannot be updated.
- For user defined fields, the “longName”, “type”, “required”, and “units” sub-fields may be updated.
- You cannot change the index of a field. If a field is deleted, the index of the following fields will be adjusted to maintain the field order.
To update/add a sensor field:
URL | http://wotkit.sensetecnic.com/api/sensors/{sensorname}/fields/{fieldname} |
Privacy | Private |
Format | json |
Method | PUT |
Returns | HTTP status code; No Content 204 if successful |
For instance, to create a new field called “test-field”:
example
curl --user {id}:{password} --request POST --header "Content-Type: application/json" --data-binary @field-data.txt 'http://wotkit.sensetecnic.com/api/sensors/test-sensor/fields/test-field'
The file field-data.txt could contain the following. (This is the minimal information needed to create a new field.)
{
"name":"test-field",
"type":"STRING"
}
To then update “test-field” sub-fields, the curl command would be used to send a PUT request.
example
curl --user {id}:{password} --request PUT --header "Content-Type: application/json" --data-binary @field-data.txt 'http://wotkit.sensetecnic.com/api/sensors/test-sensor/fields/test-field'
And ‘’field-data.txt’’ could now contain the following.
{
"name":"test-field",
"type":"NUMBER",
"longName":"Test Field",
"required":true,
"units":"mm"
}
2.5.3. Deleting a Sensor Field¶
You can delete an existing sensor field by performing a DELETE and including the field name in the URL.
To delete a sensor field:
URL | http://wotkit.sensetecnic.com/api/sensors/{sensorname}/fields/{fieldname} |
Privacy | Private |
Format | n/a |
Method | DELETE |
Returns | HTTP status code; No Content 204 if successful |