First success full read of json data provided by timing editor webinterface.
This commit is contained in:
parent
975e0d140d
commit
120a0e3efd
4 changed files with 22 additions and 3 deletions
|
@ -315,4 +315,5 @@ if (xhr.readyState === 4 && xhr.status === 200) {
|
||||||
console.log('Data successfully sent to server!');
|
console.log('Data successfully sent to server!');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
|
@ -484,6 +484,7 @@ void init_webserver()
|
||||||
if (server.hasArg("data"))
|
if (server.hasArg("data"))
|
||||||
{
|
{
|
||||||
String jsonData = server.arg("data");
|
String jsonData = server.arg("data");
|
||||||
|
Serial.println("Received: " + jsonData);
|
||||||
tc_jsonDataBlocksToEEPROM(jsonData);
|
tc_jsonDataBlocksToEEPROM(jsonData);
|
||||||
server.send(200, "text/html", "tcdata saved");
|
server.send(200, "text/html", "tcdata saved");
|
||||||
}
|
}
|
||||||
|
|
|
@ -396,6 +396,6 @@ function sendDataToServer() {
|
||||||
console.log('Data successfully sent to server!');
|
console.log('Data successfully sent to server!');
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
//xhr.send();
|
xhr.send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -415,13 +415,16 @@ String tc_getJsonData()
|
||||||
|
|
||||||
void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
||||||
{
|
{
|
||||||
StaticJsonDocument<512> doc;
|
StaticJsonDocument<1289> doc;
|
||||||
deserializeJson(doc, json_data_string);
|
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
|
// 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++)
|
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
|
// Check and set the limits of the hour value
|
||||||
int hour = obj["hour"];
|
int hour = obj["hour"];
|
||||||
|
@ -431,6 +434,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
||||||
hour = 23;
|
hour = 23;
|
||||||
}
|
}
|
||||||
tc_data[i].hh = hour;
|
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
|
// Check and set the limits of the minute value
|
||||||
int minute = obj["min"];
|
int minute = obj["min"];
|
||||||
|
@ -440,6 +444,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
||||||
minute = 59;
|
minute = 59;
|
||||||
}
|
}
|
||||||
tc_data[i].mm = minute;
|
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
|
// Check and set the limits of the ch1 value
|
||||||
int ch1 = obj["ch1"];
|
int ch1 = obj["ch1"];
|
||||||
|
@ -449,6 +454,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
||||||
ch1 = 255;
|
ch1 = 255;
|
||||||
}
|
}
|
||||||
tc_data[i].ch1 = ch1;
|
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
|
// Check and set the limits of the ch2 value
|
||||||
int ch2 = obj["ch2"];
|
int ch2 = obj["ch2"];
|
||||||
|
@ -458,6 +464,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
||||||
ch2 = 255;
|
ch2 = 255;
|
||||||
}
|
}
|
||||||
tc_data[i].ch2 = ch2;
|
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
|
// Check and set the limits of the ch3 value
|
||||||
int ch3 = obj["ch3"];
|
int ch3 = obj["ch3"];
|
||||||
|
@ -467,6 +474,7 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
||||||
ch3 = 255;
|
ch3 = 255;
|
||||||
}
|
}
|
||||||
tc_data[i].ch3 = ch3;
|
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
|
// Check and set the limits of the ch4 value
|
||||||
int ch4 = obj["ch4"];
|
int ch4 = obj["ch4"];
|
||||||
|
@ -476,12 +484,21 @@ void tc_jsonDataBlocksToEEPROM(String json_data_string)
|
||||||
ch4 = 255;
|
ch4 = 255;
|
||||||
}
|
}
|
||||||
tc_data[i].ch4 = ch4;
|
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
|
// 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++)
|
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));
|
EEPROM.write(EEPROM_TIMING_DATA_ADDRESS + i, *((uint8_t*)&tc_data + i));
|
||||||
|
/*if (((i+1) % 6 == 0))
|
||||||
|
{
|
||||||
|
Serial.println("---");
|
||||||
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
EEPROM.commit();
|
EEPROM.commit();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue