From 120a0e3efd96a3002c1a963312c0caf0fd1873ef Mon Sep 17 00:00:00 2001 From: Kai Lauterbach Date: Sat, 6 May 2023 13:38:56 +0200 Subject: [PATCH] First success full read of json data provided by timing editor webinterface. --- firmware/data/bottom.js | 1 + firmware/firmware.ino | 1 + firmware/html/bottom.js | 2 +- firmware/timing_control.ino | 21 +++++++++++++++++++-- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/firmware/data/bottom.js b/firmware/data/bottom.js index 981ef00..976c0d9 100644 --- a/firmware/data/bottom.js +++ b/firmware/data/bottom.js @@ -315,4 +315,5 @@ if (xhr.readyState === 4 && xhr.status === 200) { console.log('Data successfully sent to server!'); } }; +xhr.send(); } diff --git a/firmware/firmware.ino b/firmware/firmware.ino index 292bd44..dda1e36 100644 --- a/firmware/firmware.ino +++ b/firmware/firmware.ino @@ -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"); } diff --git a/firmware/html/bottom.js b/firmware/html/bottom.js index 905768b..c19e1bd 100644 --- a/firmware/html/bottom.js +++ b/firmware/html/bottom.js @@ -396,6 +396,6 @@ function sendDataToServer() { console.log('Data successfully sent to server!'); } }; - //xhr.send(); + xhr.send(); } diff --git a/firmware/timing_control.ino b/firmware/timing_control.ino index bde9364..64ace7c 100644 --- a/firmware/timing_control.ino +++ b/firmware/timing_control.ino @@ -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(); }