Skip to content

Commit

Permalink
partial MAC in title
Browse files Browse the repository at this point in the history
• Last three octets of MAC address in title to differentiate devices with the same model name.
• fixed memory leak
• process optimisation
  • Loading branch information
DigiH committed Mar 2, 2023
1 parent 9850d1d commit 9c661c4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
21 changes: 16 additions & 5 deletions main/ZdisplaySSD1306.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -192,15 +192,14 @@ 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);
strlcpy(message->title, strtok(topic, "/"), OLED_TEXT_WIDTH);
free(topic);

Oled.display->normalDisplay();
// Oled.display->normalDisplay();

switch (hash(message->title)) {
case hash("SYStoMQTT"): {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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<String>().substring(9, 17);
line0.toCharArray(message->title, OLED_TEXT_WIDTH);
free(topic);

// Line 1
strlcpy(message->line1, data["model"], OLED_TEXT_WIDTH);

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions main/ZgatewayBT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down

0 comments on commit 9c661c4

Please sign in to comment.