-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmaps.ino
73 lines (56 loc) · 2.25 KB
/
maps.ino
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <google-maps-device-locator.h>
// NOTE: localData.h should contain the ubidots token in this form:
// This value comes from ubidots -> menu -> API keys -> Authentication token
// #define UBIDOTS_TOKEN "skljfhsakldjdfh29841283840922324"
// Alternatively, do not create localData.h, remove line 8 below
// and define UBIDOTS_TOKEN in the current file
#include "localData.h"
/*******************************************************************************
ubidots variables
webhook definition:
Event name: ubidotsLatLong
url: https://things.ubidots.com/api/v1.6/devices/{{ubi-dsl-vl}}/values/?token={{ubi-token}}
Request type: POST
Device: Any
Advanced settings:
Send custom data: JSON
and then enter:
{
"value": "{{ubi-value}}",
"context": {
"lat": " {{google-lat}}",
"lng": "{{google-lng}}"
}
}
include default data: no
enforce ssl: yes
*******************************************************************************/
// This value comes from ubidots
const String ubidotsToken = UBIDOTS_TOKEN;
GoogleMapsDeviceLocator locator;
#define APP_NAME "googleMaps"
String VERSION = "Version 0.01";
/*******************************************************************************
* changes in version 0.01:
* Initial version
*******************************************************************************/
SYSTEM_MODE(AUTOMATIC);
void setup()
{
Particle.publish(APP_NAME, VERSION, PRIVATE);
// Scan for visible networks and publish to the cloud every 30 seconds
// Pass the returned location to be handled by the locationCallback() method
locator.withSubscribe(locationCallback).withLocatePeriodic(60);
}
void loop() {
locator.loop();
}
void locationCallback(float lat, float lon, float accuracy) {
// Handle the returned location data for the device. This method is passed three arguments:
// - Latitude
// - Longitude
// - Accuracy of estimated location (in meters)
String name = "geo";
String value = "1"; //dummy value
Particle.publish("ubidotsLatLong", "{\"ubi-dsl-vl\":\"" + Particle.deviceID() + "/" + name + "\", \"ubi-token\":\"" + ubidotsToken + "\", \"ubi-value\":\"" + value + "\" , \"google-lat\":\"" + lat + "\" , \"google-lng\":\"" + lon + "\"}", 60, PRIVATE);
}