First success full read of json data provided by timing editor webinterface.

This commit is contained in:
Kai Lauterbach 2023-05-06 13:38:56 +02:00
parent 975e0d140d
commit 120a0e3efd
4 changed files with 22 additions and 3 deletions

View file

@ -315,4 +315,5 @@ if (xhr.readyState === 4 && xhr.status === 200) {
console.log('Data successfully sent to server!');
}
};
xhr.send();
}

View file

@ -484,6 +484,7 @@ void init_webserver()
if (server.hasArg("data"))
{
String jsonData = server.arg("data");
Serial.println("Received: " + jsonData);
tc_jsonDataBlocksToEEPROM(jsonData);
server.send(200, "text/html", "tcdata saved");
}

View file

@ -396,6 +396,6 @@ function sendDataToServer() {
console.log('Data successfully sent to server!');
}
};
//xhr.send();
xhr.send();
}

View file

@ -415,13 +415,16 @@ String tc_getJsonData()
void tc_jsonDataBlocksToEEPROM(String json_data_string)
{
StaticJsonDocument<512> doc;
StaticJsonDocument<1289> doc;
deserializeJson(doc, json_data_string);
Serial.println("Reading data from json data:");
// Loop through each data block in the JSON data and store it in the tc_data array
for (uint8_t i = 0; i < NUMBER_OF_TIMER_DATA_BLOCKS; i++)
{
JsonObject obj = doc[i];
//Serial.println("<< " + (String)i);
JsonObject obj = doc["tcdata"][i];
// Check and set the limits of the hour value
int hour = obj["hour"];
@ -431,6 +434,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
hour = 23;
}
tc_data[i].hh = hour;
Serial.print("hour = " + (String)tc_data[i].hh + " " + (String)obj["hour"] + " ");
// Check and set the limits of the minute value
int minute = obj["min"];
@ -440,6 +444,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
minute = 59;
}
tc_data[i].mm = minute;
Serial.print("minute = " + (String)tc_data[i].mm + " " + (String)obj["min"] + " ");
// Check and set the limits of the ch1 value
int ch1 = obj["ch1"];
@ -449,6 +454,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
ch1 = 255;
}
tc_data[i].ch1 = ch1;
Serial.print("ch1 = " + (String)tc_data[i].ch1 + " " + (String)obj["ch1"] + " ");
// Check and set the limits of the ch2 value
int ch2 = obj["ch2"];
@ -458,6 +464,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
ch2 = 255;
}
tc_data[i].ch2 = ch2;
Serial.print("ch2 = " + (String)tc_data[i].ch2 + " " + (String)obj["ch2"] + " ");
// Check and set the limits of the ch3 value
int ch3 = obj["ch3"];
@ -467,6 +474,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
ch3 = 255;
}
tc_data[i].ch3 = ch3;
Serial.print("ch3 = " + (String)tc_data[i].ch3 + " " + (String)obj["ch3"] + " ");
// Check and set the limits of the ch4 value
int ch4 = obj["ch4"];
@ -476,12 +484,21 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
ch4 = 255;
}
tc_data[i].ch4 = ch4;
Serial.println("ch4 = " + (String)tc_data[i].ch4 + " " + (String)obj["ch4"] + "\n---");
}
Serial.println("Writing to EEPROM...");
// Write the tc_data array to the EEPROM
for (uint16_t i = 0; i < (NUMBER_OF_TIMER_DATA_BLOCKS * LENGTH_OF_TIMER_DATA_BLOCK); i++)
{
//Serial.println(" " + (String)(EEPROM_TIMING_DATA_ADDRESS + i) + " " + (String)(*((uint8_t*)&tc_data + i)));
EEPROM.write(EEPROM_TIMING_DATA_ADDRESS + i, *((uint8_t*)&tc_data + i));
/*if (((i+1) % 6 == 0))
{
Serial.println("---");
}*/
}
EEPROM.commit();
}