Skip to content

Commit cd720e5

Browse files
committed
[SD] first working offline log to sd
1 parent 7207778 commit cd720e5

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

src/Wippersnapper_V2.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1200,7 +1200,7 @@ void Wippersnapper_V2::connectV2() {
12001200
// Parse the JSON file
12011201
if (!WsV2._sdCardV2->parseConfigFile())
12021202
haltErrorV2("Failed to parse incoming JSON file");
1203-
WS_DEBUG_PRINT("[Offline] Attempting to configure hardware...");
1203+
WS_DEBUG_PRINTLN("[Offline] Attempting to configure hardware...");
12041204
#ifndef OFFLINE_MODE_DEBUG
12051205
// Create a new file to store the json log
12061206
if (!WsV2._sdCardV2->CreateNewLogFile()) {
@@ -1210,7 +1210,7 @@ void Wippersnapper_V2::connectV2() {
12101210
// Call the TL signal decoder to parse the incoming JSON data
12111211
callDecodeB2D();
12121212
WS_DEBUG_PRINTLN(
1213-
"[Offline] Hardware configured, skipping network setup...");
1213+
"[Offline] Hardware configured, skipping network setup and running app...");
12141214
return;
12151215
} else {
12161216
WS_DEBUG_PRINTLN("Running in online mode...");

src/components/analogIO/controller.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,7 @@ bool AnalogIOController::EncodePublishPinEvent(
197197
}
198198
WS_DEBUG_PRINTLN("Published AnalogIOEvent message to broker!")
199199
} else {
200-
// Print event data
201-
WS_DEBUG_PRINTLN("AnalogIOEvent message:");
202-
WS_DEBUG_PRINT("Pin Name: ");
203-
WS_DEBUG_PRINTLN(c_pin_name);
204-
WS_DEBUG_PRINT("Value: ");
205-
WS_DEBUG_PRINTLN(value);
206-
WS_DEBUG_PRINT("Read Type: ");
207-
WS_DEBUG_PRINTLN(read_type);
208-
WS_DEBUG_PRINTLN("[analogio] Offline analogIOEvent message not published!");
200+
209201
// TODO: Log out this data by calling a logging function in sdcard class
210202
}
211203

@@ -225,7 +217,6 @@ bool AnalogIOController::EncodePublishPinEvent(
225217
/***************************************************************************/
226218
bool AnalogIOController::EncodePublishPinValue(uint8_t pin, uint16_t value) {
227219
if (WsV2._sdCardV2->isModeOffline()) {
228-
WS_DEBUG_PRINTLN("Logging offline analogio event...");
229220
return WsV2._sdCardV2->LogGPIOSensorEventToSD(
230221
pin, value, wippersnapper_sensor_SensorType_SENSOR_TYPE_RAW);
231222
} else {

src/components/ds18x20/controller.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,22 @@ bool DS18X20Controller::Handle_Ds18x20Add(pb_istream_t *stream) {
9797
// If the sensor was successfully initialized, add it to the controller
9898
if (is_initialized == true)
9999
_DS18X20_pins.push_back(std::move(new_dsx_driver));
100+
101+
// Print out the details
102+
WS_DEBUG_PRINTLN("[ds18x] New Sensor Added!");
103+
WS_DEBUG_PRINT("\tPin: ");
104+
WS_DEBUG_PRINTLN(pin_name);
105+
WS_DEBUG_PRINT("\tResolution: ");
106+
WS_DEBUG_PRINTLN(_DS18X20_model->GetDS18x20AddMsg()->sensor_resolution);
107+
WS_DEBUG_PRINT("\tPeriod: ");
108+
WS_DEBUG_PRINTLN(_DS18X20_model->GetDS18x20AddMsg()->period);
109+
WS_DEBUG_PRINT("\tSI Units: ");
110+
for (int i = 0; i < _DS18X20_model->GetDS18x20AddMsg()->sensor_types_count;
111+
i++) {
112+
WS_DEBUG_PRINT(_DS18X20_model->GetDS18x20AddMsg()->sensor_types[i]);
113+
WS_DEBUG_PRINT(", ");
114+
}
115+
WS_DEBUG_PRINTLN("");
100116
} else {
101117
WS_DEBUG_PRINTLN("ERROR | DS18x20: Unable to get sensor ID!");
102118
is_initialized = false;

src/provisioning/sdcard/ws_sdcard.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -457,13 +457,13 @@ bool ws_sdcard::parseConfigFile() {
457457
DeserializationError error;
458458
JsonDocument doc;
459459
#ifndef OFFLINE_MODE_DEBUG
460-
WS_DEBUG_PRINTLN("[SD] Parsing config.txt from SD card...");
461-
if (!_sd.exists("config.txt")) {
460+
WS_DEBUG_PRINTLN("[SD] Parsing config.json from SD card...");
461+
if (!_sd.exists("config.json")) {
462462
WS_DEBUG_PRINTLN(
463-
"[SD] FATAL Error - config.txt file not found on SD Card!");
463+
"[SD] FATAL Error - config.json file not found on SD Card!");
464464
return false;
465465
}
466-
file_config = _sd.open("config.txt", O_RDONLY);
466+
file_config = _sd.open("config.json", O_RDONLY);
467467
error = deserializeJson(doc, file_config);
468468
#else
469469
// Test Mode - do not use the SD card, use test data instead!
@@ -744,7 +744,6 @@ void ws_sdcard::BuildJSONDoc(JsonDocument &doc, uint8_t pin, uint16_t value,
744744
char pin_name[12];
745745
sprintf(pin_name, "A%d", pin);
746746
doc["timestamp"] = GetTimestamp();
747-
;
748747
doc["pin"] = pin_name;
749748
doc["value"] = value;
750749
doc["si_unit"] = SensorTypeToString(read_type);
@@ -761,17 +760,23 @@ void ws_sdcard::BuildJSONDoc(JsonDocument &doc, uint8_t pin, bool value,
761760
}
762761

763762
bool ws_sdcard::LogJSONDoc(JsonDocument &doc) {
764-
File32 file;
765763
size_t szJson;
766764
// Serialize the JSON document
767765
#ifndef OFFLINE_MODE_DEBUG
768-
if (!_sd.open("log.json", FILE_WRITE))
766+
File32 file;
767+
file = _sd.open(_log_filename, FILE_WRITE);
768+
if (!file) {
769+
WS_DEBUG_PRINTLN("[SD] FATAL Error - Unable to open the log file for writing!");
769770
return false;
771+
}
770772
BufferingPrint bufferedFile(file, 64); // Add buffering to the file
771773
szJson = serializeJson(
772774
doc, file); // Serialize the JSON to the file in 64-byte chunks
773775
bufferedFile.print("\n"); // JSONL format specifier
774776
bufferedFile.flush(); // Send the remaining bytes
777+
// print the doc to the serial
778+
serializeJson(doc, Serial);
779+
Serial.print("\n");
775780
#else
776781
szJson = serializeJson(doc, Serial); // TODO: Add buffering here, too?
777782
Serial.print("\n"); // JSONL format specifier

0 commit comments

Comments
 (0)