update to start with millis reporting
This commit is contained in:
@@ -35,7 +35,7 @@ void wifi_associate() {
|
||||
net.setInsecure(); // Do not check fingerprint
|
||||
net.setTimeout(15000); // 15 Seconds
|
||||
|
||||
/* PRINT_SERIAL("Setting time using SNTP");
|
||||
PRINT_SERIAL("Setting time using SNTP");
|
||||
configTime(-5 * 3600, 0, "pool.ntp.org", "time.nist.gov");
|
||||
now = time(nullptr);
|
||||
while (now < 1510592825) {
|
||||
@@ -47,16 +47,64 @@ void wifi_associate() {
|
||||
struct tm timeinfo;
|
||||
gmtime_r(&now, &timeinfo);
|
||||
PRINT_SERIAL("Current time: ");
|
||||
APPENDLN_SERIAL(asctime(&timeinfo)); */
|
||||
APPENDLN_SERIAL(asctime(&timeinfo));
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_checkin() {
|
||||
// 'Native' in WiFiClient because we need to push the entire clientbuffer in the API
|
||||
// As a result copying the buffer in to a new String for HTTPClient library use is highly inefficient
|
||||
if (!net.connect(OTA_SERVER, OTA_PORT)) {
|
||||
Serial.println("HTTPS connection failed");
|
||||
} else {
|
||||
Serial.println("HTTPS connection up");
|
||||
|
||||
// Check for firmware upgrades
|
||||
String version = settings.name;
|
||||
version.concat("-v");
|
||||
version.concat(FW_VERSION);
|
||||
|
||||
String json = "{\"mac\":\"" + WiFi.macAddress() + "\",";
|
||||
json.concat("\"version\":\"" + version + "\",");
|
||||
json.concat("\"millis\":" + String(millis()) + "}");
|
||||
|
||||
// Send request to the server:
|
||||
net.println("POST " OTA_CHECKIN " HTTP/1.1");
|
||||
net.println("Host: " OTA_SERVER);
|
||||
net.println("Accept: */*");
|
||||
net.println("Content-Type: application/json");
|
||||
net.print("Content-Length: ");
|
||||
net.println(json.length());
|
||||
net.println("Connection: close");
|
||||
net.println();
|
||||
// Construct the REST/JSON POST data
|
||||
net.print(json);
|
||||
Serial.println("POST sent");
|
||||
|
||||
while (net.connected()) {
|
||||
String line = net.readStringUntil('\n');
|
||||
if (line == "\r") {
|
||||
Serial.println("Headers received");
|
||||
break;
|
||||
}
|
||||
}
|
||||
String line = net.readStringUntil('\n');
|
||||
Serial.println("reply was:");
|
||||
Serial.println("==========");
|
||||
Serial.println(line);
|
||||
Serial.println("==========");
|
||||
Serial.println("closing connection");
|
||||
net.stop(); // DISCONNECT FROM THE SERVER
|
||||
}
|
||||
}
|
||||
|
||||
void wifi_setup() {
|
||||
// WifiManager.setAPCallback(WifiManagerCallback); // Enable WifiManager callback to clear the cache
|
||||
wifi_associate();
|
||||
}
|
||||
|
||||
void wifi_loop() {
|
||||
|
||||
if(WiFi.status() != WL_CONNECTED) {
|
||||
PRINTLN_SERIAL("Wifi disconnected, trying to reconnect");
|
||||
wifi_associate();
|
||||
@@ -74,6 +122,8 @@ void wifi_loop() {
|
||||
PRINTLN_SERIAL("net.status: " + String(net.status()));
|
||||
|
||||
t_httpUpdate_return ret = ESPhttpUpdate.update(net, OTA_SERVER, OTA_PORT, OTA_URI, version);
|
||||
PRINTLN_SERIAL("after httpupdate check net.status: " + String(net.status()));
|
||||
|
||||
switch(ret) {
|
||||
case HTTP_UPDATE_FAILED: // HTTP 403, 404
|
||||
PRINT_SERIAL("Connection error, update failed ");
|
||||
@@ -90,5 +140,9 @@ void wifi_loop() {
|
||||
break;
|
||||
}
|
||||
ota_lastcheck = ota_check;
|
||||
|
||||
// Check in with IoT server
|
||||
wifi_checkin();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user