conf save fixed, group chann polling. tested

This commit is contained in:
2021-10-08 01:44:12 +03:00
parent 196e34266a
commit 034319ed67
4 changed files with 12 additions and 16 deletions

View File

@@ -58,10 +58,7 @@ bool systemConfig::isValidSysConf()
stream->seek(offsetof(systemConfigData,MQTTpwd));
short bytes=stream->readBytesUntil(0,buffer,bufLen-1);
stream->close();
Serial.println("valid");
Serial.println(offsetof(systemConfigData,MQTTpwd));
Serial.println(bytes);
Serial.write(buffer,bytes);
if (bytes)
{
buffer[bytes]=0;

View File

@@ -121,7 +121,7 @@ NRFFlashStorage EEPROM;
switch (fileNum) {
case FN_CONFIG_JSON:
pos = 0;
//streamSize = _size;
streamSize = MAX_JSON_CONF_SIZE;
startPos = EEPROM_offsetJSON;
textMode = true;
contentType = HTTP_TEXT_JSON;
@@ -204,7 +204,6 @@ NRFFlashStorage EEPROM;
#if defined(__SAM3X8E__)
size_t flashStream::write(const uint8_t *buffer, size_t size)
{
//debugSerial<<("Write from:")<<pos<<" "<<size<<" bytes"<<endl;
EEPROM.write(startPos+pos,(byte*)buffer,size);
pos+=size;
return size;
@@ -215,7 +214,7 @@ NRFFlashStorage EEPROM;
#if defined(ESP8266) || defined(ESP32)
void flashStream::putEOF()
{
write (255);
if (textMode) write (EOFchar);
EEPROM.commit();
};
#endif

View File

@@ -279,10 +279,12 @@ uint16_t httpHandler(Client& client, String request, long contentLength, bool au
Item item((char*)request.c_str());
if (!item.isValid()) return 400;
itemCmd ic;
ic.loadItem(&item,SEND_COMMAND|SEND_PARAMETERS);
if (item.itemType == CH_GROUP)
{if (item.isActive()) item.setCmd(CMD_ON); else item.setCmd(CMD_OFF);}
itemCmd ic;
ic.loadItem(&item,SEND_COMMAND|SEND_PARAMETERS);
char buf[32];
response=ic.toString(buf, sizeof(buf));
return 200 | HTTP_TEXT_PLAIN;
@@ -297,10 +299,10 @@ uint16_t httpHandler(Client& client, String request, long contentLength, bool au
request+=body;
debugSerial<<F("Cmd: ")<<request<<endl;
if (request=="reboot ") client.stop();
if (request=="reboot ") ArduinoOTA.sendHttpResponse(client,200);
const char* res=request.c_str();
cmd_parse((char*) res);
return 200 | HTTP_TEXT_PLAIN;
return 200;
}
else return 0; //Unknown
}
@@ -1295,14 +1297,12 @@ if (arg_cnt>1)
aJsonStringStream stringStream(NULL, outBuf, MAX_JSON_CONF_SIZE);
aJson.print(root, &stringStream);
int len = strlen(outBuf);
outBuf[len++]= 255;
//JSONStream.seek();
outBuf[len++]= EOFchar;
size_t res = sysConfStream.write((byte*) outBuf,len);
free (outBuf);
infoSerial<<res<< F("bytes from ")<<len<<F(" are saved to EEPROM")<<endl;
#else
//JSONStream.open('w');
//JSONStream.seek();
aJsonStream jsonEEPROMStream = aJsonStream(&sysConfStream);
infoSerial<<F("Saving config to EEPROM..");
aJson.print(root, &jsonEEPROMStream);

View File

@@ -4,7 +4,7 @@
#ifndef MAX_JSON_CONF_SIZE
#if defined(__SAM3X8E__)
#define MAX_JSON_CONF_SIZE 16000
#define MAX_JSON_CONF_SIZE 24000
#elif defined(ARDUINO_ARCH_AVR)
#define MAX_JSON_CONF_SIZE 4096
#elif defined(ARDUINO_ARCH_ESP32)