Fixes in firmware

This commit is contained in:
Martin Bauer 2020-05-16 12:33:53 +02:00
parent d0ba98f12e
commit f20ab7ac9a
6 changed files with 103 additions and 60 deletions

View File

@ -12,7 +12,9 @@ public:
void init(uint32_t epochStartTime) {
currentChunk = &chunks[0];
otherChunk = &chunks[1];
currentChunk->init(epochStartTime, 0);
otherChunk->init(0, 0);
}
bool addPoint(Measurement_T measurement) {
@ -22,7 +24,7 @@ public:
rotate();
const bool secondInsertSuccess = currentChunk->addPoint(measurement);
assert(secondInsertSuccess, "Session: insertion after rotation failed");
//TODO check that there is place for file - remove old files
// TODO check that there is place for file - remove old files
}
return true;
}
@ -80,7 +82,7 @@ private:
const auto fileName = chunkFileName(chunkNr, chunk->getStartTime());
Serial.print("Writing session to file ");
Serial.println(fileName);
Writer writer( fileName );
Writer writer(fileName);
chunk->serialize(writer.encoder());
};
@ -91,7 +93,7 @@ private:
if( startIdx >= currentChunk->getStartIndex() ) {
encoder.sendArrayPartialContents( currentChunk->getDataPointer(), currentChunk->numMeasurements() );
return currentChunk->getStartIndex() + currentChunk->numMeasurements();
return currentChunk->getStartIndex() + currentChunk->numMeasurements();
} else if( startIdx >= otherChunk->getStartIndex() && otherChunkFilled() ) {
encoder.sendArrayPartialContents( otherChunk->getDataPointer(), otherChunk->numMeasurements() );
assert( otherChunk->numMeasurements(), CHUNK_SIZE );

View File

@ -10,15 +10,12 @@ public:
encoder_(&f_),
fileName_(fileName)
{
Serial.println("Opened file for writing successful?");
bool success = f_;
Serial.println(success);
}
~SpiffsStorageWriter() {
f_.close();
Serial.print("Closing file: ");
Serial.println(fileName_);
Serial.print("File exists: ");
Serial.println(SPIFFS.exists(fileName_));
}
StreamingMsgPackEncoder<File> &encoder() { return encoder_; }
@ -34,7 +31,7 @@ class SpiffsStorageReader
{
public:
SpiffsStorageReader(const String &fileName) :
f_(SPIFFS.open(fileName, "w"))
f_(SPIFFS.open(fileName, "r"))
{}
~SpiffsStorageReader() {
f_.close();

View File

@ -17,6 +17,7 @@ namespace webdav_constants {
FLASH_TEXT(RESOURCETYPE_START) = "<D:resourcetype>";
FLASH_TEXT(RESOURCETYPE_END) = "</D:resourcetype>";
FLASH_TEXT(RESOURCE_COLLECTION) = "<D:collection/>";
FLASH_TEXT(HTTP_204_NO_CONTENT) = "HTTP/1.1 204 No Content";
FLASH_TEXT(CONTENTLEN_START) = "<D:getcontentlength>";
FLASH_TEXT(CONTENTLEN_END) = "</D:getcontentlength>";
@ -31,8 +32,14 @@ void listFiles(AsyncResponseStream * response, const char *folderPath, Dir * dir
{
using namespace webdav_constants;
response->println(MULTISTATUS_START);
Serial.println("Before rewind");
dir->rewind();
Serial.println("After rewind");
while (dir->next()) {
Serial.println("Inside dir loop");
Serial.println(folderPath);
Serial.println(dir->fileName());
response->print(RESPONSE_START);
response->print(HREF_START);
response->print(folderPath);
@ -53,7 +60,7 @@ void listFiles(AsyncResponseStream * response, const char *folderPath, Dir * dir
response->print(PROP_END);
response->print(STATUS_OK);
response->print(PROPSTAT_END);
response->print(webdav_constants::RESPONSE_END);
response->println(webdav_constants::RESPONSE_END);
}
response->println(MULTISTATUS_END);
}
@ -75,14 +82,14 @@ public:
virtual void handleRequest(AsyncWebServerRequest *request) override final
{
if (request->url() == prefix_ && request->method() == HTTP_PROPFIND) {
if (request->url() == prefix_ + "/" && request->method() == HTTP_PROPFIND) {
Serial.println("Propfind start");
AsyncResponseStream * response = request->beginResponseStream("application/xml");
Dir dir = SPIFFS.openDir(folder_);
listFiles(response, "/", &dir);
request->send(response);
} else if(request->url() == prefix_ && request->method() == HTTP_GET) {
AsyncResponseStream * response = request->beginResponseStream("text/plain");
} else if(request->url() == prefix_ + "/" && request->method() == HTTP_GET) {
AsyncResponseStream * response = request->beginResponseStream("text/plain", 1460*10);
Dir dir = SPIFFS.openDir(folder_);
Serial.print("Opening folder ");
Serial.println(folder_);
@ -95,15 +102,21 @@ public:
}
else if (request->method() == HTTP_GET) {
auto path = folder_ + request->url().substring(prefix_.length());
Serial.print("Testing if path exists: ");
Serial.println(path);
if (SPIFFS.exists(path)) {
Serial.println("Exists!");
request->send(SPIFFS, path, "application/x-msgpack");
} else {
Serial.println("Does not exist :(");
request->send(404, "text/plain", "Webdav: File not found");
}
} else if (request->method() == HTTP_DELETE) {
auto path = folder_ + request->url().substring(prefix_.length());
if (SPIFFS.exists(path)) {
if(SPIFFS.remove(path))
request->send(204, "text/plain", "Success");
else
request->send(404, "text/plain", "Webdav: Invalid delete request");
} else {
request->send(404, "text/plain", "Webdav: File to delete not found");
}
} else {
request->send(404, "text/plain", "Webdav: Invalid request");
}

View File

@ -2,4 +2,4 @@
const char *CONFIG_WIFI_SSID = "WLAN";
const char *CONFIG_WIFI_PASSWORD = "Bau3rWLAN";
const char* CONFIG_HOSTNAME = "smartcords";
const char* CONFIG_HOSTNAME = "smartswim";

69
src/DeviceInfoLog.h Normal file
View File

@ -0,0 +1,69 @@
#include <FS.h>
inline void printDeviceInfo()
{
FSInfo fs_info;
SPIFFS.info(fs_info);
float fileTotalKB = (float)fs_info.totalBytes / 1024.0;
float fileUsedKB = (float)fs_info.usedBytes / 1024.0;
float flashChipSize = (float)ESP.getFlashChipSize() / 1024.0 / 1024.0;
float realFlashChipSize = (float)ESP.getFlashChipRealSize() / 1024.0 / 1024.0;
float flashFreq = (float)ESP.getFlashChipSpeed() / 1000.0 / 1000.0;
FlashMode_t ideMode = ESP.getFlashChipMode();
Serial.printf("\n#####################\n");
Serial.printf("__________________________\n\n");
Serial.println("Firmware: ");
Serial.printf(" Chip Id: %08X\n", ESP.getChipId());
Serial.print(" Core version: ");
Serial.println(ESP.getCoreVersion());
Serial.print(" SDK version: ");
Serial.println(ESP.getSdkVersion());
Serial.print(" Boot version: ");
Serial.println(ESP.getBootVersion());
Serial.print(" Boot mode: ");
Serial.println(ESP.getBootMode());
Serial.printf("__________________________\n\n");
Serial.println("Flash chip information: ");
Serial.printf(" Flash chip Id: %08X (for example: Id=001640E0 Manuf=E0, Device=4016 (swap bytes))\n", ESP.getFlashChipId());
Serial.printf(" Sketch thinks Flash RAM is size: ");
Serial.print(flashChipSize);
Serial.println(" MB");
Serial.print(" Actual size based on chip Id: ");
Serial.print(realFlashChipSize);
Serial.println(" MB ... given by (2^( Device - 1) / 8 / 1024");
Serial.print(" Flash frequency: ");
Serial.print(flashFreq);
Serial.println(" MHz");
Serial.printf(" Flash write mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
Serial.printf("__________________________\n\n");
Serial.println("File system (SPIFFS): ");
Serial.print(" Total KB: ");
Serial.print(fileTotalKB);
Serial.println(" KB");
Serial.print(" Used KB: ");
Serial.print(fileUsedKB);
Serial.println(" KB");
Serial.printf(" Block size: %u\n", fs_info.blockSize);
Serial.printf(" Page size: %u\n", fs_info.pageSize);
Serial.printf(" Maximum open files: %u\n", fs_info.maxOpenFiles);
Serial.printf(" Maximum path length: %u\n\n", fs_info.maxPathLength);
String str = "";
Dir dir = SPIFFS.openDir("/dat");
while (dir.next())
{
str += dir.fileName();
str += " / ";
str += dir.fileSize();
str += "\r\n";
}
Serial.print(str);
}

View File

@ -11,6 +11,7 @@
#include "MockScale.h"
#include "MeasurementSession.h"
#include "SpiffsStorage.h"
#include "DeviceInfoLog.h"
// Configuration
#include "ConfigWifi.h"
@ -39,6 +40,7 @@ public:
void startMeasurements() {
measuring_ = true;
lastCallTime_ = 0;
session.init( timeClient.getEpochTime() );
}
@ -97,12 +99,12 @@ void onNotFound(AsyncWebServerRequest *request) {
template<typename Session_T>
void httpSetup(SessionManager<Session_T> * sessionManager)
{
server.on("/api/session/start", HTTP_POST, [sessionManager](AsyncWebServerRequest * req) {
server.on("/api/session/start", HTTP_POST | HTTP_GET, [sessionManager](AsyncWebServerRequest * req) {
req->send(200, "text/plain", F("OK"));
sessionManager->startMeasurements();
Serial.println("Started measurements");
});
server.on("/api/session/stop", HTTP_POST, [sessionManager](AsyncWebServerRequest * req) {
server.on("/api/session/stop", HTTP_POST | HTTP_GET, [sessionManager](AsyncWebServerRequest * req) {
req->send(200, "text/plain", F("OK"));
sessionManager->stopMeasurements();
Serial.println("Stopped measurements");
@ -152,53 +154,13 @@ void setup()
// File system
SPIFFS.begin();
Serial.print("SPIFFS begin ");
FSInfo fs_info;
SPIFFS.info(fs_info);
float fileTotalKB = (float)fs_info.totalBytes / 1024.0;
float fileUsedKB = (float)fs_info.usedBytes / 1024.0;
float flashChipSize = (float)ESP.getFlashChipSize() / 1024.0 / 1024.0;
float realFlashChipSize = (float)ESP.getFlashChipRealSize() / 1024.0 / 1024.0;
float flashFreq = (float)ESP.getFlashChipSpeed() / 1000.0 / 1000.0;
FlashMode_t ideMode = ESP.getFlashChipMode();
Serial.printf("\n#####################\n");
Serial.printf("__________________________\n\n");
Serial.println("Firmware: ");
Serial.printf(" Chip Id: %08X\n", ESP.getChipId());
Serial.print(" Core version: "); Serial.println(ESP.getCoreVersion());
Serial.print(" SDK version: "); Serial.println(ESP.getSdkVersion());
Serial.print(" Boot version: "); Serial.println(ESP.getBootVersion());
Serial.print(" Boot mode: "); Serial.println(ESP.getBootMode());
Serial.printf("__________________________\n\n");
Serial.println("Flash chip information: ");
Serial.printf(" Flash chip Id: %08X (for example: Id=001640E0 Manuf=E0, Device=4016 (swap bytes))\n", ESP.getFlashChipId());
Serial.printf(" Sketch thinks Flash RAM is size: "); Serial.print(flashChipSize); Serial.println(" MB");
Serial.print(" Actual size based on chip Id: "); Serial.print(realFlashChipSize);
Serial.println(" MB ... given by (2^( Device - 1) / 8 / 1024");
Serial.print(" Flash frequency: "); Serial.print(flashFreq); Serial.println(" MHz");
Serial.printf(" Flash write mode: %s\n", (ideMode == FM_QIO ? "QIO" : ideMode == FM_QOUT ? "QOUT" : ideMode == FM_DIO ? "DIO" : ideMode == FM_DOUT ? "DOUT" : "UNKNOWN"));
Serial.printf("__________________________\n\n");
Serial.println("File system (SPIFFS): ");
Serial.print(" Total KB: "); Serial.print(fileTotalKB); Serial.println(" KB");
Serial.print(" Used KB: "); Serial.print(fileUsedKB); Serial.println(" KB");
Serial.printf(" Block size: %lu\n", fs_info.blockSize);
Serial.printf(" Page size: %lu\n", fs_info.pageSize);
Serial.printf(" Maximum open files: %lu\n", fs_info.maxOpenFiles);
Serial.printf(" Maximum path length: %lu\n\n", fs_info.maxPathLength);
printDeviceInfo();
// WiFi
WiFi.mode(WIFI_STA);
WiFi.begin(CONFIG_WIFI_SSID, CONFIG_WIFI_PASSWORD);
WiFi.hostname(CONFIG_HOSTNAME);
Serial.print(F("\n\n"));
Serial.println(F("Waiting for WIFI connection..."));
while (WiFi.status() != WL_CONNECTED) {