add uniq device id to every request

pull/1/head
Thomas Ballmann 4 years ago
parent e7da88612c
commit ec149bc475

@ -3,6 +3,7 @@
#include <Arduino.h> #include <Arduino.h>
#include <pgmspace.h> #include <pgmspace.h>
#include <ArduinoUniqueID.h>
void setupDevice(); void setupDevice();
@ -12,5 +13,6 @@ void deviceSetSleepInterval(long interval);
long deviceGetSleepInterval(); long deviceGetSleepInterval();
unsigned int deviceGetBootCount(); unsigned int deviceGetBootCount();
extern char DeviceId[21 +1];
#endif #endif

@ -29,6 +29,7 @@ lib_deps =
https://github.com/kikuchan/pngle.git https://github.com/kikuchan/pngle.git
JPEGDecoder@~1.8.0 JPEGDecoder@~1.8.0
Wire Wire
ArduinoUniqueID@~1.0.9
# Semantic Versioning Rules # Semantic Versioning Rules
# http://docs.platformio.org/page/userguide/lib/cmd_install.html#description # http://docs.platformio.org/page/userguide/lib/cmd_install.html#description

@ -78,6 +78,7 @@ void setupApp()
doc["wifi"]["dns"] = WiFi.dnsIP().toString(); doc["wifi"]["dns"] = WiFi.dnsIP().toString();
doc["wifi"]["gateway"] = WiFi.gatewayIP().toString(); doc["wifi"]["gateway"] = WiFi.gatewayIP().toString();
doc["device"]["id"] = DeviceId;
doc["device"]["heap"] = ESP.getFreeHeap(); doc["device"]["heap"] = ESP.getFreeHeap();
doc["device"]["bootCycle"] = deviceGetBootCount(); doc["device"]["bootCycle"] = deviceGetBootCount();
doc["device"]["screen"]["width"] = 640; doc["device"]["screen"]["width"] = 640;
@ -393,26 +394,6 @@ void setupApiFace()
void setupApiUpdate() void setupApiUpdate()
{ {
server.on("/api/update", HTTP_GET, [](AsyncWebServerRequest *request) { 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("<li>FILE[%s]: %s, size: %u</li>", p->name().c_str(), p->value().c_str(), p->size());
}
else if (p->isPost())
{
Serial.printf("<li>POST[%s]: %s</li>", p->name().c_str(), p->value().c_str());
}
else
{
Serial.printf("<li>GET[%s]: %s</li>", p->name().c_str(), p->value().c_str());
}
}
*/
if (request->hasParam("datetime")) if (request->hasParam("datetime"))
{ {
Serial.println("update datetime..."); Serial.println("update datetime...");
@ -434,7 +415,7 @@ void setupApiUpdate()
updateCalendarData(); updateCalendarData();
} }
if (request->hasParam("file")) if (request->getParam("url") && request->hasParam("file"))
{ {
Serial.println("file..."); Serial.println("file...");

@ -6,6 +6,7 @@ RTC_DATA_ATTR unsigned int bootCount = 0;
RTC_DATA_ATTR long config_DeepSleepInterval = 10; // sec RTC_DATA_ATTR long config_DeepSleepInterval = 10; // sec
unsigned long bootTime = 0; unsigned long bootTime = 0;
char DeviceId[21 + 1];
// private methods // private methods
void sleepDevice(); void sleepDevice();
@ -19,6 +20,9 @@ void setupDevice()
// increment boot number and print it every reboot // increment boot number and print it every reboot
bootCount++; bootCount++;
bootTime = millis(); 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() void loopDevice()
@ -58,7 +62,6 @@ unsigned int deviceGetBootCount()
return bootCount; return bootCount;
} }
bool isBootTimeOver() bool isBootTimeOver()
{ {
return millis() - bootTime >= 60000; return millis() - bootTime >= 60000;

@ -1,6 +1,7 @@
#include <HTTPClient.h> #include <HTTPClient.h>
#include <SPIFFS.h> #include <SPIFFS.h>
#include "download.h" #include "download.h"
#include "device.h"
HTTPClient http; HTTPClient http;
@ -24,8 +25,13 @@ bool downloadFile(String url, const char *path)
return false; 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.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); http.begin(url);
int httpCode = http.GET(); int httpCode = http.GET();
if (httpCode != HTTP_CODE_OK) if (httpCode != HTTP_CODE_OK)

Loading…
Cancel
Save