Skip to content

Commit

Permalink
log fix for Issue 1technophile#931
Browse files Browse the repository at this point in the history
  • Loading branch information
Odyno committed Jul 7, 2021
1 parent 2ae8f0c commit 80b0acb
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions main/main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ void pub(const char* topicori, const char* payload, bool retainFlag) {
void pub(const char* topicori, JsonObject& data) {
Log.notice(F("Subject: %s" CR), topicori);
digitalWrite(LED_SEND_RECEIVE, LED_SEND_RECEIVE_ON);
logJson(data);
logJson("Sent: ", data);
if (client.connected()) {
String topic = String(mqtt_topic) + String(gateway_name) + String(topicori);
#ifdef valueAsASubject
Expand Down Expand Up @@ -457,14 +457,18 @@ void pubMQTT(String topic, unsigned long payload) {
client.publish(topic.c_str(), val);
}

void logJson(JsonObject& jsondata) {
void logJson(String comment, JsonObject& jsondata) {
#if defined(ESP8266) || defined(ESP32) || defined(__AVR_ATmega2560__) || defined(__AVR_ATmega1280__)
char JSONmessageBuffer[jsondata.measureLength() + 1];
#else
char JSONmessageBuffer[JSON_MSG_BUFFER];
#endif
jsondata.printTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
Log.notice(F("Received json : %s" CR), JSONmessageBuffer);
Log.notice("%s%s\n", comment.c_str(), JSONmessageBuffer);
}

void logJson(JsonObject& jsondata) {
logJson("Json: ", jsondata);
}

bool cmpToMainTopic(const char* topicOri, const char* toAdd) {
Expand Down Expand Up @@ -1615,7 +1619,7 @@ void receivingMQTT(char* topicOri, char* datacallback) {

if (jsondata.success()) { // json object ok -> json decoding
// log the received json
logJson(jsondata);
logJson("Received: ", jsondata);
#ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing due to its numerous parameters
MQTTtoPilight(topicOri, jsondata);
#endif
Expand Down

0 comments on commit 80b0acb

Please sign in to comment.