From 9f7ad700aba83f1772712d067674622859dc224d Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 14 Sep 2023 09:47:07 +0100 Subject: [PATCH 1/4] Add Lilygo T-RSC3 target --- sensor/platformio.ini | 7 +++++++ sensor/src/sensor.ino | 13 ++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/sensor/platformio.ini b/sensor/platformio.ini index bf58527..e05df6c 100644 --- a/sensor/platformio.ini +++ b/sensor/platformio.ini @@ -37,3 +37,10 @@ upload_flags = [env:d1_mini_lite] board = d1_mini_lite platform = espressif8266 + +[env:t-rsc3] ; Lilygo T-RSC3 +platform = espressif32 +board = esp32-c3-devkitm-1 +build_flags = -D RSC3 +lib_deps = ${env.lib_deps} + https://github.com/FastLED/FastLED.git#3.6.0 \ No newline at end of file diff --git a/sensor/src/sensor.ino b/sensor/src/sensor.ino index dd5f08d..5b237f3 100644 --- a/sensor/src/sensor.ino +++ b/sensor/src/sensor.ino @@ -56,7 +56,14 @@ const int MINUTES_PER_DEGC = 45; int delayTime = 40; -#ifdef ESP32 + +#ifdef RSC3 +#define tub Serial1 +#define RX_PIN 10 +#define TX_PIN 3 +#define RTS_PIN 5 // RS485 direction control, RequestToSend TX or RX, required for MAX485 board. +#define PIN_5_PIN 6 +#elif ESP32 #define tub Serial2 #define RX_PIN 19 #define TX_PIN 23 @@ -410,7 +417,7 @@ String lastRaw5 = ""; String lastRaw6 = ""; String lastRaw7 = ""; String lastJSON = ""; -int lastUptime = 0; +uint32_t lastUptime = 0; String timeString = ""; int msgLength = 0; @@ -666,7 +673,7 @@ void handleMessage() { float timeToTempValue = (tempDiff * MINUTES_PER_DEGC); timeToTemp.setValue(timeToTempValue); } else { - timeToTemp.setValue(0); + timeToTemp.setValue((float) 0); } } } else if (result.substring(10, 12) == "2d") { // "-" From 06524e53b884abd2bdc4e9908de778bced78cc61 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 14 Sep 2023 10:35:05 +0100 Subject: [PATCH 2/4] Add status led for RS3C --- sensor/platformio.ini | 2 +- sensor/src/constants.h | 4 ++++ sensor/src/sensor.ino | 33 +++++++++++++++++++++++++++++++-- 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/sensor/platformio.ini b/sensor/platformio.ini index e05df6c..edae11b 100644 --- a/sensor/platformio.ini +++ b/sensor/platformio.ini @@ -43,4 +43,4 @@ platform = espressif32 board = esp32-c3-devkitm-1 build_flags = -D RSC3 lib_deps = ${env.lib_deps} - https://github.com/FastLED/FastLED.git#3.6.0 \ No newline at end of file + https://github.com/adafruit/Adafruit_NeoPixel.git#1.11.1 \ No newline at end of file diff --git a/sensor/src/constants.h b/sensor/src/constants.h index 6d84e99..fcb6b14 100644 --- a/sensor/src/constants.h +++ b/sensor/src/constants.h @@ -25,3 +25,7 @@ #else #define PUMP2_STATE_HIGH 1 #endif + +#define STATUS_BOOT 0 +#define STATUS_WIFI 2 +#define STATUS_OK 1 \ No newline at end of file diff --git a/sensor/src/sensor.ino b/sensor/src/sensor.ino index 5b237f3..888df2b 100644 --- a/sensor/src/sensor.ino +++ b/sensor/src/sensor.ino @@ -59,10 +59,14 @@ int delayTime = 40; #ifdef RSC3 #define tub Serial1 -#define RX_PIN 10 -#define TX_PIN 3 +#define RX_PIN 3 +#define TX_PIN 10 #define RTS_PIN 5 // RS485 direction control, RequestToSend TX or RX, required for MAX485 board. #define PIN_5_PIN 6 + +#include +Adafruit_NeoPixel pixels(1, 4, NEO_GRB + NEO_KHZ800); + #elif ESP32 #define tub Serial2 #define RX_PIN 19 @@ -234,13 +238,36 @@ void onTargetTemperatureCommand(HANumeric temperature, HAHVAC* sender) { // the control unit reports that assume our commands worked } +void setPixel(uint8_t color) { +#ifdef RSC3 + switch(color) { + case 0: + pixels.setPixelColor(0, pixels.Color(255,0,0)); + break; + case 1: + pixels.setPixelColor(0, pixels.Color(0,255,0)); + break; + case 2: + pixels.setPixelColor(0, pixels.Color(0,0,255)); + break; + } + pixels.show(); +#endif +} + boolean isConnected = false; void setup() { Serial.begin(115200); delay(1000); +#ifdef RSC3 + pixels.begin(); + pixels.setBrightness(255); + setPixel(STATUS_BOOT); +#else pinMode(LED_BUILTIN, OUTPUT); digitalWrite(LED_BUILTIN, HIGH); +#endif // Make sure you're in station mode WiFi.mode(WIFI_STA); @@ -267,6 +294,7 @@ void setup() { Serial.print("."); } } + setPixel(STATUS_WIFI); if (WiFi.status() != WL_CONNECTED) { #ifdef AP_FALLBACK @@ -426,6 +454,7 @@ void handleBytes(size_t len, uint8_t buf[]); void loop() { bool panelSelect = digitalRead(PIN_5_PIN); // LOW when we are meant to read data if (tub.available() > 0) { + setPixel(STATUS_OK); size_t len = tub.available(); // Serial.printf("bytes avail = %u\n", len); uint8_t buf[len]; // TODO: swap to fixed buffer to help prevent fragmentation of memory From fc99dd4dc787e048dda64674f73786118314871d Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 14 Sep 2023 14:45:44 +0100 Subject: [PATCH 3/4] Fix serial logging --- sensor/platformio.ini | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/sensor/platformio.ini b/sensor/platformio.ini index edae11b..05cafd2 100644 --- a/sensor/platformio.ini +++ b/sensor/platformio.ini @@ -41,6 +41,10 @@ platform = espressif8266 [env:t-rsc3] ; Lilygo T-RSC3 platform = espressif32 board = esp32-c3-devkitm-1 -build_flags = -D RSC3 -lib_deps = ${env.lib_deps} - https://github.com/adafruit/Adafruit_NeoPixel.git#1.11.1 \ No newline at end of file +lib_deps = + ${env.lib_deps} + https://github.com/adafruit/Adafruit_NeoPixel.git#1.11.1 +build_flags = + -D RSC3 + -DARDUINO_USB_MODE=1 + -DARDUINO_USB_CDC_ON_BOOT=1 From 22c504198e07b4f156b193619913a697966e9c60 Mon Sep 17 00:00:00 2001 From: Will Tatam Date: Thu, 14 Sep 2023 14:56:54 +0100 Subject: [PATCH 4/4] Add extra status to LED --- sensor/src/constants.h | 4 +++- sensor/src/sensor.ino | 16 +++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sensor/src/constants.h b/sensor/src/constants.h index fcb6b14..acc1651 100644 --- a/sensor/src/constants.h +++ b/sensor/src/constants.h @@ -28,4 +28,6 @@ #define STATUS_BOOT 0 #define STATUS_WIFI 2 -#define STATUS_OK 1 \ No newline at end of file +#define STATUS_OK 1 +#define STATUS_WAITING_DATA 3 +#define STATUS_WAITING_PANEL 4 \ No newline at end of file diff --git a/sensor/src/sensor.ino b/sensor/src/sensor.ino index 656c0a8..e1936bc 100644 --- a/sensor/src/sensor.ino +++ b/sensor/src/sensor.ino @@ -250,6 +250,12 @@ void setPixel(uint8_t color) { case 2: pixels.setPixelColor(0, pixels.Color(0,0,255)); break; + case 3: + pixels.setPixelColor(0, pixels.Color(255,255,0)); + break; + case 4: + pixels.setPixelColor(0, pixels.Color(255,0,255)); + break; } pixels.show(); #endif @@ -468,6 +474,14 @@ void loop() { msgLength = 0; } } + else { + if(panelDetected) { + setPixel(STATUS_WAITING_DATA); + } + else { + setPixel(STATUS_WAITING_PANEL); + } + } if (panelSelect == HIGH || !panelDetected) { // Controller talking to other topside panels - we are in effect idle @@ -484,7 +498,7 @@ void loop() { telnetLoop(); - if (sendBuffer.isEmpty()) { // Only handle status is we aren't trying to send commands, webserver and websocket + if (sendBuffer.isEmpty() || !panelDetected) { // Only handle status is we aren't trying to send commands, webserver and websocket // can both block for a long time webserver.handleClient();