Today I want to show you how to configure HTTP channel to parse custom json to flespi format. For example we will take StarLine retranslator (SLNet Retranslator) protocol.
Position messages will come in the following format (HTTP protocol):
POST / HTTP/1.1\r\n
Host: *****************\r\n
Accept-Encoding: gzip, deflate\r\n
User-Agent: python-requests/2.4.3 CPython/3.4.2 Linux/4.15.18-9-pve\r\n
Accept: */*\r\n
Content-Type: application/json\r\n
Content-Length: 360\r\n
Connection: keep-alive\r\n
\r\n
{"messages": [{"imei": "******", "type": "position", "device_id": *****, "position": {"hdop": 2.2, "altitude": 226, "glonass": 0, "mileage": 4408000, "ignition": false, "gps": 6, "time": 1597926696, "direction": 0, "mileage_type": 1, "longitude": **.******, "latitude": **.******, "partial_distance": 8, "speed": 0}, "received": 1597926709}]}
Also you can catch event messages. It looks like:
POST / HTTP/1.1\r\n
Host: *****************\r\n
User-Agent: python-requests/2.4.3 CPython/3.4.2 Linux/4.15.18-24-pve\r\n
Content-Length: 178\r\n
Content-Type: application/json\r\n
Accept-Encoding: gzip, deflate\r\n
Accept: */*\r\n
Connection: keep-alive\r\n
\r\n
{"messages": [{"device_id": ******, "received": 1597927602, "imei": "******", "type": "event", "event": {"time": 1597927596, "event_id": 501, "group": "ARM"}}]}
You must create a channel with http protocol. You can copy and paste the JSON to fill out the form:
{
"messages_ttl": 2592000,
"enabled": true,
"name": "StarLine HTTP",
"configuration": {
"ident": "%imei%",
"parameters": [
{
"name": "position.altitude",
"type": "manual",
"value": "/position/altitude"
},
{
"name": "position.longitude",
"type": "manual",
"value": "/position/longitude"
},
{
"name": "position.latitude",
"type": "manual",
"value": "/position/latitude"
},
{
"name": "position.direction",
"type": "manual",
"value": "/position/direction"
},
{
"name": "timestamp",
"type": "manual",
"value": "/position/time"
},
{
"name": "timestamp",
"type": "manual",
"value": "/event/time"
},
{
"name": "glonass.position.satellites",
"type": "manual",
"value": "/position/glonass"
},
{
"name": "gps.position.satellites",
"type": "manual",
"value": "/position/gps"
},
{
"name": "engine.ignition.status",
"type": "manual",
"value": "/position/ignition"
},
{
"name": "position.hdop",
"type": "manual",
"value": "/position/hdop"
},
{
"name": "vehicle.mileage",
"type": "manual",
"value": "/position/mileage"
},
{
"name": "message.type",
"type": "manual",
"value": "/type"
},
{
"name": "event.group",
"type": "manual",
"value": "/event/group"
},
{
"name": "event.id",
"type": "manual",
"value": "/event/event_id"
}
],
"path": "messages"
},
"commands_ttl": 86400,
"protocol_id": 37
}
The "path" configuration field declares where the parser can find the messages array or message object.
Now you can see the parsed messages and work with them as native flespi messages.
For example you can create a device with ident = imei device_type = http and collect messages by device.
Note: To start receiving messages from the Starline platform, you should request StarLine technical support to point the StarLine retranslator to the uri of your channel.
That is it.