From deb2148e9a442455a00c447397f3ec4a6302af12 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Fri, 7 Feb 2020 17:27:58 +0100 Subject: [PATCH 1/7] Software serial for development boards. Added a few extra boards --- .github/workflows/build.yml | 2 + .github/workflows/release.yml | 18 +++++++ lib/HanReader/src/HanReader.cpp | 4 +- lib/HanReader/src/HanReader.h | 6 +-- platformio-user.ini-example | 7 +-- platformio.ini | 29 +++++++---- src/AmsToMqttBridge.h | 64 ++++++++++++++++++++++++ src/AmsToMqttBridge.ino | 86 ++++++++++++++------------------- 8 files changed, 148 insertions(+), 68 deletions(-) create mode 100644 src/AmsToMqttBridge.h diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 158595c8..cc5540b3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -40,6 +40,8 @@ jobs: run: | python -m pip install --upgrade pip pip install -U platformio + - name: Configure build targets + run: echo "[platformio]\ndefault_envs = hw1esp12e, esp12e, esp32" > platformio-user.ini - name: PlatformIO lib install run: pio lib install - name: PlatformIO run diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 8d6805c5..ffea33d9 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -69,6 +69,24 @@ jobs: asset_path: .pio/build/hw1esp12e/firmware.bin asset_name: ams2mqtt-hw1esp12e-${{ steps.release_tag.outputs.tag }}.bin asset_content_type: application/octet-stream + - name: Upload d1mini binary to release + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: .pio/build/d1mini/firmware.bin + asset_name: ams2mqtt-d1mini-${{ steps.release_tag.outputs.tag }}.bin + asset_content_type: application/octet-stream + - name: Upload esp32 binary to release + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: .pio/build/esp32/firmware.bin + asset_name: ams2mqtt-esp32-${{ steps.release_tag.outputs.tag }}.bin + asset_content_type: application/octet-stream - name: Upload featheresp32 binary to release uses: actions/upload-release-asset@v1.0.1 env: diff --git a/lib/HanReader/src/HanReader.cpp b/lib/HanReader/src/HanReader.cpp index 6012a432..9d6df8b4 100644 --- a/lib/HanReader/src/HanReader.cpp +++ b/lib/HanReader/src/HanReader.cpp @@ -5,7 +5,7 @@ HanReader::HanReader() } -void HanReader::setup(HardwareSerial *hanPort, Stream *debugPort) +void HanReader::setup(Stream *hanPort, Stream *debugPort) { han = hanPort; bytesRead = 0; @@ -13,7 +13,7 @@ void HanReader::setup(HardwareSerial *hanPort, Stream *debugPort) if (debug) debug->println("MBUS serial setup complete"); } -void HanReader::setup(HardwareSerial *hanPort) +void HanReader::setup(Stream *hanPort) { setup(hanPort, NULL); } diff --git a/lib/HanReader/src/HanReader.h b/lib/HanReader/src/HanReader.h index 95753b9b..5e91e6ce 100644 --- a/lib/HanReader/src/HanReader.h +++ b/lib/HanReader/src/HanReader.h @@ -18,8 +18,8 @@ public: bool compensateFor09HeaderBug = false; HanReader(); - void setup(HardwareSerial *hanPort); - void setup(HardwareSerial *hanPort, Stream *debugPort); + void setup(Stream *hanPort); + void setup(Stream *hanPort, Stream *debugPort); bool read(); bool read(byte data); int getListSize(); @@ -30,7 +30,7 @@ public: private: Stream *debug; - HardwareSerial *han; + Stream *han; byte buffer[512]; int bytesRead; DlmsReader reader; diff --git a/platformio-user.ini-example b/platformio-user.ini-example index cd08b246..b232ae10 100644 --- a/platformio-user.ini-example +++ b/platformio-user.ini-example @@ -7,8 +7,9 @@ board = esp12e framework = ${common.framework} lib_deps = ${common.lib_deps} build_flags = - -D HAS_DALLAS_TEMP_SENSOR=0 - -D IS_CUSTOM_AMS_BOARD=0 + -D HW_ROARFRED=1 -D DEBUG_MODE=1 monitor_speed = 2400 -monitor_flags = --parity E +monitor_flags = + --parity + E diff --git a/platformio.ini b/platformio.ini index 40f5cfde..46ff65fb 100755 --- a/platformio.ini +++ b/platformio.ini @@ -4,16 +4,13 @@ extra_configs = platformio-user.ini [common] framework = arduino -lib_deps = HanConfigAp@1.0.0, HanReader@1.0.0, HanToJson@1.0.0, ArduinoJson@^6.0.0, MQTT@^2.4.0, DallasTemperature@^3.8.0 +lib_deps = HanConfigAp@1.0.0, HanReader@1.0.0, HanToJson@1.0.0, ArduinoJson@^6.0.0, MQTT@^2.4.0, DallasTemperature@^3.8.0, EspSoftwareSerial@^6.7.1 [env:esp12e] platform = espressif8266 board = esp12e framework = ${common.framework} lib_deps = ${common.lib_deps} -build_flags = - -D HAS_DALLAS_TEMP_SENSOR=0 - -D IS_CUSTOM_AMS_BOARD=0 extra_scripts = pre:scripts/addversion.py scripts/makeweb.py @@ -24,8 +21,7 @@ board = esp12e framework = ${common.framework} lib_deps = ${common.lib_deps} build_flags = - -D HAS_DALLAS_TEMP_SENSOR=1 - -D IS_CUSTOM_AMS_BOARD=1 + -D HW_ROARFRED=1 extra_scripts = pre:scripts/addversion.py scripts/makeweb.py @@ -35,9 +31,24 @@ platform = espressif32 board = featheresp32 framework = ${common.framework} lib_deps = ${common.lib_deps} -build_flags = - -D HAS_DALLAS_TEMP_SENSOR=0 - -D IS_CUSTOM_AMS_BOARD=0 +extra_scripts = + pre:scripts/addversion.py + scripts/makeweb.py + +[env:esp32] +platform = espressif32 +board = esp32dev +framework = ${common.framework} +lib_deps = ${common.lib_deps} +extra_scripts = + pre:scripts/addversion.py + scripts/makeweb.py + +[env:d1mini] +platform = espressif8266 +board = d1_mini +framework = ${common.framework} +lib_deps = ${common.lib_deps} extra_scripts = pre:scripts/addversion.py scripts/makeweb.py diff --git a/src/AmsToMqttBridge.h b/src/AmsToMqttBridge.h new file mode 100644 index 00000000..144d7c3c --- /dev/null +++ b/src/AmsToMqttBridge.h @@ -0,0 +1,64 @@ +#define WIFI_CONNECTION_TIMEOUT 30000; + + +#if defined(ESP8266) +#include +#elif defined(ESP32) +#include +#endif + +// Build settings for custom hardware by Roar Fredriksen +#if HW_ROARFRED +#define LED_PIN 2 // The blue on-board LED of the ESP8266 custom AMS board +#define LED_ACTIVE_HIGH 0 +#define AP_BUTTON_PIN 0 + +#include +#include +#define TEMP_SENSOR_PIN 5 // Temperature sensor connected to GPIO5 + +HardwareSerial *hanSerial = &Serial; + +// Build settings for Wemos Lolin D32 +#elif defined(ARDUINO_LOLIN_D32) +#define LED_PIN 5 +#define LED_ACTIVE_HIGH 0 +#define AP_BUTTON_PIN INVALID_BUTTON_PIN + +#define SOFTWARE_SERIAL 1 +#include +SoftwareSerial *hanSerial = new SoftwareSerial(GPIO_NUM_21); + +// Build settings for Wemos D1 mini +#elif defined(ARDUINO_ESP8266_WEMOS_D1MINI) +#define LED_PIN LED_BUILTIN +#define LED_ACTIVE_HIGH 0 +#define AP_BUTTON_PIN INVALID_BUTTON_PIN + +#define SOFTWARE_SERIAL 1 +#include +SoftwareSerial *hanSerial = new SoftwareSerial(D1); + +// Build settings for Adafruit Feather ESP32 +#elif defined(ARDUINO_FEATHER_ESP32) +#define LED_PIN LED_BUILTIN +#define LED_ACTIVE_HIGH 1 +#define AP_BUTTON_PIN INVALID_BUTTON_PIN + +HardwareSerial *hanSerial = &Serial; + +// Default build settings +#else +#define LED_PIN 2 +#define LED_ACTIVE_HIGH 0 +#define AP_BUTTON_PIN INVALID_BUTTON_PIN +#define SOFTWARE_SERIAL 1 +#include +SoftwareSerial *hanSerial = new SoftwareSerial(5); +#endif + + +#if defined TEMP_SENSOR_PIN +OneWire oneWire(TEMP_SENSOR_PIN); +DallasTemperature tempSensor(&oneWire); +#endif \ No newline at end of file diff --git a/src/AmsToMqttBridge.ino b/src/AmsToMqttBridge.ino index 520a8872..1e62e723 100644 --- a/src/AmsToMqttBridge.ino +++ b/src/AmsToMqttBridge.ino @@ -4,57 +4,22 @@ Author: roarf */ - -//#define HAS_DALLAS_TEMP_SENSOR 1 // Set to zero if Dallas one wire temp sensor is not present -//#define IS_CUSTOM_AMS_BOARD 1 // Set to zero if using NodeMCU or board not designed by Roar Fredriksen - +#include "AmsToMqttBridge.h" #include #include -#if HAS_DALLAS_TEMP_SENSOR -#include -#include -#endif - -#if defined(ESP8266) -#include -#elif defined(ESP32) -#include -#endif - #include "web/AmsWebServer.h" #include "HanConfigAp.h" #include "HanReader.h" #include "HanToJson.h" -#define WIFI_CONNECTION_TIMEOUT 30000; - -#if IS_CUSTOM_AMS_BOARD -#define LED_PIN 2 // The blue on-board LED of the ESP8266 custom AMS board -#define LED_ACTIVE_HIGH 0 -#define AP_BUTTON_PIN 0 -#elif defined(ARDUINO_LOLIN_D32) -#define LED_PIN 5 -#define LED_ACTIVE_HIGH 0 -#define AP_BUTTON_PIN INVALID_BUTTON_PIN -#else -#define LED_PIN LED_BUILTIN -#define LED_ACTIVE_HIGH 1 -#define AP_BUTTON_PIN INVALID_BUTTON_PIN -#endif - -#if HAS_DALLAS_TEMP_SENSOR -#define TEMP_SENSOR_PIN 5 // Temperature sensor connected to GPIO5 - -OneWire oneWire(TEMP_SENSOR_PIN); -DallasTemperature tempSensor(&oneWire); -#endif - +// Configuration configuration config; // Object used to boot as Access Point HanConfigAp ap; +// Web server AmsWebServer ws; // WiFi client and MQTT client @@ -69,21 +34,23 @@ HanReader hanReader; // the setup function runs once when you press reset or power the board void setup() { - -#if DEBUG_MODE - debugger = &Serial; -#endif - if(config.hasConfig()) { config.load(); } - if(config.meterType == 3) { - Serial.begin(2400, SERIAL_8N1); - } else { - Serial.begin(2400, SERIAL_8E1); - } - while (!Serial); +#if DEBUG_MODE + debugger = &Serial; + #if SOFTWARE_SERIAL + debugger->begin(115200, SERIAL_8N1); + #else + if(config.meterType == 3) { + hanSerial->begin(2400, SERIAL_8N1); + } else { + hanSerial->begin(2400, SERIAL_8E1); + } + #endif + while (!&debugger); +#endif if (debugger) { debugger->println(""); @@ -112,8 +79,25 @@ void setup() { sendMqttData("Connected!"); } // Configure uart for AMS data +#if defined SOFTWARE_SERIAL + if(config.meterType == 3) { + hanSerial->begin(2400, SWSERIAL_8N1); + } else { + hanSerial->begin(2400, SWSERIAL_8E1); + } +#else + if(config.meterType == 3) { + hanSerial->begin(2400, SERIAL_8N1); + } else { + hanSerial->begin(2400, SERIAL_8E1); + } +#if defined UART2 + hanSerial->swap(); +#endif +#endif + while (!&hanSerial); - hanReader.setup(&Serial, debugger); + hanReader.setup(hanSerial, debugger); // Compensate for the known Kaifa bug hanReader.compensateFor09HeaderBug = (config.meterType == 1); @@ -234,7 +218,7 @@ void readHanPort() // to keep the data from the meter itself JsonObject data = json.createNestedObject("data"); -#if HAS_DALLAS_TEMP_SENSOR +#if defined TEMP_SENSOR_PIN // Get the temperature too tempSensor.requestTemperatures(); data["temp"] = tempSensor.getTempCByIndex(0); From 2e7b9e8e43a57dca0cc8903a3b959e06b6aa2d82 Mon Sep 17 00:00:00 2001 From: Gunnar Skjold Date: Fri, 7 Feb 2020 22:26:17 +0100 Subject: [PATCH 2/7] Fixed missing check in checkbox when configuration opened in firefox --- web/boot.css | 31 +++++-------------------------- web/configuration.html | 3 ++- web/index.html | 2 +- 3 files changed, 8 insertions(+), 28 deletions(-) diff --git a/web/boot.css b/web/boot.css index c3239894..28d5e0e3 100644 --- a/web/boot.css +++ b/web/boot.css @@ -243,29 +243,7 @@ a { input:not([type="image" i]) { box-sizing: border-box; } -input { - -webkit-writing-mode: horizontal-tb !important; - text-rendering: auto; - color: -internal-light-dark-color(black, white); - letter-spacing: normal; - word-spacing: normal; - text-transform: none; - text-indent: 0px; - text-shadow: none; - display: inline-block; - text-align: start; - -webkit-appearance: textfield; - background-color: -internal-light-dark-color(white, black); - -webkit-rtl-ordering: logical; - cursor: text; - margin: 0em; - font: 400 13.3333px Arial; - padding: 1px 0px; - border-width: 2px; - border-style: inset; - border-color: initial; - border-image: initial; -} + button, input { overflow: visible; } @@ -275,6 +253,10 @@ button, input, optgroup, select, textarea { font-size: inherit; line-height: inherit; } +input[type="radio"], input[type="checkbox"] { + box-sizing: border-box; + padding: 0; +} hr { margin-top: 1rem; margin-bottom: 1rem; @@ -324,6 +306,3 @@ hr { *, ::after, ::before { box-sizing: border-box; } -*, ::after, ::before { - box-sizing: border-box; -} diff --git a/web/configuration.html b/web/configuration.html index f89f10cd..d0faab58 100644 --- a/web/configuration.html +++ b/web/configuration.html @@ -5,7 +5,7 @@ AMS reader - configuration - +