Skip to content

Commit

Permalink
Debug on/off via MQTT
Browse files Browse the repository at this point in the history
  • Loading branch information
Romkabouter committed Nov 20, 2019
1 parent 1f57a37 commit 4adc4a7
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion PlatformIO/src/MatrixVoiceAudioServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ extern "C" {
#define CHANNELS 1
#define DATA_CHUNK_ID 0x61746164
#define FMT_CHUNK_ID 0x20746d66
#define DEBUG 1

// These parameters enable you to select the default value for output
enum {
Expand Down Expand Up @@ -172,6 +171,7 @@ bool hotword_detected = false;
bool isUpdateInProgess = false;
bool streamingBytes = false;
bool endStream = false;
bool DEBUG = false;
std::string finishedMsg = "";
int message_count;
int CHUNK = 256; // set to multiplications of 256, voice return a set of 256
Expand Down Expand Up @@ -350,6 +350,7 @@ void onMqttConnect(bool sessionPresent) {
asyncClient.subscribe(everloopTopic.c_str(), 0);
asyncClient.subscribe(restartTopic.c_str(), 0);
asyncClient.subscribe(audioTopic.c_str(), 0);
asyncClient.subscribe(debugTopic.c_str(), 0);
publishDebug("Connected to asynch MQTT!");
// xEventGroupClearBits(everloopGroup, ANIMATE);
}
Expand Down Expand Up @@ -525,6 +526,16 @@ void onMqttMessage(char *topic, char *payload, AsyncMqttClientMessageProperties
} else {
publishDebug(err.c_str());
}
} else if (topicstr.find(debugTopic.c_str()) != std::string::npos) {
std::string payloadstr(payload);
StaticJsonDocument<300> doc;
DeserializationError err = deserializeJson(doc, payloadstr.c_str());
if (!err) {
JsonObject root = doc.as<JsonObject>();
if (root.containsKey("debug")) {
DEBUG = (root["debug"] == "true") ? true : false;
}
}
}
} else {
// len + index < total ==> partial message
Expand Down

0 comments on commit 4adc4a7

Please sign in to comment.