· 7 years ago · Jun 03, 2018, 08:24 PM
1void executeEntryPoint1();
2void executeEntryPoint2();
3
4void sendHTTP(String url,String secretkey);
5int callBackHttp(HttpConnection& connection, bool success);
6
7
8int callBackHttp(HttpConnection& connection, bool success)
9{
10 if(success) {
11 Serial.println(connection.getResponseString());
12 Serial.println(connection.getResponseCode());
13 }
14 return 0;
15}
16
17void sendHTTP(String url,String secretkey)
18{
19 HttpClient *httpClient;
20 HttpHeaders headers;
21
22
23 headers["Authorization"] = "Bearer "+secretkey;
24 headers["Connection"]="Close";
25 headers["ContentType"] = "application/json";
26
27
28 httpClient->send(
29 httpClient->request(url)
30 ->setMethod(HTTP_GET)
31 ->setHeaders(headers)
32 ->onRequestComplete(callBackHttp)
33 );
34
35
36 Serial.println("############################################");
37 String heap = String(system_get_free_heap_size());
38 Serial.println("Memory HEAP "+heap);
39 Serial.println("############################################");
40}
41
42
43void executeEntryPoint1()
44{
45 sendHTTP("http://automacao-iot.com.br/api/device/A1472FBA268D778E1DBF370DE7580A7F/info","5025003AF915DC944B8ACAAFA4A0D405E87E83B6D7AE2FD4870742E86D35229D");
46}
47
48void executeEntryPoint2()
49{
50 sendHTTP("http://automacao-iot.com.br/api/device/ECEEFFEA77FD3CC970B87670B70809CD/info","E0F565CBE3D0FCBE4FE75B27733AD3450D16AB4F9DB6F13F291989D556C5E8BE");
51}
52
53
54// Connection failed
55void connectionFailed(String ssid, uint8_t ssidLength, uint8_t *bssid, uint8_t reason)
56{
57 debugf("Not Connected");
58 system_restart();
59}
60
61//Station connected
62void connected(IPAddress ip, IPAddress mask, IPAddress gateway)
63{
64 debugf("Connected");
65 executeEntryPoint1();
66 executeEntryPoint2();
67}