[SYS] Update arduino core to 3.1.1 + refactor ino to cpp (#2177)
* Update arduino core to 3.1.1 * Fix Blufi build * Update arduinojson, fix build errors with idf * Fix narrowing * fix RF builds * WIP-Convert ino files to cpp * Fix pilight build * Fix Somfy actuator build. * Update esp32dev-rf partition * Fix Weatherstation build * Fix GFSunInverter build * Fix esp32dev-ir build * Fix ble-aws build * Fix eth builds * Fix m5Stack missing pins_arduino.h * Fix build errors for M5 stack/tough, others are upstream issues. * Fix RTL 433 build - remaining errors are from radolib * Fix nodemcu build * fix 2g builds * Fix serial build * Fix actuator on off builds * Fix SSD1306 build - remaining errors are from radiolib * Fix multiple definition of OTAserver_cert * Fix nodemcu rf2 build * Fix ADC builds * Fix sensor builds * Fix LORA builds * Fix multi-receiver builds - remaining errors are in radiolib * Fix fastled builds * Fix theegns board builds * Fix broker builds * Update fastled - old version failed all-test build * Fix RN8209 builds * Fix max temp actuator builds * Fix PWM builds * Fix C37 sensor builds * Fix HTU21 builds * Fix INA266 builds * Fix undefined variables in mqtt discovery * Fix webui build * Fix fastled invalid pin error * Fix wifi manual setup builds * Fix onewire/all-test build - bin too big error remaining * Fix theengs plug build * Fix rfbridge builds * Fix blufi builds * Fix undefined functions in serial * Fix preprocessor definition checks * Set IDF log level to erre * Add delay in loop to prevent watchdog timeout * Use xTaskCreateUniveral to support single core processors * Remove old HTTPUpdate files - upsteam fixed. * Cleanup and move common declarations to header file * Use custom partiton table to fix builds where bin is too large * Update M5StickC - fixs esp32-m5stick-c-ble build * Revert to Arduino core 2.x for builds with incompatible libs * Remove "Z" from file names and rename omg_common to TheengsCommon * Fix gateway name when using MAC with new Arduino core * Update IDF config to reduce loop task stack use * Update esp-nimble-cpp version, corrects BLE uppercase ID's * Update wifi manager to fix watchdog timeout error
This commit is contained in:
1 parent
6e77efb11b
commit
585df9a420
83 files changed
+1275
-1293
No files matched your search
+2
-1
@@ -15,4 +15,5 @@ dependencies.lock
|
||||
sdkconfig.*
|
||||
!sdkconfig.defaults
|
||||
__pycache__
|
||||
*.pem
|
||||
*.pem
|
||||
managed_components
|
||||
+28
-20
@@ -188,7 +188,7 @@ custom_hardware = Theengs Plug
|
||||
platform = ${com.esp32_platform}
|
||||
board = esp32dev
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
board_build.partitions = partitions/no_coredump.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.ble}
|
||||
@@ -270,6 +270,7 @@ build_flags =
|
||||
[env:esp32dev-rf]
|
||||
platform = ${com.esp32_platform}
|
||||
board = esp32dev
|
||||
board_build.partitions = min_spiffs.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.rc-switch}
|
||||
@@ -311,6 +312,7 @@ custom_description = Gateway using ESPilight library only, need CC1101
|
||||
[env:esp32dev-somfy-cc1101]
|
||||
platform = ${com.esp32_platform}
|
||||
board = esp32dev
|
||||
board_build.partitions = min_spiffs.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.somfy_remote}
|
||||
@@ -342,6 +344,7 @@ custom_description = Gateway using Somfy Remote and ESPilight library, need CC11
|
||||
[env:esp32dev-weatherstation]
|
||||
platform = ${com.esp32_platform}
|
||||
board = esp32dev
|
||||
board_build.partitions = min_spiffs.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.rfWeatherStation}
|
||||
@@ -354,6 +357,7 @@ custom_description = Gateway to retrieve weather station data Ventus W174/W132 (
|
||||
[env:esp32dev-gf-sun-inverter]
|
||||
platform = ${com.esp32_platform}
|
||||
board = esp32dev
|
||||
board_build.partitions = min_spiffs.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.emodbus}
|
||||
@@ -598,10 +602,10 @@ custom_description = BLE gateway using wifi
|
||||
custom_hardware = OLIMEX ESP32 Gateway
|
||||
|
||||
[env:esp32-m5stick-ble]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = m5stack-core-esp32
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
board_build.partitions = partitions/no_coredump.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.ble}
|
||||
@@ -622,7 +626,7 @@ custom_description = Expandable module with BLE gateway, display, and little IR
|
||||
custom_hardware = M5Stick Grey
|
||||
|
||||
[env:esp32-m5stack-ble]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = m5stack-core-esp32
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
@@ -647,7 +651,7 @@ custom_description = Expandable module with BLE gateway and display
|
||||
custom_hardware = M5Stack Core
|
||||
|
||||
[env:esp32-m5tough-ble]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = m5stack-core-esp32
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
@@ -666,7 +670,7 @@ custom_description = Expandable module with BLE gateway and display, suitable fo
|
||||
custom_hardware = M5Tough rugged
|
||||
|
||||
[env:esp32-m5stick-c-ble]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = m5stick-c
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
@@ -697,10 +701,10 @@ custom_description = Expandable module with BLE gateway, display, and little IR
|
||||
custom_hardware = M5Stick C
|
||||
|
||||
[env:esp32-m5stick-cp-ble]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = pico32
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
board_build.partitions = partitions/no_coredump.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.ble}
|
||||
@@ -731,7 +735,7 @@ custom_hardware = M5Stick CP
|
||||
platform = ${com.esp32_platform}
|
||||
board = pico32
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
board_build.partitions = partitions/no_coredump.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.ble}
|
||||
@@ -762,7 +766,7 @@ custom_hardware = M5 ATOM Matrix
|
||||
platform = ${com.esp32_platform}
|
||||
board = pico32
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = min_spiffs.csv
|
||||
board_build.partitions = partitions/no_coredump.csv
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.ble}
|
||||
@@ -785,7 +789,7 @@ custom_description = Compact enclosure ESP32 with BLE gateway
|
||||
custom_hardware = M5 ATOM Lite
|
||||
|
||||
[env:esp32doitv1-aithinker-r01-sx1278]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = esp32doit-devkit-v1
|
||||
board_build.partitions = min_spiffs.csv
|
||||
lib_deps =
|
||||
@@ -864,7 +868,7 @@ upload_flags =
|
||||
--port=8266
|
||||
|
||||
[env:esp32dev-rtl_433]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = esp32dev
|
||||
board_build.partitions = min_spiffs.csv
|
||||
lib_deps =
|
||||
@@ -904,7 +908,7 @@ build_flags =
|
||||
custom_description = Gateway using RTL_433_ESP library, need CC1101
|
||||
|
||||
[env:heltec-rtl_433]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = heltec_wifi_lora_32_V2
|
||||
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
|
||||
board_build.partitions = min_spiffs.csv
|
||||
@@ -933,7 +937,7 @@ custom_description = Gateway using RTL_433_ESP and RadioLib
|
||||
custom_hardware = ESP32 HELTEC LORA32 V2
|
||||
|
||||
[env:heltec-rtl_433-fsk]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = heltec_wifi_lora_32_V2
|
||||
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
|
||||
board_build.partitions = min_spiffs.csv
|
||||
@@ -991,7 +995,7 @@ custom_description = Heltec BLE gateway with adaptive scanning activated, automa
|
||||
custom_hardware = ESP32 HELTEC LORA32 V2
|
||||
|
||||
[env:lilygo-rtl_433]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = ttgo-lora32-v21
|
||||
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
|
||||
board_build.partitions = min_spiffs.csv
|
||||
@@ -1020,7 +1024,7 @@ custom_description = For ESP32, Gateway using RTL_433_ESP and RadioLib
|
||||
custom_hardware = ESP32 LILYGO LoRa32 V2.1
|
||||
|
||||
[env:lilygo-rtl_433-fsk]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = ttgo-lora32-v21
|
||||
; ~/.platformio/packages/framework-arduinoespressif32/variants/.../pins_arduino.h
|
||||
board_build.partitions = min_spiffs.csv
|
||||
@@ -1078,7 +1082,7 @@ custom_description = LilyGo BLE gateway with adaptive scanning activated, automa
|
||||
custom_hardware = ESP32 LILYGO LoRa32 V2.1
|
||||
|
||||
[env:esp32dev-multi_receiver]
|
||||
platform = ${com.esp32_platform}
|
||||
platform = espressif32@6.1.0
|
||||
board = esp32dev
|
||||
board_build.partitions = min_spiffs.csv
|
||||
lib_deps =
|
||||
@@ -1896,11 +1900,16 @@ framework = arduino, espidf
|
||||
board = esp32dev
|
||||
extra_scripts = ${com-esp32.extra_scripts}
|
||||
board_build.partitions = partitions/min_spiffs.csv
|
||||
board_build.embed_txtfiles =
|
||||
managed_components/espressif__esp_insights/server_certs/https_server.crt
|
||||
managed_components/espressif__esp_rainmaker/server_certs/rmaker_mqtt_server.crt
|
||||
managed_components/espressif__esp_rainmaker/server_certs/rmaker_claim_service_server.crt
|
||||
managed_components/espressif__esp_rainmaker/server_certs/rmaker_ota_server.crt
|
||||
lib_deps =
|
||||
${com-esp32.lib_deps}
|
||||
${libraries.decoder}
|
||||
h2zero/esp-nimble-cpp@2.0.1
|
||||
h2zero/NimBLEOta@0.1.0
|
||||
h2zero/esp-nimble-cpp@2.1.1
|
||||
h2zero/NimBLEOta@0.2.0
|
||||
build_flags =
|
||||
${com-esp32.build_flags}
|
||||
'-DZgatewayBT="BT"'
|
||||
@@ -1909,5 +1918,4 @@ build_flags =
|
||||
'-DGateway_Name="OMG_ESP32_BLE"'
|
||||
'-DUSE_BLUFI=1'
|
||||
'-DenableMultiGTWSync=false'
|
||||
'-DCONFIG_NIMBLE_CPP_FREERTOS_TASK_BLOCK_BIT=31'
|
||||
custom_description = Regular BLE gateway based on esp-idf with adaptive scanning activated, automatically adapts the scan parameters depending on your devices
|
||||
@@ -0,0 +1,100 @@
|
||||
#pragma once
|
||||
|
||||
#include "User_config.h"
|
||||
|
||||
#define ARDUINOJSON_USE_LONG_LONG 1
|
||||
#define ARDUINOJSON_ENABLE_STD_STRING 1
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoLog.h>
|
||||
|
||||
#if defined(ESP32)
|
||||
# include <Preferences.h>
|
||||
extern Preferences preferences;
|
||||
#endif
|
||||
|
||||
// Flags definition for white list, black list, discovery management
|
||||
#define device_flags_init 0 << 0
|
||||
#define device_flags_isDisc 1 << 0
|
||||
#define device_flags_isWhiteL 1 << 1
|
||||
#define device_flags_isBlackL 1 << 2
|
||||
#define device_flags_connect 1 << 3
|
||||
#define isWhite(device) device->isWhtL
|
||||
#define isBlack(device) device->isBlkL
|
||||
#define isDiscovered(device) device->isDisc
|
||||
|
||||
enum GatewayState {
|
||||
WAITING_ONBOARDING,
|
||||
ONBOARDING,
|
||||
OFFLINE,
|
||||
NTWK_CONNECTED,
|
||||
BROKER_CONNECTED,
|
||||
PROCESSING,
|
||||
NTWK_DISCONNECTED,
|
||||
BROKER_DISCONNECTED,
|
||||
LOCAL_OTA_IN_PROGRESS,
|
||||
REMOTE_OTA_IN_PROGRESS,
|
||||
SLEEPING,
|
||||
ERROR
|
||||
};
|
||||
|
||||
enum PowerMode {
|
||||
DEACTIVATED = -1,
|
||||
ALWAYS_ON,
|
||||
INTERVAL,
|
||||
ACTION
|
||||
};
|
||||
|
||||
struct SYSConfig_s {
|
||||
bool mqtt; // if true the gateway will publish the received data on the MQTT broker
|
||||
bool serial; // if true the gateway will publish the received data on the SERIAL
|
||||
bool blufi; // if true the gateway will be accesible with blufi
|
||||
bool offline;
|
||||
bool discovery; // HA discovery convention
|
||||
#ifdef LED_ADDRESSABLE
|
||||
int rgbbrightness; // brightness of the RGB LED
|
||||
#endif
|
||||
enum PowerMode powerMode;
|
||||
};
|
||||
|
||||
extern GatewayState gatewayState;
|
||||
extern SYSConfig_s SYSConfig;
|
||||
extern bool ready_to_sleep;
|
||||
extern char mqtt_topic[];
|
||||
extern char gateway_name[];
|
||||
extern unsigned long lastDiscovery; // Time of the last discovery to trigger automaticaly to off after DiscoveryAutoOffTimer
|
||||
|
||||
extern bool enqueueJsonObject(const StaticJsonDocument<JSON_MSG_BUFFER>& jsonDoc, int timeout);
|
||||
extern bool enqueueJsonObject(const StaticJsonDocument<JSON_MSG_BUFFER>& jsonDoc);
|
||||
extern void buildTopicFromId(JsonObject& Jsondata, const char* origin);
|
||||
extern bool pubMQTT(const char* topic, const char* payload);
|
||||
extern bool pubMQTT(const char* topic, const char* payload, bool retainFlag);
|
||||
extern bool pubMQTT(String topic, const char* payload);
|
||||
extern bool pubMQTT(const char* topic, unsigned long payload);
|
||||
extern bool pubMQTT(const char* topic, unsigned long long payload);
|
||||
extern bool pubMQTT(const char* topic, String payload);
|
||||
extern bool pubMQTT(String topic, String payload);
|
||||
extern bool pubMQTT(String topic, int payload);
|
||||
extern bool pubMQTT(String topic, unsigned long long payload);
|
||||
extern bool pubMQTT(String topic, float payload);
|
||||
extern bool pubMQTT(const char* topic, float payload);
|
||||
extern bool pubMQTT(const char* topic, int payload);
|
||||
extern bool pubMQTT(const char* topic, unsigned int payload);
|
||||
extern bool pubMQTT(const char* topic, long payload);
|
||||
extern bool pubMQTT(const char* topic, double payload);
|
||||
extern bool pubMQTT(String topic, unsigned long payload);
|
||||
extern unsigned long uptime();
|
||||
extern bool cmpToMainTopic(const char*, const char*);
|
||||
extern bool pub(const char*, const char*, bool);
|
||||
extern bool pub(const char*, const char*);
|
||||
|
||||
template <typename T>
|
||||
void Config_update(JsonObject& data, const char* key, T& var) {
|
||||
if (data.containsKey(key)) {
|
||||
if (var != data[key].as<T>()) {
|
||||
var = data[key].as<T>();
|
||||
Log.notice(F("Config %s changed to: %T" CR), key, data[key].as<T>());
|
||||
} else {
|
||||
Log.notice(F("Config %s unchanged, currently: %T" CR), key, data[key].as<T>());
|
||||
}
|
||||
}
|
||||
}
|
||||
+17
-55
@@ -226,7 +226,8 @@
|
||||
|
||||
#if AWS_IOT
|
||||
// Enable the use of ALPN for AWS IoT Core with the port 443
|
||||
const char* alpnProtocols[] = {"x-amzn-mqtt-ca", NULL};
|
||||
# define ALPN_PROTOCOLS \
|
||||
{ "x-amzn-mqtt-ca", NULL }
|
||||
#endif
|
||||
|
||||
//# define MQTT_HTTPS_FW_UPDATE //uncomment to enable updating via MQTT message.
|
||||
@@ -251,7 +252,7 @@ const char* alpnProtocols[] = {"x-amzn-mqtt-ca", NULL};
|
||||
# define RELEASE_LINK_DEV "https://ota.openmqttgateway.com/binaries/dev/"
|
||||
# define RELEASE_LINK "https://ota.openmqttgateway.com/binaries/"
|
||||
#else
|
||||
const char* OTAserver_cert = "";
|
||||
static const char* OTAserver_cert = "";
|
||||
#endif
|
||||
|
||||
#ifndef MQTT_SECURE_SIGNED_CLIENT
|
||||
@@ -289,12 +290,15 @@ struct ss_cnt_parameters {
|
||||
bool validConnection;
|
||||
};
|
||||
|
||||
# define CNT_PARAMS_ARR \
|
||||
{ \
|
||||
{ss_server_cert, ss_client_cert, ss_client_key, OTAserver_cert, MQTT_SERVER, MQTT_PORT, MQTT_USER, MQTT_PASS, MQTT_SECURE_DEFAULT, MQTT_CERT_VALIDATE_DEFAULT, false}, \
|
||||
{"", "", "", "", MQTT_SERVER, MQTT_PORT, MQTT_USER, MQTT_PASS, MQTT_SECURE_DEFAULT, MQTT_CERT_VALIDATE_DEFAULT, false}, \
|
||||
{ "", "", "", "", MQTT_SERVER, MQTT_PORT, MQTT_USER, MQTT_PASS, MQTT_SECURE_DEFAULT, MQTT_CERT_VALIDATE_DEFAULT, false } \
|
||||
}
|
||||
# define cnt_parameters_array_size 3
|
||||
|
||||
ss_cnt_parameters cnt_parameters_array[cnt_parameters_array_size] = {
|
||||
{ss_server_cert, ss_client_cert, ss_client_key, OTAserver_cert, MQTT_SERVER, MQTT_PORT, MQTT_USER, MQTT_PASS, MQTT_SECURE_DEFAULT, MQTT_CERT_VALIDATE_DEFAULT, false},
|
||||
{"", "", "", "", MQTT_SERVER, MQTT_PORT, MQTT_USER, MQTT_PASS, MQTT_SECURE_DEFAULT, MQTT_CERT_VALIDATE_DEFAULT, false},
|
||||
{"", "", "", "", MQTT_SERVER, MQTT_PORT, MQTT_USER, MQTT_PASS, MQTT_SECURE_DEFAULT, MQTT_CERT_VALIDATE_DEFAULT, false}};
|
||||
extern ss_cnt_parameters cnt_parameters_array[];
|
||||
#endif
|
||||
|
||||
#define MIN_CERT_LENGTH 200 // Minimum length of a certificate to be considered valid
|
||||
@@ -527,7 +531,7 @@ ss_cnt_parameters cnt_parameters_array[cnt_parameters_array_size] = {
|
||||
|
||||
#ifdef ESP8266
|
||||
//# define TRIGGER_GPIO 14 // pin D5 as full reset button (long press >10s)
|
||||
#elif ESP32
|
||||
#elif defined(ESP32)
|
||||
//# define TRIGGER_GPIO 0 // boot button as full reset button (long press >10s)
|
||||
//# define NO_INT_TEMP_READING true //Define if we don't want internal temperature reading for the ESP32
|
||||
#endif
|
||||
@@ -621,60 +625,14 @@ ss_cnt_parameters cnt_parameters_array[cnt_parameters_array_size] = {
|
||||
#define displayPrint(...) // only print if not in low power mode
|
||||
#define lpDisplayPrint(...) // print in low power mode
|
||||
|
||||
/*----------- SHARED WITH OMG MODULES --------------*/
|
||||
|
||||
char mqtt_topic[parameters_size + 1] = Base_Topic;
|
||||
char gateway_name[parameters_size + 1] = Gateway_Name;
|
||||
|
||||
void connectMQTT();
|
||||
|
||||
unsigned long uptime();
|
||||
bool cmpToMainTopic(const char*, const char*);
|
||||
bool pub(const char*, const char*, bool);
|
||||
bool pub(const char*, const char*);
|
||||
|
||||
#if defined(ESP32)
|
||||
# include <Preferences.h>
|
||||
Preferences preferences;
|
||||
#endif
|
||||
|
||||
unsigned long lastDiscovery = 0; // Time of the last discovery to trigger automaticaly to off after DiscoveryAutoOffTimer
|
||||
#ifndef DEFAULT_DISCOVERY
|
||||
# define DEFAULT_DISCOVERY true
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
// Flags definition for white list, black list, discovery management
|
||||
#define device_flags_init 0 << 0
|
||||
#define device_flags_isDisc 1 << 0
|
||||
#define device_flags_isWhiteL 1 << 1
|
||||
#define device_flags_isBlackL 1 << 2
|
||||
#define device_flags_connect 1 << 3
|
||||
#define isWhite(device) device->isWhtL
|
||||
#define isBlack(device) device->isBlkL
|
||||
#define isDiscovered(device) device->isDisc
|
||||
|
||||
enum PowerMode { DEACTIVATED = -1,
|
||||
ALWAYS_ON,
|
||||
INTERVAL,
|
||||
ACTION };
|
||||
|
||||
/*--------------------Minimum freeHeap--------------------*/
|
||||
// Below this parameter we trigger a restart, this avoid stuck boards like seen in https://github.com/1technophile/OpenMQTTGateway/issues/1693
|
||||
#define MinimumMemory 40000
|
||||
|
||||
/*----------------CONFIGURABLE PARAMETERS-----------------*/
|
||||
struct SYSConfig_s {
|
||||
bool mqtt; // if true the gateway will publish the received data on the MQTT broker
|
||||
bool serial; // if true the gateway will publish the received data on the SERIAL
|
||||
bool blufi; // if true the gateway will be accesible with blufi
|
||||
bool offline;
|
||||
bool discovery; // HA discovery convention
|
||||
#ifdef LED_ADDRESSABLE
|
||||
int rgbbrightness; // brightness of the RGB LED
|
||||
#ifndef DEFAULT_DISCOVERY
|
||||
# define DEFAULT_DISCOVERY true
|
||||
#endif
|
||||
enum PowerMode powerMode;
|
||||
};
|
||||
|
||||
#ifndef DEFAULT_MQTT
|
||||
# define DEFAULT_MQTT true
|
||||
@@ -697,4 +655,8 @@ void storeSignalValue(uint64_t);
|
||||
#define convertTemp_CtoF(c) ((c * 1.8) + 32)
|
||||
#define convertTemp_FtoC(f) ((f - 32) * 5 / 9)
|
||||
|
||||
#ifndef QueueSize
|
||||
# define QueueSize 18
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@@ -26,6 +26,8 @@
|
||||
|
||||
# include <FastLED.h>
|
||||
|
||||
# include "config_FASTLED.h"
|
||||
|
||||
enum LEDState {
|
||||
OFF,
|
||||
FIRE,
|
||||
@@ -41,10 +43,12 @@ const long blinkInterval = 300;
|
||||
const long fireUpdate = 10;
|
||||
CRGBPalette16 gPal;
|
||||
|
||||
void Fire2012WithPalette();
|
||||
|
||||
void setupFASTLED() {
|
||||
Log.notice(F("FASTLED_DATA_GPIO: %d" CR), FASTLED_DATA_GPIO);
|
||||
Log.notice(F("FASTLED_NUM_LEDS: %d" CR), FASTLED_NUM_LEDS);
|
||||
Log.trace(F("ZactuatorFASTLED setup done " CR));
|
||||
Log.trace(F("actuatorFASTLED setup done " CR));
|
||||
FastLED.addLeds<FASTLED_TYPE, FASTLED_DATA_GPIO>(leds, FASTLED_NUM_LEDS);
|
||||
}
|
||||
|
||||
@@ -30,7 +30,15 @@
|
||||
|
||||
#ifdef ZactuatorONOFF
|
||||
|
||||
# include "LEDManager.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_ONOFF.h"
|
||||
|
||||
extern LEDManager ledManager;
|
||||
extern void ActuatorTrigger();
|
||||
|
||||
# ifdef ESP32
|
||||
|
||||
// Global struct to store live ONOFF configuration data
|
||||
ONOFFConfig_s ONOFFConfig;
|
||||
|
||||
@@ -94,9 +102,9 @@ void ONOFFConfig_load() {
|
||||
}
|
||||
}
|
||||
# else
|
||||
void ONOFFConfig_init(){};
|
||||
void ONOFFConfig_fromJson(JsonObject& ONOFFdata){};
|
||||
void ONOFFConfig_load(){};
|
||||
void ONOFFConfig_init() {};
|
||||
void ONOFFConfig_fromJson(JsonObject& ONOFFdata) {};
|
||||
void ONOFFConfig_load() {};
|
||||
# endif
|
||||
|
||||
void updatePowerIndicator() {
|
||||
@@ -109,6 +117,33 @@ void updatePowerIndicator() {
|
||||
# endif
|
||||
}
|
||||
|
||||
//Check regularly temperature of the ESP32 board and switch OFF the relay if temperature is more than MAX_TEMP_ACTUATOR
|
||||
# ifdef MAX_TEMP_ACTUATOR
|
||||
extern float intTemperatureRead();
|
||||
|
||||
void overLimitTemp(void* pvParameters) {
|
||||
# if defined(ESP32) && !defined(NO_INT_TEMP_READING)
|
||||
for (;;) {
|
||||
static float previousInternalTempc = 0;
|
||||
float internalTempc = intTemperatureRead();
|
||||
Log.trace(F("Internal temperature of the ESP32 %F" CR), internalTempc);
|
||||
// We switch OFF the actuator if the temperature of the ESP32 is more than MAX_TEMP_ACTUATOR two consecutive times, so as to avoid false single readings to trigger the relay OFF.
|
||||
if (internalTempc > MAX_TEMP_ACTUATOR && previousInternalTempc > MAX_TEMP_ACTUATOR) {
|
||||
if (digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) { // This could be with the previous condition, but it is better to trigger the digitalRead only if the previous condition is met to avoid the digitalRead
|
||||
Log.error(F("[ActuatorONOFF] OverTemperature detected ( %F > %F ) switching OFF Actuator" CR), internalTempc, MAX_TEMP_ACTUATOR);
|
||||
ActuatorTrigger();
|
||||
# ifdef LED_ACTUATOR_ONOFF
|
||||
ledManager.setMode(LED_ACTUATOR_ONOFF, 0, LEDManager::Mode::STATIC, LED_ERROR_COLOR, -1);
|
||||
# endif
|
||||
}
|
||||
}
|
||||
previousInternalTempc = internalTempc;
|
||||
vTaskDelay(TimeBetweenReadingIntTemp);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
|
||||
void setupONOFF() {
|
||||
# ifdef MAX_TEMP_ACTUATOR
|
||||
xTaskCreate(overLimitTemp, "overLimitTemp", 4000, NULL, 10, NULL);
|
||||
@@ -130,7 +165,7 @@ void setupONOFF() {
|
||||
}
|
||||
# endif
|
||||
updatePowerIndicator();
|
||||
Log.trace(F("ZactuatorONOFF setup done" CR));
|
||||
Log.trace(F("actuatorONOFF setup done" CR));
|
||||
}
|
||||
|
||||
# if jsonReceiving
|
||||
@@ -239,31 +274,6 @@ void XtoONOFF(const char* topicOri, const char* datacallback) {
|
||||
}
|
||||
# endif
|
||||
|
||||
//Check regularly temperature of the ESP32 board and switch OFF the relay if temperature is more than MAX_TEMP_ACTUATOR
|
||||
# ifdef MAX_TEMP_ACTUATOR
|
||||
void overLimitTemp(void* pvParameters) {
|
||||
# if defined(ESP32) && !defined(NO_INT_TEMP_READING)
|
||||
for (;;) {
|
||||
static float previousInternalTempc = 0;
|
||||
float internalTempc = intTemperatureRead();
|
||||
Log.trace(F("Internal temperature of the ESP32 %F" CR), internalTempc);
|
||||
// We switch OFF the actuator if the temperature of the ESP32 is more than MAX_TEMP_ACTUATOR two consecutive times, so as to avoid false single readings to trigger the relay OFF.
|
||||
if (internalTempc > MAX_TEMP_ACTUATOR && previousInternalTempc > MAX_TEMP_ACTUATOR) {
|
||||
if (digitalRead(ACTUATOR_ONOFF_GPIO) == ACTUATOR_ON) { // This could be with the previous condition, but it is better to trigger the digitalRead only if the previous condition is met to avoid the digitalRead
|
||||
Log.error(F("[ActuatorONOFF] OverTemperature detected ( %F > %F ) switching OFF Actuator" CR), internalTempc, MAX_TEMP_ACTUATOR);
|
||||
ActuatorTrigger();
|
||||
# ifdef LED_ACTUATOR_ONOFF
|
||||
ledManager.setMode(LED_ACTUATOR_ONOFF, 0, LEDManager::Mode::STATIC, LED_ERROR_COLOR, -1);
|
||||
# endif
|
||||
}
|
||||
}
|
||||
previousInternalTempc = internalTempc;
|
||||
vTaskDelay(TimeBetweenReadingIntTemp);
|
||||
}
|
||||
# endif
|
||||
}
|
||||
# endif
|
||||
|
||||
// Check regularly current the relay and switch it OFF if the current is more than MAX_CURRENT_ACTUATOR
|
||||
# ifdef MAX_CURRENT_ACTUATOR
|
||||
void overLimitCurrent(float RN8209current) {
|
||||
@@ -68,7 +68,7 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZactuatorPWM
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_PWM.h"
|
||||
|
||||
static long previousUpdateTime = 0; // milliseconds
|
||||
@@ -128,15 +128,14 @@ void setupPWM() {
|
||||
// Configure the pin for PWM output.
|
||||
// I think this is the fastest frequency that allows for a 16-bit
|
||||
// duty cycle on an ESP32
|
||||
ledcSetup(i, 625.0, kNumDutyCycleBits);
|
||||
ledcAttachPin(channelPins[i], i);
|
||||
ledcAttachChannel(channelPins[i], 625.0, kNumDutyCycleBits, i);
|
||||
# endif
|
||||
calibrationMinLinear[i] = 0.f;
|
||||
calibrationMaxLinear[i] = 1.f;
|
||||
calibrationGamma[i] = PWM_DEFAULT_GAMMA;
|
||||
}
|
||||
|
||||
Log.trace(F("ZactuatorPWM setup done " CR));
|
||||
Log.trace(F("actuatorPWM setup done " CR));
|
||||
}
|
||||
|
||||
// This applies a power curve to the input to try to make the inputs
|
||||
@@ -1,15 +1,15 @@
|
||||
/*
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
|
||||
This actor enables to:
|
||||
- receive MQTT data from a topic and send Somfy RTS remote control signals corresponding to the received MQTT data
|
||||
|
||||
|
||||
Copyright (C) 2020 Leon Kiefer
|
||||
|
||||
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
|
||||
@@ -24,15 +24,21 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZactuatorSomfy
|
||||
|
||||
# include <EEPROM.h>
|
||||
# include <EEPROMRollingCodeStorage.h>
|
||||
# include <SomfyRemote.h>
|
||||
|
||||
# include "config_RF.h"
|
||||
# include "config_Somfy.h"
|
||||
# ifdef ZradioCC1101
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
# endif
|
||||
|
||||
void disableCurrentReceiver();
|
||||
void enableActiveReceiver();
|
||||
void initCC1101();
|
||||
void setupSomfy();
|
||||
|
||||
void setupSomfy() {
|
||||
pinMode(RF_EMITTER_GPIO, OUTPUT);
|
||||
digitalWrite(RF_EMITTER_GPIO, LOW);
|
||||
@@ -45,7 +51,7 @@ void setupSomfy() {
|
||||
EEPROM.begin(max(4, SOMFY_REMOTE_NUM * 2));
|
||||
# endif
|
||||
|
||||
Log.trace(F("ZactuatorSomfy setup done " CR));
|
||||
Log.trace(F("actuatorSomfy setup done " CR));
|
||||
}
|
||||
|
||||
# if jsonReceiving
|
||||
@@ -61,7 +67,7 @@ void XtoSomfy(const char* topicOri, JsonObject& jsonData) {
|
||||
|
||||
const int remoteIndex = jsonData["remote"];
|
||||
if (remoteIndex >= SOMFY_REMOTE_NUM) {
|
||||
Log.warning(F("ZactuatorSomfy remote does not exist" CR));
|
||||
Log.warning(F("actuatorSomfy remote does not exist" CR));
|
||||
return;
|
||||
}
|
||||
const String commandData = jsonData["command"];
|
||||
@@ -26,15 +26,23 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#if defined(ESP32) && defined(USE_BLUFI)
|
||||
# include <PicoMQTT.h>
|
||||
# include <WiFiManager.h>
|
||||
|
||||
# include "NimBLEDevice.h"
|
||||
# include "NimBLEOta.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "User_config.h"
|
||||
# include "esp_blufi_api.h"
|
||||
# include "esp_mac.h"
|
||||
# include "esp_timer.h"
|
||||
|
||||
extern "C" {
|
||||
# include "esp_blufi.h"
|
||||
}
|
||||
|
||||
extern void receivingDATA(const char* topicOri, const char* datacallback);
|
||||
|
||||
static esp_timer_handle_t connection_timer = nullptr;
|
||||
static NimBLEOta* pNimBLEOta;
|
||||
static NimBLECharacteristic* pCommandCharacteristic;
|
||||
@@ -62,6 +70,10 @@ static uint8_t gl_sta_passwd[64];
|
||||
static int gl_sta_ssid_len;
|
||||
static bool gl_sta_is_connecting = false;
|
||||
static esp_blufi_extra_info_t gl_sta_conn_info;
|
||||
extern bool ethConnected;
|
||||
extern bool mqttSetupPending;
|
||||
extern std::unique_ptr<PicoMQTT::Client> mqtt;
|
||||
extern WiFiManager wifiManager;
|
||||
|
||||
static void example_event_callback(esp_blufi_cb_event_t event, esp_blufi_cb_param_t* param);
|
||||
void wifi_event_handler(arduino_event_id_t event);
|
||||
@@ -93,7 +105,7 @@ void receivingCommandTask(void* pvParameters) {
|
||||
Log.error(F("deserialize config failed: %s, buffer capacity: %u" CR), error.c_str(), json.capacity());
|
||||
} else {
|
||||
if (jsonBlufi.containsKey("target") && jsonBlufi["target"].is<char*>()) {
|
||||
char topic[(parameters_size)*2 + jsonBlufi["target"].size() + 1];
|
||||
char topic[(parameters_size) * 2 + jsonBlufi["target"].size() + 1];
|
||||
snprintf(topic, sizeof(topic), "%s%s%s", mqtt_topic, gateway_name, jsonBlufi["target"].as<const char*>());
|
||||
jsonBlufi.remove("target");
|
||||
char jsonStr[JSON_MSG_BUFFER_MAX];
|
||||
@@ -105,7 +117,7 @@ void receivingCommandTask(void* pvParameters) {
|
||||
json["cnt_index"] = CNT_DEFAULT_INDEX;
|
||||
json["save_cnt"] = true;
|
||||
}
|
||||
char topic[(parameters_size)*2 + strlen(subjectMQTTtoSYSset) + 1];
|
||||
char topic[(parameters_size) * 2 + strlen(subjectMQTTtoSYSset) + 1];
|
||||
snprintf(topic, sizeof(topic), "%s%s%s", mqtt_topic, gateway_name, subjectMQTTtoSYSset);
|
||||
char jsonStr[JSON_MSG_BUFFER_MAX];
|
||||
serializeJson(jsonBlufi, jsonStr);
|
||||
@@ -320,7 +332,7 @@ void wifi_event_handler(arduino_event_id_t event) {
|
||||
gl_sta_is_connecting = false;
|
||||
esp_blufi_extra_info_t info = {};
|
||||
const String current_ssid = WiFi.SSID();
|
||||
gl_sta_ssid_len = std::min(current_ssid.length(), sizeof(gl_sta_ssid) - 1);
|
||||
gl_sta_ssid_len = std::min<uint32_t>(current_ssid.length(), sizeof(gl_sta_ssid) - 1);
|
||||
std::copy_n(current_ssid.c_str(), gl_sta_ssid_len, gl_sta_ssid);
|
||||
gl_sta_ssid[gl_sta_ssid_len] = '\0';
|
||||
uint8_t* bssid = WiFi.BSSID();
|
||||
@@ -6,8 +6,11 @@
|
||||
|
||||
#if defined(ESP32) && defined(USE_BLUFI)
|
||||
|
||||
# include <ArduinoLog.h>
|
||||
|
||||
# include "esp_blufi_api.h"
|
||||
# include "esp_crc.h"
|
||||
# include "esp_random.h"
|
||||
# include "mbedtls/aes.h"
|
||||
# include "mbedtls/dhm.h"
|
||||
# include "mbedtls/md5.h"
|
||||
@@ -48,6 +51,12 @@ static int myrand(void* rng_state, unsigned char* output, size_t len) {
|
||||
extern "C" void btc_blufi_report_error(esp_blufi_error_state_t state);
|
||||
|
||||
void blufi_dh_negotiate_data_handler(uint8_t* data, int len, uint8_t** output_data, int* output_len, bool* need_free) {
|
||||
if (data == NULL || len < 3) {
|
||||
Log.error(F("BLUFI Invalid data format" CR));
|
||||
btc_blufi_report_error(ESP_BLUFI_DATA_FORMAT_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
int ret;
|
||||
uint8_t type = data[0];
|
||||
|
||||
@@ -66,6 +75,7 @@ void blufi_dh_negotiate_data_handler(uint8_t* data, int len, uint8_t** output_da
|
||||
}
|
||||
blufi_sec->dh_param = (uint8_t*)malloc(blufi_sec->dh_param_len);
|
||||
if (blufi_sec->dh_param == NULL) {
|
||||
blufi_sec->dh_param_len = 0; /* Reset length to avoid using unallocated memory */
|
||||
btc_blufi_report_error(ESP_BLUFI_DH_MALLOC_ERROR);
|
||||
Log.error(F("%s, malloc failed\n" CR), __func__);
|
||||
return;
|
||||
@@ -77,6 +87,13 @@ void blufi_dh_negotiate_data_handler(uint8_t* data, int len, uint8_t** output_da
|
||||
btc_blufi_report_error(ESP_BLUFI_DH_PARAM_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
if (len < (blufi_sec->dh_param_len + 1)) {
|
||||
Log.error(F("%s, invalid dh param len" CR), __func__);
|
||||
btc_blufi_report_error(ESP_BLUFI_DH_PARAM_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t* param = blufi_sec->dh_param;
|
||||
memcpy(blufi_sec->dh_param, &data[1], blufi_sec->dh_param_len);
|
||||
ret = mbedtls_dhm_read_params(&blufi_sec->dhm, ¶m, ¶m[blufi_sec->dh_param_len]);
|
||||
@@ -88,7 +105,15 @@ void blufi_dh_negotiate_data_handler(uint8_t* data, int len, uint8_t** output_da
|
||||
free(blufi_sec->dh_param);
|
||||
blufi_sec->dh_param = NULL;
|
||||
|
||||
ret = mbedtls_dhm_make_public(&blufi_sec->dhm, (int)mbedtls_mpi_size(&blufi_sec->dhm.P), blufi_sec->self_public_key, blufi_sec->dhm.len, myrand, NULL);
|
||||
const int dhm_len = mbedtls_dhm_get_len(&blufi_sec->dhm);
|
||||
|
||||
if (dhm_len > DH_SELF_PUB_KEY_LEN) {
|
||||
Log.error(F("%s dhm len not support %d" CR), __func__, dhm_len);
|
||||
btc_blufi_report_error(ESP_BLUFI_DH_PARAM_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
ret = mbedtls_dhm_make_public(&blufi_sec->dhm, dhm_len, blufi_sec->self_public_key, DH_SELF_PUB_KEY_LEN, myrand, NULL);
|
||||
if (ret) {
|
||||
Log.error(F("%s make public failed %d" CR), __func__, ret);
|
||||
btc_blufi_report_error(ESP_BLUFI_MAKE_PUBLIC_ERROR);
|
||||
@@ -106,13 +131,19 @@ void blufi_dh_negotiate_data_handler(uint8_t* data, int len, uint8_t** output_da
|
||||
return;
|
||||
}
|
||||
|
||||
mbedtls_md5(blufi_sec->share_key, blufi_sec->share_len, blufi_sec->psk);
|
||||
ret = mbedtls_md5(blufi_sec->share_key, blufi_sec->share_len, blufi_sec->psk);
|
||||
|
||||
mbedtls_aes_setkey_enc(&blufi_sec->aes, blufi_sec->psk, 128);
|
||||
if (ret) {
|
||||
Log.error(F("%s mbedtls_md5 failed %d" CR), __func__, ret);
|
||||
btc_blufi_report_error(ESP_BLUFI_CALC_MD5_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
mbedtls_aes_setkey_enc(&blufi_sec->aes, blufi_sec->psk, PSK_LEN * 8);
|
||||
|
||||
/* alloc output data */
|
||||
*output_data = &blufi_sec->self_public_key[0];
|
||||
*output_len = blufi_sec->dhm.len;
|
||||
*output_len = dhm_len;
|
||||
*need_free = false;
|
||||
|
||||
} break;
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH)
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_M5.h"
|
||||
# ifdef ZboardM5STICKC
|
||||
# include <M5StickC.h>
|
||||
# endif
|
||||
@@ -41,6 +43,13 @@
|
||||
# ifdef ZboardM5TOUGH
|
||||
# include <M5Tough.h>
|
||||
# endif
|
||||
|
||||
void wakeScreen(int brightness);
|
||||
void displayIntro(int i, int X, int Y);
|
||||
void drawLogo(int logoSize, int circle1X, int circle1Y, bool circle1, bool circle2, bool circle3, bool circle4, bool circle5, bool circle6);
|
||||
void sleepScreen();
|
||||
void setBrightness(int brightness);
|
||||
|
||||
void logToLCD(bool display) {
|
||||
display ? Log.begin(LOG_LEVEL_LCD, &M5.Lcd) : Log.begin(LOG_LEVEL, &Serial); // Log on LCD following LOG_LEVEL_LCD
|
||||
}
|
||||
@@ -1,6 +1,17 @@
|
||||
#if SELF_TEST
|
||||
# include <Arduino.h>
|
||||
# include <ETH.h>
|
||||
# include <LEDManager.h>
|
||||
# include <WiFi.h>
|
||||
# include <esp_chip_info.h>
|
||||
# include <esp_system.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "User_config.h"
|
||||
|
||||
extern LEDManager ledManager;
|
||||
extern void ESPRestart(byte reason);
|
||||
|
||||
String getChipModel() {
|
||||
esp_chip_info_t chip_info;
|
||||
esp_chip_info(&chip_info);
|
||||
@@ -1,4 +1,7 @@
|
||||
const char* ss_client_cert PROGMEM = R"EOF("
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
static const char* ss_client_cert PROGMEM = R"EOF("
|
||||
-----BEGIN CERTIFICATE-----
|
||||
...
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
const char* ss_client_key PROGMEM = R"EOF("
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
static const char* ss_client_key PROGMEM = R"EOF("
|
||||
-----BEGIN RSA PRIVATE KEY-----
|
||||
...
|
||||
-----END RSA PRIVATE KEY-----
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
// The certificate must be in PEM ascii format.
|
||||
// The default certificate is for ota.openmqttgateway.com
|
||||
const char* OTAserver_cert PROGMEM = R"EOF("
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
static const char* OTAserver_cert PROGMEM = R"EOF("
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIIDQTCCAimgAwIBAgITBmyfz5m/jAo54vB4ikPmljZbyjANBgkqhkiG9w0BAQsF
|
||||
ADA5MQswCQYDVQQGEwJVUzEPMA0GA1UEChMGQW1hem9uMRkwFwYDVQQDExBBbWF6
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
const char* ss_server_cert PROGMEM = R"EOF("
|
||||
#pragma once
|
||||
#include <Arduino.h>
|
||||
|
||||
static const char* ss_server_cert PROGMEM = R"EOF("
|
||||
-----BEGIN CERTIFICATE-----
|
||||
...
|
||||
-----END CERTIFICATE-----
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
|
||||
Act as a wifi or ethernet gateway between your BLE/433mhz/infrared IR signal and an MQTT broker
|
||||
Act as a wifi or ethernet gateway between your BLE/433mhz/infrared IR signal and an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
|
||||
|
||||
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
|
||||
@@ -29,6 +29,17 @@
|
||||
# ifdef ZradioCC1101
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
# endif
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_RF.h"
|
||||
|
||||
# ifdef ZgatewayRTL_433
|
||||
# include <rtl_433_ESP.h>
|
||||
extern rtl_433_ESP rtl_433;
|
||||
# endif
|
||||
|
||||
RFConfig_s RFConfig;
|
||||
void RFConfig_init();
|
||||
void RFConfig_load();
|
||||
|
||||
void initCC1101() {
|
||||
# ifdef ZradioCC1101 //receiving with CC1101
|
||||
@@ -26,6 +26,8 @@
|
||||
#ifndef config_2G_h
|
||||
#define config_2G_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setup2G();
|
||||
extern bool _2GtoX();
|
||||
extern void Xto2G(const char* topicOri, const char* datacallback);
|
||||
|
||||
@@ -47,8 +47,7 @@ extern void MeasureLightIntensity();
|
||||
/*----------------------------USER PARAMETERS-----------------------------*/
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define subjectBH1750toMQTT "/BH1750toMQTT"
|
||||
//Time used to wait for an interval before resending measured values
|
||||
unsigned long timebh1750 = 0;
|
||||
int BH1750_i2c_addr = 0x23; // Light Sensor I2C Address
|
||||
|
||||
#define BH1750_I2C_ADDR 0x23; // Light Sensor I2C Address
|
||||
|
||||
#endif
|
||||
@@ -53,9 +53,7 @@ extern void MeasureTempHumAndPressure();
|
||||
# define BMETOPIC "/CLIMAtoMQTT/bme"
|
||||
#endif
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
unsigned long timebme280 = 0;
|
||||
int BME280_i2c_addr = 0x76; // Bosch BME280 I2C Address
|
||||
#define BME280_I2C_ADDR 0x76
|
||||
|
||||
// Only supported for ESP
|
||||
#ifndef BME280_PIN_SDA
|
||||
|
||||
+3
-2
@@ -26,6 +26,8 @@
|
||||
#ifndef config_BT_h
|
||||
#define config_BT_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupBT();
|
||||
extern void XtoBT(const char* topicOri, JsonObject& RFdata);
|
||||
extern void launchBTDiscovery(bool overrideDiscovery);
|
||||
@@ -34,7 +36,6 @@ extern String stateBTMeasures(bool);
|
||||
|
||||
#ifdef ESP32
|
||||
# include "NimBLEDevice.h"
|
||||
|
||||
#endif
|
||||
|
||||
/*-----------BT TOPICS & COMPILATION PARAMETERS-----------*/
|
||||
@@ -135,7 +136,7 @@ extern String stateBTMeasures(bool);
|
||||
# define BLE_CNCT_TIMEOUT 3000
|
||||
#endif
|
||||
|
||||
unsigned long scanCount = 0;
|
||||
extern unsigned long scanCount;
|
||||
|
||||
#ifndef pubBLEAdvData
|
||||
# define pubBLEAdvData false // define true if you want to publish all advertisement data
|
||||
|
||||
@@ -24,6 +24,8 @@
|
||||
#ifndef config_FASTLED_h
|
||||
#define config_FASTLED_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupFASTLED();
|
||||
extern void FASTLEDLoop();
|
||||
extern void XtoFASTLED(const char*, const char*);
|
||||
@@ -82,7 +84,7 @@ extern void XtoFASTLED(const char*, JsonObject&);
|
||||
# define FASTLED_ESP8266_D1_GPIO_ORDER
|
||||
# define FASTLED_DATA_GPIO D2 // only D2 works by me
|
||||
//#define FASTLED_CLOCK_GPIO 13
|
||||
#elif ESP32
|
||||
#elif defined(ESP32)
|
||||
# ifndef FASTLED_DATA_GPIO
|
||||
# define FASTLED_DATA_GPIO 16
|
||||
# endif
|
||||
|
||||
@@ -27,10 +27,6 @@
|
||||
#ifndef config_GFSunInverter_h
|
||||
#define config_GFSunInverter_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <GfSun2000.h>
|
||||
|
||||
extern void setupGFSunInverter();
|
||||
extern void ZgatewayGFSunInverterMQTT();
|
||||
|
||||
|
||||
+4
-2
@@ -26,6 +26,8 @@
|
||||
#ifndef config_IR_h
|
||||
#define config_IR_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupIR();
|
||||
extern void IRtoX();
|
||||
extern void XtoIR(const char* topicOri, const char* datacallback);
|
||||
@@ -182,7 +184,7 @@ extern void XtoIR(const char* topicOri, JsonObject& RFdata);
|
||||
#ifndef IR_RECEIVER_GPIO
|
||||
# ifdef ESP8266
|
||||
# define IR_RECEIVER_GPIO 2 //D4 /replace by 4 with sonoff rf bridge
|
||||
# elif ESP32
|
||||
# elif defined(ESP32)
|
||||
# define IR_RECEIVER_GPIO 26
|
||||
# endif
|
||||
#endif
|
||||
@@ -190,7 +192,7 @@ extern void XtoIR(const char* topicOri, JsonObject& RFdata);
|
||||
#ifndef IR_EMITTER_GPIO
|
||||
# ifdef ESP8266
|
||||
# define IR_EMITTER_GPIO 16 //D0/ replace by 0 (D3) if you use IR LOLIN controller shield /replace by 5 with sonoff rf bridge
|
||||
# elif ESP32
|
||||
# elif defined(ESP32)
|
||||
# define IR_EMITTER_GPIO 14
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#ifndef config_LORA_h
|
||||
#define config_LORA_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupLORA();
|
||||
extern void LORAtoX();
|
||||
extern void XtoLORA(const char* topicOri, const char* datacallback);
|
||||
|
||||
@@ -62,7 +62,4 @@ extern void MQ2toX();
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define subjectMQ2toMQTT "/GAStoMQTT/mq2"
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
unsigned long timemq2 = 0;
|
||||
|
||||
#endif
|
||||
+3
-1
@@ -26,6 +26,8 @@
|
||||
#ifndef config_ONOFF_h
|
||||
#define config_ONOFF_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupONOFF();
|
||||
extern void XtoONOFF(const char* topicOri, const char* datacallback);
|
||||
extern void XtoONOFF(const char* topicOri, JsonObject& RFdata);
|
||||
@@ -70,7 +72,7 @@ extern void stateONOFFMeasures();
|
||||
#ifndef ACTUATOR_ONOFF_GPIO
|
||||
# ifdef ESP8266
|
||||
# define ACTUATOR_ONOFF_GPIO 15 //12 for sonoff basic relay
|
||||
# elif ESP32
|
||||
# elif defined(ESP32)
|
||||
# define ACTUATOR_ONOFF_GPIO 15
|
||||
# else
|
||||
# define ACTUATOR_ONOFF_GPIO 13
|
||||
|
||||
@@ -22,7 +22,10 @@
|
||||
*/
|
||||
|
||||
/*-------------------PWM topics & parameters----------------------*/
|
||||
#ifndef config_PWM_h
|
||||
#define config_PWM_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
// PWM MQTT Subjects
|
||||
|
||||
extern void setupPWM();
|
||||
@@ -55,3 +58,5 @@ extern void XtoPWM(const char*, JsonObject&);
|
||||
#ifndef PWM_DEFAULT_GAMMA
|
||||
# define PWM_DEFAULT_GAMMA 2.2f
|
||||
#endif
|
||||
|
||||
#endif // config_PWM_h
|
||||
+16
-9
@@ -26,8 +26,7 @@
|
||||
#ifndef config_RF_h
|
||||
#define config_RF_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
#ifdef ZgatewayRF
|
||||
extern void setupRF();
|
||||
@@ -47,14 +46,10 @@ extern void enableRF2Receive();
|
||||
#ifdef ZgatewayPilight
|
||||
extern void setupPilight();
|
||||
extern void PilighttoX();
|
||||
extern void XtoPilight(const char* topicOri, const char* datacallback);
|
||||
extern void XtoPilight(const char* topicOri, JsonObject& RFdata);
|
||||
extern void disablePilightReceive();
|
||||
extern void enablePilightReceive();
|
||||
#endif
|
||||
#ifdef ZgatewayRTL_433
|
||||
# include <rtl_433_ESP.h>
|
||||
rtl_433_ESP rtl_433;
|
||||
|
||||
extern void RTL_433Loop();
|
||||
extern void setupRTL_433();
|
||||
@@ -217,7 +212,19 @@ struct RFConfig_s {
|
||||
#define ACTIVE_RTL 3
|
||||
#define ACTIVE_RF2 4
|
||||
|
||||
RFConfig_s RFConfig;
|
||||
#ifdef ZgatewayRF
|
||||
# define ACTIVE_RECEIVER ACTIVE_RF
|
||||
#elif defined(ZgatewayRF2)
|
||||
# define ACTIVE_RECEIVER ACTIVE_RF2
|
||||
#elif defined(ZgatewayPilight)
|
||||
# define ACTIVE_RECEIVER ACTIVE_PILIGHT
|
||||
#elif defined(ZgatewayRTL_433)
|
||||
# define ACTIVE_RECEIVER ACTIVE_RTL
|
||||
#else
|
||||
# define ACTIVE_RECEIVER ACTIVE_NONE
|
||||
#endif
|
||||
|
||||
extern RFConfig_s RFConfig;
|
||||
|
||||
/*-------------------CC1101 DefaultTXPower----------------------*/
|
||||
//Adjust the default TX-Power for sending radio if ZradioCC1101 is used.
|
||||
@@ -230,7 +237,7 @@ RFConfig_s RFConfig;
|
||||
#ifndef RF_RECEIVER_GPIO
|
||||
# ifdef ESP8266
|
||||
# define RF_RECEIVER_GPIO 0 // D3 on nodemcu // put 4 with rf bridge direct mod
|
||||
# elif ESP32
|
||||
# elif defined(ESP32)
|
||||
# define RF_RECEIVER_GPIO 27 // D27 on DOIT ESP32
|
||||
# endif
|
||||
#endif
|
||||
@@ -238,7 +245,7 @@ RFConfig_s RFConfig;
|
||||
#ifndef RF_EMITTER_GPIO
|
||||
# ifdef ESP8266
|
||||
# define RF_EMITTER_GPIO 3 // RX on nodemcu if it doesn't work with 3, try with 4 (D2) // put 5 with rf bridge direct mod
|
||||
# elif ESP32
|
||||
# elif defined(ESP32)
|
||||
# define RF_EMITTER_GPIO 12 // D12 on DOIT ESP32
|
||||
# else
|
||||
//IMPORTANT NOTE: On arduino UNO connect IR emitter pin to D9 , comment #define IR_USE_TIMER2 and uncomment #define IR_USE_TIMER1 on library <library>IRremote/boarddefs.h so as to free pin D3 for RF RECEIVER PIN
|
||||
|
||||
+8
-6
@@ -26,6 +26,8 @@
|
||||
#ifndef config_RFM69_h
|
||||
#define config_RFM69_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupRFM69();
|
||||
extern bool RFM69toX();
|
||||
extern void XtoRFM69(const char* topicOri, const char* datacallback);
|
||||
@@ -43,12 +45,12 @@ extern void XtoRFM69(const char* topicOri, JsonObject& RFdata);
|
||||
#define defaultRFM69ReceiverId 99
|
||||
|
||||
// Default values
|
||||
const char PROGMEM ENCRYPTKEY[] = "sampleEncryptKey";
|
||||
const char PROGMEM MDNS_NAME[] = "rfm69gw1";
|
||||
const char PROGMEM MQTT_BROKER[] = "raspi2";
|
||||
const char PROGMEM RFM69AP_NAME[] = "RFM69-AP";
|
||||
#define NETWORKID 200 //the same on all nodes that talk to each other
|
||||
#define NODEID 10
|
||||
#define RFM69_ENCRYPTKEY "sampleEncryptKey";
|
||||
#define RFM69_MDNS_NAME "rfm69gw1";
|
||||
#define RFM69_MQTT_BROKER "raspi2";
|
||||
#define RFM69_RFM69AP_NAME "RFM69-AP";
|
||||
#define RFM69_NETWORKID 200 //the same on all nodes that talk to each other
|
||||
#define RFM69_NODEID 10
|
||||
|
||||
//Match frequency to the hardware version of the radio
|
||||
#define FREQUENCY RF69_433MHZ
|
||||
|
||||
@@ -26,6 +26,8 @@
|
||||
#ifndef config_SERIAL_h
|
||||
#define config_SERIAL_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupSERIAL();
|
||||
extern void SERIALtoX();
|
||||
extern bool XtoSERIAL(const char* topicOri, JsonObject& SERIALdata);
|
||||
@@ -131,7 +133,7 @@ extern bool XtoSERIAL(const char* topicOri, JsonObject& SERIALdata);
|
||||
// define transmit pin (for software serial and/or ESP32)
|
||||
# if defined(ESP8266) && !defined(SERIAL_UART)
|
||||
# define SERIAL_TX_GPIO 2 //D4
|
||||
# elif ESP32
|
||||
# elif defined(ESP32)
|
||||
# define SERIAL_TX_GPIO 14
|
||||
# endif
|
||||
#endif
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#ifndef config_SRFB_h
|
||||
#define config_SRFB_h
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupSRFB();
|
||||
extern bool SRFBtoX();
|
||||
extern void XtoSRFB(const char* topicOri, const char* datacallback);
|
||||
|
||||
+1
-54
@@ -34,11 +34,7 @@
|
||||
#ifndef config_SSD1306_h
|
||||
#define config_SSD1306_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "SSD1306Wire.h"
|
||||
#include "TheengsCommon.h"
|
||||
#include "config_WebUI.h"
|
||||
|
||||
/*-------------------DEFINE LOG LEVEL----------------------*/
|
||||
@@ -140,53 +136,4 @@ void ssd1306Print(char*);
|
||||
|
||||
/*-------------------End of Global Variables----------------------*/
|
||||
|
||||
// This pattern was borrowed from HardwareSerial and modified to support the ssd1306 display
|
||||
|
||||
class OledSerial : public Stream {
|
||||
public:
|
||||
OledSerial(int);
|
||||
void begin();
|
||||
void drawLogo(int xshift, int yshift);
|
||||
boolean displayPage(webUIQueueMessage*);
|
||||
|
||||
SSD1306Wire* display;
|
||||
|
||||
int available(void); // Dummy functions
|
||||
int peek(void); // Dummy functions
|
||||
int read(void); // Dummy functions
|
||||
void flush(void); // Dummy functions
|
||||
|
||||
void fillScreen(OLEDDISPLAY_COLOR); // fillScreen display and set color
|
||||
|
||||
// This is a bit of lazy programmer simplification for the semaphore 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);
|
||||
}
|
||||
inline size_t write(const char* s) {
|
||||
return write((uint8_t*)s, strlen(s));
|
||||
}
|
||||
inline size_t write(unsigned long n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(long n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(unsigned int n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(int n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
extern OledSerial Oled;
|
||||
|
||||
#endif
|
||||
+1
-2
@@ -24,8 +24,7 @@
|
||||
#ifndef config_Somfy_h
|
||||
#define config_Somfy_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
extern void setupSomfy();
|
||||
extern void XtoSomfy(const char* topicOri, JsonObject& RFdata);
|
||||
|
||||
@@ -49,7 +49,4 @@ extern void MeasureLightIntensityTEMT6000();
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define subjectTEMT6000toMQTT "/LIGHTtoMQTT"
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
unsigned long timetemt6000 = 0;
|
||||
|
||||
#endif
|
||||
@@ -48,8 +48,4 @@ extern void MeasureLightIntensityTSL2561();
|
||||
/*-------------DEFINE YOUR MQTT PARAMETERS BELOW----------------*/
|
||||
#define subjectTSL12561toMQTT "/LIGHTtoMQTT"
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
unsigned long timetsl2561 = 0;
|
||||
//int TSL2561_i2c_addr = 0x37; // Light Sensor I2C Address (Set in Adafruit library)
|
||||
|
||||
#endif
|
||||
@@ -26,9 +26,6 @@
|
||||
#ifndef config_WeatherStation_h
|
||||
#define config_WeatherStation_h
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
extern void setupWeatherStation();
|
||||
extern void ZgatewayWeatherStationtoX();
|
||||
/*----------------------------USER PARAMETERS-----------------------------*/
|
||||
@@ -39,7 +36,7 @@ extern void ZgatewayWeatherStationtoX();
|
||||
#ifndef RF_WS_RECEIVER_GPIO
|
||||
# ifdef ESP8266
|
||||
# define RF_WS_RECEIVER_GPIO 0 // D3 on nodemcu // put 4 with rf bridge direct mod
|
||||
# elif ESP32
|
||||
# elif defined(ESP32)
|
||||
# define RF_WS_RECEIVER_GPIO 27 // D27 on DOIT ESP32
|
||||
# endif
|
||||
#endif
|
||||
|
||||
+13
-10
@@ -1,15 +1,15 @@
|
||||
/*
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
|
||||
This files enables to set your parameter for the DHT11/22 sensor
|
||||
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
|
||||
|
||||
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
|
||||
@@ -26,9 +26,10 @@
|
||||
#ifndef config_WebUI_h
|
||||
#define config_WebUI_h
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <Wire.h>
|
||||
|
||||
#include "TheengsCommon.h"
|
||||
|
||||
#define WEBUI_TEXT_WIDTH 128
|
||||
|
||||
/*------------------- Optional Compiler Directives ----------------------*/
|
||||
@@ -65,6 +66,8 @@
|
||||
# define WEBUI_LOGIN "admin"
|
||||
#endif
|
||||
|
||||
extern char ota_pass[];
|
||||
|
||||
/*------------------- End of Compiler Directives ----------------------*/
|
||||
|
||||
#define WEBUI_SECURE \
|
||||
@@ -92,7 +95,7 @@ struct webUIQueueMessage {
|
||||
char line2[WEBUI_TEXT_WIDTH];
|
||||
char line3[WEBUI_TEXT_WIDTH];
|
||||
char line4[WEBUI_TEXT_WIDTH];
|
||||
} webUIQueueMessage_t;
|
||||
};
|
||||
|
||||
/*------------------- Global Functions and Variables ----------------------*/
|
||||
|
||||
@@ -106,8 +109,8 @@ void XtoWebUI(const char*, JsonObject&);
|
||||
|
||||
String stateWebUIStatus();
|
||||
|
||||
webUIQueueMessage* currentWebUIMessage;
|
||||
bool newSSD1306Message = false; // Flag to indicate new message to display
|
||||
extern webUIQueueMessage* currentWebUIMessage;
|
||||
extern bool newSSD1306Message; // Flag to indicate new message to display
|
||||
|
||||
/*------------------- End of Global Functions ----------------------*/
|
||||
|
||||
|
||||
+10
-90
@@ -32,7 +32,7 @@ extern void pubMqttDiscovery();
|
||||
|
||||
/**
|
||||
* Create a discover messages form a list of attribute
|
||||
*
|
||||
*
|
||||
* @param mac the MAC address
|
||||
* @param sensorList[][0] = component type
|
||||
* @param sensorList[][1] = name
|
||||
@@ -57,7 +57,7 @@ extern void createDiscoveryFromList(const char* mac,
|
||||
|
||||
/**
|
||||
* @brief Generate message and publish it on an MQTT discovery exploiter. For HA @see https://www.home-assistant.io/docs/mqtt/discovery/
|
||||
*
|
||||
*
|
||||
* @param sensor_type the Type
|
||||
* @param st_topic set state topic,
|
||||
* @param s_name set name,
|
||||
@@ -71,15 +71,15 @@ extern void createDiscoveryFromList(const char* mac,
|
||||
* @param off_delay set off_delay
|
||||
* @param payload_available set payload_available,
|
||||
* @param payload_not_available set payload_not_available
|
||||
* @param gateway_entity set is a gateway entity,
|
||||
* @param gateway_entity set is a gateway entity,
|
||||
* @param cmd_topic set command topic
|
||||
* @param device_name set device name,
|
||||
* @param device_manufacturer set device manufacturer,
|
||||
* @param device_model set device model,
|
||||
* @param device_mac set device MAC,
|
||||
* @param device_name set device name,
|
||||
* @param device_manufacturer set device manufacturer,
|
||||
* @param device_model set device model,
|
||||
* @param device_mac set device MAC,
|
||||
* @param retainCmd set retain
|
||||
* @param state_class set state class
|
||||
*
|
||||
*
|
||||
* */
|
||||
extern void createDiscovery(const char* sensor_type,
|
||||
const char* state_topic, const char* s_name, const char* unique_id,
|
||||
@@ -95,7 +95,7 @@ extern void createDiscovery(const char* sensor_type,
|
||||
* @param topic Mandatory - The MQTT topic subscribed to receive trigger events.
|
||||
* @param type The type of the trigger, e.g. button_short_press. Entries supported by the HA Frontend: button_short_press, button_short_release, button_long_press, button_long_release, button_double_press, button_triple_press, button_quadruple_press, button_quintuple_press. If set to an unsupported value, will render as subtype type, e.g. button_1 spammed with type set to spammed and subtype set to button_1
|
||||
* @param subtype The subtype of the trigger, e.g. button_1. Entries supported by the HA frontend: turn_on, turn_off, button_1, button_2, button_3, button_4, button_5, button_6. If set to an unsupported value, will render as subtype type, e.g. left_button pressed with type set to button_short_press and subtype set to left_button
|
||||
* @param object_id The object_id of the trigger.
|
||||
* @param object_id The object_id of the trigger.
|
||||
* @param value_template The template to render the value of the trigger. The template can use the variables trigger.id, trigger.type, trigger.subtype, trigger.payload, trigger.payload_json, trigger.topic, trigger.timestamp, trigger.value, trigger.value_json. The template can be a string or a JSON object. If the template is a JSON object, it must be a valid JSON object. If the template is a string, it will be rendered as a string. If the template is a JSON object, it will be rendered as a JSON object.
|
||||
*/
|
||||
void announceGatewayTrigger(const char* topic,
|
||||
@@ -111,7 +111,7 @@ void announceGatewayTrigger(const char* topic,
|
||||
#ifndef discovery_Prefix
|
||||
# define discovery_Prefix "homeassistant"
|
||||
#endif
|
||||
char discovery_prefix[parameters_size + 1] = discovery_Prefix;
|
||||
extern char discovery_prefix[];
|
||||
|
||||
// discovery_republish_on_reconnect false to publish discovery topics over MQTT only with first connect
|
||||
// discovery_republish_on_reconnect true to always republish discovery topics over MQTT when connection is re-established
|
||||
@@ -176,86 +176,6 @@ char discovery_prefix[parameters_size + 1] = discovery_Prefix;
|
||||
#define stateClassTotal "total"
|
||||
#define stateClassTotalIncreasing "total_increasing"
|
||||
|
||||
// From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L225
|
||||
// List of classes available in Home Assistant
|
||||
const char* availableHASSClasses[] = {"battery_charging",
|
||||
"battery",
|
||||
"carbon_dioxide",
|
||||
"carbon_monoxide",
|
||||
"current",
|
||||
"data_size",
|
||||
"distance",
|
||||
"door",
|
||||
"duration",
|
||||
"energy",
|
||||
"enum",
|
||||
"gas",
|
||||
"humidity",
|
||||
"illuminance",
|
||||
"irradiance",
|
||||
"lock",
|
||||
"motion",
|
||||
"moving",
|
||||
"pm1",
|
||||
"pm10",
|
||||
"pm25",
|
||||
"power_factor",
|
||||
"power",
|
||||
"precipitation_intensity",
|
||||
"precipitation",
|
||||
"pressure",
|
||||
"problem",
|
||||
"restart",
|
||||
"signal_strength",
|
||||
"sound_pressure",
|
||||
"temperature",
|
||||
"timestamp",
|
||||
"voltage",
|
||||
"water",
|
||||
"weight",
|
||||
"wind_speed",
|
||||
"window"};
|
||||
|
||||
// From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L379
|
||||
// List of units available in Home Assistant
|
||||
const char* availableHASSUnits[] = {"W",
|
||||
"kW",
|
||||
"V",
|
||||
"kWh",
|
||||
"A",
|
||||
"W",
|
||||
"°C",
|
||||
"°F",
|
||||
"ms",
|
||||
"s",
|
||||
"min",
|
||||
"hPa",
|
||||
"L",
|
||||
"kg",
|
||||
"lb",
|
||||
"µS/cm",
|
||||
"ppm",
|
||||
"μg/m³",
|
||||
"m³",
|
||||
"mg/m³",
|
||||
"m/s²",
|
||||
"mV",
|
||||
"lx",
|
||||
"Ω",
|
||||
"%",
|
||||
"bar",
|
||||
"bpm",
|
||||
"dB",
|
||||
"dBm",
|
||||
"B",
|
||||
"UV index",
|
||||
"m/s",
|
||||
"km/h",
|
||||
"°",
|
||||
"mm",
|
||||
"mm/h",
|
||||
"cm"};
|
||||
|
||||
// Define the command used to update through OTA depending if we want to update from dev nightly or latest release
|
||||
#if DEVELOPMENTOTA
|
||||
# define LATEST_OR_DEV "{\"version\":\"dev\"}"
|
||||
|
||||
@@ -31,17 +31,61 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "User_config.h"
|
||||
|
||||
#if defined(ZdisplaySSD1306)
|
||||
|
||||
# include <ArduinoJson.h>
|
||||
|
||||
# include "ArduinoLog.h"
|
||||
# include "User_config.h"
|
||||
# include "SSD1306Wire.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_SSD1306.h"
|
||||
# ifdef DISPLAY_BLANKING
|
||||
# include "driver/touch_sensor.h"
|
||||
# endif
|
||||
|
||||
// This pattern was borrowed from HardwareSerial and modified to support the ssd1306 display
|
||||
|
||||
class OledSerial : public Stream {
|
||||
public:
|
||||
OledSerial(int);
|
||||
void begin();
|
||||
void drawLogo(int xshift, int yshift);
|
||||
boolean displayPage(webUIQueueMessage*);
|
||||
|
||||
SSD1306Wire* display;
|
||||
|
||||
int available(void); // Dummy functions
|
||||
int peek(void); // Dummy functions
|
||||
int read(void); // Dummy functions
|
||||
void flush(void); // Dummy functions
|
||||
|
||||
void fillScreen(OLEDDISPLAY_COLOR); // fillScreen display and set color
|
||||
|
||||
// This is a bit of lazy programmer simplification for the semaphore 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);
|
||||
}
|
||||
inline size_t write(const char* s) {
|
||||
return write((uint8_t*)s, strlen(s));
|
||||
}
|
||||
inline size_t write(unsigned long n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(long n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(unsigned int n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
inline size_t write(int n) {
|
||||
return write((uint8_t)n);
|
||||
}
|
||||
} Oled(0); // Oled object
|
||||
|
||||
SemaphoreHandle_t semaphoreOLEDOperation;
|
||||
|
||||
boolean logToOLEDDisplay = LOG_TO_OLED;
|
||||
@@ -50,7 +94,11 @@ boolean displayFlip = DISPLAY_FLIP;
|
||||
boolean displayState = DISPLAY_STATE;
|
||||
boolean idlelogo = DISPLAY_IDLE_LOGO;
|
||||
uint8_t displayBrightness = DISPLAY_BRIGHTNESS;
|
||||
bool newSSD1306Message = false; // Flag to indicate new message to display
|
||||
|
||||
void SSD1306Config_init();
|
||||
bool SSD1306Config_load();
|
||||
void SSD1306Config_save();
|
||||
/*
|
||||
Toogle log display
|
||||
*/
|
||||
@@ -66,12 +114,12 @@ void setupSSD1306() {
|
||||
SSD1306Config_init();
|
||||
SSD1306Config_load();
|
||||
Log.trace(F("Setup SSD1306 Display" CR));
|
||||
Log.trace(F("ZdisplaySSD1306 command topic: %s" CR), subjectMQTTtoSSD1306set);
|
||||
Log.trace(F("ZdisplaySSD1306 log-oled: %T" CR), logToOLEDDisplay);
|
||||
Log.trace(F("ZdisplaySSD1306 json-oled: %T" CR), jsonDisplay);
|
||||
Log.trace(F("ZdisplaySSD1306 DISPLAY_PAGE_INTERVAL: %d" CR), DISPLAY_PAGE_INTERVAL);
|
||||
Log.trace(F("ZdisplaySSD1306 DISPLAY_IDLE_LOGO: %T" CR), idlelogo);
|
||||
Log.trace(F("ZdisplaySSD1306 DISPLAY_FLIP: %T" CR), displayFlip);
|
||||
Log.trace(F("displaySSD1306 command topic: %s" CR), subjectMQTTtoSSD1306set);
|
||||
Log.trace(F("displaySSD1306 log-oled: %T" CR), logToOLEDDisplay);
|
||||
Log.trace(F("displaySSD1306 json-oled: %T" CR), jsonDisplay);
|
||||
Log.trace(F("displaySSD1306 DISPLAY_PAGE_INTERVAL: %d" CR), DISPLAY_PAGE_INTERVAL);
|
||||
Log.trace(F("displaySSD1306 DISPLAY_IDLE_LOGO: %T" CR), idlelogo);
|
||||
Log.trace(F("displaySSD1306 DISPLAY_FLIP: %T" CR), displayFlip);
|
||||
Oled.begin();
|
||||
Log.notice(F("Setup SSD1306 Display end" CR));
|
||||
|
||||
@@ -316,7 +364,6 @@ void ssd1306Print(char* line1) {
|
||||
|
||||
// This pattern was borrowed from HardwareSerial and modified to support the ssd1306 display
|
||||
|
||||
OledSerial Oled(0); // Not sure about this, came from Hardwareserial
|
||||
OledSerial::OledSerial(int x) {
|
||||
# if defined(WIFI_Kit_32) || defined(WIFI_LoRa_32) || defined(WIFI_LoRa_32_V2)
|
||||
pinMode(RST_OLED, OUTPUT); // https://github.com/espressif/arduino-esp32/issues/4278
|
||||
@@ -30,7 +30,12 @@
|
||||
#ifdef Zgateway2G
|
||||
|
||||
# include <A6lib.h> // library for controling A6 or A7 module
|
||||
# include <ArduinoJson.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_2G.h"
|
||||
|
||||
void signalStrengthAnalysis();
|
||||
void setupGSM(bool deleteSMS);
|
||||
|
||||
// Instantiate the library with TxPin, RxPin.
|
||||
A6lib A6l(_2G_TX_GPIO, _2G_RX_GPIO); //D6 to A6 RX, D7 to A6 TX
|
||||
@@ -43,7 +48,7 @@ void setup2G() {
|
||||
Log.notice(F("_2G_TX_GPIO: %d " CR), _2G_TX_GPIO);
|
||||
Log.notice(F("_2G_RX_GPIO: %d " CR), _2G_RX_GPIO);
|
||||
setupGSM(false);
|
||||
Log.trace(F("Zgateway2G setup done " CR));
|
||||
Log.trace(F("gateway2G setup done " CR));
|
||||
}
|
||||
|
||||
void setupGSM(bool deleteSMS) {
|
||||
@@ -1,12 +1,13 @@
|
||||
#ifdef ESP32
|
||||
# include "User_config.h"
|
||||
# ifdef ZgatewayBT
|
||||
# include "ArduinoJson.h"
|
||||
# include "ArduinoLog.h"
|
||||
# include "ZgatewayBLEConnect.h"
|
||||
# include "gatewayBLEConnect.h"
|
||||
# include "mbedtls/aes.h"
|
||||
|
||||
# define convertTemp_CtoF(c) ((c * 1.8) + 32)
|
||||
|
||||
extern std::vector<BLEdevice*> devices;
|
||||
extern bool BTProcessLock;
|
||||
|
||||
NimBLERemoteCharacteristic* zBLEConnect::getCharacteristic(const NimBLEUUID& service,
|
||||
const NimBLEUUID& characteristic) {
|
||||
@@ -2,8 +2,8 @@
|
||||
#define zBLEConnect_h
|
||||
|
||||
#ifdef ESP32
|
||||
# include "ArduinoJson.h"
|
||||
# include "NimBLEDevice.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_BT.h"
|
||||
|
||||
class zBLEConnect {
|
||||
@@ -29,11 +29,12 @@ Thanks to wolass https://github.com/wolass for suggesting me HM 10 and dinosd ht
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayBT
|
||||
# include "TheengsCommon.h"
|
||||
|
||||
SemaphoreHandle_t semaphoreCreateOrUpdateDevice;
|
||||
SemaphoreHandle_t semaphoreBLEOperation;
|
||||
QueueHandle_t BLEQueue;
|
||||
// Headers used for deep sleep functions
|
||||
unsigned long scanCount = 0;
|
||||
# include <NimBLEAdvertisedDevice.h>
|
||||
# include <NimBLEDevice.h>
|
||||
# include <NimBLEScan.h>
|
||||
@@ -43,7 +44,9 @@ QueueHandle_t BLEQueue;
|
||||
|
||||
# include <atomic>
|
||||
|
||||
# include "ZgatewayBLEConnect.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_mqttDiscovery.h"
|
||||
# include "gatewayBLEConnect.h"
|
||||
# include "soc/timer_group_reg.h"
|
||||
# include "soc/timer_group_struct.h"
|
||||
|
||||
@@ -71,15 +74,26 @@ vector<BLEAction> BLEactions;
|
||||
vector<BLEdevice*> devices;
|
||||
int newDevices = 0;
|
||||
|
||||
static BLEdevice NO_BT_DEVICE_FOUND = {{0},
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
UNKWNON_MODEL};
|
||||
static BLEdevice NO_BT_DEVICE_FOUND = {
|
||||
{0},
|
||||
0,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
(int)UNKWNON_MODEL,
|
||||
0,
|
||||
};
|
||||
static bool oneWhite = false;
|
||||
|
||||
extern bool BTProcessLock;
|
||||
extern int queueLength;
|
||||
|
||||
void setupBTTasksAndBLE();
|
||||
bool checkIfIsTracker(char ch);
|
||||
void hass_presence(JsonObject& HomePresence);
|
||||
void BTforceScan();
|
||||
|
||||
void BTConfig_init() {
|
||||
BTConfig.bleConnect = AttemptBLEConnect;
|
||||
BTConfig.BLEinterval = TimeBtwRead;
|
||||
@@ -846,7 +860,7 @@ void setupBTTasksAndBLE() {
|
||||
BLEDevice::setScanDuplicateCacheSize(BLEScanDuplicateCacheSize);
|
||||
# endif
|
||||
BLEDevice::init("");
|
||||
xTaskCreatePinnedToCore(
|
||||
xTaskCreateUniversal(
|
||||
procBLETask, /* Function to implement the task */
|
||||
"procBLETask", /* Name of the task */
|
||||
# if defined(USE_ESP_IDF) || defined(USE_BLUFI)
|
||||
@@ -860,7 +874,7 @@ void setupBTTasksAndBLE() {
|
||||
1); /* Core where the task should run */
|
||||
|
||||
// we setup a task with priority one to avoid conflict with other gateways
|
||||
xTaskCreatePinnedToCore(
|
||||
xTaskCreateUniversal(
|
||||
coreTask, /* Function to implement the task */
|
||||
"coreTask", /* Name of the task */
|
||||
5120, /* Stack size in bytes */
|
||||
@@ -897,9 +911,9 @@ void setupBT() {
|
||||
BLEQueue = xQueueCreate(QueueSize, sizeof(NimBLEAdvertisedDevice*));
|
||||
if (BTConfig.enabled) {
|
||||
setupBTTasksAndBLE();
|
||||
Log.notice(F("ZgatewayBT multicore ESP32 setup done" CR));
|
||||
Log.notice(F("gatewayBT multicore ESP32 setup done" CR));
|
||||
} else {
|
||||
Log.notice(F("ZgatewayBT multicore ESP32 setup disabled" CR));
|
||||
Log.notice(F("gatewayBT multicore ESP32 setup disabled" CR));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1399,7 +1413,7 @@ void immediateBTAction(void* pvParameters) {
|
||||
|
||||
void startBTActionTask() {
|
||||
TaskHandle_t th;
|
||||
xTaskCreatePinnedToCore(
|
||||
xTaskCreateUniversal(
|
||||
immediateBTAction, /* Function to implement the task */
|
||||
"imActTask", /* Name of the task */
|
||||
8000, /* Stack size in bytes */
|
||||
@@ -27,6 +27,11 @@
|
||||
|
||||
#ifdef ZgatewayGFSunInverter
|
||||
|
||||
# include <GfSun2000.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_GFSunInverter.h"
|
||||
|
||||
GfSun2000 GF = GfSun2000();
|
||||
|
||||
void GFSunInverterDataHandler(GfSun2000Data data) {
|
||||
@@ -79,7 +84,7 @@ void setupGFSunInverter() {
|
||||
GF.setup(Serial2);
|
||||
GF.setDataHandler(GFSunInverterDataHandler);
|
||||
GF.setErrorHandler(GFSunInverterErrorHandler);
|
||||
Log.trace(F("ZgatewayGFSunInverter setup done " CR));
|
||||
Log.trace(F("gatewayGFSunInverter setup done " CR));
|
||||
}
|
||||
|
||||
void ZgatewayGFSunInverterMQTT() {
|
||||
@@ -28,11 +28,13 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayIR
|
||||
|
||||
# include <IRrecv.h> // Needed if you want to receive IR commands.
|
||||
# include <IRremoteESP8266.h>
|
||||
# include <IRsend.h> // Needed if you want to send IR commands.
|
||||
# include <IRutils.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_IR.h"
|
||||
# ifdef DumpMode // in dump mode we increase the size of the buffer to catch big codes
|
||||
IRrecv irrecv(IR_RECEIVER_GPIO, 1024, 15U, true);
|
||||
# else
|
||||
@@ -99,7 +101,7 @@ void setupIR() {
|
||||
|
||||
Log.notice(F("IR_EMITTER_GPIO: %d " CR), IR_EMITTER_GPIO);
|
||||
Log.notice(F("IR_RECEIVER_GPIO: %d " CR), IR_RECEIVER_GPIO);
|
||||
Log.trace(F("ZgatewayIR setup done " CR));
|
||||
Log.trace(F("gatewayIR setup done " CR));
|
||||
}
|
||||
|
||||
void IRtoX() {
|
||||
@@ -1084,7 +1086,7 @@ bool sendIdentifiedProtocol(const char* protocol_name, uint64_t data, const char
|
||||
}
|
||||
# endif
|
||||
# ifdef IR_ZEPEAL
|
||||
if (strcmp(protocol_name, "ZEPEAL") == 0) {
|
||||
if (strcmp(protocol_name, "EPEAL") == 0) {
|
||||
Log.notice(F("Sending IR signal with %s" CR), protocol_name);
|
||||
if (valueRPT == repeatIRwNumber)
|
||||
valueRPT = std::max(valueRPT, kZepealMinRepeat);
|
||||
@@ -28,18 +28,35 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayLORA
|
||||
|
||||
# include <LoRa.h>
|
||||
# include <SPI.h>
|
||||
# include <TheengsUtils.h>
|
||||
# include <Wire.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_LORA.h"
|
||||
# include "config_mqttDiscovery.h"
|
||||
|
||||
# define WIPHONE_MESSAGE_MAGIC 0x6c6d
|
||||
# define WIPHONE_MESSAGE_MIN_LEN sizeof(wiphone_message) - WIPHONE_MAX_MESSAGE_LEN
|
||||
# define WIPHONE_MAX_MESSAGE_LEN 230
|
||||
|
||||
LORAConfig_s LORAConfig;
|
||||
|
||||
void LORAConfig_fromJson(JsonObject& LORAdata);
|
||||
String stateLORAMeasures();
|
||||
|
||||
# ifdef ZmqttDiscovery
|
||||
# include "config_mqttDiscovery.h"
|
||||
extern void createDiscovery(const char* sensor_type,
|
||||
const char* st_topic, const char* s_name, const char* unique_id,
|
||||
const char* availability_topic, const char* device_class, const char* value_template,
|
||||
const char* payload_on, const char* payload_off, const char* unit_of_meas,
|
||||
int off_delay,
|
||||
const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* cmd_topic,
|
||||
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_id, bool retainCmd,
|
||||
const char* state_class, const char* state_off, const char* state_on, const char* enum_options, const char* command_template);
|
||||
|
||||
SemaphoreHandle_t semaphorecreateOrUpdateDeviceLORA;
|
||||
std::vector<LORAdevice*> LORAdevices;
|
||||
int newLORADevices = 0;
|
||||
@@ -389,9 +406,8 @@ void setupLORA() {
|
||||
LoRa.setPins(LORA_SS, LORA_RST, LORA_DI0);
|
||||
|
||||
if (!LoRa.begin(LORAConfig.frequency)) {
|
||||
Log.error(F("ZgatewayLORA setup failed!" CR));
|
||||
while (1)
|
||||
;
|
||||
Log.error(F("gatewayLORA setup failed!" CR));
|
||||
while (1);
|
||||
}
|
||||
LoRa.receive();
|
||||
Log.notice(F("LORA_SCK: %d" CR), LORA_SCK);
|
||||
@@ -400,7 +416,7 @@ void setupLORA() {
|
||||
Log.notice(F("LORA_SS: %d" CR), LORA_SS);
|
||||
Log.notice(F("LORA_RST: %d" CR), LORA_RST);
|
||||
Log.notice(F("LORA_DI0: %d" CR), LORA_DI0);
|
||||
Log.trace(F("ZgatewayLORA setup done" CR));
|
||||
Log.trace(F("gatewayLORA setup done" CR));
|
||||
}
|
||||
|
||||
void LORAtoX() {
|
||||
@@ -28,6 +28,15 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayPilight
|
||||
# include "TheengsCommon.h"
|
||||
|
||||
# if defined(ESP32)
|
||||
# include <SPIFFS.h>
|
||||
# else
|
||||
# include <FS.h>
|
||||
# endif
|
||||
|
||||
# include "config_RF.h"
|
||||
|
||||
# ifdef ZradioCC1101
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
@@ -41,6 +50,10 @@ ESPiLight rf(RF_EMITTER_GPIO); // use -1 to disable transmitter
|
||||
bool pilightRawEnabled = 0;
|
||||
# endif
|
||||
|
||||
void disableCurrentReceiver();
|
||||
void initCC1101();
|
||||
void enableActiveReceiver();
|
||||
|
||||
void pilightCallback(const String& protocol, const String& message, int status,
|
||||
size_t repeats, const String& deviceID) {
|
||||
if (status == VALID) {
|
||||
@@ -297,7 +310,7 @@ extern void enablePilightReceive() {
|
||||
Log.notice(F("Switching to Pilight Receiver: %F" CR), RFConfig.frequency);
|
||||
Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
|
||||
Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
|
||||
Log.trace(F("ZgatewayPilight command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoPilight);
|
||||
Log.trace(F("gatewayPilight command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoPilight);
|
||||
|
||||
initCC1101();
|
||||
|
||||
@@ -311,6 +324,6 @@ extern void enablePilightReceive() {
|
||||
pinMode(RF_EMITTER_GPIO, OUTPUT); // Set this here, because if this is the RX pin it was reset to INPUT by Serial.end();
|
||||
rf.enableReceiver();
|
||||
loadPilightConfig();
|
||||
Log.trace(F("ZgatewayPilight setup done " CR));
|
||||
Log.trace(F("gatewayPilight setup done " CR));
|
||||
};
|
||||
#endif
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
|
||||
This gateway enables to:
|
||||
- receive MQTT data from a topic and send RF 433Mhz signal corresponding to the received MQTT data
|
||||
- publish MQTT data to a different topic related to received 433Mhz signal
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
|
||||
|
||||
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
|
||||
@@ -28,15 +28,18 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayRF
|
||||
# include <ArduinoJson.h>
|
||||
# include <ArduinoLog.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_RF.h"
|
||||
# ifdef ZradioCC1101
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
extern void initCC1101();
|
||||
# endif
|
||||
|
||||
# include <RCSwitch.h> // library for controling Radio frequency switch
|
||||
|
||||
void disableCurrentReceiver();
|
||||
void enableActiveReceiver();
|
||||
|
||||
RCSwitch mySwitch = RCSwitch();
|
||||
|
||||
/**
|
||||
@@ -49,7 +52,7 @@ RCSwitch mySwitch = RCSwitch();
|
||||
* - 'F' represents "01" in the binary string
|
||||
*
|
||||
* If the input binary string contains any other combination, the function returns "-".
|
||||
*
|
||||
*
|
||||
* @note CONVERSION function from https://github.com/sui77/rc-switch/tree/master/examples/ReceiveDemo_Advanced
|
||||
*
|
||||
* @param bin The input binary string.
|
||||
@@ -88,7 +91,7 @@ static const char* bin2tristate(const char* bin) {
|
||||
*
|
||||
* @note The returned string is stored in a static buffer, so it will be overwritten by subsequent
|
||||
* calls to this function. The buffer size is fixed at 64 characters.
|
||||
*
|
||||
*
|
||||
* @note CONVERSION function from https://github.com/sui77/rc-switch/tree/master/examples/ReceiveDemo_Advanced
|
||||
*
|
||||
*/
|
||||
@@ -146,13 +149,13 @@ void announceGatewayTriggerTypeToHASS(uint64_t MQTTvalue) {
|
||||
|
||||
/**
|
||||
* @brief Processes received RF signals and converts them to JSON format for further handling.
|
||||
*
|
||||
*
|
||||
* This function checks if an RF signal is available, extracts relevant data from the signal,
|
||||
* and stores it in a JSON object. It also handles duplicate signal detection and optionally
|
||||
* publishes the signal data for MQTT discovery and repetition.
|
||||
*
|
||||
*
|
||||
* @note This function is designed to work with both ESP32 and ESP8266 platforms.
|
||||
*
|
||||
*
|
||||
* @details The function performs the following steps:
|
||||
* - Checks if an RF signal is available.
|
||||
* - Logs the reception of the RF signal.
|
||||
@@ -162,7 +165,7 @@ void announceGatewayTriggerTypeToHASS(uint64_t MQTTvalue) {
|
||||
* - Resets the availability status of the RF signal.
|
||||
* - Checks for duplicate signals and processes the signal if it is not a duplicate.
|
||||
* - Optionally publishes the signal data for MQTT discovery and repetition.
|
||||
*
|
||||
*
|
||||
* @param None
|
||||
* @return void
|
||||
*/
|
||||
@@ -384,8 +387,8 @@ void disableRFReceive() {
|
||||
/**
|
||||
* @brief Enables the RF receiver and optionally the RF transmitter.
|
||||
*
|
||||
* This function initializes the RF receiver on the specified GPIO pin and, if not disabled,
|
||||
* initializes the RF transmitter on the specified GPIO pin. It also sets the RF frequency
|
||||
* This function initializes the RF receiver on the specified GPIO pin and, if not disabled,
|
||||
* initializes the RF transmitter on the specified GPIO pin. It also sets the RF frequency
|
||||
* and logs the configuration details.
|
||||
*
|
||||
* @param rfFrequency The frequency for the RF communication in MHz. Default is RFConfig.frequency.
|
||||
@@ -1,17 +1,17 @@
|
||||
/*
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
|
||||
This gateway enables to:
|
||||
- publish MQTT data to a different topic related to received 433Mhz signal DIO/new kaku protocol
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
Copyright: (c)Randy Simons http://randysimons.nl/
|
||||
|
||||
|
||||
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
|
||||
@@ -36,6 +36,9 @@ sudo mosquitto_pub -t home/commands/MQTTtoRF2/CODE_8233372/UNIT_0/PERIOD_272 -m/
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayRF2
|
||||
# include "TheengsCommon.h"
|
||||
# include "TheengsUtils.h"
|
||||
# include "config_RF.h"
|
||||
|
||||
# ifdef ZradioCC1101
|
||||
# include <ELECHOUSE_CC1101_SRC_DRV.h>
|
||||
@@ -44,6 +47,9 @@ sudo mosquitto_pub -t home/commands/MQTTtoRF2/CODE_8233372/UNIT_0/PERIOD_272 -m/
|
||||
# include <NewRemoteReceiver.h>
|
||||
# include <NewRemoteTransmitter.h>
|
||||
|
||||
void disableCurrentReceiver();
|
||||
void enableActiveReceiver();
|
||||
|
||||
struct RF2rxd {
|
||||
unsigned int period;
|
||||
unsigned long address;
|
||||
@@ -55,7 +61,12 @@ struct RF2rxd {
|
||||
|
||||
RF2rxd rf2rd;
|
||||
|
||||
extern void initCC1101();
|
||||
|
||||
# ifdef ZmqttDiscovery
|
||||
# include "config_mqttDiscovery.h"
|
||||
extern String getUniqueId(String name, String sufix);
|
||||
|
||||
//Register for autodiscover in Home Assistant
|
||||
void RF2toMQTTdiscovery(JsonObject& data) {
|
||||
Log.trace(F("switchRF2Discovery" CR));
|
||||
@@ -310,10 +321,10 @@ void enableRF2Receive() {
|
||||
|
||||
Log.notice(F("RF_EMITTER_GPIO: %d " CR), RF_EMITTER_GPIO);
|
||||
Log.notice(F("RF_RECEIVER_GPIO: %d " CR), RF_RECEIVER_GPIO);
|
||||
Log.trace(F("ZgatewayRF2 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRF2);
|
||||
Log.trace(F("gatewayRF2 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRF2);
|
||||
pinMode(RF_EMITTER_GPIO, OUTPUT);
|
||||
digitalWrite(RF_EMITTER_GPIO, LOW);
|
||||
Log.trace(F("ZgatewayRF2 setup done " CR));
|
||||
Log.trace(F("gatewayRF2 setup done " CR));
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -31,15 +31,21 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayRFM69
|
||||
|
||||
# include <EEPROM.h>
|
||||
# include <RFM69.h> //https://www.github.com/lowpowerlab/rfm69
|
||||
|
||||
char RadioConfig[128];
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_RFM69.h"
|
||||
|
||||
// vvvvvvvvv Global Configuration vvvvvvvvvvv
|
||||
static char RadioConfig[128];
|
||||
static const char* PROGMEM ENCRYPTKEY = RFM69_ENCRYPTKEY;
|
||||
static const char* PROGMEM MDNS_NAME = RFM69_MDNS_NAME;
|
||||
static const char* PROGMEM MQTT_BROKER = RFM69_MQTT_BROKER;
|
||||
static const char* PROGMEM RFM69AP_NAME = RFM69_RFM69AP_NAME
|
||||
|
||||
struct _GLOBAL_CONFIG {
|
||||
// vvvvvvvvv Global Configuration vvvvvvvvvvv
|
||||
|
||||
struct _GLOBAL_CONFIG {
|
||||
uint32_t checksum;
|
||||
char rfmapname[32];
|
||||
char encryptkey[16 + 1];
|
||||
@@ -75,8 +81,8 @@ void eeprom_setup() {
|
||||
memset(pGC, 0, sizeof(*pGC));
|
||||
strcpy_P(pGC->encryptkey, ENCRYPTKEY);
|
||||
strcpy_P(pGC->rfmapname, RFM69AP_NAME);
|
||||
pGC->networkid = NETWORKID;
|
||||
pGC->nodeid = NODEID;
|
||||
pGC->networkid = RFM69_NETWORKID;
|
||||
pGC->nodeid = RFM69_NODEID;
|
||||
pGC->powerlevel = ((IS_RFM69HCW) ? 0x80 : 0x00) | POWER_LEVEL;
|
||||
pGC->rfmfrequency = FREQUENCY;
|
||||
pGC->checksum = gc_checksum();
|
||||
@@ -97,7 +103,7 @@ void setupRFM69(void) {
|
||||
|
||||
// Initialize radio
|
||||
if (!radio.initialize(pGC->rfmfrequency, pGC->nodeid, pGC->networkid)) {
|
||||
Log.error(F("ZgatewayRFM69 initialization failed" CR));
|
||||
Log.error(F("gatewayRFM69 initialization failed" CR));
|
||||
}
|
||||
|
||||
if (GC_IS_RFM69HCW) {
|
||||
@@ -125,7 +131,7 @@ void setupRFM69(void) {
|
||||
freq = -1;
|
||||
break;
|
||||
}
|
||||
Log.notice(F("ZgatewayRFM69 Listening and transmitting at: %d" CR), freq);
|
||||
Log.notice(F("gatewayRFM69 Listening and transmitting at: %d" CR), freq);
|
||||
|
||||
size_t len = snprintf_P(RadioConfig, sizeof(RadioConfig), JSONtemplate,
|
||||
freq, GC_IS_RFM69HCW, pGC->networkid, GC_POWER_LEVEL);
|
||||
@@ -26,19 +26,22 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef ZgatewayRTL_433
|
||||
|
||||
# include <ArduinoJson.h>
|
||||
# include <config_RF.h>
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewayRTL_433
|
||||
# include <rtl_433_ESP.h>
|
||||
|
||||
# include "ArduinoLog.h"
|
||||
# include "User_config.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_RF.h"
|
||||
# ifdef ZmqttDiscovery
|
||||
# include "config_mqttDiscovery.h"
|
||||
# endif
|
||||
|
||||
char messageBuffer[JSON_MSG_BUFFER];
|
||||
# include <vector>
|
||||
|
||||
static char messageBuffer[JSON_MSG_BUFFER];
|
||||
rtl_433_ESP rtl_433;
|
||||
|
||||
# ifdef ZmqttDiscovery
|
||||
SemaphoreHandle_t semaphorecreateOrUpdateDeviceRTL_433;
|
||||
@@ -314,8 +317,8 @@ void setupRTL_433() {
|
||||
semaphorecreateOrUpdateDeviceRTL_433 = xSemaphoreCreateBinary();
|
||||
xSemaphoreGive(semaphorecreateOrUpdateDeviceRTL_433);
|
||||
# endif
|
||||
Log.trace(F("ZgatewayRTL_433 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRFset);
|
||||
Log.notice(F("ZgatewayRTL_433 setup done " CR));
|
||||
Log.trace(F("gatewayRTL_433 command topic: %s%s%s" CR), mqtt_topic, gateway_name, subjectMQTTtoRFset);
|
||||
Log.notice(F("gatewayRTL_433 setup done " CR));
|
||||
}
|
||||
|
||||
void RTL_433Loop() {
|
||||
@@ -28,6 +28,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewaySERIAL
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_SERIAL.h"
|
||||
|
||||
# ifndef SERIAL_UART // software serial mode
|
||||
# include <SoftwareSerial.h>
|
||||
@@ -48,6 +50,8 @@ const TickType_t semaphoreTimeout = pdMS_TO_TICKS(1000); // 1 second timeout
|
||||
# define SEMAPHORE_SERIAL_GIVE
|
||||
# endif
|
||||
|
||||
extern void receivingDATA(const char* topicOri, const char* datacallback);
|
||||
|
||||
// use pointer to stream class for serial communication to make code
|
||||
// compatible with both softwareSerial as hardwareSerial.
|
||||
Stream* SERIALStream = NULL;
|
||||
@@ -64,6 +68,10 @@ const unsigned long maxHeartbeatInterval = 60000; // Maximum interval of 1 minut
|
||||
unsigned long heartbeatInterval = 5000; // 5 seconds
|
||||
bool isOverflow = false;
|
||||
|
||||
static void sendHeartbeat();
|
||||
static void sendHeartbeatAck();
|
||||
static void handleHeartbeat();
|
||||
|
||||
void setupSERIAL() {
|
||||
//Initalize serial port
|
||||
# ifdef SERIAL_UART // Hardware serial
|
||||
@@ -130,7 +138,7 @@ void setupSERIAL() {
|
||||
SERIALStream->read();
|
||||
|
||||
Log.notice(F("SERIALBaud: %d" CR), SERIALBaud);
|
||||
Log.trace(F("ZgatewaySERIAL setup done" CR));
|
||||
Log.trace(F("gatewaySERIAL setup done" CR));
|
||||
}
|
||||
|
||||
# if SERIALtoMQTTmode == 0 // Convert received data to single MQTT topic
|
||||
@@ -31,12 +31,19 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZgatewaySRFB
|
||||
# include <TheengsUtils.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_SRFB.h"
|
||||
|
||||
unsigned char _uartbuf[RF_MESSAGE_SIZE + 3] = {0};
|
||||
unsigned char _uartpos = 0;
|
||||
|
||||
void _rfbDecode();
|
||||
void _rfbAck();
|
||||
|
||||
void setupSRFB() {
|
||||
Log.trace(F("ZgatewaySRFB setup done " CR));
|
||||
Log.trace(F("gatewaySRFB setup done " CR));
|
||||
Log.trace(F("Serial Baud: %l" CR), SERIAL_BAUD);
|
||||
}
|
||||
|
||||
@@ -27,10 +27,14 @@
|
||||
|
||||
#ifdef ZgatewayWeatherStation
|
||||
# include <WeatherStationDataRx.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_WeatherStation.h"
|
||||
|
||||
WeatherStationDataRx wsdr(RF_WS_RECEIVER_GPIO, true);
|
||||
|
||||
void PairedDeviceAdded(byte newID) {
|
||||
Serial.printf("ZgatewayWeatherStation: New device paired %d\r\n", newID);
|
||||
Serial.printf("gatewayWeatherStation: New device paired %d\r\n", newID);
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> RFdataBuffer;
|
||||
JsonObject RFdata = RFdataBuffer.to<JsonObject>();
|
||||
RFdata["sensor"] = newID;
|
||||
@@ -44,7 +48,7 @@ void setupWeatherStation() {
|
||||
Log.notice(F("RF_WS_RECEIVER_GPIO %d" CR), RF_WS_RECEIVER_GPIO);
|
||||
wsdr.begin();
|
||||
wsdr.pair(NULL, PairedDeviceAdded);
|
||||
Log.trace(F("ZgatewayWeatherStation setup done " CR));
|
||||
Log.trace(F("gatewayWeatherStation setup done " CR));
|
||||
}
|
||||
|
||||
void sendWindSpeedData(byte id, float wind_speed, byte battery_status) {
|
||||
@@ -25,22 +25,16 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include "User_config.h"
|
||||
|
||||
enum GatewayState {
|
||||
WAITING_ONBOARDING,
|
||||
ONBOARDING,
|
||||
OFFLINE,
|
||||
NTWK_CONNECTED,
|
||||
BROKER_CONNECTED,
|
||||
PROCESSING,
|
||||
NTWK_DISCONNECTED,
|
||||
BROKER_DISCONNECTED,
|
||||
LOCAL_OTA_IN_PROGRESS,
|
||||
REMOTE_OTA_IN_PROGRESS,
|
||||
SLEEPING,
|
||||
ERROR
|
||||
};
|
||||
#include <PicoMQTT.h>
|
||||
|
||||
#include <memory>
|
||||
#include <queue>
|
||||
|
||||
#include "LEDManager.h"
|
||||
#include "TheengsCommon.h"
|
||||
#include "TheengsUtils.h"
|
||||
|
||||
GatewayState gatewayState = GatewayState::WAITING_ONBOARDING;
|
||||
|
||||
// Macros and structure to enable the duplicates removing on the following gateways
|
||||
@@ -56,6 +50,12 @@ ReceivedSignal receivedSignal[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0}, {0, 0
|
||||
# define struct_size (sizeof(receivedSignal) / sizeof(ReceivedSignal))
|
||||
#endif
|
||||
|
||||
int queueLength = -1; // We want to give one cycle of the loop before starting modules that are big msgs producers (example BT), to avoid queue overloading
|
||||
unsigned long queueLengthSum = 0;
|
||||
unsigned long blockedMessages = 0;
|
||||
unsigned long receivedMessages = 0;
|
||||
int maxQueueLength = 0;
|
||||
|
||||
//Time used to wait for an interval before measures
|
||||
unsigned long timer_sys_measures = 0;
|
||||
|
||||
@@ -65,34 +65,12 @@ unsigned long timer_sys_checks = 0;
|
||||
// First Start of offline mode modules
|
||||
bool firstStart = true;
|
||||
|
||||
#define ARDUINOJSON_USE_LONG_LONG 1
|
||||
#define ARDUINOJSON_ENABLE_STD_STRING 1
|
||||
|
||||
#include <queue>
|
||||
int queueLength = -1; // We want to give one cycle of the loop before starting modules that are big msgs producers (example BT), to avoid queue overloading
|
||||
unsigned long queueLengthSum = 0;
|
||||
unsigned long blockedMessages = 0;
|
||||
unsigned long receivedMessages = 0;
|
||||
int maxQueueLength = 0;
|
||||
#ifndef QueueSize
|
||||
# define QueueSize 18
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Deep-sleep for the ESP8266 & ESP32 we need some form of indicator that we have posted the measurements and am ready to deep sleep.
|
||||
* Set this to true in the sensor code after publishing the measurement.
|
||||
*/
|
||||
bool ready_to_sleep = false;
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoLog.h>
|
||||
#include <PicoMQTT.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "LEDManager.h"
|
||||
#include "TheengsUtils.h"
|
||||
|
||||
LEDManager ledManager;
|
||||
|
||||
struct JsonBundle {
|
||||
@@ -112,12 +90,16 @@ SemaphoreHandle_t xMqttMutex;
|
||||
StaticJsonDocument<JSON_MSG_BUFFER> modulesBuffer;
|
||||
JsonArray modules = modulesBuffer.to<JsonArray>();
|
||||
bool ethConnected = false;
|
||||
char mqtt_topic[parameters_size + 1] = Base_Topic;
|
||||
char gateway_name[parameters_size + 1] = Gateway_Name;
|
||||
unsigned long lastDiscovery = 0;
|
||||
#if !MQTT_BROKER_MODE
|
||||
ss_cnt_parameters cnt_parameters_array[cnt_parameters_array_size] = CNT_PARAMS_ARR;
|
||||
#endif
|
||||
|
||||
#ifndef ZgatewayGFSunInverter
|
||||
// Arduino IDE compiles, it automatically creates all the header declarations for all the functions you have in your *.ino file.
|
||||
// Unfortunately it ignores #if directives.
|
||||
// This is a simple workaround for this problem.
|
||||
struct GfSun2000Data {};
|
||||
#if defined(ESP32)
|
||||
# include <Preferences.h>
|
||||
Preferences preferences;
|
||||
#endif
|
||||
|
||||
// Modules config inclusion
|
||||
@@ -235,9 +217,53 @@ struct GfSun2000Data {};
|
||||
#if defined(ZgatewaySERIAL)
|
||||
# include "config_SERIAL.h"
|
||||
#endif
|
||||
#if defined(USE_BLUFI) && defined(ESP32)
|
||||
extern bool isBlufiConnected();
|
||||
extern bool isStaConnecting();
|
||||
extern bool startBlufi();
|
||||
extern bool stopBlufi();
|
||||
#endif
|
||||
/*------------------------------------------------------------------------*/
|
||||
|
||||
bool pub(JsonObject& data);
|
||||
bool pubMQTT(const char* topic, const char* payload);
|
||||
bool pubMQTT(const char* topic, const char* payload, bool retainFlag);
|
||||
bool pubMQTT(String topic, const char* payload);
|
||||
bool pubMQTT(const char* topic, unsigned long payload);
|
||||
bool pubMQTT(const char* topic, unsigned long long payload);
|
||||
bool pubMQTT(const char* topic, String payload);
|
||||
bool pubMQTT(String topic, String payload);
|
||||
bool pubMQTT(String topic, int payload);
|
||||
bool pubMQTT(String topic, unsigned long long payload);
|
||||
bool pubMQTT(String topic, float payload);
|
||||
bool pubMQTT(const char* topic, float payload);
|
||||
bool pubMQTT(const char* topic, int payload);
|
||||
bool pubMQTT(const char* topic, unsigned int payload);
|
||||
bool pubMQTT(const char* topic, long payload);
|
||||
bool pubMQTT(const char* topic, double payload);
|
||||
bool pubMQTT(String topic, unsigned long payload);
|
||||
void checkButton();
|
||||
void ESPRestart(byte reason);
|
||||
void eraseConfig();
|
||||
void readCntParameters(int index);
|
||||
void saveConfig();
|
||||
void receivingDATA(const char* topicOri, const char* datacallback);
|
||||
void updateAndHandleLEDsTask(void* pvParameters);
|
||||
void updateAndHandleLEDsTask();
|
||||
bool loadConfigFromFlash();
|
||||
void setupWiFiManager();
|
||||
void setOTA();
|
||||
void setupCommonRF();
|
||||
void sleep();
|
||||
bool checkForUpdates();
|
||||
String stateMeasures();
|
||||
String stateRFMeasures();
|
||||
int getMin();
|
||||
void XtoRFset(const char* topicOri, JsonObject& RFdata);
|
||||
void MQTTHttpsFWUpdate(const char* topicOri, JsonObject& HttpsFwUpdateData);
|
||||
void setup_ethernet_esp32();
|
||||
void setupTLS(int index = CNT_DEFAULT_INDEX);
|
||||
void XtoSYS(const char* topicOri, JsonObject& SYSdata);
|
||||
|
||||
char ota_pass[parameters_size] = gw_password;
|
||||
#ifdef USE_MAC_AS_GATEWAY_NAME
|
||||
@@ -256,7 +282,7 @@ SYSConfig_s SYSConfig;
|
||||
|
||||
bool failSafeMode = false;
|
||||
bool ProcessLock = true; // Process lock when we want to use a critical function like OTA for example
|
||||
static bool mqttSetupPending = true;
|
||||
bool mqttSetupPending = true;
|
||||
static int cnt_index = CNT_DEFAULT_INDEX;
|
||||
|
||||
#ifdef ESP32
|
||||
@@ -367,20 +393,6 @@ std::unique_ptr< ::Client> eClient;
|
||||
std::unique_ptr<PicoMQTT::Client> mqtt;
|
||||
#endif
|
||||
|
||||
template <typename T> // Declared here to avoid pre-compilation issue (missing "template" in auto declaration by pio)
|
||||
void Config_update(JsonObject& data, const char* key, T& var);
|
||||
template <typename T>
|
||||
void Config_update(JsonObject& data, const char* key, T& var) {
|
||||
if (data.containsKey(key)) {
|
||||
if (var != data[key].as<T>()) {
|
||||
var = data[key].as<T>();
|
||||
Log.notice(F("Config %s changed to: %T" CR), key, data[key].as<T>());
|
||||
} else {
|
||||
Log.notice(F("Config %s unchanged, currently: %T" CR), key, data[key].as<T>());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Dispatch json messages towards the communication layer
|
||||
*
|
||||
@@ -419,7 +431,7 @@ bool jsonDispatch(JsonObject& data) {
|
||||
}
|
||||
|
||||
// Add a document to the queue
|
||||
boolean enqueueJsonObject(const StaticJsonDocument<JSON_MSG_BUFFER>& jsonDoc, int timeout) {
|
||||
bool enqueueJsonObject(const StaticJsonDocument<JSON_MSG_BUFFER>& jsonDoc, int timeout) {
|
||||
receivedMessages++;
|
||||
if (jsonDoc.size() == 0) {
|
||||
Log.error(F("Empty JSON, skipping" CR));
|
||||
@@ -1351,7 +1363,7 @@ void setup() {
|
||||
Serial.end();
|
||||
Serial.begin(SERIAL_BAUD, SERIAL_8N1, SERIAL_TX_ONLY); // enable on ESP8266 to free some pin
|
||||
# endif
|
||||
#elif ESP32
|
||||
#elif defined(ESP32)
|
||||
xTaskCreate(updateAndHandleLEDsTask, "updateAndHandleLEDsTask", 2500, NULL, 1, NULL);
|
||||
xQueueMutex = xSemaphoreCreateMutex();
|
||||
xMqttMutex = xSemaphoreCreateMutex();
|
||||
@@ -1405,8 +1417,10 @@ void setup() {
|
||||
#endif
|
||||
|
||||
#if defined(ESPWifiManualSetup)
|
||||
extern void setupWiFiFromBuild();
|
||||
setupWiFiFromBuild();
|
||||
#else
|
||||
WiFi.mode(WIFI_STA);
|
||||
if (loadConfigFromFlash()) { // Config present
|
||||
Log.notice(F("Config loaded from flash" CR));
|
||||
# ifdef ESP32_ETHERNET
|
||||
@@ -1421,6 +1435,7 @@ void setup() {
|
||||
|
||||
# if SELF_TEST
|
||||
// Check serial input to trigger a Self Test sequence if required
|
||||
extern void checkSerial();
|
||||
checkSerial();
|
||||
# endif
|
||||
|
||||
@@ -1503,21 +1518,12 @@ void setup() {
|
||||
#endif
|
||||
#ifdef ZgatewayRF
|
||||
modules.add(ZgatewayRF);
|
||||
# define ACTIVE_RECEIVER ACTIVE_RF
|
||||
#endif
|
||||
#ifdef ZgatewayRF2
|
||||
modules.add(ZgatewayRF2);
|
||||
# ifdef ACTIVE_RECEIVER
|
||||
# undef ACTIVE_RECEIVER
|
||||
# endif
|
||||
# define ACTIVE_RECEIVER ACTIVE_RF2
|
||||
#endif
|
||||
#ifdef ZgatewayPilight
|
||||
modules.add(ZgatewayPilight);
|
||||
# ifdef ACTIVE_RECEIVER
|
||||
# undef ACTIVE_RECEIVER
|
||||
# endif
|
||||
# define ACTIVE_RECEIVER ACTIVE_PILIGHT
|
||||
#endif
|
||||
#ifdef ZgatewayWeatherStation
|
||||
setupWeatherStation();
|
||||
@@ -1568,10 +1574,6 @@ void setup() {
|
||||
modules.add(ZactuatorPWM);
|
||||
#endif
|
||||
#ifdef ZactuatorSomfy
|
||||
# ifdef ACTIVE_RECEIVER
|
||||
# undef ACTIVE_RECEIVER
|
||||
# endif
|
||||
# define ACTIVE_RECEIVER ACTIVE_NONE
|
||||
setupSomfy();
|
||||
modules.add(ZactuatorSomfy);
|
||||
#endif
|
||||
@@ -1599,10 +1601,6 @@ void setup() {
|
||||
setupSHTC3();
|
||||
#endif
|
||||
#ifdef ZgatewayRTL_433
|
||||
# ifdef ACTIVE_RECEIVER
|
||||
# undef ACTIVE_RECEIVER
|
||||
# endif
|
||||
# define ACTIVE_RECEIVER ACTIVE_RTL
|
||||
setupRTL_433();
|
||||
modules.add(ZgatewayRTL_433);
|
||||
#endif
|
||||
@@ -1722,6 +1720,7 @@ void setupTLS(int index) {
|
||||
# if AWS_IOT
|
||||
if (strcmp(cnt_parameters_array[index].mqtt_port, "443") == 0) {
|
||||
Log.notice(F("Using ALPN" CR));
|
||||
static const char* alpnProtocols[] = ALPN_PROTOCOLS;
|
||||
sClient->setAlpnProtocols(alpnProtocols);
|
||||
}
|
||||
# endif
|
||||
@@ -1889,6 +1888,7 @@ void blockingWaitForReset() {
|
||||
Log.notice(F("Button Held" CR));
|
||||
// Switching off the relay during reset or failsafe operations
|
||||
# ifdef ZactuatorONOFF
|
||||
extern void ActuatorTrigger();
|
||||
uint8_t level = digitalRead(ACTUATOR_ONOFF_GPIO);
|
||||
if (level == ACTUATOR_ON) {
|
||||
ActuatorTrigger();
|
||||
@@ -2192,7 +2192,6 @@ bool loadConfigFromFlash() {
|
||||
|
||||
void setupWiFiManager() {
|
||||
delay(10);
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
# ifdef USE_MAC_AS_GATEWAY_NAME
|
||||
String s = WiFi.macAddress();
|
||||
@@ -2497,6 +2496,7 @@ void loop() {
|
||||
}
|
||||
if (firstStart) {
|
||||
#ifdef ZgatewaySERIAL
|
||||
extern bool isSerialReady();
|
||||
if (SYSConfig.serial && isSerialReady()) {
|
||||
# ifdef ZgatewayBT
|
||||
BTProcessLock = !BTConfig.enabled;
|
||||
@@ -2569,6 +2569,7 @@ void loop() {
|
||||
stateSSD1306Display();
|
||||
#endif
|
||||
#ifdef ZgatewayLORA
|
||||
extern String stateLORAMeasures();
|
||||
stateLORAMeasures();
|
||||
#endif
|
||||
#if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
|
||||
@@ -2604,6 +2605,7 @@ void loop() {
|
||||
MeasureLightIntensity(); //Addon to measure Light Intensity with a BH1750
|
||||
#endif
|
||||
#ifdef ZsensorMQ2
|
||||
extern void MeasureGasMQ2();
|
||||
MeasureGasMQ2();
|
||||
#endif
|
||||
#ifdef ZsensorTEMT6000
|
||||
@@ -2704,6 +2706,7 @@ void loop() {
|
||||
if (ready_to_sleep) {
|
||||
sleep();
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2979,6 +2982,7 @@ void receivingDATA(const char* topicOri, const char* datacallback) {
|
||||
//Log.notice(F("[ MQTT->OMG ]: %s" CR), buffer.c_str());
|
||||
|
||||
#ifdef ZgatewayPilight // ZgatewayPilight is only defined with json publishing due to its numerous parameters
|
||||
extern void XtoPilight(const char* topicOri, JsonObject& RFdata);
|
||||
XtoPilight(strTopicOri.c_str(), jsondata);
|
||||
#endif
|
||||
#if defined(ZgatewayRTL_433) || defined(ZgatewayPilight) || defined(ZgatewayRF) || defined(ZgatewayRF2) || defined(ZactuatorSomfy)
|
||||
@@ -3016,6 +3020,7 @@ void receivingDATA(const char* topicOri, const char* datacallback) {
|
||||
XtoPWM(strTopicOri.c_str(), jsondata);
|
||||
# endif
|
||||
# if defined(ZboardM5STICKC) || defined(ZboardM5STICKCP) || defined(ZboardM5STACK) || defined(ZboardM5TOUGH)
|
||||
void XtoM5(const char* topicOri, JsonObject& M5data);
|
||||
XtoM5(strTopicOri.c_str(), jsondata);
|
||||
# endif
|
||||
# if defined(ZdisplaySSD1306)
|
||||
@@ -3076,8 +3081,7 @@ void receivingDATA(const char* topicOri, const char* datacallback) {
|
||||
String latestVersion;
|
||||
# ifdef ESP32
|
||||
# include <HTTPClient.h>
|
||||
|
||||
# include "zzHTTPUpdate.h"
|
||||
# include <HTTPUpdate.h>
|
||||
|
||||
# if CHECK_OTA_UPDATE
|
||||
/**
|
||||
@@ -3358,6 +3362,7 @@ void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
SYSConfig.rgbbrightness = TheengsUtils::round2(SYSdata["rgbb"]);
|
||||
ledManager.setBrightness(SYSConfig.rgbbrightness);
|
||||
# ifdef ZactuatorONOFF
|
||||
extern void updatePowerIndicator();
|
||||
updatePowerIndicator();
|
||||
# endif
|
||||
Log.notice(F("RGB brightness: %d" CR), SYSConfig.rgbbrightness);
|
||||
@@ -3577,8 +3582,10 @@ void XtoSYS(const char* topicOri, JsonObject& SYSdata) { // json object decoding
|
||||
lastDiscovery = millis();
|
||||
SYSConfig.discovery = SYSdata["disc"];
|
||||
publishState = true;
|
||||
if (SYSConfig.discovery)
|
||||
if (SYSConfig.discovery) {
|
||||
extern void pubMqttDiscovery();
|
||||
pubMqttDiscovery();
|
||||
}
|
||||
} else {
|
||||
Log.warning(F("Discovery command not a boolean" CR));
|
||||
}
|
||||
@@ -24,14 +24,107 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <ArduinoJson.h>
|
||||
#include <ArduinoLog.h>
|
||||
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZmqttDiscovery
|
||||
# include "TheengsCommon.h"
|
||||
|
||||
# ifdef ESP8266
|
||||
# include <ESP8266WiFi.h>
|
||||
# elif defined(ESP32)
|
||||
# include <WiFi.h>
|
||||
|
||||
# include "esp_mac.h"
|
||||
# endif
|
||||
# ifdef ESP32_ETHERNET
|
||||
# include <ETH.h>
|
||||
# endif
|
||||
# include "config_mqttDiscovery.h"
|
||||
|
||||
extern bool ethConnected;
|
||||
extern JsonArray modules;
|
||||
|
||||
char discovery_prefix[parameters_size + 1] = discovery_Prefix;
|
||||
// From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L225
|
||||
// List of classes available in Home Assistant
|
||||
const char* availableHASSClasses[] = {"battery_charging",
|
||||
"battery",
|
||||
"carbon_dioxide",
|
||||
"carbon_monoxide",
|
||||
"current",
|
||||
"data_size",
|
||||
"distance",
|
||||
"door",
|
||||
"duration",
|
||||
"energy",
|
||||
"enum",
|
||||
"gas",
|
||||
"humidity",
|
||||
"illuminance",
|
||||
"irradiance",
|
||||
"lock",
|
||||
"motion",
|
||||
"moving",
|
||||
"pm1",
|
||||
"pm10",
|
||||
"pm25",
|
||||
"power_factor",
|
||||
"power",
|
||||
"precipitation_intensity",
|
||||
"precipitation",
|
||||
"pressure",
|
||||
"problem",
|
||||
"restart",
|
||||
"signal_strength",
|
||||
"sound_pressure",
|
||||
"temperature",
|
||||
"timestamp",
|
||||
"voltage",
|
||||
"water",
|
||||
"weight",
|
||||
"wind_speed",
|
||||
"window"};
|
||||
|
||||
// From https://github.com/home-assistant/core/blob/d7ac4bd65379e11461c7ce0893d3533d8d8b8cbf/homeassistant/const.py#L379
|
||||
// List of units available in Home Assistant
|
||||
const char* availableHASSUnits[] = {"W",
|
||||
"kW",
|
||||
"V",
|
||||
"kWh",
|
||||
"A",
|
||||
"W",
|
||||
"°C",
|
||||
"°F",
|
||||
"ms",
|
||||
"s",
|
||||
"min",
|
||||
"hPa",
|
||||
"L",
|
||||
"kg",
|
||||
"lb",
|
||||
"µS/cm",
|
||||
"ppm",
|
||||
"μg/m³",
|
||||
"m³",
|
||||
"mg/m³",
|
||||
"m/s²",
|
||||
"mV",
|
||||
"lx",
|
||||
"Ω",
|
||||
"%",
|
||||
"bar",
|
||||
"bpm",
|
||||
"dB",
|
||||
"dBm",
|
||||
"B",
|
||||
"UV index",
|
||||
"m/s",
|
||||
"km/h",
|
||||
"°",
|
||||
"mm",
|
||||
"mm/h",
|
||||
"cm"};
|
||||
|
||||
String getMacAddress() {
|
||||
uint8_t baseMac[6];
|
||||
char baseMacChr[13] = {0};
|
||||
@@ -53,9 +146,10 @@ String getUniqueId(String name, String sufix) {
|
||||
}
|
||||
|
||||
# if defined(ZgatewayBT) || defined(SecondaryModule)
|
||||
# include "config_BT.h"
|
||||
/**
|
||||
* Create a discover messages form a list of attribute
|
||||
*
|
||||
*
|
||||
* @param mac the MAC address
|
||||
* @param sensorList[][0] = component type
|
||||
* @param sensorList[][1] = name
|
||||
@@ -94,15 +188,15 @@ void createDiscoveryFromList(const char* mac,
|
||||
# endif
|
||||
|
||||
/**
|
||||
* @brief Announce that the Gateway have the ability to raise Trigger.
|
||||
* This function provide the configuration of the MQTT Device trigger ( @see https://www.home-assistant.io/integrations/device_trigger.mqtt/ ).
|
||||
* All messages published by this function will be interpreted as configuration messages of Gateway Triggers.
|
||||
* @brief Announce that the Gateway have the ability to raise Trigger.
|
||||
* This function provide the configuration of the MQTT Device trigger ( @see https://www.home-assistant.io/integrations/device_trigger.mqtt/ ).
|
||||
* All messages published by this function will be interpreted as configuration messages of Gateway Triggers.
|
||||
* Instead, all messages published on the "triggerTopic" will be interpreted as Gateway trigger.
|
||||
*
|
||||
* @param triggerTopic Mandatory - The MQTT topic subscribed to receive trigger events.
|
||||
* @param type The type of the trigger, e.g. button_short_press. Entries supported by the HA Frontend: button_short_press, button_short_release, button_long_press, button_long_release, button_double_press, button_triple_press, button_quadruple_press, button_quintuple_press. If set to an unsupported value, will render as subtype type, e.g. button_1 spammed with type set to spammed and subtype set to button_1
|
||||
* @param subtype The subtype of the trigger, e.g. button_1. Entries supported by the HA frontend: turn_on, turn_off, button_1, button_2, button_3, button_4, button_5, button_6. If set to an unsupported value, will render as subtype type, e.g. left_button pressed with type set to button_short_press and subtype set to left_button
|
||||
* @param object_id The object_id of the trigger.
|
||||
* @param object_id The object_id of the trigger.
|
||||
* @param value_template The template to render the value of the trigger. The template can use the variables trigger.id, trigger.type, trigger.subtype, trigger.payload, trigger.payload_json, trigger.topic, trigger.timestamp, trigger.value, trigger.value_json. The template can be a string or a JSON object. If the template is a JSON object, it must be a valid JSON object. If the template is a string, it will be rendered as a string. If the template is a JSON object, it will be rendered as a JSON object.
|
||||
*/
|
||||
void announceGatewayTrigger(const char* triggerTopic,
|
||||
@@ -116,7 +210,7 @@ void announceGatewayTrigger(const char* triggerTopic,
|
||||
|
||||
/**
|
||||
* The type of automation, must be ‘trigger’.
|
||||
* @see https://www.home-assistant.io/integrations/device_trigger.mqtt/#automation_type
|
||||
* @see https://www.home-assistant.io/integrations/device_trigger.mqtt/#automation_type
|
||||
*/
|
||||
sensor["automation_type"] = "trigger";
|
||||
|
||||
@@ -146,7 +240,7 @@ void announceGatewayTrigger(const char* triggerTopic,
|
||||
}
|
||||
|
||||
/**
|
||||
* The type of the trigger, e.g. button_short_press.
|
||||
* The type of the trigger, e.g. button_short_press.
|
||||
* Entries supported by the HA frontend: button_short_press, button_short_release, button_long_press, button_long_release, button_double_press, button_triple_press, button_quadruple_press, button_quintuple_press.
|
||||
* If set to an unsupported value, will render as subtype type, e.g. button_1 spammed with type set to spammed and subtype set to button_1
|
||||
*/
|
||||
@@ -157,8 +251,8 @@ void announceGatewayTrigger(const char* triggerTopic,
|
||||
}
|
||||
|
||||
/**
|
||||
* The subtype of the trigger, e.g. turn_on.
|
||||
* Entries supported by the frontend: turn_on, turn_off, button_1, button_2, button_3, button_4, button_5, button_6.
|
||||
* The subtype of the trigger, e.g. turn_on.
|
||||
* Entries supported by the frontend: turn_on, turn_off, button_1, button_2, button_3, button_4, button_5, button_6.
|
||||
* If set to an unsupported value, will render as subtype type, e.g. left_button pressed with type set to button_short_press and subtype set to left_button
|
||||
*/
|
||||
if (subtype && subtype[0] != 0) {
|
||||
@@ -187,7 +281,7 @@ void announceGatewayTrigger(const char* triggerTopic,
|
||||
}
|
||||
|
||||
/*
|
||||
* A list of connections of the device to the outside world as a list of tuples [connection_type, connection_identifier].
|
||||
* A list of connections of the device to the outside world as a list of tuples [connection_type, connection_identifier].
|
||||
* For example the MAC address of a network interface: "connections": [["mac", "02:5b:26:a8:dc:12"]].
|
||||
*/
|
||||
JsonArray connections = device.createNestedArray("connections");
|
||||
@@ -223,12 +317,12 @@ void announceGatewayTrigger(const char* triggerTopic,
|
||||
sensor["value_template"] = String(value_template);
|
||||
}
|
||||
|
||||
/* Publish on the topic
|
||||
The discovery topic needs to be: <discovery_prefix>/device_automation/[<node_id>/]<object_id>/config.
|
||||
|
||||
Note that only one trigger may be defined per unique discovery topic.
|
||||
/* Publish on the topic
|
||||
The discovery topic needs to be: <discovery_prefix>/device_automation/[<node_id>/]<object_id>/config.
|
||||
|
||||
Note that only one trigger may be defined per unique discovery topic.
|
||||
Also note that the combination of type and subtype should be unique for a device.
|
||||
|
||||
|
||||
*/
|
||||
|
||||
String topic_to_publish = String(discovery_prefix) + "/device_automation/" + String(unique_id) + "/" + object_id + "/config";
|
||||
@@ -254,7 +348,7 @@ std::string remove_substring(std::string s, const std::string& p) {
|
||||
|
||||
/**
|
||||
* @brief Generate message and publish it on an MQTT discovery explorer. For HA @see https://www.home-assistant.io/docs/mqtt/discovery/
|
||||
*
|
||||
*
|
||||
* @param sensor_type the Type
|
||||
* @param st_topic set state topic,
|
||||
* @param s_name set name,
|
||||
@@ -268,15 +362,15 @@ std::string remove_substring(std::string s, const std::string& p) {
|
||||
* @param off_delay set off_delay
|
||||
* @param payload_available set payload_available,
|
||||
* @param payload_not_available set payload_not_available
|
||||
* @param gateway_entity set is a gateway entity,
|
||||
* @param gateway_entity set is a gateway entity,
|
||||
* @param cmd_topic set command topic
|
||||
* @param device_name set device name,
|
||||
* @param device_manufacturer set device manufacturer,
|
||||
* @param device_model set device model,
|
||||
* @param device_id set device(BLE)/entity(RTL_433) identification,
|
||||
* @param device_name set device name,
|
||||
* @param device_manufacturer set device manufacturer,
|
||||
* @param device_model set device model,
|
||||
* @param device_id set device(BLE)/entity(RTL_433) identification,
|
||||
* @param retainCmd set retain
|
||||
* @param state_class set state class
|
||||
*
|
||||
*
|
||||
* */
|
||||
void createDiscovery(const char* sensor_type,
|
||||
const char* st_topic, const char* s_name, const char* unique_id,
|
||||
@@ -644,6 +738,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZdisplaySSD1306
|
||||
# include "config_SSD1306.h"
|
||||
createDiscovery("switch", //set Type
|
||||
subjectSSD1306toMQTT, "SSD1306: Control", (char*)getUniqueId("onstate", "").c_str(), //set state_topic,name,uniqueId
|
||||
will_Topic, "", "{{ value_json.onstate }}", //set availability_topic,device_class,value_template,
|
||||
@@ -795,6 +890,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorBME280
|
||||
# include "config_BME280.h"
|
||||
# define BMEparametersCount 5
|
||||
Log.trace(F("bme280Discovery" CR));
|
||||
char* BMEsensor[BMEparametersCount][8] = {
|
||||
@@ -819,6 +915,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorHTU21
|
||||
# include "config_HTU21.h"
|
||||
# define HTUparametersCount 2
|
||||
Log.trace(F("htu21Discovery" CR));
|
||||
char* HTUsensor[HTUparametersCount][8] = {
|
||||
@@ -856,6 +953,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorAHTx0
|
||||
# include "config_AHTx0.h"
|
||||
# define AHTparametersCount 2
|
||||
Log.trace(F("AHTx0Discovery" CR));
|
||||
char* AHTsensor[AHTparametersCount][8] = {
|
||||
@@ -877,6 +975,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorDHT
|
||||
# include "config_DHT.h"
|
||||
# define DHTparametersCount 2
|
||||
Log.trace(F("DHTDiscovery" CR));
|
||||
char* DHTsensor[DHTparametersCount][8] = {
|
||||
@@ -899,6 +998,8 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorADC
|
||||
# include "config_ADC.h"
|
||||
|
||||
Log.trace(F("ADCDiscovery" CR));
|
||||
char* ADCsensor[8] = {"sensor", "adc", "", "", jsonAdc, "", "", ""};
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
@@ -915,6 +1016,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorBH1750
|
||||
# include "config_BH1750.h"
|
||||
# define BH1750parametersCount 3
|
||||
Log.trace(F("BH1750Discovery" CR));
|
||||
char* BH1750sensor[BH1750parametersCount][8] = {
|
||||
@@ -938,6 +1040,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorMQ2
|
||||
# include "config_MQ2.h"
|
||||
# define MQ2parametersCount 2
|
||||
Log.trace(F("MQ2Discovery" CR));
|
||||
char* MQ2sensor[MQ2parametersCount][8] = {
|
||||
@@ -959,6 +1062,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorTEMT6000
|
||||
# include "config_TEMT6000.h"
|
||||
# define TEMT6000parametersCount 3
|
||||
Log.trace(F("TEMT6000Discovery" CR));
|
||||
char* TEMT6000sensor[TEMT6000parametersCount][8] = {
|
||||
@@ -982,6 +1086,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorTSL2561
|
||||
# include "config_TSL2561.h"
|
||||
# define TSL2561parametersCount 3
|
||||
Log.trace(F("TSL2561Discovery" CR));
|
||||
char* TSL2561sensor[TSL2561parametersCount][8] = {
|
||||
@@ -1005,6 +1110,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorHCSR501
|
||||
# include "config_HCSR501.h"
|
||||
Log.trace(F("HCSR501Discovery" CR));
|
||||
char* HCSR501sensor[8] = {"binary_sensor", "hcsr501", "", "motion", jsonPresence, "true", "false", ""};
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
@@ -1021,6 +1127,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorGPIOInput
|
||||
# include "config_GPIOInput.h"
|
||||
Log.trace(F("GPIOInputDiscovery" CR));
|
||||
char* GPIOInputsensor[8] = {"binary_sensor", "GPIOInput", "", "", jsonGpio, INPUT_GPIO_ON_VALUE, INPUT_GPIO_OFF_VALUE, ""};
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
@@ -1037,6 +1144,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorINA226
|
||||
# include "config_INA226.h"
|
||||
# define INA226parametersCount 3
|
||||
Log.trace(F("INA226Discovery" CR));
|
||||
char* INA226sensor[INA226parametersCount][8] = {
|
||||
@@ -1060,11 +1168,13 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorDS1820
|
||||
extern void pubOneWire_HADiscovery();
|
||||
// Publish any DS1820 sensors found on the OneWire bus
|
||||
pubOneWire_HADiscovery();
|
||||
# endif
|
||||
|
||||
# ifdef ZactuatorONOFF
|
||||
# include "config_ONOFF.h"
|
||||
Log.trace(F("actuatorONOFFDiscovery" CR));
|
||||
char* actuatorONOFF[8] = {"switch", "actuatorONOFF", "", "", "{{ value_json.cmd }}", "{\"cmd\":1}", "{\"cmd\":0}", ""};
|
||||
//component type,name,availability topic,device class,value template,payload on, payload off, unit of measurement
|
||||
@@ -1082,6 +1192,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZsensorRN8209
|
||||
# include "config_RN8209.h"
|
||||
# define RN8209parametersCount 4
|
||||
Log.trace(F("RN8209Discovery" CR));
|
||||
char* RN8209sensor[RN8209parametersCount][8] = {
|
||||
@@ -1130,6 +1241,8 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayRF2
|
||||
# include "config_RF.h"
|
||||
|
||||
// Sensor to display RF received value
|
||||
Log.trace(F("gatewayRF2Discovery" CR));
|
||||
char* gatewayRF2[8] = {"sensor", "gatewayRF2", "", "", jsonAddress, "", "", ""};
|
||||
@@ -1152,6 +1265,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayRFM69
|
||||
# include "config_RFM69.h"
|
||||
// Sensor to display RF received value
|
||||
Log.trace(F("gatewayRFM69Discovery" CR));
|
||||
char* gatewayRFM69[8] = {"sensor", "gatewayRFM69", "", "", jsonVal, "", "", ""};
|
||||
@@ -1169,6 +1283,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayLORA
|
||||
# include "config_LORA.h"
|
||||
// Sensor to display RF received value
|
||||
Log.trace(F("gatewayLORADiscovery" CR));
|
||||
char* gatewayLORA[8] = {"sensor", "gatewayLORA", "", "", jsonMsg, "", "", ""};
|
||||
@@ -1219,6 +1334,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewaySRFB
|
||||
# include "config_SRFB.h"
|
||||
// Sensor to display RF received value
|
||||
Log.trace(F("gatewaySRFBDiscovery" CR));
|
||||
char* gatewaySRFB[8] = {"sensor", "gatewaySRFB", "", "", jsonVal, "", "", ""};
|
||||
@@ -1236,6 +1352,8 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayPilight
|
||||
# include "config_RF.h"
|
||||
|
||||
// Sensor to display RF received value
|
||||
Log.trace(F("gatewayPilightDiscovery" CR));
|
||||
char* gatewayPilight[8] = {"sensor", "gatewayPilight", "", "", jsonMsg, "", "", ""};
|
||||
@@ -1258,6 +1376,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef ZgatewayIR
|
||||
# include "config_IR.h"
|
||||
// Sensor to display IR received value
|
||||
Log.trace(F("gatewayIRDiscovery" CR));
|
||||
char* gatewayIR[8] = {"sensor", "gatewayIR", "", "", jsonVal, "", "", ""};
|
||||
@@ -1275,6 +1394,7 @@ void pubMqttDiscovery() {
|
||||
# endif
|
||||
|
||||
# ifdef Zgateway2G
|
||||
# include "config_2G.h"
|
||||
// Sensor to display 2G received value
|
||||
Log.trace(F("gateway2GDiscovery" CR));
|
||||
char* gateway2G[8] = {"sensor", "gateway2G", "", "", jsonMsg, "", "", ""};
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorADC
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_ADC.h"
|
||||
|
||||
# if defined(ESP8266)
|
||||
ADC_MODE(ADC_TOUT);
|
||||
@@ -41,6 +41,7 @@
|
||||
# include <stdint.h>
|
||||
|
||||
# include "Adafruit_AHTX0.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h" // Library for communication with I2C / TWI devices
|
||||
# include "config_AHTx0.h"
|
||||
|
||||
@@ -39,9 +39,15 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorBH1750
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h" // Library for communication with I2C / TWI devices
|
||||
# include "config_BH1750.h"
|
||||
# include "math.h" // Library for trig and exponential functions
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
static unsigned long timebh1750 = 0;
|
||||
static int BH1750_i2c_addr = BH1750_I2C_ADDR;
|
||||
|
||||
void setupZsensorBH1750() {
|
||||
Log.notice(F("Setup BH1750 on adress: %H" CR), BH1750_i2c_addr);
|
||||
Wire.begin();
|
||||
@@ -43,10 +43,14 @@
|
||||
# include <stdint.h>
|
||||
|
||||
# include "SparkFunBME280.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h" // Library for communication with I2C / TWI devices
|
||||
# include "config_BME280.h"
|
||||
|
||||
//Global sensor object
|
||||
BME280 mySensor;
|
||||
//Time used to wait for an interval before resending measured values
|
||||
static unsigned long timebme280 = 0;
|
||||
static int BME280_i2c_addr = BME280_I2C_ADDR; // Default I2C address for BME280 is 0x76, for BMP280 is 0x77
|
||||
static BME280 mySensor;
|
||||
|
||||
void setupZsensorBME280() {
|
||||
// Allow custom pins on ESP Platforms
|
||||
@@ -24,6 +24,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorC37_YL83_HMRD
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_C37_YL83_HMRD.h"
|
||||
|
||||
//Time used to wait for an interval before resending temp and hum
|
||||
unsigned long timeC37YL83HMRD = 0;
|
||||
@@ -33,6 +33,9 @@
|
||||
# include <DHT.h>
|
||||
# include <DHT_U.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_DHT.h"
|
||||
|
||||
DHT dht(DHT_RECEIVER_GPIO, DHT_SENSOR_TYPE);
|
||||
|
||||
//Time used to wait for an interval before resending temp and hum
|
||||
@@ -29,6 +29,9 @@
|
||||
# include <DallasTemperature.h>
|
||||
# include <OneWire.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_DS1820.h"
|
||||
|
||||
OneWire owbus(DS1820_OWBUS_GPIO);
|
||||
DallasTemperature ds1820(&owbus);
|
||||
DeviceAddress ds1820_address, ds1820_devices[OW_MAX_SENSORS];
|
||||
@@ -38,6 +41,15 @@ static uint8_t ds1820_resolution[OW_MAX_SENSORS];
|
||||
static String ds1820_type[OW_MAX_SENSORS];
|
||||
static String ds1820_addr[OW_MAX_SENSORS];
|
||||
|
||||
extern void createDiscovery(const char* sensor_type,
|
||||
const char* st_topic, const char* s_name, const char* unique_id,
|
||||
const char* availability_topic, const char* device_class, const char* value_template,
|
||||
const char* payload_on, const char* payload_off, const char* unit_of_meas,
|
||||
int off_delay,
|
||||
const char* payload_available, const char* payload_not_available, bool gateway_entity, const char* cmd_topic,
|
||||
const char* device_name, const char* device_manufacturer, const char* device_model, const char* device_id, bool retainCmd,
|
||||
const char* state_class, const char* state_off, const char* state_on, const char* enum_options, const char* command_template);
|
||||
|
||||
void setupZsensorDS1820() {
|
||||
Log.trace(F("DS1820: configured pin: %d for 1-wire bus" CR), DS1820_OWBUS_GPIO);
|
||||
ds1820.begin();
|
||||
@@ -100,6 +112,8 @@ void setupZsensorDS1820() {
|
||||
void pubOneWire_HADiscovery() {
|
||||
// If zmqttDiscovery is enabled, create a sensor topic for each DS18b20 sensor found on the bus, using addr as uniqueID
|
||||
# ifdef ZmqttDiscovery
|
||||
# include "config_mqttDiscovery.h"
|
||||
|
||||
// If zmqtt discovery is enabled, create a sensor topic for each DS18b20 sensor found on the bus, using addr as uniqueID
|
||||
if (SYSConfig.discovery) {
|
||||
for (int index = 0; index < ds1820_count; index++) {
|
||||
@@ -29,6 +29,12 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorGPIOInput
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_GPIOInput.h"
|
||||
|
||||
extern void ActuatorTrigger();
|
||||
extern void eraseConfig();
|
||||
|
||||
# if defined(TRIGGER_GPIO) && INPUT_GPIO == TRIGGER_GPIO
|
||||
unsigned long resetTime = 0;
|
||||
# endif
|
||||
@@ -26,6 +26,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorGPIOKeyCode
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_GPIOKeyCode.h"
|
||||
|
||||
int InputStateGPIOKeyCode = 0x0f; // Set to 3 so that it reads on startup
|
||||
int lastInputStateGPIOKeyCode = 0x0f;
|
||||
@@ -30,6 +30,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorHCSR04
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_HCSR04.h"
|
||||
|
||||
unsigned long timeHCSR04 = 0;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorHCSR501
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_HCSR501.h"
|
||||
|
||||
void setupHCSR501() {
|
||||
Log.notice(F("HCSR501 pin: %d" CR), HCSR501_GPIO);
|
||||
@@ -41,6 +41,7 @@
|
||||
# include <stdint.h>
|
||||
|
||||
# include "SparkFunHTU21D.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h" // Library for communication with I2C / TWI devices
|
||||
# include "config_HTU21.h"
|
||||
|
||||
@@ -37,6 +37,12 @@
|
||||
#ifdef ZsensorINA226
|
||||
# include <Wire.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_INA226.h"
|
||||
|
||||
static void writeRegister(byte reg, word value);
|
||||
static word readRegister(byte reg);
|
||||
|
||||
float rShunt = 0.1; // Shunt Widerstand festlegen, hier 0.1 Ohm
|
||||
const int INA226_ADDR = 0x40; // A0 und A1 auf GND > Adresse 40 Hex auf Seite 18 im Datenblatt
|
||||
|
||||
@@ -77,7 +83,7 @@ void MeasureINA226() {
|
||||
}
|
||||
}
|
||||
|
||||
static void writeRegister(byte reg, word value) {
|
||||
void writeRegister(byte reg, word value) {
|
||||
Wire.beginTransmission(INA226_ADDR);
|
||||
Wire.write(reg);
|
||||
Wire.write((value >> 8) & 0xFF);
|
||||
@@ -85,7 +91,7 @@ static void writeRegister(byte reg, word value) {
|
||||
Wire.endTransmission();
|
||||
}
|
||||
|
||||
static word readRegister(byte reg) {
|
||||
word readRegister(byte reg) {
|
||||
word res = 0x0000;
|
||||
Wire.beginTransmission(INA226_ADDR);
|
||||
Wire.write(reg);
|
||||
@@ -41,6 +41,7 @@
|
||||
# include <stdint.h>
|
||||
|
||||
# include "Temperature_LM75_Derived.h"
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h" // Library for communication with I2C / TWI devices
|
||||
# include "config_LM75.h"
|
||||
|
||||
@@ -36,10 +36,14 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorMQ2
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h"
|
||||
# include "config_MQ2.h"
|
||||
# include "math.h"
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
unsigned long timemq2 = 0;
|
||||
|
||||
void setupZsensorMQ2() {
|
||||
Log.notice(F("Setup MQ2 detection on pin: %d" CR), MQ2SENSORDETECTPIN);
|
||||
pinMode(MQ2SENSORDETECTPIN, INPUT); // declare GPIOInput pin as input_pullup to prevent floating. Pin will be high when not connected to ground
|
||||
@@ -24,14 +24,21 @@
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#ifdef ZsensorRN8209
|
||||
#include "User_config.h"
|
||||
|
||||
# include "ArduinoJson.h"
|
||||
# include "driver/uart.h"
|
||||
# include "rn8209_flash.h"
|
||||
# include "rn8209c_user.h"
|
||||
#ifdef ZsensorRN8209
|
||||
# include <TheengsUtils.h>
|
||||
# include <driver/uart.h>
|
||||
# include <rn8209_flash.h>
|
||||
# include <rn8209c_user.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_RN8209.h"
|
||||
|
||||
extern "C" bool init_8209c_interface();
|
||||
extern void overLimitCurrent(float RN8209current);
|
||||
|
||||
extern bool ProcessLock;
|
||||
|
||||
float voltage = 0;
|
||||
float current = 0;
|
||||
@@ -112,7 +119,7 @@ void setupRN8209() {
|
||||
init_8209c_interface();
|
||||
xTaskCreate(rn8209_loop, "rn8209_loop", RN8209_TASK_STACK_SIZE_OVERRIDE, NULL, 10, &rn8209TaskHandle);
|
||||
//esp_task_wdt_add(rn8209TaskHandle);
|
||||
Log.trace(F("ZsensorRN8209 setup done " CR));
|
||||
Log.trace(F("sensorRN8209 setup done " CR));
|
||||
}
|
||||
|
||||
#endif // ZsensorRN8209
|
||||
@@ -3,6 +3,8 @@
|
||||
#ifdef ZsensorSHTC3
|
||||
# include <SparkFun_SHTC3.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
|
||||
SHTC3 mySHTC3;
|
||||
|
||||
//Time used to wait for an interval before resending temp and hum
|
||||
@@ -38,10 +38,14 @@
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorTEMT6000
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h"
|
||||
# include "config_TEMT6000.h"
|
||||
# include "math.h"
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
static unsigned long timetemt6000 = 0;
|
||||
|
||||
void setupZsensorTEMT6000() {
|
||||
Log.notice(F("Setup TEMT6000 on pin: %i" CR), TEMT6000LIGHTSENSORPIN);
|
||||
pinMode(TEMT6000LIGHTSENSORPIN, INPUT);
|
||||
@@ -43,9 +43,15 @@
|
||||
# include <Adafruit_Sensor.h>
|
||||
# include <Adafruit_TSL2561_U.h>
|
||||
|
||||
# include "TheengsCommon.h"
|
||||
# include "Wire.h"
|
||||
# include "config_TSL2561.h"
|
||||
# include "math.h"
|
||||
|
||||
//Time used to wait for an interval before resending measured values
|
||||
static unsigned long timetsl2561 = 0;
|
||||
//int TSL2561_i2c_addr = 0x37; // Light Sensor I2C Address (Set in Adafruit library)
|
||||
|
||||
Adafruit_TSL2561_Unified tsl = Adafruit_TSL2561_Unified(TSL2561_ADDR_FLOAT, 12345);
|
||||
|
||||
void displaySensorDetails(void) {
|
||||
@@ -1,155 +1,153 @@
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
For esp32, touch sensor reading add-on.
|
||||
|
||||
Copyright: (c) Florian Xhumari
|
||||
|
||||
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
|
||||
(at your option) any later version.
|
||||
|
||||
OpenMQTTGateway is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#include <HardwareSerial.h>
|
||||
|
||||
#include "ArduinoJson.h"
|
||||
#include "User_config.h"
|
||||
#include "config_Touch.h"
|
||||
|
||||
#ifdef ZsensorTouch
|
||||
|
||||
# ifndef ESP32
|
||||
# error Only supported on esp32
|
||||
# endif
|
||||
|
||||
//Time used to wait for an interval before resending touch sensor value
|
||||
static unsigned long touchTimeRead = 0;
|
||||
|
||||
// for each touch button
|
||||
struct TouchStatus {
|
||||
uint8_t pin;
|
||||
uint16_t timePublished = 0;
|
||||
uint16_t timeStatusChanged = 0;
|
||||
uint16_t avg = 10 * 256; // starting value; multiplied by 256
|
||||
bool isOn = false;
|
||||
bool wasOn = false;
|
||||
int onCount = 0; // number of consecutive readings that were considered "ON"
|
||||
unsigned long onTime; // time the button was turned on
|
||||
};
|
||||
|
||||
static TouchStatus status[TOUCH_SENSORS];
|
||||
|
||||
void setupTouch() {
|
||||
# if TOUCH_SENSORS > 0
|
||||
status[0].pin = TOUCH_GPIO_0;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 1
|
||||
status[1].pin = TOUCH_GPIO_1;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 2
|
||||
status[2].pin = TOUCH_GPIO_2;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 3
|
||||
status[3].pin = TOUCH_GPIO_3;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 4
|
||||
status[4].pin = TOUCH_GPIO_4;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 5
|
||||
status[5].pin = TOUCH_GPIO_5;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 6
|
||||
status[6].pin = TOUCH_GPIO_6;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 7
|
||||
status[7].pin = TOUCH_GPIO_7;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 8
|
||||
status[8].pin = TOUCH_GPIO_8;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 9
|
||||
status[9].pin = TOUCH_GPIO_9;
|
||||
# endif
|
||||
for (int i = 0; i < TOUCH_SENSORS; i++) {
|
||||
Log.notice(F("TOUCH_GPIO_%d: %d" CR), i, status[i].pin);
|
||||
}
|
||||
touchTimeRead = millis() - TOUCH_TIME_BETWEEN_READINGS; // so we get a first reading at the beginning
|
||||
}
|
||||
|
||||
void MeasureTouch() {
|
||||
unsigned long now = millis();
|
||||
if (now - touchTimeRead < TOUCH_TIME_BETWEEN_READINGS) {
|
||||
return;
|
||||
}
|
||||
touchTimeRead = now;
|
||||
for (int i = 0; i < TOUCH_SENSORS; i++) {
|
||||
TouchStatus* button = &status[i];
|
||||
|
||||
uint16_t val = touchRead(button->pin);
|
||||
if (val == 0) {
|
||||
// just ignore a 0 reading
|
||||
continue;
|
||||
}
|
||||
|
||||
// we'll work in 1/265th of a unit value returned by touchRead(), in order
|
||||
// to have a better precision when performing averages and divisions, while
|
||||
// not using floating point calculations.
|
||||
uint16_t curValue = val * 256;
|
||||
bool isOn = (curValue < button->avg * (TOUCH_THRESHOLD * 256 / 100) / 256); // just so that we divide by 256 and not by 100
|
||||
if (!isOn) {
|
||||
button->avg = (button->avg * 127 + val * 256 * 1) / 128; // exponential averaging, factor = 1/128
|
||||
}
|
||||
int lastOnCount = button->onCount;
|
||||
if (isOn) {
|
||||
++button->onCount;
|
||||
} else {
|
||||
button->onCount = 0;
|
||||
}
|
||||
|
||||
bool isStatusChanged = false;
|
||||
if (((button->wasOn && !isOn) || (!button->wasOn && isOn && button->onCount >= TOUCH_MIN_DURATION / TOUCH_TIME_BETWEEN_READINGS)) && now - button->timeStatusChanged > TOUCH_DEBOUNCE_TIME) { // debounce
|
||||
isStatusChanged = true;
|
||||
button->wasOn = isOn;
|
||||
button->timeStatusChanged = now;
|
||||
if (isOn) {
|
||||
button->onTime = now;
|
||||
}
|
||||
}
|
||||
// keep timeStatusChanged from getting too old, so not to go
|
||||
// beyond timestamp wrapping
|
||||
if (now - button->timeStatusChanged > 100000) {
|
||||
button->timeStatusChanged = now - 100000;
|
||||
}
|
||||
if (isStatusChanged) {
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonDoc;
|
||||
JsonObject touchData = jsonDoc.to<JsonObject>();
|
||||
touchData["id"] = i;
|
||||
touchData["on"] = (isOn ? 1 : 0);
|
||||
touchData["value"] = (int)(curValue / 256);
|
||||
if (!isOn) { // when turning off, send the duration the button was on
|
||||
touchData["onDuration"] = now - button->onTime + TOUCH_MIN_DURATION;
|
||||
}
|
||||
touchData["origin"] = subjectTouchtoMQTT;
|
||||
enqueueJsonObject(touchData);
|
||||
button->timePublished = now;
|
||||
}
|
||||
// adjust measure time so that min(avg of all buttons) is around 60 (between 40 and 80)
|
||||
// TODO
|
||||
|
||||
} // loop
|
||||
}
|
||||
#endif
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
For esp32, touch sensor reading add-on.
|
||||
|
||||
Copyright: (c) Florian Xhumari
|
||||
|
||||
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
|
||||
(at your option) any later version.
|
||||
|
||||
OpenMQTTGateway is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "User_config.h"
|
||||
|
||||
#ifdef ZsensorTouch
|
||||
# include "TheengsCommon.h"
|
||||
# include "config_Touch.h"
|
||||
# ifndef ESP32
|
||||
# error Only supported on esp32
|
||||
# endif
|
||||
|
||||
//Time used to wait for an interval before resending touch sensor value
|
||||
static unsigned long touchTimeRead = 0;
|
||||
|
||||
// for each touch button
|
||||
struct TouchStatus {
|
||||
uint8_t pin;
|
||||
uint16_t timePublished = 0;
|
||||
uint16_t timeStatusChanged = 0;
|
||||
uint16_t avg = 10 * 256; // starting value; multiplied by 256
|
||||
bool isOn = false;
|
||||
bool wasOn = false;
|
||||
int onCount = 0; // number of consecutive readings that were considered "ON"
|
||||
unsigned long onTime; // time the button was turned on
|
||||
};
|
||||
|
||||
static TouchStatus status[TOUCH_SENSORS];
|
||||
|
||||
void setupTouch() {
|
||||
# if TOUCH_SENSORS > 0
|
||||
status[0].pin = TOUCH_GPIO_0;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 1
|
||||
status[1].pin = TOUCH_GPIO_1;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 2
|
||||
status[2].pin = TOUCH_GPIO_2;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 3
|
||||
status[3].pin = TOUCH_GPIO_3;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 4
|
||||
status[4].pin = TOUCH_GPIO_4;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 5
|
||||
status[5].pin = TOUCH_GPIO_5;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 6
|
||||
status[6].pin = TOUCH_GPIO_6;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 7
|
||||
status[7].pin = TOUCH_GPIO_7;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 8
|
||||
status[8].pin = TOUCH_GPIO_8;
|
||||
# endif
|
||||
# if TOUCH_SENSORS > 9
|
||||
status[9].pin = TOUCH_GPIO_9;
|
||||
# endif
|
||||
for (int i = 0; i < TOUCH_SENSORS; i++) {
|
||||
Log.notice(F("TOUCH_GPIO_%d: %d" CR), i, status[i].pin);
|
||||
}
|
||||
touchTimeRead = millis() - TOUCH_TIME_BETWEEN_READINGS; // so we get a first reading at the beginning
|
||||
}
|
||||
|
||||
void MeasureTouch() {
|
||||
unsigned long now = millis();
|
||||
if (now - touchTimeRead < TOUCH_TIME_BETWEEN_READINGS) {
|
||||
return;
|
||||
}
|
||||
touchTimeRead = now;
|
||||
for (int i = 0; i < TOUCH_SENSORS; i++) {
|
||||
TouchStatus* button = &status[i];
|
||||
|
||||
uint16_t val = touchRead(button->pin);
|
||||
if (val == 0) {
|
||||
// just ignore a 0 reading
|
||||
continue;
|
||||
}
|
||||
|
||||
// we'll work in 1/265th of a unit value returned by touchRead(), in order
|
||||
// to have a better precision when performing averages and divisions, while
|
||||
// not using floating point calculations.
|
||||
uint16_t curValue = val * 256;
|
||||
bool isOn = (curValue < button->avg * (TOUCH_THRESHOLD * 256 / 100) / 256); // just so that we divide by 256 and not by 100
|
||||
if (!isOn) {
|
||||
button->avg = (button->avg * 127 + val * 256 * 1) / 128; // exponential averaging, factor = 1/128
|
||||
}
|
||||
int lastOnCount = button->onCount;
|
||||
if (isOn) {
|
||||
++button->onCount;
|
||||
} else {
|
||||
button->onCount = 0;
|
||||
}
|
||||
|
||||
bool isStatusChanged = false;
|
||||
if (((button->wasOn && !isOn) || (!button->wasOn && isOn && button->onCount >= TOUCH_MIN_DURATION / TOUCH_TIME_BETWEEN_READINGS)) && now - button->timeStatusChanged > TOUCH_DEBOUNCE_TIME) { // debounce
|
||||
isStatusChanged = true;
|
||||
button->wasOn = isOn;
|
||||
button->timeStatusChanged = now;
|
||||
if (isOn) {
|
||||
button->onTime = now;
|
||||
}
|
||||
}
|
||||
// keep timeStatusChanged from getting too old, so not to go
|
||||
// beyond timestamp wrapping
|
||||
if (now - button->timeStatusChanged > 100000) {
|
||||
button->timeStatusChanged = now - 100000;
|
||||
}
|
||||
if (isStatusChanged) {
|
||||
const int JSON_MSG_CALC_BUFFER = JSON_OBJECT_SIZE(4);
|
||||
StaticJsonDocument<JSON_MSG_CALC_BUFFER> jsonDoc;
|
||||
JsonObject touchData = jsonDoc.to<JsonObject>();
|
||||
touchData["id"] = i;
|
||||
touchData["on"] = (isOn ? 1 : 0);
|
||||
touchData["value"] = (int)(curValue / 256);
|
||||
if (!isOn) { // when turning off, send the duration the button was on
|
||||
touchData["onDuration"] = now - button->onTime + TOUCH_MIN_DURATION;
|
||||
}
|
||||
touchData["origin"] = subjectTouchtoMQTT;
|
||||
enqueueJsonObject(touchData);
|
||||
button->timePublished = now;
|
||||
}
|
||||
// adjust measure time so that min(avg of all buttons) is around 60 (between 40 and 80)
|
||||
// TODO
|
||||
|
||||
} // loop
|
||||
}
|
||||
#endif
|
||||
@@ -1,13 +1,13 @@
|
||||
/*
|
||||
/*
|
||||
Theengs OpenMQTTGateway - We Unite Sensors in One Open-Source Interface
|
||||
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Act as a gateway between your 433mhz, infrared IR, BLE, LoRa signal and one interface like an MQTT broker
|
||||
Send and receiving command by MQTT
|
||||
|
||||
Copyright: (c)Florian ROBERT
|
||||
|
||||
|
||||
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
|
||||
@@ -23,11 +23,10 @@
|
||||
*/
|
||||
#include "User_config.h"
|
||||
#if defined(ZwebUI) && defined(ESP32)
|
||||
# include <ArduinoJson.h>
|
||||
# include <SPIFFS.h>
|
||||
# include <WebServer.h> // Docs for this are here - https://github.com/espressif/arduino-esp32/tree/master/libraries/WebServer
|
||||
# include <WiFi.h>
|
||||
|
||||
# include "ArduinoLog.h"
|
||||
# include "config_WebContent.h"
|
||||
# include "config_WebUI.h"
|
||||
|
||||
@@ -39,15 +38,34 @@
|
||||
# include "config_SSD1306.h"
|
||||
# endif
|
||||
|
||||
extern String stateRFMeasures();
|
||||
|
||||
uint32_t requestToken = 0;
|
||||
|
||||
QueueHandle_t webUIQueue;
|
||||
|
||||
WebServer server(80);
|
||||
|
||||
webUIQueueMessage* currentWebUIMessage;
|
||||
|
||||
extern JsonArray modules;
|
||||
extern char discovery_prefix[];
|
||||
extern String latestVersion;
|
||||
|
||||
bool WebUIConfig_save();
|
||||
void sendRestartPage();
|
||||
bool WebUIConfig_load();
|
||||
void WebUIConfig_init();
|
||||
void addLog(const uint8_t* buffer, size_t size);
|
||||
|
||||
/*------------------- External functions ----------------------*/
|
||||
extern void eraseConfig();
|
||||
extern unsigned long uptime();
|
||||
extern void ESPRestart(byte reason);
|
||||
extern void XtoSYS(const char* topicOri, JsonObject& SYSdata);
|
||||
extern String stateMeasures();
|
||||
extern void MQTTHttpsFWUpdate(const char* topicOri, JsonObject& HttpsFwUpdateData);
|
||||
extern void receivingDATA(const char* topicOri, const char* datacallback);
|
||||
|
||||
/*------------------- Web Console Globals ----------------------*/
|
||||
|
||||
@@ -284,30 +302,6 @@ void AddLogData(uint32_t loglevel, const char* log_data, const char* log_data_pa
|
||||
}
|
||||
}
|
||||
|
||||
bool NeedLogRefresh(uint32_t req_loglevel, uint32_t index) {
|
||||
if (!log_buffer) {
|
||||
return false;
|
||||
} // Leave now if there is no buffer available
|
||||
|
||||
# ifdef ESP32
|
||||
// this takes the mutex, and will be release when the class is destroyed -
|
||||
// i.e. when the functon leaves You CAN call mutex.give() to leave early.
|
||||
TasAutoMutex mutex((SemaphoreHandle_t*)&log_buffer_mutex);
|
||||
# endif // ESP32
|
||||
|
||||
// Skip initial buffer fill
|
||||
if (strlen(log_buffer) < LOG_BUFFER_SIZE / 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char* line;
|
||||
size_t len;
|
||||
if (!GetLog(req_loglevel, &index, &line, &len)) {
|
||||
return false;
|
||||
}
|
||||
return ((line - log_buffer) < LOG_BUFFER_SIZE / 4);
|
||||
}
|
||||
|
||||
bool GetLog(uint32_t req_loglevel, uint32_t* index_p, char** entry_pp, size_t* len_p) {
|
||||
if (!log_buffer) {
|
||||
return false;
|
||||
@@ -365,6 +359,30 @@ bool GetLog(uint32_t req_loglevel, uint32_t* index_p, char** entry_pp, size_t* l
|
||||
return false;
|
||||
}
|
||||
|
||||
bool NeedLogRefresh(uint32_t req_loglevel, uint32_t index) {
|
||||
if (!log_buffer) {
|
||||
return false;
|
||||
} // Leave now if there is no buffer available
|
||||
|
||||
# ifdef ESP32
|
||||
// this takes the mutex, and will be release when the class is destroyed -
|
||||
// i.e. when the functon leaves You CAN call mutex.give() to leave early.
|
||||
TasAutoMutex mutex((SemaphoreHandle_t*)&log_buffer_mutex);
|
||||
# endif // ESP32
|
||||
|
||||
// Skip initial buffer fill
|
||||
if (strlen(log_buffer) < LOG_BUFFER_SIZE / 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
char* line;
|
||||
size_t len;
|
||||
if (!GetLog(req_loglevel, &index, &line, &len)) {
|
||||
return false;
|
||||
}
|
||||
return ((line - log_buffer) < LOG_BUFFER_SIZE / 4);
|
||||
}
|
||||
|
||||
/*------------------- Local functions ----------------------*/
|
||||
|
||||
# ifdef WEBUI_DEVELOPMENT
|
||||
@@ -394,7 +412,7 @@ bool exists(String path) {
|
||||
|
||||
/**
|
||||
* @brief / - Page
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleRoot() {
|
||||
WEBUI_TRACE_LOG(F("handleRoot: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -454,7 +472,7 @@ void handleRoot() {
|
||||
|
||||
/**
|
||||
* @brief /CN - Configuration Page
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleCN() {
|
||||
WEBUI_SECURE
|
||||
@@ -688,7 +706,7 @@ void handleWI() {
|
||||
* T: handleMQ Arg: 0, mh=192.168.1.11
|
||||
* T: handleMQ Arg: 1, ml=1883
|
||||
* T: handleMQ Arg: 2, mu=1234
|
||||
* T: handleMQ Arg: 3, mp=
|
||||
* T: handleMQ Arg: 3, mp=
|
||||
* T: handleMQ Arg: 4, sc=on
|
||||
* T: handleMQ Arg: 5, h=
|
||||
* T: handleMQ Arg: 6, mt=home/
|
||||
@@ -937,6 +955,11 @@ void handleLO() {
|
||||
}
|
||||
|
||||
# ifdef ZgatewayLORA
|
||||
# include "config_LORA.h"
|
||||
extern void LORAConfig_fromJson(JsonObject& LORAdata);
|
||||
extern String stateLORAMeasures();
|
||||
extern LORAConfig_s LORAConfig;
|
||||
|
||||
/**
|
||||
* @brief /LA - Configure LORA Page
|
||||
* T: handleLA: uri: /la, args: 11, method: 1
|
||||
@@ -1108,6 +1131,17 @@ std::map<int, String> activeReceiverOptions = {
|
||||
# endif
|
||||
};
|
||||
|
||||
struct RFConfig_s {
|
||||
float frequency;
|
||||
int rssiThreshold;
|
||||
int newOokThreshold;
|
||||
int activeReceiver;
|
||||
};
|
||||
extern RFConfig_s RFConfig;
|
||||
|
||||
bool validFrequency(float mhz);
|
||||
void RFConfig_fromJson(JsonObject& RFdata);
|
||||
|
||||
bool isValidReceiver(int receiverId) {
|
||||
// Check if the receiverId exists in the activeReceiverOptions map
|
||||
return activeReceiverOptions.find(receiverId) != activeReceiverOptions.end();
|
||||
@@ -1209,7 +1243,7 @@ void handleRF() {
|
||||
|
||||
/**
|
||||
* @brief /RT - Reset configuration ( Erase and Restart ) from Configuration menu
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleRT() {
|
||||
WEBUI_TRACE_LOG(F("handleRT: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -1246,7 +1280,7 @@ void handleRT() {
|
||||
# if defined(ZgatewayCloud)
|
||||
/**
|
||||
* @brief /CL - Cloud Configuration
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleCL() {
|
||||
WEBUI_TRACE_LOG(F("handleCL: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -1300,7 +1334,7 @@ void handleCL() {
|
||||
|
||||
/**
|
||||
* @brief /TK - Receive Cloud Device Token
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleTK() {
|
||||
WEBUI_TRACE_LOG(F("handleTK: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -1343,7 +1377,7 @@ void handleTK() {
|
||||
|
||||
/**
|
||||
* @brief /IN - Information Page
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleIN() {
|
||||
WEBUI_TRACE_LOG(F("handleCN: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -1360,6 +1394,7 @@ void handleIN() {
|
||||
|
||||
// }1 json-oled }2 true } }1 Cloud }2 cloudEnabled}2true}1c
|
||||
# if defined(ZgatewayBT)
|
||||
String stateBTMeasures(bool start);
|
||||
informationDisplay += "1<BR>BT}2}1"; // }1 the bracket is not needed as the previous message ends with }
|
||||
informationDisplay += stateBTMeasures(false);
|
||||
# endif
|
||||
@@ -1421,7 +1456,7 @@ void handleIN() {
|
||||
|
||||
/**
|
||||
* @brief /handleFavicon - Send Favicon
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleFavicon() {
|
||||
WEBUI_TRACE_LOG(F("handleCN: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -1432,7 +1467,7 @@ void handleFavicon() {
|
||||
# if defined(ESP32) && defined(MQTT_HTTPS_FW_UPDATE)
|
||||
/**
|
||||
* @brief /UP - Firmware Upgrade Page
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleUP() {
|
||||
WEBUI_TRACE_LOG(F("handleUP: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -1518,7 +1553,7 @@ void sendRestartPage() {
|
||||
|
||||
/**
|
||||
* @brief /CS - Serial Console and Command Line
|
||||
*
|
||||
*
|
||||
*/
|
||||
void handleCS() {
|
||||
WEBUI_TRACE_LOG(F("handleCS: uri: %s, args: %d, method: %d" CR), server.uri(), server.args(), server.method());
|
||||
@@ -1583,7 +1618,7 @@ void handleCS() {
|
||||
|
||||
/**
|
||||
* @brief Page not found handler
|
||||
*
|
||||
*
|
||||
*/
|
||||
void notFound() {
|
||||
WEBUI_SECURE
|
||||
@@ -1608,7 +1643,7 @@ void notFound() {
|
||||
}
|
||||
|
||||
void WebUISetup() {
|
||||
WEBUI_TRACE_LOG(F("ZwebUI setup start" CR));
|
||||
WEBUI_TRACE_LOG(F("webUI setup start" CR));
|
||||
|
||||
WebUIConfig_load();
|
||||
webUIQueue = xQueueCreate(5, sizeof(webUIQueueMessage*));
|
||||
@@ -1663,7 +1698,7 @@ void WebUISetup() {
|
||||
Log.trace(F("[WebUI] WebUI Secure %T" CR), webUISecure);
|
||||
Log.notice(F("OpenMQTTGateway URL: http://%s/" CR), WiFi.localIP().toString().c_str());
|
||||
displayPrint("URL: http://", (char*)WiFi.localIP().toString().c_str());
|
||||
Log.notice(F("ZwebUI setup done" CR));
|
||||
Log.notice(F("webUI setup done" CR));
|
||||
}
|
||||
|
||||
unsigned long nextWebUIMessage = uptime() + DISPLAY_WEBUI_INTERVAL;
|
||||
@@ -1674,7 +1709,9 @@ void WebUILoop() {
|
||||
if (uptime() >= nextWebUIMessage && uxQueueMessagesWaiting(webUIQueue)) {
|
||||
webUIQueueMessage* message = nullptr;
|
||||
xQueueReceive(webUIQueue, &message, portMAX_DELAY);
|
||||
# if defined(ZdisplaySSD1306)
|
||||
newSSD1306Message = true;
|
||||
# endif
|
||||
|
||||
if (currentWebUIMessage) {
|
||||
free(currentWebUIMessage);
|
||||
@@ -1,408 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @file HTTPUpdate.cpp based om ESP8266HTTPUpdate.cpp
|
||||
* @date 16.10.2018
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the ESP32 Http Updater.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
#ifdef ESP32
|
||||
# include "zzHTTPUpdate.h"
|
||||
|
||||
# include <StreamString.h>
|
||||
# include <esp_ota_ops.h> // get running partition
|
||||
# include <esp_partition.h>
|
||||
|
||||
// To do extern "C" uint32_t _SPIFFS_start;
|
||||
// To do extern "C" uint32_t _SPIFFS_end;
|
||||
|
||||
HTTPUpdate::HTTPUpdate(void)
|
||||
: _httpClientTimeout(8000), _ledPin(-1) {
|
||||
_followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
|
||||
}
|
||||
|
||||
HTTPUpdate::HTTPUpdate(int httpClientTimeout)
|
||||
: _httpClientTimeout(httpClientTimeout), _ledPin(-1) {
|
||||
_followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
|
||||
}
|
||||
|
||||
HTTPUpdate::~HTTPUpdate(void) {
|
||||
}
|
||||
|
||||
HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& url, const String& currentVersion) {
|
||||
HTTPClient http;
|
||||
if (!http.begin(client, url)) {
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
return handleUpdate(http, currentVersion, false);
|
||||
}
|
||||
|
||||
HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& currentVersion) {
|
||||
return handleUpdate(httpClient, currentVersion, true);
|
||||
}
|
||||
|
||||
HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion) {
|
||||
HTTPClient http;
|
||||
if (!http.begin(client, url)) {
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
return handleUpdate(http, currentVersion, true);
|
||||
}
|
||||
|
||||
HTTPUpdateResult HTTPUpdate::update(HTTPClient& httpClient,
|
||||
const String& currentVersion) {
|
||||
return handleUpdate(httpClient, currentVersion, false);
|
||||
}
|
||||
|
||||
HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& host, uint16_t port, const String& uri,
|
||||
const String& currentVersion) {
|
||||
HTTPClient http;
|
||||
if (!http.begin(client, host, port, uri)) {
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
return handleUpdate(http, currentVersion, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* return error code as int
|
||||
* @return int error code
|
||||
*/
|
||||
int HTTPUpdate::getLastError(void) {
|
||||
return _lastError;
|
||||
}
|
||||
|
||||
/**
|
||||
* return error code as String
|
||||
* @return String error
|
||||
*/
|
||||
String HTTPUpdate::getLastErrorString(void) {
|
||||
if (_lastError == 0) {
|
||||
return String(); // no error
|
||||
}
|
||||
|
||||
// error from Update class
|
||||
if (_lastError > 0) {
|
||||
StreamString error;
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
return String("Update error: ") + error;
|
||||
}
|
||||
|
||||
// error from http client
|
||||
if (_lastError > -100) {
|
||||
return String("HTTP error: ") + HTTPClient::errorToString(_lastError);
|
||||
}
|
||||
|
||||
switch (_lastError) {
|
||||
case HTTP_UE_TOO_LESS_SPACE:
|
||||
return "Not Enough space";
|
||||
case HTTP_UE_SERVER_NOT_REPORT_SIZE:
|
||||
return "Server Did Not Report Size";
|
||||
case HTTP_UE_SERVER_FILE_NOT_FOUND:
|
||||
return "File Not Found (404)";
|
||||
case HTTP_UE_SERVER_FORBIDDEN:
|
||||
return "Forbidden (403)";
|
||||
case HTTP_UE_SERVER_WRONG_HTTP_CODE:
|
||||
return "Wrong HTTP Code";
|
||||
case HTTP_UE_SERVER_FAULTY_MD5:
|
||||
return "Wrong MD5";
|
||||
case HTTP_UE_BIN_VERIFY_HEADER_FAILED:
|
||||
return "Verify Bin Header Failed";
|
||||
case HTTP_UE_BIN_FOR_WRONG_FLASH:
|
||||
return "New Binary Does Not Fit Flash Size";
|
||||
case HTTP_UE_NO_PARTITION:
|
||||
return "Partition Could Not be Found";
|
||||
}
|
||||
|
||||
return String();
|
||||
}
|
||||
|
||||
String getSketchSHA256() {
|
||||
const size_t HASH_LEN = 32; // SHA-256 digest length
|
||||
|
||||
uint8_t sha_256[HASH_LEN] = {0};
|
||||
|
||||
// get sha256 digest for running partition
|
||||
if (esp_partition_get_sha256(esp_ota_get_running_partition(), sha_256) == 0) {
|
||||
char buffer[2 * HASH_LEN + 1];
|
||||
|
||||
for (size_t index = 0; index < HASH_LEN; index++) {
|
||||
uint8_t nibble = (sha_256[index] & 0xf0) >> 4;
|
||||
buffer[2 * index] = nibble < 10 ? char(nibble + '0') : char(nibble - 10 + 'A');
|
||||
|
||||
nibble = sha_256[index] & 0x0f;
|
||||
buffer[2 * index + 1] = nibble < 10 ? char(nibble + '0') : char(nibble - 10 + 'A');
|
||||
}
|
||||
|
||||
buffer[2 * HASH_LEN] = '\0';
|
||||
|
||||
return String(buffer);
|
||||
} else {
|
||||
return String();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param http HTTPClient *
|
||||
* @param currentVersion const char *
|
||||
* @return HTTPUpdateResult
|
||||
*/
|
||||
HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs) {
|
||||
HTTPUpdateResult ret = HTTP_UPDATE_FAILED;
|
||||
|
||||
// use HTTP/1.0 for update since the update handler not support any transfer Encoding
|
||||
http.useHTTP10(true);
|
||||
http.setTimeout(_httpClientTimeout);
|
||||
http.setFollowRedirects(_followRedirects);
|
||||
http.setUserAgent("ESP32-http-Update");
|
||||
http.addHeader("Cache-Control", "no-cache");
|
||||
http.addHeader("x-ESP32-STA-MAC", WiFi.macAddress());
|
||||
http.addHeader("x-ESP32-AP-MAC", WiFi.softAPmacAddress());
|
||||
http.addHeader("x-ESP32-free-space", String(ESP.getFreeSketchSpace()));
|
||||
http.addHeader("x-ESP32-sketch-size", String(ESP.getSketchSize()));
|
||||
String sketchMD5 = ESP.getSketchMD5();
|
||||
if (sketchMD5.length() != 0) {
|
||||
http.addHeader("x-ESP32-sketch-md5", sketchMD5);
|
||||
}
|
||||
// Add also a SHA256
|
||||
String sketchSHA256 = getSketchSHA256();
|
||||
if (sketchSHA256.length() != 0) {
|
||||
http.addHeader("x-ESP32-sketch-sha256", sketchSHA256);
|
||||
}
|
||||
http.addHeader("x-ESP32-chip-size", String(ESP.getFlashChipSize()));
|
||||
http.addHeader("x-ESP32-sdk-version", ESP.getSdkVersion());
|
||||
|
||||
if (spiffs) {
|
||||
http.addHeader("x-ESP32-mode", "spiffs");
|
||||
} else {
|
||||
http.addHeader("x-ESP32-mode", "sketch");
|
||||
}
|
||||
|
||||
if (currentVersion && currentVersion[0] != 0x00) {
|
||||
http.addHeader("x-ESP32-version", currentVersion);
|
||||
}
|
||||
|
||||
const char* headerkeys[] = {"x-MD5"};
|
||||
size_t headerkeyssize = sizeof(headerkeys) / sizeof(char*);
|
||||
|
||||
// track these headers
|
||||
http.collectHeaders(headerkeys, headerkeyssize);
|
||||
|
||||
int code = http.GET();
|
||||
int len = http.getSize();
|
||||
|
||||
if (code <= 0) {
|
||||
log_e("HTTP error: %s\n", http.errorToString(code).c_str());
|
||||
_lastError = code;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
log_d("Header read fin.\n");
|
||||
log_d("Server header:\n");
|
||||
log_d(" - code: %d\n", code);
|
||||
log_d(" - len: %d\n", len);
|
||||
|
||||
if (http.hasHeader("x-MD5")) {
|
||||
log_d(" - MD5: %s\n", http.header("x-MD5").c_str());
|
||||
}
|
||||
|
||||
log_d("ESP32 info:\n");
|
||||
log_d(" - free Space: %d\n", ESP.getFreeSketchSpace());
|
||||
log_d(" - current Sketch Size: %d\n", ESP.getSketchSize());
|
||||
|
||||
if (currentVersion && currentVersion[0] != 0x00) {
|
||||
log_d(" - current version: %s\n", currentVersion.c_str());
|
||||
}
|
||||
|
||||
switch (code) {
|
||||
case HTTP_CODE_OK: ///< OK (Start Update)
|
||||
if (len > 0) {
|
||||
bool startUpdate = true;
|
||||
if (spiffs) {
|
||||
const esp_partition_t* _partition = esp_partition_find_first(ESP_PARTITION_TYPE_DATA, ESP_PARTITION_SUBTYPE_DATA_SPIFFS, NULL);
|
||||
if (!_partition) {
|
||||
_lastError = HTTP_UE_NO_PARTITION;
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
if (len > _partition->size) {
|
||||
log_e("spiffsSize to low (%d) needed: %d\n", _partition->size, len);
|
||||
startUpdate = false;
|
||||
}
|
||||
} else {
|
||||
int sketchFreeSpace = ESP.getFreeSketchSpace();
|
||||
if (!sketchFreeSpace) {
|
||||
_lastError = HTTP_UE_NO_PARTITION;
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
|
||||
if (len > sketchFreeSpace) {
|
||||
log_e("FreeSketchSpace to low (%d) needed: %d\n", sketchFreeSpace, len);
|
||||
startUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!startUpdate) {
|
||||
_lastError = HTTP_UE_TOO_LESS_SPACE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
} else {
|
||||
WiFiClient* tcp = http.getStreamPtr();
|
||||
|
||||
// To do? WiFiUDP::stopAll();
|
||||
// To do? WiFiClient::stopAllExcept(tcp);
|
||||
|
||||
delay(100);
|
||||
|
||||
int command;
|
||||
|
||||
if (spiffs) {
|
||||
command = U_SPIFFS;
|
||||
log_d("runUpdate spiffs...\n");
|
||||
} else {
|
||||
command = U_FLASH;
|
||||
log_d("runUpdate flash...\n");
|
||||
}
|
||||
|
||||
if (!spiffs) {
|
||||
/* To do
|
||||
uint8_t buf[4];
|
||||
if(tcp->peekBytes(&buf[0], 4) != 4) {
|
||||
log_e("peekBytes magic header failed\n");
|
||||
_lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
*/
|
||||
|
||||
// check for valid first magic byte
|
||||
// if(buf[0] != 0xE9) {
|
||||
if (tcp->peek() != 0xE9) {
|
||||
log_e("Magic header does not start with 0xE9\n");
|
||||
_lastError = HTTP_UE_BIN_VERIFY_HEADER_FAILED;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
/* To do
|
||||
uint32_t bin_flash_size = ESP.magicFlashChipSize((buf[3] & 0xf0) >> 4);
|
||||
|
||||
// check if new bin fits to SPI flash
|
||||
if(bin_flash_size > ESP.getFlashChipRealSize()) {
|
||||
log_e("New binary does not fit SPI Flash size\n");
|
||||
_lastError = HTTP_UE_BIN_FOR_WRONG_FLASH;
|
||||
http.end();
|
||||
return HTTP_UPDATE_FAILED;
|
||||
}
|
||||
*/
|
||||
}
|
||||
if (runUpdate(*tcp, len, http.header("x-MD5"), command)) {
|
||||
ret = HTTP_UPDATE_OK;
|
||||
log_d("Update ok\n");
|
||||
http.end();
|
||||
|
||||
if (_rebootOnUpdate && !spiffs) {
|
||||
ESP.restart();
|
||||
}
|
||||
|
||||
} else {
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
log_e("Update failed\n");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
_lastError = HTTP_UE_SERVER_NOT_REPORT_SIZE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
log_e("Content-Length was 0 or wasn't set by Server?!\n");
|
||||
}
|
||||
break;
|
||||
case HTTP_CODE_NOT_MODIFIED:
|
||||
///< Not Modified (No updates)
|
||||
ret = HTTP_UPDATE_NO_UPDATES;
|
||||
break;
|
||||
case HTTP_CODE_NOT_FOUND:
|
||||
_lastError = HTTP_UE_SERVER_FILE_NOT_FOUND;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
break;
|
||||
case HTTP_CODE_FORBIDDEN:
|
||||
_lastError = HTTP_UE_SERVER_FORBIDDEN;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
break;
|
||||
default:
|
||||
_lastError = HTTP_UE_SERVER_WRONG_HTTP_CODE;
|
||||
ret = HTTP_UPDATE_FAILED;
|
||||
log_e("HTTP Code is (%d)\n", code);
|
||||
break;
|
||||
}
|
||||
|
||||
http.end();
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* write Update to flash
|
||||
* @param in Stream&
|
||||
* @param size uint32_t
|
||||
* @param md5 String
|
||||
* @return true if Update ok
|
||||
*/
|
||||
bool HTTPUpdate::runUpdate(Stream& in, uint32_t size, String md5, int command) {
|
||||
StreamString error;
|
||||
|
||||
if (!Update.begin(size, command, _ledPin, _ledOn)) {
|
||||
_lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
log_e("Update.begin failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (md5.length()) {
|
||||
if (!Update.setMD5(md5.c_str())) {
|
||||
_lastError = HTTP_UE_SERVER_FAULTY_MD5;
|
||||
log_e("Update.setMD5 failed! (%s)\n", md5.c_str());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// To do: the SHA256 could be checked if the server sends it
|
||||
|
||||
if (Update.writeStream(in) != size) {
|
||||
_lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
log_e("Update.writeStream failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!Update.end()) {
|
||||
_lastError = Update.getError();
|
||||
Update.printError(error);
|
||||
error.trim(); // remove line ending
|
||||
log_e("Update.end failed! (%s)\n", error.c_str());
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
# if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE)
|
||||
HTTPUpdate httpUpdate;
|
||||
# endif
|
||||
#endif
|
||||
@@ -1,113 +0,0 @@
|
||||
/**
|
||||
*
|
||||
* @file HTTPUpdate.h based on ESP8266HTTPUpdate.h
|
||||
* @date 16.10.2018
|
||||
* @author Markus Sattler
|
||||
*
|
||||
* Copyright (c) 2015 Markus Sattler. All rights reserved.
|
||||
* This file is part of the ESP32 Http Updater.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 2.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
*/
|
||||
#ifdef ESP32
|
||||
# ifndef ___zzHTTP_UPDATE_H___
|
||||
# define ___zzHTTP_UPDATE_H___
|
||||
|
||||
# include <Arduino.h>
|
||||
# include <HTTPClient.h>
|
||||
# include <Update.h>
|
||||
# include <WiFi.h>
|
||||
# include <WiFiClient.h>
|
||||
# include <WiFiUdp.h>
|
||||
|
||||
/// note we use HTTP client errors too so we start at 100
|
||||
# define HTTP_UE_TOO_LESS_SPACE (-100)
|
||||
# define HTTP_UE_SERVER_NOT_REPORT_SIZE (-101)
|
||||
# define HTTP_UE_SERVER_FILE_NOT_FOUND (-102)
|
||||
# define HTTP_UE_SERVER_FORBIDDEN (-103)
|
||||
# define HTTP_UE_SERVER_WRONG_HTTP_CODE (-104)
|
||||
# define HTTP_UE_SERVER_FAULTY_MD5 (-105)
|
||||
# define HTTP_UE_BIN_VERIFY_HEADER_FAILED (-106)
|
||||
# define HTTP_UE_BIN_FOR_WRONG_FLASH (-107)
|
||||
# define HTTP_UE_NO_PARTITION (-108)
|
||||
|
||||
enum HTTPUpdateResult {
|
||||
HTTP_UPDATE_FAILED,
|
||||
HTTP_UPDATE_NO_UPDATES,
|
||||
HTTP_UPDATE_OK
|
||||
};
|
||||
|
||||
typedef HTTPUpdateResult t_httpUpdate_return; // backward compatibility
|
||||
|
||||
class HTTPUpdate {
|
||||
public:
|
||||
HTTPUpdate(void);
|
||||
HTTPUpdate(int httpClientTimeout);
|
||||
~HTTPUpdate(void);
|
||||
|
||||
void rebootOnUpdate(bool reboot) {
|
||||
_rebootOnUpdate = reboot;
|
||||
}
|
||||
|
||||
/**
|
||||
* set redirect follow mode. See `followRedirects_t` enum for avaliable modes.
|
||||
* @param follow
|
||||
*/
|
||||
void setFollowRedirects(followRedirects_t follow) {
|
||||
_followRedirects = follow;
|
||||
}
|
||||
|
||||
void setLedPin(int ledPin = -1, uint8_t ledOn = HIGH) {
|
||||
_ledPin = ledPin;
|
||||
_ledOn = ledOn;
|
||||
}
|
||||
|
||||
t_httpUpdate_return update(WiFiClient& client, const String& url, const String& currentVersion = "");
|
||||
|
||||
t_httpUpdate_return update(WiFiClient& client, const String& host, uint16_t port, const String& uri = "/",
|
||||
const String& currentVersion = "");
|
||||
|
||||
t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = "");
|
||||
|
||||
t_httpUpdate_return update(HTTPClient& httpClient,
|
||||
const String& currentVersion = "");
|
||||
|
||||
t_httpUpdate_return updateSpiffs(HTTPClient& httpClient, const String& currentVersion = "");
|
||||
|
||||
int getLastError(void);
|
||||
String getLastErrorString(void);
|
||||
|
||||
protected:
|
||||
t_httpUpdate_return handleUpdate(HTTPClient& http, const String& currentVersion, bool spiffs = false);
|
||||
bool runUpdate(Stream& in, uint32_t size, String md5, int command = U_FLASH);
|
||||
|
||||
int _lastError;
|
||||
bool _rebootOnUpdate = true;
|
||||
|
||||
private:
|
||||
int _httpClientTimeout;
|
||||
followRedirects_t _followRedirects;
|
||||
|
||||
int _ledPin;
|
||||
uint8_t _ledOn;
|
||||
};
|
||||
|
||||
# if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_HTTPUPDATE)
|
||||
extern HTTPUpdate httpUpdate;
|
||||
# endif
|
||||
|
||||
# endif /* ___HTTP_UPDATE_H___ */
|
||||
#endif
|
||||
@@ -0,0 +1,6 @@
|
||||
# Name, Type, SubType, Offset, Size, Flags
|
||||
nvs, data, nvs, 0x9000, 0x5000,
|
||||
otadata, data, ota, 0xe000, 0x2000,
|
||||
app0, app, ota_0, 0x10000, 0x1F0000,
|
||||
app1, app, ota_1, 0x200000,0x1F0000,
|
||||
spiffs, data, spiffs, 0x3F0000,0x10000,
|
||||
|
+12
-12
@@ -114,15 +114,15 @@ extra_configs =
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
[libraries]
|
||||
arduinojson = ArduinoJson@6.18.3
|
||||
arduinojson = ArduinoJson@6.18.5
|
||||
arduinolog = https://github.com/1technophile/Arduino-Log.git#f634509
|
||||
picomqtt = PicoMQTT@1.1.1
|
||||
rc-switch = https://github.com/1technophile/rc-switch.git#98537e9
|
||||
newremoteswitch = https://github.com/1technophile/NewRemoteSwitch.git#8eb980e
|
||||
ble = https://github.com/h2zero/NimBLE-Arduino.git#2.2.1
|
||||
irremoteesp = IRremoteESP8266@2.8.5
|
||||
irremoteesp = https://github.com/theengs/IRremoteESP8266#arduinov3
|
||||
lora = https://github.com/sandeepmistry/arduino-LoRa.git#f4a1d27
|
||||
esppilight = ESPiLight@0.17.0
|
||||
esppilight = https://github.com/theengs/ESPiLight#b9dd7a1
|
||||
rfWeatherStation = WeatherStationDataRx@0.3.1
|
||||
rfm69 = https://github.com/LowPowerLab/RFM69.git#2e915ea
|
||||
rfm69spi = https://github.com/lowpowerlab/spiflash.git#9c0c2b9
|
||||
@@ -136,19 +136,19 @@ htu21 = SparkFun HTU21D Humidity and Temperature Sensor Breakout@1.1.3
|
||||
ahtx0 = Adafruit AHTX0
|
||||
ina226 = https://github.com/jarzebski/Arduino-INA226.git#968a684
|
||||
a6lib = https://github.com/h2zero/A6lib
|
||||
wifimanager32 = https://github.com/tzapu/WiFiManager.git#9f5981e
|
||||
wifimanager32 = https://github.com/h2zero/WiFiManager.git#1ac24f4
|
||||
wifimanager8266 = https://github.com/tzapu/WiFiManager.git#2.0.5-beta
|
||||
ethernet = Ethernet
|
||||
esp8266_mdns = esp8266_mdns
|
||||
wire = Wire
|
||||
fastled = fastled/FastLED@3.5.0
|
||||
fastled = fastled/FastLED@3.9.15
|
||||
adafruit_neopixel = adafruit/Adafruit NeoPixel@^1.11.0
|
||||
onewire = paulstoffregen/OneWire@2.3.7
|
||||
onewire = https://github.com/h2zero/OneWire#GPIO-fix
|
||||
dallastemperature = DallasTemperature
|
||||
m5stickc = M5StickC@0.2.0
|
||||
m5stickcp = https://github.com/m5stack/M5StickC-Plus.git#0.0.2
|
||||
m5stack = M5Stack@0.3.1
|
||||
m5tough = https://github.com/m5stack/M5Tough.git#b502416
|
||||
m5stickc = M5StickC@0.2.5
|
||||
m5stickcp = https://github.com/m5stack/M5StickC-Plus.git#0.1.1
|
||||
m5stack = M5Stack@0.4.6
|
||||
m5tough = https://github.com/m5stack/M5Tough.git#ccf49e1
|
||||
smartrc-cc1101-driver-lib = SmartRC-CC1101-Driver-Lib@2.5.7
|
||||
stl = https://github.com/mike-matera/ArduinoSTL.git#7411816
|
||||
shtc3 = https://github.com/sparkfun/SparkFun_SHTC3_Arduino_Library
|
||||
@@ -176,7 +176,7 @@ monitor_speed = 115200
|
||||
|
||||
[com]
|
||||
esp8266_platform = espressif8266@4.2.1
|
||||
esp32_platform = espressif32@6.1.0
|
||||
esp32_platform = https://github.com/pioarduino/platform-espressif32#53.03.11
|
||||
esp32_solo_platform = https://github.com/tasmota/platform-espressif32/releases/download/2023.02.00/platform-espressif32.zip
|
||||
atmelavr_platform = atmelavr@3.3.0
|
||||
|
||||
@@ -223,4 +223,4 @@ lib_deps =
|
||||
${libraries.ethernet}
|
||||
build_flags =
|
||||
${env.build_flags}
|
||||
'-DsimpleReceiving=false'
|
||||
'-DsimpleReceiving=false'
|
||||
+84
-23
@@ -125,6 +125,8 @@ CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_ECDSA=y
|
||||
CONFIG_MBEDTLS_KEY_EXCHANGE_ECDH_RSA=y
|
||||
# end of TLS Key Exchange Methods
|
||||
|
||||
CONFIG_MBEDTLS_DHM_C=y
|
||||
|
||||
#
|
||||
# Arduino Configuration
|
||||
#
|
||||
@@ -151,7 +153,6 @@ CONFIG_ARDUINO_UDP_RUN_CORE0=y
|
||||
# CONFIG_ARDUINO_UDP_RUN_NO_AFFINITY is not set
|
||||
CONFIG_ARDUINO_UDP_RUNNING_CORE=0
|
||||
CONFIG_ARDUINO_UDP_TASK_PRIORITY=3
|
||||
CONFIG_ESP_TASK_WDT_CHECK_IDLE_TASK_CPU1=n
|
||||
# CONFIG_ARDUINO_ISR_IRAM is not set
|
||||
# CONFIG_DISABLE_HAL_LOCKS is not set
|
||||
|
||||
@@ -177,35 +178,95 @@ CONFIG_ARDUHAL_PARTITION_SCHEME_MIN_SPIFFS=y
|
||||
CONFIG_ARDUHAL_PARTITION_SCHEME="min_spiffs"
|
||||
# CONFIG_AUTOCONNECT_WIFI is not set
|
||||
CONFIG_ARDUINO_SELECTIVE_COMPILATION=y
|
||||
CONFIG_ARDUINO_SELECTIVE_ArduinoOTA=y
|
||||
CONFIG_ARDUINO_SELECTIVE_AsyncUDP=y
|
||||
# CONFIG_ARDUINO_SELECTIVE_AzureIoT is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_BLE is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set
|
||||
CONFIG_ARDUINO_SELECTIVE_DNSServer=y
|
||||
CONFIG_ARDUINO_SELECTIVE_EEPROM=y
|
||||
CONFIG_ARDUINO_SELECTIVE_ESP32=y
|
||||
CONFIG_ARDUINO_SELECTIVE_ESPmDNS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_FFat=y
|
||||
CONFIG_ARDUINO_SELECTIVE_FS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_HTTPClient=y
|
||||
CONFIG_ARDUINO_SELECTIVE_LITTLEFS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_NetBIOS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_Preferences=y
|
||||
CONFIG_ARDUINO_SELECTIVE_SD=y
|
||||
CONFIG_ARDUINO_SELECTIVE_SD_MMC=y
|
||||
# CONFIG_ARDUINO_SELECTIVE_SimpleBLE is not set
|
||||
CONFIG_ARDUINO_SELECTIVE_SPI=y
|
||||
CONFIG_ARDUINO_SELECTIVE_SPIFFS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_Wire=y
|
||||
CONFIG_ARDUINO_SELECTIVE_ESP_SR=y
|
||||
# CONFIG_ARDUINO_SELECTIVE_EEPROM is not set
|
||||
CONFIG_ARDUINO_SELECTIVE_Preferences=y
|
||||
CONFIG_ARDUINO_SELECTIVE_Ticker=y
|
||||
CONFIG_ARDUINO_SELECTIVE_Update=y
|
||||
# CONFIG_ARDUINO_SELECTIVE_Zigbee is not set
|
||||
CONFIG_ARDUINO_SELECTIVE_FS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_SD=y
|
||||
CONFIG_ARDUINO_SELECTIVE_SD_MMC=y
|
||||
CONFIG_ARDUINO_SELECTIVE_SPIFFS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_FFat=y
|
||||
CONFIG_ARDUINO_SELECTIVE_LittleFS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_Network=y
|
||||
CONFIG_ARDUINO_SELECTIVE_Ethernet=y
|
||||
CONFIG_ARDUINO_SELECTIVE_PPP=y
|
||||
CONFIG_ARDUINO_SELECTIVE_ArduinoOTA=y
|
||||
CONFIG_ARDUINO_SELECTIVE_AsyncUDP=y
|
||||
CONFIG_ARDUINO_SELECTIVE_DNSServer=y
|
||||
CONFIG_ARDUINO_SELECTIVE_ESPmDNS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_HTTPClient=y
|
||||
# CONFIG_ARDUINO_SELECTIVE_Matter is not set
|
||||
CONFIG_ARDUINO_SELECTIVE_NetBIOS=y
|
||||
CONFIG_ARDUINO_SELECTIVE_WebServer=y
|
||||
CONFIG_ARDUINO_SELECTIVE_WiFi=y
|
||||
CONFIG_ARDUINO_SELECTIVE_WiFiClientSecure=y
|
||||
CONFIG_ARDUINO_SELECTIVE_WiFiProv=y
|
||||
CONFIG_ARDUINO_SELECTIVE_Wire=y
|
||||
CONFIG_ARDUINO_SELECTIVE_NetworkClientSecure=y
|
||||
# CONFIG_ARDUINO_SELECTIVE_WiFiProv is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_BLE is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_BluetoothSerial is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_SimpleBLE is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_RainMaker is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_OpenThread is not set
|
||||
# CONFIG_ARDUINO_SELECTIVE_Insights is not set
|
||||
# end of Arduino Configuration
|
||||
# end of Arduino Configuration
|
||||
|
||||
# CONFIG_ESP32_WIFI_IRAM_OPT is not set
|
||||
# CONFIG_ESP32_WIFI_RX_IRAM_OPT is not set
|
||||
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL_NONE=y
|
||||
CONFIG_BOOTLOADER_LOG_LEVEL=0
|
||||
CONFIG_LOG_DEFAULT_LEVEL_ERROR=y
|
||||
CONFIG_LOG_DEFAULT_LEVEL=1
|
||||
|
||||
CONFIG_BOOTLOADER_APP_ROLLBACK_ENABLE=y
|
||||
CONFIG_BOOTLOADER_SKIP_VALIDATE_IN_DEEP_SLEEP=y
|
||||
CONFIG_COMPILER_OPTIMIZATION_SIZE=y
|
||||
CONFIG_ESP_INT_WDT_TIMEOUT_MS=300
|
||||
CONFIG_ESP_IPC_TASK_STACK_SIZE=1024
|
||||
CONFIG_ESP_MAIN_TASK_STACK_SIZE=4096
|
||||
CONFIG_ESP_SYSTEM_EVENT_TASK_STACK_SIZE=2048
|
||||
CONFIG_ESP_TASK_WDT_PANIC=y
|
||||
CONFIG_ESP_TIMER_TASK_STACK_SIZE=4096
|
||||
CONFIG_ESP_WIFI_STATIC_RX_BUFFER_NUM=8
|
||||
CONFIG_ESP_WIFI_STATIC_TX_BUFFER_NUM=8
|
||||
CONFIG_ESP_WIFI_CACHE_TX_BUFFER_NUM=16
|
||||
CONFIG_FREERTOS_IDLE_TASK_STACKSIZE=1024
|
||||
CONFIG_HEAP_POISONING_LIGHT=y
|
||||
CONFIG_HTTPD_MAX_REQ_HDR_LEN=1024
|
||||
CONFIG_HTTPD_WS_SUPPORT=y
|
||||
# CONFIG_LOG_COLORS is not set
|
||||
|
||||
# CONFIG_LWIP_DHCP_DOES_ARP_CHECK is not set
|
||||
CONFIG_LWIP_TCP_SYNMAXRTX=6
|
||||
CONFIG_LWIP_TCP_MSS=1436
|
||||
CONFIG_LWIP_TCP_RTO_TIME=3000
|
||||
CONFIG_LWIP_TCPIP_TASK_STACK_SIZE=4096
|
||||
CONFIG_LWIP_TCPIP_TASK_AFFINITY_CPU0=y
|
||||
CONFIG_LWIP_MAX_SOCKETS=16
|
||||
CONFIG_LWIP_IP_FORWARD=y
|
||||
CONFIG_LWIP_IPV4_NAPT=y
|
||||
CONFIG_LWIP_DHCP_RESTORE_LAST_IP=n
|
||||
CONFIG_LWIP_DHCP_OPTIONS_LEN=128
|
||||
CONFIG_LWIP_SNTP_MAX_SERVERS=3
|
||||
CONFIG_LWIP_SNTP_UPDATE_DELAY=10800000
|
||||
CONFIG_LWIP_DHCP_GET_NTP_SRV=y
|
||||
CONFIG_LWIP_IPV6_AUTOCONFIG=y
|
||||
CONFIG_LWIP_IPV6_DHCP6=y
|
||||
CONFIG_LWIP_IPV6_RDNSS_MAX_DNS_SERVERS=2
|
||||
CONFIG_LWIP_PPP_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_NOTIFY_PHASE_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_PAP_SUPPORT=y
|
||||
CONFIG_LWIP_PPP_ENABLE_IPV6=n
|
||||
CONFIG_LWIP_HOOK_IP6_ROUTE_DEFAULT=y
|
||||
CONFIG_LWIP_HOOK_ND6_GET_GW_DEFAULT=y
|
||||
CONFIG_LWIP_HOOK_IP6_SELECT_SRC_ADDR_DEFAULT=y
|
||||
CONFIG_LWIP_HOOK_NETCONN_EXT_RESOLVE_DEFAULT=y
|
||||
CONFIG_LWIP_HOOK_IP6_INPUT_CUSTOM=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_BUFFER=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_PEER_CERT=y
|
||||
CONFIG_MBEDTLS_DYNAMIC_FREE_CONFIG_DATA=y
|
||||
Reference in new issue
Block a user