From 9c661c4b3f166dd389efcf788ac1da16637e5350 Mon Sep 17 00:00:00 2001 From: DigiH Date: Thu, 2 Mar 2023 03:52:56 +0100 Subject: [PATCH] partial MAC in title MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit • Last three octets of MAC address in title to differentiate devices with the same model name. • fixed memory leak • process optimisation --- main/ZdisplaySSD1306.ino | 21 ++++++++++++++++----- main/ZgatewayBT.ino | 5 ++--- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/main/ZdisplaySSD1306.ino b/main/ZdisplaySSD1306.ino index 00f78ccede..a4ad9152db 100644 --- a/main/ZdisplaySSD1306.ino +++ b/main/ZdisplaySSD1306.ino @@ -93,7 +93,7 @@ void loopSSD1306() { long enough since the last message and display not being used and a queue message waiting */ - if (jsonDisplay) { + if (jsonDisplay && displayState) { if (uptime() >= nextDisplayPage && uxSemaphoreGetCount(semaphoreOLEDOperation) && uxQueueMessagesWaiting(displayQueue)) { displayQueueMessage* message = nullptr; xQueueReceive(displayQueue, &message, portMAX_DELAY); @@ -108,7 +108,7 @@ void loopSSD1306() { /* Display logo if it has been more than DISPLAY_PAGE_INTERVAL */ - if (uptime() > nextDisplayPage + 1 && !logoDisplayed && idlelogo) { + if (uptime() > nextDisplayPage + 1 && !logoDisplayed && idlelogo && displayState) { Oled.fillScreen(BLACK); Oled.drawLogo(rand() % 13 - 5, rand() % 32 - 13); logoDisplayed = true; @@ -192,7 +192,7 @@ constexpr unsigned int hash(const char* s, int off = 0) { // workaround for swit Parse json message from module into a format for displaying on screen, and queue for display */ void ssd1306PubPrint(const char* topicori, JsonObject& data) { - if (jsonDisplay) { + if (jsonDisplay && displayState) { displayQueueMessage* message = (displayQueueMessage*)malloc(sizeof(displayQueueMessage)); if (message != NULL) { char* topic = strdup(topicori); @@ -200,7 +200,6 @@ void ssd1306PubPrint(const char* topicori, JsonObject& data) { free(topic); Oled.display->normalDisplay(); - // Oled.display->normalDisplay(); switch (hash(message->title)) { case hash("SYStoMQTT"): { @@ -303,6 +302,7 @@ void ssd1306PubPrint(const char* topicori, JsonObject& data) { if (xQueueSend(displayQueue, (void*)&message, 0) != pdTRUE) { Log.error(F("[ SSD1306 ] displayQueue full, discarding signal %s" CR), message->title); + free(message); } else { // Log.notice(F("Queued %s" CR), message->title); } @@ -667,6 +667,13 @@ void ssd1306PubPrint(const char* topicori, JsonObject& data) { line4 = properties[4] + properties[5]; if (!(line2 == "" && line3 == "" && line4 == "")) { + // Titel + char* topic = strdup(topicori); + String heading = strtok(topic, "/"); + String line0 = heading + " " + data["id"].as().substring(9, 17); + line0.toCharArray(message->title, OLED_TEXT_WIDTH); + free(topic); + // Line 1 strlcpy(message->line1, data["model"], OLED_TEXT_WIDTH); @@ -680,9 +687,13 @@ void ssd1306PubPrint(const char* topicori, JsonObject& data) { } else { // Log.notice(F("Queued %s" CR), message->title); } + } else { + free(message); } break; + } else { + free(message); } } # endif @@ -751,7 +762,7 @@ OledSerial::OledSerial(int x) { } /* -Initialize ssd1306 oled display for use, and display animated OMG logo +Initialize ssd1306 oled display for use, and display OMG logo */ void OledSerial::begin() { // SSD1306.begin(); // User OMG serial support diff --git a/main/ZgatewayBT.ino b/main/ZgatewayBT.ino index d9ed3095f3..fae6871e62 100644 --- a/main/ZgatewayBT.ino +++ b/main/ZgatewayBT.ino @@ -991,9 +991,8 @@ void launchBTDiscovery(bool overrideDiscovery) { void PublishDeviceData(JsonObject& BLEdata, bool processBLEData) { if (abs((int)BLEdata["rssi"] | 0) < abs(BTConfig.minRssi)) { // process only the devices close enough if (processBLEData) process_bledata(BLEdata); - String topic = subjectBTtoMQTT; - if (BLEdata.containsKey("model") || BLEdata.containsKey("distance")) { // Only display sensor data - pubOled((char*)topic.c_str(), BLEdata); + if (BLEdata.containsKey("type") && (BLEdata.containsKey("model") || BLEdata.containsKey("distance"))) { // Only display sensor data with type + pubOled(subjectBTtoMQTT, BLEdata); } if (!BTConfig.pubAdvData) { BLEdata.remove("servicedatauuid");