-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathget_location.cpp
102 lines (98 loc) · 4.2 KB
/
get_location.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* ********************************************************************************************** */
/* */
/* Smart Watch Firmware ::::::::: ::: */
/* get_location.cpp :+: :+: :+: :+: */
/* +:+ +:+ +:+ +:+ */
/* By: Roman Alexandrov <r.aleksandroff@gmail.com> +#++:++#: +#++:++#++: */
/* +#+ +#+ +#+ +#+ */
/* Created: 2023/06/28 14:49:16 #+# #+# #+# #+# */
/* Updated: 2023/11/12 13:48:41 ### ### ### ### */
/* */
/* */
/* This sketch retrieves location values from the UnwiredLabs server. */
/* */
/* ********************************************************************************************** */
/*
#include "header.h"
void ft_get_location(void)
{
const char* server_name;
int http_response;
char bssid[6];
String IP;
String jsonString;
DynamicJsonDocument doc(264);
String line;
const char* status;
const char* address_detail_city;
server_name = "https://ap1.unwiredlabs.com/v2/process.php";
status = "Error";
IP = WiFi.localIP().toString();
DEBUG_PRINT("ft_get_location function BEGIN");
DEBUG_PRINT("Current IP: "); DEBUG_PRINT(IP);
jsonString = "{\n";
jsonString += "\"token\": \"";
jsonString += token;
jsonString += "\",\n";
jsonString += "\"ip\": \"";
jsonString += IP;
jsonString += "\",\n";
jsonString += "\"fallbacks\": {\n";
jsonString += "\"ipf\" : \"1\"\n";
jsonString += "},\n";
jsonString += "\"address\": 2\n";
jsonString += "}\n";
client.setFingerprint(sslFingerprint);
HTTPClient http;
http.begin(client, server_name);
DEBUG_PRINT("Target server: ");
DEBUG_PRINT(server_name);
http.addHeader("Content-Type", "application/json");
http_response = http.POST(jsonString);
DEBUG_PRINT("Outgoing request: ");
DEBUG_PRINT(http_response);
if (client.connect(Host, 443)) // Connect to the client and make the api call
{
DEBUG_PRINT("Server connection SUCCESS");
client.println("POST " + endpoint + " HTTP/1.1");
client.println("Host: " + (String)Host);
client.println("Connection: close");
client.println("Content-Type: application/json");
client.println("User-Agent: Arduino/1.0");
client.println("Content-Length: ");
client.println(jsonString.length());
client.println();
client.print(jsonString);
delay(500); // Approx. real time gap is 250-380 ms
}
else
{
DEBUG_PRINT("Server connection FAILED");
return;
}
while (client.available())
{
DEBUG_PRINT("Server connection SUCCESS");
line = client.readString();
StaticJsonDocument<384> doc;
DeserializationError error = deserializeJson(doc, line);
if (error)
{
DEBUG_PRINT("Deserialization error");
return;
}
DEBUG_PRINT("Deserialization successful");
status = doc["status"];
lat = doc["lat"];
lon = doc["lon"];
JsonObject address_detail = doc["address_detail"];
address_detail_city = address_detail["city"];
DEBUG_PRINT(status);
DEBUG_PRINT(lat);
DEBUG_PRINT(lon);
DEBUG_PRINT(address_detail_city);
}
http.end();
DEBUG_PRINT("ft_get_location function FINISHED");
}
*/