Open udellc opened 2 years ago
Update: Changing the order of logging from SD then MQTT - to MQTT then SD did not make a difference. It must be that in FeatherFault, when a fault is detected, it renames the Feather.internal_json to "Errors" temporarily. The funny thing is, SD logging is stall able to log data to the correct file. Recommendation: we need to look at the log SD functions and see from where the JSON packet is being pulled to ensure data keeps going to the proper named file. Then use that example to ensure MQTT logs to the correct topic. Stretch goal would be to make MQTT log like SD logs: i.e. Sensor data to the correct topic, and any errors to a separate errors topic with a reasonable name to identify from which device the error log belongs to. See code I tried below:
void loop() { Feather.measure(); Feather.package(); Feather.display_data(); // *edit: Swapped the order of publishing to MQTT and then to SD // Because SD Hard Faults and makes the MQTT json packet change topic name to Errors# // Log online to MongoDB via MQTT WiFi connect_to_wifi(); connect_to_broker(1); // Build JSON document to publish via MQTT doc.clear(); jsonSerialized = ""; doc.add(Feather.internal_json(false)); serializeJson(doc, jsonSerialized); publish_mqtt(topic, jsonSerialized); // Log using default filename as provided in configuration // in this case, 'datafile.csv' getSD(Feather).log(); // Or log to a specific file (does not change what default file is set to) // getSD(Feather)log("specific.csv"); // Set RTC Timer for wake up and sample to next time interval getInterruptManager(Feather).RTC_alarm_duration(TimeSpan(days,hours,mins,secs)); getInterruptManager(Feather).reconnect_interrupt(12); disconnect_wifi(); // Disable WiFi for power savings digitalWrite(5, HIGH); // Disable 3.3V rail digitalWrite(6, LOW); // Disable 5V rail // Disable SPI pins/SD chip select to save power pinMode(23, INPUT); pinMode(24, INPUT); pinMode(10, INPUT); // Needs to be correct pin for SD CS on Hypnos Feather.power_down(); getSleepManager(Feather).sleep(); // Sketch pauses here until RTC alarm digitalWrite(5, LOW); // Enable 3.3V rail digitalWrite(6, HIGH); // Enable 5V rail pinMode(23, OUTPUT); pinMode(24, OUTPUT); pinMode(10, OUTPUT); // Needs to be correct pin for SD CS on Hypnos // *** SITS Here in Sleep till p12 RTC Alarm Wake Signal ... Feather.power_up(); delay(1000); // Delay for power }
Edit: We imposed a non-integrated soft fix for creating and posting to the correct topic. The issue fundamentally is NOT resolved and should be addressed in the near future for a true integrated version. Code for soft fix follows:
// Build JSON document to publish via MQTT doc.clear(); jsonSerialized = ""; doc.add(Feather.internal_json(false)); serializeJson(doc, jsonSerialized); //publish_mqtt(topic, jsonSerialized); publish_mqtt(String(SITE_NAME)+"/Chime"+String(Feather.get_instance_num()), jsonSerialized); // Replace content in Quotes with the Topic name
Describe the bug WeatherChimes publishes data to MongoDB via MQTT. The current method automatically names the MQTT topic from the sending device's name and id number from the manager. This works fine until there is a Hard Fault in the system; in which case, the topic name being published is changed to "Errors[device id number]." SD publishing seems to handle hard fault cases the way we want, continuing to log to the same file as intended, and only logging errors to the errors.csv file.
I suspect, because the hard fault is occurring in the SD.cpp area, that the current method of building the MQTT JSON document after the faulting log SD operation is screwing up the name in the JSON area. As a band aid we could move MQTT logging to before the SD log operation, but it would be even better to fix how we are generating the MQTT JSON document so even if we get a hard fault we will still publish data to the intended topic.
Chime #4 (Chime #3 seems to be experiencing additional SDI-12 related hardware issues) Feather M0 WiFi Hypnos Board: SD, DS3231 RTC, 3v 5v Power rail switching TSL2591 GS3 (SDI-12 soil moisture sensor by Meter) SHT-30 Air Temp, Humidity
To Reproduce Steps to reproduce the behavior: Change WiFi router info in arduino_secrets for: SECRET_SSID, SECRET_PASS for your internet router Ask Will or Chet for arduino secrets for MQTT broker and input Upload attached WeatherChimesV4SDSleepMQTT.ino and config.h to WeatherChimes Hardware
Expected behavior We want the device to continue publishing to the intended MQTT topic [device name][device id] instead of Errors[device id]. SD publishing seems to handle hard fault cases the way we want, continuing to log to the same file as intended, and only logging errors to the errors.csv file.
Code
Config
MQTT.h
arduino_secrets.h
Additional context Add any other context about the problem here. chimes170.csv Errors.csv