33 if(command ==
"get_time_range"){
35 StaticJsonDocument<256> doc;
36 deserializeJson(doc, message);
39 JsonArray topic_filter_ja = {};
42 if(!doc.containsKey(
"page_size")){
43 if(
USB_DEBUG) Serial.println(
"[ERROR] MQTT command \'get_time_range\' missing key \'page_size\' so using default size of 20");
47 page_size = doc[
"page_size"];
50 if(!doc.containsKey(
"time_range")){
51 if(
USB_DEBUG) Serial.println(
"[ERROR] MQTT command \'get_time_range\' missing key \'time_range\' so quitting");
55 time_range = doc[
"time_range"].as<
string>();
58 if(!doc.containsKey(
"topic_filter")){
59 if(
USB_DEBUG) Serial.println(
"[ERROR] MQTT command \'get_time_range\' missing key \'topic_filter\' so using default \"\"");
60 topic_filter_ja.add(
"");
62 topic_filter_ja = doc[
"topic_filter"];
66 vector<string> topic_filter_v = {};
69 for(JsonVariant n : topic_filter_ja){
70 topic_filter_v.push_back(n.as<
string>());
74 int ampersand_pos = time_range.find(
"&");
75 string epoch = time_range.substr(0, ampersand_pos);
76 string terminus = time_range.substr(ampersand_pos+1);
82 if(epoch.find(
"T") != string::npos){
88 if(terminus.find(
"T") != string::npos){
96 Serial.println(
"[DEBUG] pulling data range");
116 Serial.print(
"[DEBUG] unkown command \'");
117 Serial.print(command.c_str());
118 Serial.println(
"\'");
123 if(
USB_DEBUG) Serial.println(
"[DEBUG] finished processing MQTT command");
146void callback(
char* topic,
byte* message,
unsigned int length){
148 for(
int i = 0; i < length; i++){
149 msg_str += (char)message[i];
152 Serial.printf(
"[MQTT] Received \'%s\'|\'%s\'\n", topic, msg_str.c_str());
156 string topic_s = topic;
157 int mac_id_pos = topic_s.find(
"/", 15);
158 string command = topic_s.substr(14, mac_id_pos - 14);
161 string mac_id = topic_s.substr(mac_id_pos + 1);
164 if(WiFi.macAddress().c_str() == mac_id){
void read_entry_range_from_files(TimeStamp epoch, TimeStamp terminus, vector< string > topic_filter, int page_length=5, string prefix="log", string filetype="csv")
Retrieve all data within the specified time range, potentially accessing multiple files.
Definition SDReader.cpp:167
void callback(char *topic, byte *message, unsigned int length)
Called when MQTT message is passed to the device by the broker.
Definition mqtt_util.hpp:146
void process_command(string command, string message)
Process a command execute it.
Definition mqtt_util.hpp:31
const bool USB_DEBUG
USB serial debugging enabled.
Definition main.cpp:62