-
Notifications
You must be signed in to change notification settings - Fork 0
/
Network.cpp
86 lines (51 loc) · 2.11 KB
/
Network.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
#include "Network.h"
#include "debug.h"
#include <WiFiClient.h>
#include <ArduinoHttpClient.h>
int _port = 80;
char _server[] = "jmge.ch";
WiFiClient wifi;
HttpClient _client = HttpClient(wifi, _server, _port);
String response;
int statusCode = 0;
/* =================================================================== */
void Network::init(){ }
void Network::connect(const char* ssid, const char* password){
if(WiFi.status() == WL_DISCONNECTED) {
WiFi.mode(WIFI_STA);
wifi_station_set_hostname("SocialCounterMatrix");
WiFi.begin(ssid, password);
delay(2000);
}
_ip = WiFi.localIP();
}
String Network::getClassName(){ return "Network"; }
String Network::getIpAddress(){
return WiFi.localIP().toString();
}
void Network::pingWebServer(){
String txtPost = "This may very well be another test";
String contentType = "application/x-www-form-urlencoded";
String path = "/api_fetch/ping.php";
String postData = "ardval=" + Network::getIpAddress();
//Serial.println(postData);
// send the POST request
_client.post(path, contentType, postData);
// read the status code and body of the response
statusCode = _client.responseStatusCode();
response = _client.responseBody();
}
void Network::wifiManager(){
WiFiManager wifiManager;
wifiManager.setBreakAfterConfig(true);
wifiManager.autoConnect("LaBox-Installation");
wifiManager.setCustomHeadElement("<style>html{filter: invert(100%); -webkit-filter: invert(100%);}</style>");
WiFiManagerParameter custom_text("<p>La Box - WiFi Configuration</p>");
wifiManager.addParameter(&custom_text);
LOGF("The box's IP is: %s\n", Network::getIpAddress());
}
void Network::configModeCallback (WiFiManager *myWiFiManager) {
LOGLN("Entered config mode");
LOGLN(WiFi.softAPIP());
LOGLN(myWiFiManager->getConfigPortalSSID());
}