Skip to content

Commit

Permalink
parent c570eea
Browse files Browse the repository at this point in the history
author Northern Man <northern.man1@gmail.com> 1666144653 -0400
committer Northern Man <northern.man1@gmail.com> 1666481801 -0400

Adding logic to reduce corruption of message display

Two piece of defensive code were added

- Only display messages to the display when operating on Core 1 ( Default Arduino ESP32 CONFIG_ARDUINO_RUNNING_CORE )

- Only display one character/string at a time

PR#1291

Update of rtl_433_ESP to version 0.1.3 - Support for SX127X transceiver module (1technophile#1291)

The main features of the upgrade to 0.1.3 of rtl_433_ESP are

1 - Change Transceiver Library to RadioLib

2 - Add support for SX127X transceiver module ( I used the 433 Mhz version of this Heltec module for development ).

3 - Added automatic calibration of the RSSI Signal detection Threshold

4 - Removed dependency on loop for start and end of signal detection, and moved to a ESP32 Task

5 - Moved received signal decoding to a ESP32 Task

6 - Identified Blueline PowerCost Monitor decoder as source of significant memory overhead and disabled.

7 - Multi Receiver support has been validated with RF, RF2 and PiLight

Create omg_firmware_version.py

Revert "Create omg_firmware_version.py"

This reverts commit 0fb1bc8.

Lint fixes
  • Loading branch information
NorthernMan54 committed Oct 22, 2022
1 parent c570eea commit be4c352
Show file tree
Hide file tree
Showing 10 changed files with 213 additions and 94 deletions.
2 changes: 1 addition & 1 deletion main/User_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ int lowpowermode = DEFAULT_LOW_POWER_MODE;
# define STRTO_UL_ULL strtoul
#endif

#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation)
#if defined(ZgatewayRF) || defined(ZgatewayIR) || defined(ZgatewaySRFB) || defined(ZgatewayWeatherStation) || defined(ZgatewayRTL_433)
// variable to avoid duplicates
# ifndef time_avoid_duplicate
# define time_avoid_duplicate 3000 // if you want to avoid duplicate MQTT message received set this to > 0, the value is the time in milliseconds during which we don't publish duplicates
Expand Down
61 changes: 31 additions & 30 deletions main/ZboardHeltec.ino
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
HELTEC ESP32 LORA - SSD1306 / Onboard 0.96-inch 128*64 dot matrix OLED display
Copyright: (c)Florian ROBERT
Contributors:
- 1technophile
- NorthernMan54
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand All @@ -32,7 +32,8 @@
#if defined(ZboardHELTEC)
# include "ArduinoLog.h"
# include "config_HELTEC.h"
// # include "heltec.h"

SemaphoreHandle_t semaphoreOLEDOperation;

void logToLCD(bool display) {
display ? Log.begin(LOG_LEVEL_LCD, &Oled) : Log.begin(LOG_LEVEL, &Serial); // Log on LCD following LOG_LEVEL_LCD
Expand Down Expand Up @@ -125,6 +126,10 @@ OledSerial::OledSerial(int x) {

void OledSerial::begin() {
// Heltec.begin(); // User OMG serial support

semaphoreOLEDOperation = xSemaphoreCreateBinary();
xSemaphoreGive(semaphoreOLEDOperation);

display->init();
display->flipScreenVertically();
display->setFont(ArialMT_Plain_10);
Expand Down Expand Up @@ -157,28 +162,24 @@ void OledSerial::fillScreen(OLEDDISPLAY_COLOR color) {
display->fillRect(0, 0, OLED_WIDTH, OLED_HEIGHT);
}

size_t OledSerial::write(uint8_t c) {
display->clear();
display->setColor(WHITE);
display->setFont(ArialMT_Plain_10);

display->write((char)c);
display->drawLogBuffer(0, 0);
display->display();
return 1;
}

size_t OledSerial::write(const uint8_t* buffer, size_t size) {
display->clear();
display->setColor(WHITE);
display->setFont(ArialMT_Plain_10);
while (size) {
display->write((char)*buffer++);
size--;
if (xPortGetCoreID() == CONFIG_ARDUINO_RUNNING_CORE) {
if (xSemaphoreTake(semaphoreOLEDOperation, pdMS_TO_TICKS(30000)) == pdTRUE) {
display->clear();
display->setColor(WHITE);
display->setFont(ArialMT_Plain_10);
while (size) {
display->write((char)*buffer++);
size--;
}
display->drawLogBuffer(0, 0);
display->display();
xSemaphoreGive(semaphoreOLEDOperation);
return size;
}
}
display->drawLogBuffer(0, 0);
display->display();
return size;
// Default to Serial output if the display is not available
return Serial.write(buffer, size);
}

/*
Expand Down Expand Up @@ -255,4 +256,4 @@ void OledSerial::drawLogo(int logoSize, int circle1X, int circle1Y, bool circle1
delay(50);
}

#endif
#endif
11 changes: 9 additions & 2 deletions main/ZgatewayPilight.ino
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
int msgLength = rf.stringToPulseTrain(raw, codes, MAXPULSESTREAMLENGTH);
if (msgLength > 0) {
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(receiveMhz); // set Transmit on
rf.disableReceiver();
# endif
rf.sendPulseTrain(codes, msgLength, repeats);
Expand Down Expand Up @@ -215,7 +218,10 @@ void MQTTtoPilight(char* topicOri, JsonObject& Pilightdata) {
if (message && protocol) {
Log.trace(F("MQTTtoPilight msg & protocol ok" CR));
# ifdef ZradioCC1101
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(receiveMhz); // set Transmit on
rf.disableReceiver();
# endif
int msgLength = rf.send(protocol, message);
Expand Down Expand Up @@ -287,6 +293,7 @@ extern void enablePilightReceive() {
# endif

# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
rf.setCallback(pilightCallback);
Expand Down
3 changes: 3 additions & 0 deletions main/ZgatewayRF.ino
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@ void RFtoMQTT() {
# if simpleReceiving
void MQTTtoRF(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101 // set Receive off and Transmitt on
disableActiveReceiver();
ELECHOUSE_cc1101.SetTx(receiveMhz);
# endif
mySwitch.disableReceive();
Expand Down Expand Up @@ -251,6 +252,7 @@ void MQTTtoRF(char* topicOri, JsonObject& RFdata) { // json object decoding
# ifdef ZradioCC1101 // set Receive off and Transmitt on
float trMhz = RFdata["mhz"] | CC1101_FREQUENCY;
if (validFrequency((int)trMhz)) {
disableActiveReceiver();
ELECHOUSE_cc1101.SetTx(trMhz);
Log.notice(F("Transmit mhz: %F" CR), trMhz);
}
Expand Down Expand Up @@ -321,6 +323,7 @@ void enableRFReceive() {
# endif

# ifdef ZradioCC1101 // set Receive on and Transmitt off
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz);
# endif
mySwitch.disableTransmit();
Expand Down
9 changes: 8 additions & 1 deletion main/ZgatewayRF2.ino
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ void rf2Callback(unsigned int period, unsigned long address, unsigned long group
void MQTTtoRF2(char* topicOri, char* datacallback) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable();
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
# endif

Expand Down Expand Up @@ -268,6 +271,9 @@ void MQTTtoRF2(char* topicOri, JsonObject& RF2data) { // json object decoding
if (boolSWITCHTYPE != 99) {
# ifdef ZradioCC1101
NewRemoteReceiver::disable();
disableActiveReceiver();
ELECHOUSE_cc1101.Init();
pinMode(RF_EMITTER_GPIO, OUTPUT);
ELECHOUSE_cc1101.SetTx(CC1101_FREQUENCY); // set Transmit on
# endif
Log.trace(F("MQTTtoRF2 switch type ok" CR));
Expand Down Expand Up @@ -356,10 +362,11 @@ void enableRF2Receive() {
disableRFReceive();
# endif

NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback);
# ifdef ZradioCC1101
ELECHOUSE_cc1101.Init();
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
# endif
NewRemoteReceiver::init(RF_RECEIVER_GPIO, 2, rf2Callback);
}

#endif
52 changes: 34 additions & 18 deletions main/ZgatewayRTL_433.ino
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,12 @@
*/
#include "User_config.h"
#ifdef ZgatewayRTL_433
# ifndef ZradioCC1101
# error "CC1101 is the only supported receiver module for RTL_433 and needs to be enabled."
# endif

# include <rtl_433_ESP.h>

char messageBuffer[JSON_MSG_BUFFER];

rtl_433_ESP rtl_433(-1); // use -1 to disable transmitter

# include <ELECHOUSE_CC1101_SRC_DRV.h>
rtl_433_ESP rtl_433(-1);

void rtl_433_Callback(char* message) {
DynamicJsonDocument jsonBuffer2(JSON_MSG_BUFFER);
Expand All @@ -49,6 +44,7 @@ void rtl_433_Callback(char* message) {
return;
}

unsigned long MQTTvalue = (int)RFrtl_433_ESPdata["id"] + round(RFrtl_433_ESPdata["temperature_C"]);
String topic = String(subjectRTL_433toMQTT);
# if valueAsATopic
String model = RFrtl_433_ESPdata["model"];
Expand All @@ -61,14 +57,16 @@ void rtl_433_Callback(char* message) {
}
# endif

pub((char*)topic.c_str(), RFrtl_433_ESPdata);
if (!isAduplicateSignal(MQTTvalue)) {
pub((char*)topic.c_str(), RFrtl_433_ESPdata);
storeSignalValue(MQTTvalue);
}
# ifdef MEMORY_DEBUG
Log.trace(F("Post rtl_433_Callback: %d" CR), ESP.getFreeHeap());
# endif
}

void setupRTL_433() {
rtl_433.initReceiver(RF_RECEIVER_GPIO, receiveMhz);
rtl_433.setCallback(rtl_433_Callback, messageBuffer, JSON_MSG_BUFFER);
Log.trace(F("ZgatewayRTL_433 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRTL_433);
Log.notice(F("ZgatewayRTL_433 setup done " CR));
Expand All @@ -93,16 +91,24 @@ extern void MQTTtoRTL_433(char* topicOri, JsonObject& RTLdata) {
success = true;
}
if (RTLdata.containsKey("rssi")) {
int minimumRssi = RTLdata["rssi"] | 0;
Log.notice(F("RTL_433 minimum RSSI: %d" CR), minimumRssi);
rtl_433.setMinimumRSSI(minimumRssi);
int rssiThreshold = RTLdata["rssi"] | 0;
Log.notice(F("RTL_433 RSSI Threshold Delta: %d " CR), rssiThreshold);
rtl_433.setRSSIThreshold(rssiThreshold);
success = true;
}
# if defined(RF_SX1276) || defined(RF_SX1278)
if (RTLdata.containsKey("ookThreshold")) {
int newOokThreshold = RTLdata["ookThreshold"] | 0;
Log.notice(F("RTL_433 ookThreshold %d" CR), newOokThreshold);
rtl_433.setOOKThreshold(newOokThreshold);
success = true;
}
# endif
if (RTLdata.containsKey("debug")) {
int debug = RTLdata["debug"] | -1;
Log.notice(F("RTL_433 set debug: %d" CR), debug);
rtl_433.setDebug(debug);
rtl_433.initReceiver(RF_RECEIVER_GPIO, receiveMhz);
// rtl_433.setDebug(debug);
rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, receiveMhz);
success = true;
}
if (RTLdata.containsKey("status")) {
Expand Down Expand Up @@ -131,9 +137,9 @@ extern void enableRTLreceive() {
# ifdef ZgatewayPilight
disablePilightReceive();
# endif
ELECHOUSE_cc1101.SetRx(receiveMhz); // set Receive on
rtl_433.enableReceiver(RF_RECEIVER_GPIO);
pinMode(RF_EMITTER_GPIO, OUTPUT); // Set this here, because if this is the RX pin it was reset to INPUT by Serial.end();

rtl_433.initReceiver(RF_MODULE_RECEIVER_GPIO, receiveMhz);
rtl_433.enableReceiver(RF_MODULE_RECEIVER_GPIO);
}

extern void disableRTLreceive() {
Expand All @@ -142,8 +148,12 @@ extern void disableRTLreceive() {
rtl_433.disableReceiver();
}

extern int getRTLMinimumRSSI() {
return rtl_433.minimumRssi;
extern int getRTLrssiThreshold() {
return rtl_433.rssiThreshold;
}

extern int getRTLAverageRSSI() {
return rtl_433.averageRssi;
}

extern int getRTLCurrentRSSI() {
Expand All @@ -154,4 +164,10 @@ extern int getRTLMessageCount() {
return rtl_433.messageCount;
}

# if defined(RF_SX1276) || defined(RF_SX1278)
extern int getOOKThresh() {
return rtl_433.OokFixedThreshold;
}
# endif

#endif
23 changes: 14 additions & 9 deletions main/config_HELTEC.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
/*
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
OpenMQTTGateway Addon - ESP8266 or Arduino program for home automation
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Act as a wifi or ethernet gateway between your 433mhz/infrared IR signal and a MQTT broker
Send and receiving command by MQTT
HELTEC ESP32 LORA - SSD1306 / Onboard 0.96-inch 128*64 dot matrix OLED display
Copyright: (c)Florian ROBERT
Contributors:
- 1technophile
- NorthernMan54
This file is part of OpenMQTTGateway.
OpenMQTTGateway is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
Expand Down Expand Up @@ -87,7 +87,12 @@ class OledSerial : public Stream {

void fillScreen(OLEDDISPLAY_COLOR); // fillScreen display and set color

size_t write(uint8_t);
// This is a bit of lazy programmer simplifacation for the semapore and core detecting code. Not sure if it is truly space efficient.

inline size_t write(uint8_t x) {
return write(&x, 1);
}

size_t write(const uint8_t* buffer, size_t size);
inline size_t write(const char* buffer, size_t size) {
return write((uint8_t*)buffer, size);
Expand All @@ -113,4 +118,4 @@ class OledSerial : public Stream {

extern OledSerial Oled;

#endif
#endif
Loading

0 comments on commit be4c352

Please sign in to comment.