-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode
More file actions
32 lines (29 loc) · 796 Bytes
/
Copy pathcode
File metadata and controls
32 lines (29 loc) · 796 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
void readMessage(int messageId, char *payload)
{
double lat_val, lng_val;
smartDelay(1000); /* Generate precise delay of 1ms */
lat_val = gps.location.lat(); /* Get latitude data */
lng_val = gps.location.lng(); /* Get longtitude data */
StaticJsonBuffer<MESSAGE_MAX_LEN> jsonBuffer;
JsonObject &root = jsonBuffer.createObject();
root["deviceId"] = DEVICE_ID;
root["messageId"] = messageId;
// NAN is not the valid json, change it to NULL
if (std::isnan(lat_val))
{
root["latitude"] = NULL;
}
else
{
root["latitude"] = lat_val;
}
if (std::isnan(lng_val))
{
root["longitude"] = NULL;
}
else
{
root["longitude"] = lng_val;
}
root.printTo(payload, MESSAGE_MAX_LEN);
}