HTTP Receiver
ResIOT comes a built-in web EndPoint for you to push data to.
Generic HTTP Receiver¶
To retrieve the URL EndPoint of your web server, head to Data Connectors -> HTTP Receivers. By default ResIOT comes with a pre-installed receiver which can be used by everyone without any configuration needed by the user.
This guide will explain how to push data to ResIOT via the pre-installed receiver.
In order to execute a valid request, when pushing data you will need to enter a few headers along with a json body in a format that ResIOT accepts.
HTTP Headers¶
Only two headers are required in your request:
Content-Type: application/json
authorization: [VALID_HTTP_SECURITY_TOKEN]
As you can see, a valid security token is needed by ResIOT in order to understand who is reaching the platform. To create a valid token for HTTP receivers, please refer to the Tokens page.
HTTP Body¶
Only a few data is required for your request to work. The request body has to be a valid JSON with the following format.
{
"msgtype" : "data_uplink",
"data" : "[your_data_payload]",
"deveui": "[your_device_DevEui]",
"appeui": "[your_device_AppEui]"
}
Here's a valid example:
{
"msgtype" : "data_uplink",
"data" : "a2b3cc",
"deveui": "1111",
"appeui": "1234123412341231"
}
The msgtype
field is mandatory, and the value must be set to data_uplink
as it tells the receiver we're talking about a device sending data. If omitted, or with a different value, the server will not treat the request as a comm_rx
.
The data
field is the application payload of your device and has to be hex-encoded.
The deveui
field is mandatory and it represents the device ID of the device sending data.
The appeui
field is optional and needed only for LoRaWAN devices, the platform will take care of assigning/retrieving the application to your device if it's omitted.
Passing Additional data¶
Using the generic receiver, the only way to pass data to the platform is using the data
field of the body. Additional JSON fields will be ignored by the platform and can not be handled programmatically.
If you really need to pass additional data in your POST body, for example adding JSON fields, please refer to the Dedicated endpoint receivers solution
Device Auto-provisioning¶
You can configure ResIOT to automatically create/register devices sending data to your HTTP endpoint.
In order to do so, head to your Settings -> Organization Settings page and make sure the HTTP Receiver Autoprovisioning
flag is checked.
Dedicated endpoint receivers¶
You have the ability to created dedicated HTTP receivers.
Each receiver will be assigned a unique HexID
that can be retrieved from the list of your receivers. In order to push data to your newly created dedicated receiver, just use the same URL as the generic one, but reaplace the generic
ending part with your dedicated receiver hexid
Here's an example:
https://eu72.resiot.io/endpoints/generic
becomes
https://eu72.resiot.io/endpoints/b2c5842d
Your dedicated receiver will receive data just as the generic one but:
- You are free to choose the format of your POST body
- The body of your push is not linked to a device anymore
You can now create a Scene the will handle your pushed data as follows:
-- My Dedicated Receiver Handler
body = resiot_comm_getparam("body")
appeui, err = json_getfield(body, "appeui") --this assumes you passed a "appeui": "...." field in your json body
deveui, err = json_getfield(body, "deveui") --this assumes you passed a "deveui": "...." field in your json body
value, err = json_getfield(body, "substruct.data.value") --this assumes your json is like {"substruct":{"data":{"value":25, ....}}}
-- refer to https://docs.resiot.io/Scene_objectjson/ to work with json objects and do not forget to handle errors!
You can finally create a smart Scene that calls your LUA scene when a push is received
Unlike the Generic Receiver, this approach does not trigger device automations such as auto-provisioning, but you can still work with your devices with a more flexible approach!