HowTo use REST/JSON
REST specific PFAL commands
-
command to sent HTTP REST with URL encodiong TCP.Send.Rest,"",,""
- : http:// must be included!; optional :<port_number> is possible
- : 0 - no encryption is used
- : url-encoded key1=val1&key2=val2&..&key=val
-
command to sent HTTP REST with JSON body
TCP.Send.JSON,"<URL>",<enableBodyEncryption>,"<Parameter-String>"
- : http:// must be included!; optional :<port_number> is possible
- : 0 - no encryption is used
- : have to start with { and end with } key names have to enclosed by escaped character ' between key and value the character : is required values: strings have to enclosed by escaped character ' fractional numbers with . as separator
-
new dynamic entry &(HttpResponse) - reports the last responded HTTP status message/error code
-
write command for Multi parameter JSON
TCP.JSON.Write,"<Parameter-String>"
write single data line to flash buffer for unsent msg, each with leading marker
- flush command for Multi parameter JSON
TCP.JSON.Flush,"<URL>",<enableBodyEncryption>,"<Parameter-String>"
send unsent data as MultiMsg JSON : JSON with additional marker as placeholder for stored single data lines {,}
EXAMPLE
simple send position data
PFAL command example
PFAL command example to write JSON data (executed multiple times)
$PFAL,TCP.JSON.Write,"{
<d4fb>\'&(Date)_&(Time)\':{\'IMEI\':&(IMEI),\'AI1\':&(IN1)}}"
PFAL command example to flush
$PFAL,TCP.JSON.Flush,"http://59.181.166.3:47000/demo/telematics",0,"{\'KEY\':\'&(Date)_&(Time)\',\'MOVELETKEY\':\'blackbox-fox3\',\'ACK\':\'SUCCESS\',\'PARTICIPANTKEY\':\'&(Date)_&(Time)\',<d4fb>}"
HTTP POST
POST /demo/telematics HTTP/1.0
HOST: 59.181.166.3..User-Agent:AVLemb/2.13
Content-Type: application/json; charset=ISO-8859-1
FAL-IMEI: 353816054730215..FAL-ENCRYPTION: 1
Content-Length: 776
{"KEY":"06.01.1980_00:09:21","MOVELETKEY":"blackbox-fox3","ACK":"SUCCESS","PARTICIPANTKEY"
:"06.01.1980_00:09:21",
"06.01.1980_00:01:00":{"LAT":0.0000000,"LON":0.0000000,"IMEI":353816054730215},
"06.01.1980_00:01:01":{"LAT":0.0000000,"LON":0.0000000,"IMEI":353816054730215},
"06.01.1980_00:01:38":{"LAT":0.0000000,"LON":0.0000000,"IMEI":353816054730215},
"06.01.1980_00:02:56":{"LAT":0.0000000,"LON":0.0000000,"IMEI":353816054730215},
"06.01.1980_00:03:15":{"LAT":0.0000000,"LON":0.0000000,"IMEI":353816054730215},
"06.01.1980_00:03:26":{"LAT":0.0000000,"LON":0.0000000,"IMEI":353816054730215},
"06.01.1980_00:04:09":{"LAT":0.0000000,"LON":0.0000000,"IMEI":353816054730215}
}
PFAL command example to send JSON data
$PFAL,TCP.JSON.Send,"http://62.91.82.12:4451/dashboard/info.php",0,"{\'title\':\'FOX3 sends JSON message directly\',\'body\':\'IMEI\':&(IMEI),\'IGN\':&(IO8),\'Lat\':&(Lat),\'Lon\':&(Lon),\'Spd\':&(Speed.kmh)km/h,\'Power\':&(Power)V,\'}"
HTTP POST
POST /dashboard/info.php HTTP/1.0 HOST: 62.91.82.12 User-Agent: AVL/3.0 Content-Type: application/json; charset=utf-8 Content-Length: 149
{ "title": "FOX3 sends JSON message directly", "body": "IMEI": 359486060345574, "IGN": 1, "Lat": 50.6734740, "Lon": 10.9809194, "Spd": 0.04km/h, "Power": 15.149V, "}