@@ -529,9 +529,8 @@ bool ws_sdcard::parseConfigFile() {
529
529
// It is not possible to continue running in offline mode without a valid
530
530
// config file
531
531
if (error) {
532
- WS_DEBUG_PRINTLN (
533
- " [SD] Runtime Error: Unable to deserialize config.json. Error Code: " +
534
- String (error.c_str ()));
532
+ WS_DEBUG_PRINT (" [SD] Runtime Error: Unable to deserialize config.json" );
533
+ WS_DEBUG_PRINTLN (" \n Error Code: " + String (error.c_str ()));
535
534
return false ;
536
535
}
537
536
WS_DEBUG_PRINTLN (" [SD] Successfully deserialized JSON config file!" );
@@ -923,4 +922,116 @@ bool ws_sdcard::LogDS18xSensorEventToSD(
923
922
LogJSONDoc (doc);
924
923
}
925
924
return true ;
926
- }
925
+ }
926
+
927
+ #ifdef OFFLINE_MODE_DEBUG
928
+ /* *************************************************************************/
929
+ /* !
930
+ @brief Waits for a valid JSON string to be received via the hardware's
931
+ serial input or from a hardcoded test JSON string.
932
+ @returns True if a valid JSON string was received, False otherwise.
933
+ */
934
+ /* *************************************************************************/
935
+ void ws_sdcard::waitForSerialConfig () {
936
+ json_test_data = " {"
937
+ " \" exportVersion\" : \" 1.0.0\" ,"
938
+ " \" exportedBy\" : \" tester\" ,"
939
+ " \" exportedAt\" : \" 2024-10-28T18:58:23.976Z\" ,"
940
+ " \" exportedFromDevice\" : {"
941
+ " \" board\" : \" metroesp32s3\" ,"
942
+ " \" firmwareVersion\" : \" 1.0.0-beta.93\" ,"
943
+ " \" referenceVoltage\" : 2.6,"
944
+ " \" totalGPIOPins\" : 11,"
945
+ " \" totalAnalogPins\" : 6"
946
+ " },"
947
+ " \" components\" : ["
948
+ " {"
949
+ " \" componentAPI\" : \" analogio\" ,"
950
+ " \" name\" : \" Analog Pin\" ,"
951
+ " \" pinName\" : \" D14\" ,"
952
+ " \" type\" : \" analog_pin\" ,"
953
+ " \" mode\" : \" ANALOG\" ,"
954
+ " \" direction\" : \" INPUT\" ,"
955
+ " \" sampleMode\" : \" TIMER\" ,"
956
+ " \" analogReadMode\" : \" PIN_VALUE\" ,"
957
+ " \" period\" : 5,"
958
+ " \" isPin\" : true"
959
+ " },"
960
+ " {"
961
+ " \" componentAPI\" : \" analogio\" ,"
962
+ " \" name\" : \" Analog Pin\" ,"
963
+ " \" pinName\" : \" D27\" ,"
964
+ " \" type\" : \" analog_pin\" ,"
965
+ " \" mode\" : \" ANALOG\" ,"
966
+ " \" direction\" : \" INPUT\" ,"
967
+ " \" sampleMode\" : \" TIMER\" ,"
968
+ " \" analogReadMode\" : \" PIN_VALUE\" ,"
969
+ " \" period\" : 5,"
970
+ " \" isPin\" : true"
971
+ " },"
972
+ " {"
973
+ " \" componentAPI\" : \" digitalio\" ,"
974
+ " \" name\" : \" Button (D4)\" ,"
975
+ " \" pinName\" : \" D4\" ,"
976
+ " \" type\" : \" push_button\" ,"
977
+ " \" mode\" : \" DIGITAL\" ,"
978
+ " \" sampleMode\" : \" EVENT\" ,"
979
+ " \" direction\" : \" INPUT\" ,"
980
+ " \" period\" : 5,"
981
+ " \" pull\" : \" UP\" ,"
982
+ " \" isPin\" : true"
983
+ " },"
984
+ " {"
985
+ " \" componentAPI\" : \" ds18x20\" ,"
986
+ " \" name\" : \" DS18B20: Temperature Sensor (°F)\" ,"
987
+ " \" sensorTypeCount\" : 2,"
988
+ " \" sensorType1\" : \" object-temp-fahrenheit\" ,"
989
+ " \" sensorType2\" : \" object-temp\" ,"
990
+ " \" pinName\" : \" D12\" ,"
991
+ " \" sensorResolution\" : 12,"
992
+ " \" period\" : 5"
993
+ " },"
994
+ " {"
995
+ " \" componentAPI\" : \" ds18x20\" ,"
996
+ " \" name\" : \" DS18B20: Temperature Sensor (°F)\" ,"
997
+ " \" sensorTypeCount\" : 2,"
998
+ " \" sensorType1\" : \" object-temp-fahrenheit\" ,"
999
+ " \" sensorType2\" : \" object-temp\" ,"
1000
+ " \" pinName\" : \" D25\" ,"
1001
+ " \" sensorResolution\" : 12,"
1002
+ " \" period\" : 5"
1003
+ " }"
1004
+ " ]"
1005
+ " }\\ n\r\n " ;
1006
+
1007
+ _serialInput = " " ; // Clear the serial input buffer
1008
+ if (!_use_test_data) {
1009
+ WS_DEBUG_PRINTLN (" [SD] Waiting for incoming JSON string..." );
1010
+ while (true ) {
1011
+ // Check if there is data available to read
1012
+ if (Serial.available () > 0 ) {
1013
+ char c = Serial.read ();
1014
+ _serialInput += c;
1015
+ if (_serialInput.endsWith (" \\ n" )) {
1016
+ WS_DEBUG_PRINTLN (" [SD] End of JSON string detected!" );
1017
+ break ;
1018
+ }
1019
+ }
1020
+ }
1021
+ }
1022
+ // Trim the newline
1023
+ _serialInput.trim ();
1024
+
1025
+ // Print out the received JSON string
1026
+ // TODO: REMOVE this for the PR
1027
+ WS_DEBUG_PRINT (" [SD][Debug] JSON string received!" );
1028
+ if (_use_test_data) {
1029
+ WS_DEBUG_PRINTLN (" [from json test data]" );
1030
+ WS_DEBUG_PRINTLN (json_test_data);
1031
+ } else {
1032
+ WS_DEBUG_PRINTLN (_serialInput);
1033
+ }
1034
+
1035
+ WS_DEBUG_PRINTLN (" [SD] JSON string received!" );
1036
+ }
1037
+ #endif
0 commit comments