diff --git a/include/device.h b/include/device.h index f3b4aca..d8bb27a 100644 --- a/include/device.h +++ b/include/device.h @@ -3,6 +3,7 @@ #include #include +#include void setupDevice(); @@ -12,5 +13,6 @@ void deviceSetSleepInterval(long interval); long deviceGetSleepInterval(); unsigned int deviceGetBootCount(); +extern char DeviceId[21 +1]; #endif \ No newline at end of file diff --git a/platformio.ini b/platformio.ini index 910850a..1a60e8c 100644 --- a/platformio.ini +++ b/platformio.ini @@ -29,6 +29,7 @@ lib_deps = https://github.com/kikuchan/pngle.git JPEGDecoder@~1.8.0 Wire + ArduinoUniqueID@~1.0.9 # Semantic Versioning Rules # http://docs.platformio.org/page/userguide/lib/cmd_install.html#description diff --git a/src/app.cpp b/src/app.cpp index cac20c7..3d502cd 100644 --- a/src/app.cpp +++ b/src/app.cpp @@ -78,6 +78,7 @@ void setupApp() doc["wifi"]["dns"] = WiFi.dnsIP().toString(); doc["wifi"]["gateway"] = WiFi.gatewayIP().toString(); + doc["device"]["id"] = DeviceId; doc["device"]["heap"] = ESP.getFreeHeap(); doc["device"]["bootCycle"] = deviceGetBootCount(); doc["device"]["screen"]["width"] = 640; @@ -393,26 +394,6 @@ void setupApiFace() void setupApiUpdate() { server.on("/api/update", HTTP_GET, [](AsyncWebServerRequest *request) { - /* - int params = request->params(); - for (int i = 0; i < params; i++) - { - AsyncWebParameter *p = request->getParam(i); - if (p->isFile()) - { - Serial.printf("
  • FILE[%s]: %s, size: %u
  • ", p->name().c_str(), p->value().c_str(), p->size()); - } - else if (p->isPost()) - { - Serial.printf("
  • POST[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); - } - else - { - Serial.printf("
  • GET[%s]: %s
  • ", p->name().c_str(), p->value().c_str()); - } - } - */ - if (request->hasParam("datetime")) { Serial.println("update datetime..."); @@ -434,7 +415,7 @@ void setupApiUpdate() updateCalendarData(); } - if (request->hasParam("file")) + if (request->getParam("url") && request->hasParam("file")) { Serial.println("file..."); diff --git a/src/device.cpp b/src/device.cpp index 7d48d92..ca66cb2 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -6,6 +6,7 @@ RTC_DATA_ATTR unsigned int bootCount = 0; RTC_DATA_ATTR long config_DeepSleepInterval = 10; // sec unsigned long bootTime = 0; +char DeviceId[21 + 1]; // private methods void sleepDevice(); @@ -19,6 +20,9 @@ void setupDevice() // increment boot number and print it every reboot bootCount++; bootTime = millis(); + + // create anonymous device id + sprintf(DeviceId, "%02X:%02X:%02X:%02X:%02X:%02X:%02X:%02X", UniqueID8[0], UniqueID8[1], UniqueID8[2], UniqueID8[3], UniqueID8[4], UniqueID8[5], UniqueID8[6], UniqueID8[7]); } void loopDevice() @@ -58,7 +62,6 @@ unsigned int deviceGetBootCount() return bootCount; } - bool isBootTimeOver() { return millis() - bootTime >= 60000; diff --git a/src/download.cpp b/src/download.cpp index a8fdcf9..b1d8bdc 100644 --- a/src/download.cpp +++ b/src/download.cpp @@ -1,6 +1,7 @@ #include #include #include "download.h" +#include "device.h" HTTPClient http; @@ -24,8 +25,13 @@ bool downloadFile(String url, const char *path) return false; } - http.useHTTP10(true); // http1.1 chunked übertragung funktioniert irgendwie nicht + http.useHTTP10(true); // http1.1 chunked is not working correctly http.setTimeout(7000); + http.setUserAgent("paperdash esp"); + + // use the last 8 bytes of the unique serial id + http.addHeader("X-PaperDash-Id", DeviceId); + http.begin(url); int httpCode = http.GET(); if (httpCode != HTTP_CODE_OK)