diff --git a/README.md b/README.md index 9950315eca..f9c93cc019 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,6 @@ +# ⚠️ This is a fork of [letscontrolit/ESPEasy](https://github.com/letscontrolit/ESPEasy) and you should prefer to start from original project! This fork is for personnal maintenance and making PR to original project. ⚠️ + + |Latest Nightly | Build Status | Downloads | Docs | Patreon | Ko-Fi | PayPal | |-------|-------|-------|-------|-------|-------|-------| | [![GitHub version](https://img.shields.io/github/release/letscontrolit/ESPEasy/all.svg)](https://github.com/letscontrolit/ESPEasy/releases/latest) | ![Build status](https://github.com/letscontrolit/ESPEasy/actions/workflows/build.yml/badge.svg) | [![Downloads](https://img.shields.io/github/downloads/letscontrolit/ESPEasy/total.svg)](https://github.com/letscontrolit/ESPEasy/releases) | [![Documentation Status](https://readthedocs.org/projects/espeasy/badge/?version=latest)](https://espeasy.readthedocs.io/en/latest/?badge=latest) | [![donate](https://img.shields.io/badge/donate-Patreon-blue.svg)](https://www.patreon.com/GrovkillenTDer) | [![donate](https://img.shields.io/badge/donate-KoFi-blue.svg)](https://ko-fi.com/grovkillentder) | [![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.me/espeasy) | diff --git a/docs/source/Plugin/P130.rst b/docs/source/Plugin/P130.rst new file mode 100644 index 0000000000..dd639be71b --- /dev/null +++ b/docs/source/Plugin/P130.rst @@ -0,0 +1,128 @@ +.. include:: ../Plugin/_plugin_substitutions_p13x.repl +.. _P130_page: + +|P130_typename| +================================================== + +|P130_shortinfo| + +Plugin details +-------------- + +Type: |P130_type| + +Name: |P130_name| + +Status: |P130_status| + +GitHub: |P130_github|_ + +Maintainer: |P130_maintainer| + +Used libraries: |P130_usedlibraries| + + + +Introduction +------------ + +.. image:: P130_vue_globale.jpg + +This plugin can be used to measure Current usage through `Irms ` using an ADS1015 through I2C. +It is the most simple schematic I succeed to create. +To get it to work, you have to buy an ADS1015 board, an ESP32 (not that ESP8266 might be too slow), and current sensors (I encouraged you to buy the black version, more robust, and smaller). +The only requirement is to buy a current sensor doing the conversion over 1Vac. You have to choose the right calibration in other cases you may definitely break your ADS1015. Say you bought a 30A/1V current sensor, if you try to measure a current of 60A, output voltage will be 2V and your ADS1015 will be burned out! +Note that each ADS1015 can manage TWO sensors! as I'm using the ADS1015 in a differential mode (this avoid managing an offset voltage and a complicated way to get a full range measure) +As ADS1015 can have four I2C addresses, you can manage up to EIGHT current sensors within one ESPEasy unit. + +Specifications: + * Output: Irms Current + * Input: 1Vac through current sensor + +Wiring +------ + +.. code-block:: none + + ESP ADS1015 + GPIO (SCL) <--> SCL + GPIO (SDA) <--> SDA + ADDR (choose on our side, see note below) + + Power + 3.3V <--> VCC + GND <--> GND + + Current Sensor 1 (Canal 1) + P1 <--> ADC0 + P2 <--> ADC1 + + Current Sensor 2 (Canal 2) + P1 <--> ADC2 + P2 <--> ADC3 + +The ADDR pin have to be used to set the wanted address of your choice (have a look on datasheet to configure one) + +Setup +----- + +.. image:: P130_device_configuration_page.png + +Task settings +~~~~~~~~~~~~~ + +* **Device**: Name of plugin +* **Name**: Name of the task (example name **Irms**) +* **Enable**: Should the task be enabled or not + +I2C options +^^^^^^^^^^^ + +* **I2C Address**: Default 0x48 is used. +* **Force Slow I2C speed**: not needed for ADS1015, and should not be used as it can reduce sampling rate + +Calibration - General +^^^^^^^^^^^^^^^^^^^^^ + +* **SPS** : Sample Per Second : based on my tests, 2400 SPS give the same real SPS as 3600 because of internal code of ESPEasy. Setting to 2400 will slo down the internal converter of the ADS1015 and so, sampling will have a more stable result. +* **Current Frequency** : Needed to calculate the period of sampling for a sinus +* **Nb Sinus to read** : more sinus implies more accuracy, BUT also more blocking time in plugin, SO: I suggest 2 sinus for 50Hz (even for 60Hz too) +* **ADC Conversion Mode Continuous** : this option was coded for test purposes but do not give better result, I suggest to leave it UNchecked (the default) +* **Small Debug to INFO log** : this allow you to get statistic of each conversion on serial console without switching global log level to debug (becuase it is slowing down conversion rate, and so bad results) +* **Voltage estimated** : this is to get from plugin a power conversion. as it is not a real value, the power value is an estimated one based on this voltage. + +Calibration +^^^^^^^^^^^ + +This is where you specify the calibration of the current sensor you connected, say you have connected a current sensor given for 50A/1V, you will indicate 50. + +* **Canal 1 - Max current** : Current value for 1V +* **Canal 2 - Max current** : Current value for 1V + +Where to buy +------------ + +.. csv-table:: + :header: "Store", "Link" + :widths: 5, 40 + + "AliExpress ESP32","" + "AliExpress ADS1015 board","" + "AliExpress SCT013","" + "AliExpress OPCT10AL","" + +* **Note : to simply help this famous project ESPEasy, just bought through referral link above!** + +Change log +---------- + +.. versionadded:: 1.0 + ... + + |added| + Initial release version. + + + + + diff --git a/docs/source/Plugin/P130_device_configuration_page.png b/docs/source/Plugin/P130_device_configuration_page.png new file mode 100644 index 0000000000..685143d50a Binary files /dev/null and b/docs/source/Plugin/P130_device_configuration_page.png differ diff --git a/docs/source/Plugin/P130_vue_globale.jpg b/docs/source/Plugin/P130_vue_globale.jpg new file mode 100644 index 0000000000..31a53fc1c2 Binary files /dev/null and b/docs/source/Plugin/P130_vue_globale.jpg differ diff --git a/docs/source/Plugin/_Plugin.rst b/docs/source/Plugin/_Plugin.rst index 0199448d7a..29d41851f7 100644 --- a/docs/source/Plugin/_Plugin.rst +++ b/docs/source/Plugin/_Plugin.rst @@ -367,6 +367,7 @@ There are different released versions of ESP Easy: ":ref:`P127_page`","|P127_status|","P127" ":ref:`P128_page`","|P128_status|","P128" ":ref:`P129_page`","|P129_status|","P129" + ":ref:`P130_page`","|P130_status|","P130" ":ref:`P131_page`","|P131_status|","P131" ":ref:`P132_page`","|P132_status|","P132" ":ref:`P133_page`","|P133_status|","P133" diff --git a/docs/source/Plugin/_plugin_substitutions_p13x.repl b/docs/source/Plugin/_plugin_substitutions_p13x.repl index 7816f26640..83b75077cf 100644 --- a/docs/source/Plugin/_plugin_substitutions_p13x.repl +++ b/docs/source/Plugin/_plugin_substitutions_p13x.repl @@ -1,3 +1,16 @@ +.. |P130_name| replace:: :cyan:`Current Irms via ADS1015 I2C` +.. |P130_type| replace:: :cyan:`Current` +.. |P130_typename| replace:: :cyan:`Current - ADS1015 (I2C)` +.. |P130_porttype| replace:: `.` +.. |P130_status| replace:: :yellow:`TESTING E` +.. |P130_github| replace:: P130_IRMS_ADS1015.ino +.. _P130_github: https://github.com/handfreezer/ESPEasy/blob/P130_01/src/_P130_IRMS_ADS1015.ino +.. |P130_usedby| replace:: `.` +.. |P130_shortinfo| replace:: `Current Irms sensor` +.. |P130_maintainer| replace:: `handfreezer` +.. |P130_compileinfo| replace:: `.` +.. |P130_usedlibraries| replace:: `(none)` + .. |P131_name| replace:: :cyan:`NeoPixel Matrix` .. |P131_type| replace:: :cyan:`Display` .. |P131_typename| replace:: :cyan:`Display - NeoPixel Matrix` diff --git a/src/Custom-sample.h b/src/Custom-sample.h index b45112ba10..b60999852c 100644 --- a/src/Custom-sample.h +++ b/src/Custom-sample.h @@ -1,592 +1,592 @@ -#ifndef ESPEASY_CUSTOM_H -#define ESPEASY_CUSTOM_H - -/* - To modify the stock configuration without changing the EspEasy.ino file : - 1) rename this file to "Custom.h" (It is ignored by Git) - 2) define your own settings below - 3) define USE_CUSTOM_H as a build flags. ie : export PLATFORMIO_BUILD_FLAGS="'-DUSE_CUSTOM_H'" - */ - - -/* - ####################################################################################################### - Your Own Default Settings - ####################################################################################################### - You can basically ovveride ALL macro defined in ESPEasy.ino. - Don't forget to first #undef each existing #define that you add below. - But since this Custom.h is included before other defines are made, you don't have to undef a lot of defines. - Here are some examples: - */ - -// --- Feature Flagging --------------------------------------------------------- -// Can be set to 1 to enable, 0 to disable, or not set to use the default (usually via define_plugin_sets.h) - -#define FEATURE_RULES_EASY_COLOR_CODE 1 // Use code highlighting, autocompletion and command suggestions in Rules -#define FEATURE_ESPEASY_P2P 1 // (1/0) enables the ESP Easy P2P protocol -#define FEATURE_ARDUINO_OTA 1 // enables the Arduino OTA capabilities -#define FEATURE_THINGSPEAK_EVENT 1 // generate an event when requesting last value of a field in thingspeak via SendToHTTP(e.g. sendToHTTP,api.thingspeak.com,80,/channels/1667332/fields/5/last) -// #define FEATURE_SD 1 // Enable SD card support -// #define FEATURE_DOWNLOAD 1 // Enable downloading a file from an url - -#ifdef BUILD_GIT -# undef BUILD_GIT -#endif // ifdef BUILD_GIT - -#define BUILD_GIT "My Build: " __DATE__ " " __TIME__ - - -#define DEFAULT_NAME "MyEspEasyDevice" // Enter your device friendly name -#define UNIT 0 // Unit Number -#define DEFAULT_DELAY 60 // Sleep Delay in seconds - -// --- Wifi AP Mode (when your Wifi Network is not reachable) ---------------------------------------- -#define DEFAULT_AP_IP 192, 168, 4, 1 // Enter IP address (comma separated) for AP (config) mode -#define DEFAULT_AP_SUBNET 255, 255, 255, 0 // Enter IP address (comma separated) for AP (config) mode -#define DEFAULT_AP_KEY "configesp" // Enter network WPA key for AP (config) mode - -// --- Wifi Client Mode ----------------------------------------------------------------------------- -#define DEFAULT_SSID "MyHomeSSID" // Enter your network SSID -#define DEFAULT_KEY "MySuperSecretPassword" // Enter your network WPA key -#define DEFAULT_SSID2 "" // Enter your fallback network SSID -#define DEFAULT_KEY2 "" // Enter your fallback network WPA key -#define DEFAULT_WIFI_INCLUDE_HIDDEN_SSID false // Allow to connect to hidden SSID APs -#define DEFAULT_USE_STATIC_IP false // (true|false) enabled or disabled static IP -#define DEFAULT_IP "192.168.0.50" // Enter your IP address -#define DEFAULT_DNS "192.168.0.1" // Enter your DNS -#define DEFAULT_GW "192.168.0.1" // Enter your Gateway -#define DEFAULT_SUBNET "255.255.255.0" // Enter your Subnet -#define DEFAULT_IPRANGE_LOW "0.0.0.0" // Allowed IP range to access webserver -#define DEFAULT_IPRANGE_HIGH "255.255.255.255" // Allowed IP range to access webserver -#define DEFAULT_IP_BLOCK_LEVEL 1 // 0: ALL_ALLOWED 1: LOCAL_SUBNET_ALLOWED 2: -// ONLY_IP_RANGE_ALLOWED -#define DEFAULT_ADMIN_USERNAME "admin" -#define DEFAULT_ADMIN_PASS "" - -#define DEFAULT_WIFI_CONNECTION_TIMEOUT 10000 // minimum timeout in ms for WiFi to be connected. -#define DEFAULT_WIFI_FORCE_BG_MODE false // when set, only allow to connect in 802.11B or G mode (not N) -#define DEFAULT_WIFI_RESTART_WIFI_CONN_LOST false // Perform wifi off and on when connection was lost. -#define DEFAULT_ECO_MODE false // When set, make idle calls between executing tasks. -#define DEFAULT_WIFI_NONE_SLEEP false // When set, the wifi will be set to no longer sleep (more power -// used and need reboot to reset mode) -#define DEFAULT_GRATUITOUS_ARP false // When set, the node will send periodical gratuitous ARP - // packets to announce itself. -#define DEFAULT_TOLERANT_LAST_ARG_PARSE false // When set, the last argument of some commands will be parsed to the end of the line - // See: https://github.com/letscontrolit/ESPEasy/issues/2724 -#define DEFAULT_SEND_TO_HTTP_ACK false // Wait for ack with SendToHttp command. - -#define DEFAULT_AP_DONT_FORCE_SETUP false // Allow optional usage of Sensor without WIFI avaiable // When set you can use the Sensor in AP-Mode without beeing forced to /setup -#define DEFAULT_DONT_ALLOW_START_AP false // Usually the AP will be started when no WiFi is defined, or the defined one cannot be found. This flag may prevent it. - -// --- Default Controller ------------------------------------------------------------------------------ -#define DEFAULT_CONTROLLER false // true or false enabled or disabled, set 1st controller - // defaults -#define DEFAULT_CONTROLLER_ENABLED true // Enable default controller by default -#define DEFAULT_CONTROLLER_USER "" // Default controller user -#define DEFAULT_CONTROLLER_PASS "" // Default controller Password - -// using a default template, you also need to set a DEFAULT PROTOCOL to a suitable MQTT protocol ! -#define DEFAULT_PUB "sensors/espeasy/%sysname%/%tskname%/%valname%" // Enter your pub -#define DEFAULT_SUB "sensors/espeasy/%sysname%/#" // Enter your sub -#define DEFAULT_SERVER "192.168.0.8" // Enter your Server IP address -#define DEFAULT_SERVER_HOST "" // Server hostname -#define DEFAULT_SERVER_USEDNS false // true: Use hostname. false: use IP -#define DEFAULT_USE_EXTD_CONTROLLER_CREDENTIALS false // true: Allow longer user credentials for controllers - -#define DEFAULT_PORT 8080 // Enter your Server port value -#define DEFAULT_CONTROLLER_TIMEOUT 100 // Default timeout in msec - -#define DEFAULT_PROTOCOL 0 // Protocol used for controller communications - // 0 = Stand-alone (no controller set) - // 1 = Domoticz HTTP - // 2 = Domoticz MQTT - // 3 = Nodo Telnet - // 4 = ThingSpeak - // 5 = Home Assistant (openHAB) MQTT - // 6 = PiDome MQTT - // 7 = EmonCMS - // 8 = Generic HTTP - // 9 = FHEM HTTP - -#ifdef ESP8266 -#define DEFAULT_PIN_I2C_SDA 4 -#endif -#ifdef ESP32 -#define DEFAULT_PIN_I2C_SDA -1 // Undefined -#endif -#ifdef ESP8266 -#define DEFAULT_PIN_I2C_SCL 5 -#endif -#ifdef ESP32 -#define DEFAULT_PIN_I2C_SCL -1 // Undefined -#endif -#define DEFAULT_I2C_CLOCK_SPEED 400000 // Use 100 kHz if working with old I2C chips -#define FEATURE_I2C_DEVICE_SCAN 1 - -#define DEFAULT_SPI 0 //0=disabled 1=enabled and for ESP32 there is option 2 =HSPI - -#define DEFAULT_PIN_STATUS_LED (-1) -#define DEFAULT_PIN_STATUS_LED_INVERSED true - -#define DEFAULT_PIN_RESET_BUTTON (-1) - - -#define DEFAULT_USE_RULES false // (true|false) Enable Rules? -#define DEFAULT_RULES_OLDENGINE true - -#define DEFAULT_MQTT_RETAIN false // (true|false) Retain MQTT messages? -#define DEFAULT_CONTROLLER_DELETE_OLDEST false // (true|false) to delete oldest message when queue is full -#define DEFAULT_CONTROLLER_MUST_CHECK_REPLY false // (true|false) Check Acknowledgment -#define DEFAULT_MQTT_DELAY 100 // Time in milliseconds to retain MQTT messages -#define DEFAULT_MQTT_LWT_TOPIC "" // Default lwt topic -#define DEFAULT_MQTT_LWT_CONNECT_MESSAGE "Connected" // Default lwt message -#define DEFAULT_MQTT_LWT_DISCONNECT_MESSAGE "Connection Lost" // Default lwt message -#define DEFAULT_MQTT_USE_UNITNAME_AS_CLIENTID 0 - -#define DEFAULT_USE_NTP false // (true|false) Use NTP Server -#define DEFAULT_NTP_HOST "" // NTP Server Hostname -#define DEFAULT_TIME_ZONE 0 // Time Offset (in minutes) -#define DEFAULT_USE_DST false // (true|false) Use Daily Time Saving - -#define DEFAULT_LATITUDE 0.0f // Default Latitude -#define DEFAULT_LONGITUDE 0.0f // Default Longitude - -#define DEFAULT_SYSLOG_IP "" // Syslog IP Address -#define DEFAULT_SYSLOG_PORT 0 // Standard syslog port: 514 -#define DEFAULT_SYSLOG_FACILITY 0 // kern -#define DEFAULT_SYSLOG_LEVEL 0 // Syslog Log Level -#define DEFAULT_SERIAL_LOG_LEVEL LOG_LEVEL_INFO // Serial Log Level -#define DEFAULT_WEB_LOG_LEVEL LOG_LEVEL_INFO // Web Log Level -#define DEFAULT_SD_LOG_LEVEL 0 // SD Card Log Level -#define DEFAULT_USE_SD_LOG false // (true|false) Enable Logging to the SD card - -#define DEFAULT_USE_SERIAL true // (true|false) Enable Logging to the Serial Port -#define DEFAULT_SERIAL_BAUD 115200 // Serial Port Baud Rate - -#define DEFAULT_SYNC_UDP_PORT 8266 // Used for ESPEasy p2p. (IANA registered port: 8266) - - -// Factory Reset defaults -#define DEFAULT_FACTORY_RESET_KEEP_UNIT_NAME true -#define DEFAULT_FACTORY_RESET_KEEP_WIFI true -#define DEFAULT_FACTORY_RESET_KEEP_NETWORK true -#define DEFAULT_FACTORY_RESET_KEEP_NTP_DST true -#define DEFAULT_FACTORY_RESET_KEEP_CONSOLE_LOG true - - -#define BUILD_NO_DEBUG - -// Custom built-in url for hosting JavaScript and CSS files. -#define CUSTOM_BUILD_CDN_URL "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/" - - - -// Special SSID/key setup only to be used in custom builds. - -// Deployment SSID will be used only when the configured SSIDs are not reachable and/or no credentials are set. -// This to make deployment of large number of nodes easier -#define CUSTOM_DEPLOYMENT_SSID "" // Enter SSID not shown in UI, to be used on custom builds to ease deployment -#define CUSTOM_DEPLOYMENT_KEY "" // Enter key not shown in UI, to be used on custom builds to ease deployment -#define CUSTOM_SUPPORT_SSID "" // Enter SSID not shown in UI, to be used on custom builds to ease support -#define CUSTOM_SUPPORT_KEY "" // Enter key not shown in UI, to be used on custom builds to ease support - - -// Emergency fallback SSID will only be attempted in the first 10 minutes after reboot. -// When found, the unit will connect to it and depending on the built in flag, it will either just connect to it, or clear set credentials. -// Use case: User connects to a public AP which does need to agree on an agreement page for the rules of conduct (e.g. open APs) -// This is seen as a valid connection, so the unit will not reconnect to another node and thus becomes inaccessible. -#define CUSTOM_EMERGENCY_FALLBACK_SSID "" // Enter SSID not shown in UI, to be used to regain access to the node -#define CUSTOM_EMERGENCY_FALLBACK_KEY "" // Enter key not shown in UI, to be used to regain access to the node - -#define CUSTOM_EMERGENCY_FALLBACK_RESET_CREDENTIALS false -#define CUSTOM_EMERGENCY_FALLBACK_START_AP false - -#define CUSTOM_EMERGENCY_FALLBACK_ALLOW_MINUTES_UPTIME 10 - -// Allow for remote provisioning of a node. -// This is only allowed for custom builds. -// To setup the configuration of the provisioning file, one must also define FEATURE_SETTINGS_ARCHIVE -// Default setting is to not allow to configure a node remotely, unless explicitly enabled. -// #define FEATURE_CUSTOM_PROVISIONING 1 - -#define FEATURE_SSDP 1 - -#define FEATURE_EXT_RTC 1 // Support for external RTC clock modules like PCF8563/PCF8523/DS3231/DS1307 - -#define FEATURE_PLUGIN_STATS 1 // Support collecting historic data + computing stats on historic data -#ifdef ESP8266 -# define PLUGIN_STATS_NR_ELEMENTS 16 -#endif // ifdef ESP8266 -# ifdef ESP32 -# define PLUGIN_STATS_NR_ELEMENTS 64 -#endif // ifdef ESP32 -#define FEATURE_CHART_JS 1 // Support for drawing charts, like PluginStats historic data - -// Optional alternative CDN links: -// Chart.js: (only used when FEATURE_CHART_JS is enabled) -// #define CDN_URL_CHART_JS "https://cdn.jsdelivr.net/npm/chart.js@4.1.2/dist/chart.umd.min.js" -// JQuery: -// #define CDN_URL_JQUERY "https://code.jquery.com/jquery-3.6.0.min.js" - - -// #define FEATURE_SETTINGS_ARCHIVE 1 -// #define FEATURE_I2CMULTIPLEXER 1 -// #define FEATURE_TRIGONOMETRIC_FUNCTIONS_RULES 1 -// #define PLUGIN_USES_ADAFRUITGFX // Used by Display plugins using Adafruit GFX library -// #define ADAGFX_ARGUMENT_VALIDATION 0 // Disable argument validation in AdafruitGFX_helper -// #define ADAGFX_SUPPORT_7COLOR 0 // Disable the support of 7-color eInk displays by AdafruitGFX_helper -// #define FEATURE_SEND_TO_HTTP 1 // Enable availability of the SendToHTTP command -// #define FEATURE_POST_TO_HTTP 1 // Enable availability of the PostToHTTP command -// #define FEATURE_PUT_TO_HTTP 1 // Enable availability of the PutToHTTP command -// #define FEATURE_I2C_DEVICE_CHECK 0 // Disable the I2C Device check feature -// #define FEATURE_I2C_GET_ADDRESS 0 // Disable fetching the I2C address from I2C plugins. Will be enabled when FEATURE_I2C_DEVICE_CHECK is enabled -// #define FEATURE_RTTTL 1 // Enable rtttl command -// #define FEATURE_ANYRTTTL_LIB 1 // Use AnyRttl library for RTTTL handling -// #define FEATURE_ANYRTTTL_ASYNC 1 // When AnyRttl enabled, use Async (nonblocking) mode instead of the default Blocking mode -// #define FEATURE_RTTTL_EVENTS 1 // Enable RTTTL events for Async use, for blocking it doesn't make sense - -#if FEATURE_CUSTOM_PROVISIONING -// For device models, see src/src/DataTypes/DeviceModel.h -// #ifdef ESP32 -// #define DEFAULT_FACTORY_DEFAULT_DEVICE_MODEL 0 // DeviceModel_default -// #endif -// #ifdef ESP8266 -// #define DEFAULT_FACTORY_DEFAULT_DEVICE_MODEL 0 // DeviceModel_default -// #endif -// #define DEFAULT_PROVISIONING_FETCH_RULES1 false -// #define DEFAULT_PROVISIONING_FETCH_RULES2 false -// #define DEFAULT_PROVISIONING_FETCH_RULES3 false -// #define DEFAULT_PROVISIONING_FETCH_RULES4 false -// #define DEFAULT_PROVISIONING_FETCH_NOTIFICATIONS false -// #define DEFAULT_PROVISIONING_FETCH_SECURITY false -// #define DEFAULT_PROVISIONING_FETCH_CONFIG false -// #define DEFAULT_PROVISIONING_FETCH_PROVISIONING false -// #define DEFAULT_PROVISIONING_FETCH_FIRMWARE false -// #define DEFAULT_PROVISIONING_SAVE_URL false -// #define DEFAULT_PROVISIONING_SAVE_CREDENTIALS false -// #define DEFAULT_PROVISIONING_ALLOW_FETCH_COMMAND false -// #define DEFAULT_PROVISIONING_URL "" -// #define DEFAULT_PROVISIONING_USER "" -// #define DEFAULT_PROVISIONING_PASS "" -#endif - - - - -/* - ####################################################################################################### - Defining web interface - ####################################################################################################### - */ - -#define MENU_INDEX_MAIN_VISIBLE true -/* -#define MENU_INDEX_CONFIG_VISIBLE false -#define MENU_INDEX_CONTROLLERS_VISIBLE false -#define MENU_INDEX_HARDWARE_VISIBLE false -#define MENU_INDEX_DEVICES_VISIBLE false -#define MENU_INDEX_RULES_VISIBLE false -#define MENU_INDEX_NOTIFICATIONS_VISIBLE false -#define MENU_INDEX_TOOLS_VISIBLE false -*/ - -#define MAIN_PAGE_SHOW_SYSINFO_BUTTON true -#define MAIN_PAGE_SHOW_WiFi_SETUP_BUTTON true -#define MAIN_PAGE_SHOW_BASIC_INFO_NOT_LOGGED_IN false - -#define MAIN_PAGE_SHOW_NODE_LIST_BUILD true -#define MAIN_PAGE_SHOW_NODE_LIST_TYPE true - -#define SETUP_PAGE_SHOW_CONFIG_BUTTON true - -// #define FEATURE_AUTO_DARK_MODE 0 // 0 = Disable auto-dark mode -// #define FEATURE_EXTENDED_TASK_VALUE_TYPES 0 // 0 = Disable extra task value types like 64 bit ints, double, etc. in Dummy tasks -// #define FEATURE_USE_DOUBLE_AS_ESPEASY_RULES_FLOAT_TYPE 0 // 0 = switch to float as floating point type for rules/formula processing. - -//#define WEBPAGE_TEMPLATE_HIDE_HELP_BUTTON - -#define SHOW_SYSINFO_JSON 1 //Enables the sysinfo_json page (by default is enabled when WEBSERVER_NEW_UI is enabled too) - -/* - ####################################################################################################### - CSS / template - ####################################################################################################### - */ -/* -#define WEBPAGE_TEMPLATE_DEFAULT_HEADER "

ESP Easy Mega: {{title}}


" -#define WEBPAGE_TEMPLATE_DEFAULT_FOOTER "" -#define WEBPAGE_TEMPLATE_AP_HEADER "

Welcome to ESP Easy Mega AP

" -#define WEBPAGE_TEMPLATE_HIDE_HELP_BUTTON -*/ -// Embed Custom CSS in Custom.h: -/* -#define WEBSERVER_EMBED_CUSTOM_CSS -static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { -... -,0}; -*/ - - -/* - ####################################################################################################### - Special settings (rendering settings incompatible with other builds) - ####################################################################################################### - */ - -// #define FEATURE_NON_STANDARD_24_TASKS 1 - -/* - ####################################################################################################### - Your Own selection of plugins and controllers - ####################################################################################################### - */ - -#define CONTROLLER_SET_NONE -#define NOTIFIER_SET_NONE -#define PLUGIN_SET_NONE - - -/* - ####################################################################################################### - ########### Plugins - ####################################################################################################### - */ - -// #define FEATURE_SERVO 1 // Uncomment and set to 0 to explicitly disable SERVO support - - -// #define USES_P001 // Switch -// #define USES_P002 // ADC -// #define USES_P003 // Pulse -// #define USES_P004 // 1-Wire Temperature (Dallas/Maxim DS18B20) -// #define USES_P005 // DHT11/12/22 SONOFF2301/7021/MS01 -// #define USES_P006 // BMP085/180 -// #define USES_P007 // PCF8591 -// #define USES_P008 // Wiegand (RFID) -// #define USES_P009 // MCP23017 - -// #define USES_P010 // BH1750 -// #define USES_P011 // ProMini Extender -// #define USES_P012 // LCD2004 -// #define USES_P013 // HC-SR04/RCW-0001 -// #define USES_P014 // SI70xx/HTU21D -// #define USES_P015 // TSL2561 -// #define USES_P017 // PN532 -// #define USES_P018 // GP2Y10 -// #define USES_P019 // PCF8574 - -// #define USES_P020 // Ser2Net -// #define USES_P021 // Level Control -// #define USES_P022 // PCA9685 -// #define USES_P023 // OLED SSD1306 -// #define USES_P024 // MLX90614 -// #define USES_P025 // ADS1x15 -// #define USES_P026 // SysInfo -// #define USES_P027 // INA219 -// #define USES_P028 // BMx280 -// #define USES_P029 // Domoticz MQTT Helper - -// #define USES_P031 // SHT1x -// #define USES_P032 // MS5611 (GY-63) -// #define USES_P033 // Dummy Device -// #define USES_P034 // DHT12 -// #define USES_P036 // OLED SSD1306/SH1106 Framed -// #define P036_FEATURE_DISPLAY_PREVIEW 1 // Enable Preview feature, shows on-display content on Devices overview page -// #define P036_FEATURE_ALIGN_PREVIEW 1 // Enable center/right-align feature when preview is enabled (auto-disabled for 1M builds) -// #define P036_ENABLE_TICKER 1 // Enable ticker function -// #define USES_P037 // MQTT Import -// #define P037_MAPPING_SUPPORT 1 // Enable Value mapping support -// #define P037_FILTER_SUPPORT 1 // Enable filtering support -// #define P037_JSON_SUPPORT 1 // Enable Json support -// #define USES_P038 // NeoPixel -// #define P038_FEATURE_NEOPIXELFOR 1 // Enable NeoPixelFor/NeoPixelForHSV commands (default enabled for ESP32) -// #define USES_P039 // Thermocouple - -// #define USES_P040 // RFID - ID12LA/RDM6300 -// #define USES_P041 // NeoPixel (Word Clock) -// #define USES_P042 // NeoPixel (Candle) -// #define USES_P043 // ClkOutput -// #define USES_P044 // P1 Wifi Gateway -// #define USES_P045 // MPU6050 -// #define USES_P046 // Ventus W266 -// #define USES_P047 // Soil moisture sensor -// #define USES_P048 // Motoshield v2 -// #define USES_P049 // MH-Z19 - -// #define USES_P050 // TCS34725 RGB Color Sensor with IR filter and White LED -// #define USES_P051 // AM2320 -// #define USES_P052 // SenseAir -// #define USES_P053 // PMSx003 / PMSx003ST -// #define USES_P054 // DMX512 -// #define USES_P055 // Chiming -// #define USES_P056 // SDS011/018/198 -// #define USES_P057 // HT16K33_LED -// #define USES_P058 // HT16K33_KeyPad -// #define USES_P059 // Rotary Encoder - -// #define USES_P060 // MCP3221 -// #define USES_P061 // PCF8574 / MCP23017 / PCA8575 -// #define USES_P062 // MPR121 -// #define USES_P063 // TTP229 -// #define USES_P064 // APDS9960 Gesture -// #define USES_P065 // DRF0299 -// #define USES_P066 // VEML6040 -// #define USES_P067 // HX711_Load_Cell -// #define USES_P068 // SHT3x -// #define USES_P069 // LM75A - -// #define USES_P070 // NeoPixel_Clock -// #define USES_P071 // Kamstrup401 -// #define USES_P072 // HDC1000/HDC1008/HDC1010/HDC1050/HDC1080 -// #define USES_P073 // 7-segment display -// #define USES_P074 // TSL2591 -// #define USES_P075 // Nextion -// #define USES_P076 // HLW8012/BL0937 (Shelly Plug S, Sonoff POW R1, Huafan SS, KMC 70011, Aplic WDP303075, SK03 Outdoor, BlitzWolf SHP, Teckin, Teckin US, Gosund SP1 v23) -// #define USES_P077 // CSE7766 (Sonoff S31, Sonoff POW R2, Sonoff POW R3xx(D), Sonoff Dual R3) -// #define USES_P078 // Eastron SDMxxx Modbus -// #define USES_P079 // Wemos / Lolin Motorshield - -// #define USES_P080 // iButton Sensor DS1990A -// #define USES_P081 // Cron -// #define USES_P082 // GPS -// #define USES_P083 // SGP30 TVOC -// #define USES_P084 // VEML6070 -// #define USES_P085 // AcuDC24x -// #define USES_P086 // Receiving values according Homie convention. Works together with C014 Homie controller -// #define USES_P087 // Serial Proxy -// #define USES_P088 // HeatpumpIR -// #define USES_P089 // Ping - -// #define USES_P090 // CCS811 TVOC -// #define USES_P091 // Serial MCU controlled switch -// #define USES_P092 // DLbus -// #define USES_P093 // Mitsubishi Heat Pump -// #define USES_P094 // CUL Reader -// #define USES_P095 // ILI934x / ILI948x -// #define USES_P096 // eInk -// #define USES_P097 // ESP32 Touch -// #define USES_P098 // PWM Motor -// #define USES_P099 // XPT2046 touchscreen - -// #define USES_P100 // DS2423 counter -// #define USES_P101 // Wake On Lan -// #define USES_P102 // PZEM-004Tv30-Multiple -// #define USES_P103 // Atlas Scientific EZO Sensors (pH, ORP, EZO, DO) -// #define USES_P104 // MAX7219 dot matrix -// #define USES_P105 // AHT10/AHT2x -// #define USES_P106 // BME68x -// #define USES_P107 // SI1145 -// #define USES_P108 // DDS238-x ZN Modbus energy meters -// #define USES_P109 // ThermoOLED - -// #define USES_P110 // VL53L0X Time of Flight sensor -// #define USES_P111 // MFRC522 RFID reader -// #define USES_P112 // AS7265x -// #define USES_P113 // VL53L1X ToF -// #define USES_P114 // VEML6075 -// #define USES_P115 // MAX1704x -// #define USES_P116 // ST77xx -// #define USES_P117 // SCD30 -// #define USES_P118 // Itho -// #define USES_P119 // ITG3205 Gyro - -// #define USES_P120 // ADXL345 I2C Acceleration / Gravity -// #define USES_P121 // HMC5883L -// #define USES_P122 // SHT2x -// #define USES_P123 // I2C Touchscreens -// #define USES_P124 // I2C Multi Relay -// #define USES_P125 // ADXL345 SPI Acceleration / Gravity -// #define USES_P126 // 74HC595 Shift register -// #define USES_P127 // CDM7160 -// #define USES_P128 // NeoPixel (BusFX) -// #define P128_USES_GRB // Default -// #define P128_USES_GRBW // Select 1 option, only first one enabled from this list will be used -// #define P128_USES_RGB -// #define P128_USES_RGBW -// #define P128_USES_BRG -// #define P128_USES_BGR -// #define P128_USES_RBG -// #define P128_ENABLE_FAKETV 1 // Enable(1)/Disable(0) FakeTV effect, disabled by default on ESP8266 (.bin size issue), enabled by default on ESP32 -// #define USES_P129 // 74HC165 Input shiftregisters - -// #define USES_P131 // NeoPixel Matrix -// #define USES_P132 // INA3221 -// #define USES_P133 // LTR390 UV -// #define USES_P134 // A02YYUW -// #define USES_P135 // SCD4x -// #define P135_FEATURE_RESET_COMMANDS 1 // Enable/Disable quite spacious (~950 bytes) 'selftest' and 'factoryreset' subcommands -// #define USES_P137 // AXP192 -// #define USES_P138 // IP5306 - -// #define USES_P141 // PCD8544 Nokia 5110 LCD -// #define USES_P142 // Position - AS5600 -// #define USES_P143 // I2C Rotary encoders -// #define P143_FEATURE_INCLUDE_M5STACK 0 // Enabled by default, can be turned off here -// #define P143_FEATURE_INCLUDE_DFROBOT 0 // Enabled by default, can be turned off here -// #define P143_FEATURE_COUNTER_COLORMAPPING 0 // Enabled by default, can be turned off here - -// #define USES_P144 // PM1006(K) (Vindriktning) -// #define USES_P145 // MQxxx (MQ135 CO2, MQ3 Alcohol) -// #define USES_P146 // Cache Reader -// #define USES_P147 // SGP4x -// #define P147_FEATURE_GASINDEXALGORITHM 0 // Enabled by default, can be turned off here - -// #define USES_P148 // POWR3xxD/THR3xxD -// #define USES_P150 // TMP117 Temperature -// #define USES_P151 // Honeywell Pressure -// #define USES_P152 // ESP32 DAC -// #define USES_P153 // SHT4x -// #define USES_P154 // BMP3xx I2C - -// #define USES_P159 // Presence - LD2410 Radar detection - -// #define USES_P162 // Output - MCP42xxx Digipot -// #define USES_P163 // Environment - RadSens I2C radiation counter -// #define USES_P164 // Gases - ENS16x TVOC/eCO2 -// #define USES_P166 // Output - GP8403 Dual channel DAC (Digital Analog Converter) -// #define USES_P167 // Environment - Sensirion SEN5x / Ikea Vindstyrka -// #define USES_P168 // Light - VEML6030/VEML7700 -// #define USES_P169 // Environment - AS3935 Lightning Detector -// #define USES_P170 // Input - I2C Liquid level sensor -// #define USES_P172 // BMP3xx SPI. -// #define USES_P173 // Environment - SHTC3 - -/* - ####################################################################################################### - ########### Controllers - ####################################################################################################### - */ - - -// #define USES_C001 // Domoticz HTTP -// #define USES_C002 // Domoticz MQTT -// #define USES_C003 // Nodo telnet -// #define USES_C004 // ThingSpeak -// #define USES_C005 // Home Assistant (openHAB) MQTT -// #define USES_C006 // PiDome MQTT -// #define USES_C007 // Emoncms -// #define USES_C008 // Generic HTTP -// #define USES_C009 // FHEM HTTP -// #define USES_C010 // Generic UDP -// #define USES_C011 // Generic HTTP Advanced -// #define USES_C012 // Blynk HTTP -// #define USES_C013 // ESPEasy P2P network -// #define USES_C014 // homie 3 & 4dev MQTT -// #define USES_C015 // Blynk -// #define USES_C016 // Cache controller -// #define USES_C017 // Zabbix -// #define USES_C018 // TTN/RN2483 - - -/* - ####################################################################################################### - ########### Notifiers - ####################################################################################################### - */ - - -// #define USES_N001 // Email -// #define USES_N002 // Buzzer - - -#endif // ESPEASY_CUSTOM_H +#ifndef ESPEASY_CUSTOM_H +#define ESPEASY_CUSTOM_H + +/* + To modify the stock configuration without changing the EspEasy.ino file : + 1) rename this file to "Custom.h" (It is ignored by Git) + 2) define your own settings below + 3) define USE_CUSTOM_H as a build flags. ie : export PLATFORMIO_BUILD_FLAGS="'-DUSE_CUSTOM_H'" + */ + + +/* + ####################################################################################################### + Your Own Default Settings + ####################################################################################################### + You can basically ovveride ALL macro defined in ESPEasy.ino. + Don't forget to first #undef each existing #define that you add below. + But since this Custom.h is included before other defines are made, you don't have to undef a lot of defines. + Here are some examples: + */ + +// --- Feature Flagging --------------------------------------------------------- +// Can be set to 1 to enable, 0 to disable, or not set to use the default (usually via define_plugin_sets.h) + +#define FEATURE_RULES_EASY_COLOR_CODE 1 // Use code highlighting, autocompletion and command suggestions in Rules +#define FEATURE_ESPEASY_P2P 1 // (1/0) enables the ESP Easy P2P protocol +#define FEATURE_ARDUINO_OTA 1 // enables the Arduino OTA capabilities +#define FEATURE_THINGSPEAK_EVENT 1 // generate an event when requesting last value of a field in thingspeak via SendToHTTP(e.g. sendToHTTP,api.thingspeak.com,80,/channels/1667332/fields/5/last) +// #define FEATURE_SD 1 // Enable SD card support +// #define FEATURE_DOWNLOAD 1 // Enable downloading a file from an url + +#ifdef BUILD_GIT +# undef BUILD_GIT +#endif // ifdef BUILD_GIT + +#define BUILD_GIT "My Build: " __DATE__ " " __TIME__ + + +#define DEFAULT_NAME "MyEspEasyDevice" // Enter your device friendly name +#define UNIT 0 // Unit Number +#define DEFAULT_DELAY 60 // Sleep Delay in seconds + +// --- Wifi AP Mode (when your Wifi Network is not reachable) ---------------------------------------- +#define DEFAULT_AP_IP 192, 168, 4, 1 // Enter IP address (comma separated) for AP (config) mode +#define DEFAULT_AP_SUBNET 255, 255, 255, 0 // Enter IP address (comma separated) for AP (config) mode +#define DEFAULT_AP_KEY "configesp" // Enter network WPA key for AP (config) mode + +// --- Wifi Client Mode ----------------------------------------------------------------------------- +#define DEFAULT_SSID "MyHomeSSID" // Enter your network SSID +#define DEFAULT_KEY "MySuperSecretPassword" // Enter your network WPA key +#define DEFAULT_SSID2 "" // Enter your fallback network SSID +#define DEFAULT_KEY2 "" // Enter your fallback network WPA key +#define DEFAULT_WIFI_INCLUDE_HIDDEN_SSID false // Allow to connect to hidden SSID APs +#define DEFAULT_USE_STATIC_IP false // (true|false) enabled or disabled static IP +#define DEFAULT_IP "192.168.0.50" // Enter your IP address +#define DEFAULT_DNS "192.168.0.1" // Enter your DNS +#define DEFAULT_GW "192.168.0.1" // Enter your Gateway +#define DEFAULT_SUBNET "255.255.255.0" // Enter your Subnet +#define DEFAULT_IPRANGE_LOW "0.0.0.0" // Allowed IP range to access webserver +#define DEFAULT_IPRANGE_HIGH "255.255.255.255" // Allowed IP range to access webserver +#define DEFAULT_IP_BLOCK_LEVEL 1 // 0: ALL_ALLOWED 1: LOCAL_SUBNET_ALLOWED 2: +// ONLY_IP_RANGE_ALLOWED +#define DEFAULT_ADMIN_USERNAME "admin" +#define DEFAULT_ADMIN_PASS "" + +#define DEFAULT_WIFI_CONNECTION_TIMEOUT 10000 // minimum timeout in ms for WiFi to be connected. +#define DEFAULT_WIFI_FORCE_BG_MODE false // when set, only allow to connect in 802.11B or G mode (not N) +#define DEFAULT_WIFI_RESTART_WIFI_CONN_LOST false // Perform wifi off and on when connection was lost. +#define DEFAULT_ECO_MODE false // When set, make idle calls between executing tasks. +#define DEFAULT_WIFI_NONE_SLEEP false // When set, the wifi will be set to no longer sleep (more power +// used and need reboot to reset mode) +#define DEFAULT_GRATUITOUS_ARP false // When set, the node will send periodical gratuitous ARP + // packets to announce itself. +#define DEFAULT_TOLERANT_LAST_ARG_PARSE false // When set, the last argument of some commands will be parsed to the end of the line + // See: https://github.com/letscontrolit/ESPEasy/issues/2724 +#define DEFAULT_SEND_TO_HTTP_ACK false // Wait for ack with SendToHttp command. + +#define DEFAULT_AP_DONT_FORCE_SETUP false // Allow optional usage of Sensor without WIFI avaiable // When set you can use the Sensor in AP-Mode without beeing forced to /setup +#define DEFAULT_DONT_ALLOW_START_AP false // Usually the AP will be started when no WiFi is defined, or the defined one cannot be found. This flag may prevent it. + +// --- Default Controller ------------------------------------------------------------------------------ +#define DEFAULT_CONTROLLER false // true or false enabled or disabled, set 1st controller + // defaults +#define DEFAULT_CONTROLLER_ENABLED true // Enable default controller by default +#define DEFAULT_CONTROLLER_USER "" // Default controller user +#define DEFAULT_CONTROLLER_PASS "" // Default controller Password + +// using a default template, you also need to set a DEFAULT PROTOCOL to a suitable MQTT protocol ! +#define DEFAULT_PUB "sensors/espeasy/%sysname%/%tskname%/%valname%" // Enter your pub +#define DEFAULT_SUB "sensors/espeasy/%sysname%/#" // Enter your sub +#define DEFAULT_SERVER "192.168.0.8" // Enter your Server IP address +#define DEFAULT_SERVER_HOST "" // Server hostname +#define DEFAULT_SERVER_USEDNS false // true: Use hostname. false: use IP +#define DEFAULT_USE_EXTD_CONTROLLER_CREDENTIALS false // true: Allow longer user credentials for controllers + +#define DEFAULT_PORT 8080 // Enter your Server port value +#define DEFAULT_CONTROLLER_TIMEOUT 100 // Default timeout in msec + +#define DEFAULT_PROTOCOL 0 // Protocol used for controller communications + // 0 = Stand-alone (no controller set) + // 1 = Domoticz HTTP + // 2 = Domoticz MQTT + // 3 = Nodo Telnet + // 4 = ThingSpeak + // 5 = Home Assistant (openHAB) MQTT + // 6 = PiDome MQTT + // 7 = EmonCMS + // 8 = Generic HTTP + // 9 = FHEM HTTP + +#ifdef ESP8266 +#define DEFAULT_PIN_I2C_SDA 4 +#endif +#ifdef ESP32 +#define DEFAULT_PIN_I2C_SDA -1 // Undefined +#endif +#ifdef ESP8266 +#define DEFAULT_PIN_I2C_SCL 5 +#endif +#ifdef ESP32 +#define DEFAULT_PIN_I2C_SCL -1 // Undefined +#endif +#define DEFAULT_I2C_CLOCK_SPEED 400000 // Use 100 kHz if working with old I2C chips +#define FEATURE_I2C_DEVICE_SCAN 1 + +#define DEFAULT_SPI 0 //0=disabled 1=enabled and for ESP32 there is option 2 =HSPI + +#define DEFAULT_PIN_STATUS_LED (-1) +#define DEFAULT_PIN_STATUS_LED_INVERSED true + +#define DEFAULT_PIN_RESET_BUTTON (-1) + + +#define DEFAULT_USE_RULES false // (true|false) Enable Rules? +#define DEFAULT_RULES_OLDENGINE true + +#define DEFAULT_MQTT_RETAIN false // (true|false) Retain MQTT messages? +#define DEFAULT_CONTROLLER_DELETE_OLDEST false // (true|false) to delete oldest message when queue is full +#define DEFAULT_CONTROLLER_MUST_CHECK_REPLY false // (true|false) Check Acknowledgment +#define DEFAULT_MQTT_DELAY 100 // Time in milliseconds to retain MQTT messages +#define DEFAULT_MQTT_LWT_TOPIC "" // Default lwt topic +#define DEFAULT_MQTT_LWT_CONNECT_MESSAGE "Connected" // Default lwt message +#define DEFAULT_MQTT_LWT_DISCONNECT_MESSAGE "Connection Lost" // Default lwt message +#define DEFAULT_MQTT_USE_UNITNAME_AS_CLIENTID 0 + +#define DEFAULT_USE_NTP false // (true|false) Use NTP Server +#define DEFAULT_NTP_HOST "" // NTP Server Hostname +#define DEFAULT_TIME_ZONE 0 // Time Offset (in minutes) +#define DEFAULT_USE_DST false // (true|false) Use Daily Time Saving + +#define DEFAULT_LATITUDE 0.0f // Default Latitude +#define DEFAULT_LONGITUDE 0.0f // Default Longitude + +#define DEFAULT_SYSLOG_IP "" // Syslog IP Address +#define DEFAULT_SYSLOG_PORT 0 // Standard syslog port: 514 +#define DEFAULT_SYSLOG_FACILITY 0 // kern +#define DEFAULT_SYSLOG_LEVEL 0 // Syslog Log Level +#define DEFAULT_SERIAL_LOG_LEVEL LOG_LEVEL_INFO // Serial Log Level +#define DEFAULT_WEB_LOG_LEVEL LOG_LEVEL_INFO // Web Log Level +#define DEFAULT_SD_LOG_LEVEL 0 // SD Card Log Level +#define DEFAULT_USE_SD_LOG false // (true|false) Enable Logging to the SD card + +#define DEFAULT_USE_SERIAL true // (true|false) Enable Logging to the Serial Port +#define DEFAULT_SERIAL_BAUD 115200 // Serial Port Baud Rate + +#define DEFAULT_SYNC_UDP_PORT 8266 // Used for ESPEasy p2p. (IANA registered port: 8266) + + +// Factory Reset defaults +#define DEFAULT_FACTORY_RESET_KEEP_UNIT_NAME true +#define DEFAULT_FACTORY_RESET_KEEP_WIFI true +#define DEFAULT_FACTORY_RESET_KEEP_NETWORK true +#define DEFAULT_FACTORY_RESET_KEEP_NTP_DST true +#define DEFAULT_FACTORY_RESET_KEEP_CONSOLE_LOG true + + +#define BUILD_NO_DEBUG + +// Custom built-in url for hosting JavaScript and CSS files. +#define CUSTOM_BUILD_CDN_URL "https://cdn.jsdelivr.net/gh/letscontrolit/ESPEasy@mega/static/" + + + +// Special SSID/key setup only to be used in custom builds. + +// Deployment SSID will be used only when the configured SSIDs are not reachable and/or no credentials are set. +// This to make deployment of large number of nodes easier +#define CUSTOM_DEPLOYMENT_SSID "" // Enter SSID not shown in UI, to be used on custom builds to ease deployment +#define CUSTOM_DEPLOYMENT_KEY "" // Enter key not shown in UI, to be used on custom builds to ease deployment +#define CUSTOM_SUPPORT_SSID "" // Enter SSID not shown in UI, to be used on custom builds to ease support +#define CUSTOM_SUPPORT_KEY "" // Enter key not shown in UI, to be used on custom builds to ease support + + +// Emergency fallback SSID will only be attempted in the first 10 minutes after reboot. +// When found, the unit will connect to it and depending on the built in flag, it will either just connect to it, or clear set credentials. +// Use case: User connects to a public AP which does need to agree on an agreement page for the rules of conduct (e.g. open APs) +// This is seen as a valid connection, so the unit will not reconnect to another node and thus becomes inaccessible. +#define CUSTOM_EMERGENCY_FALLBACK_SSID "" // Enter SSID not shown in UI, to be used to regain access to the node +#define CUSTOM_EMERGENCY_FALLBACK_KEY "" // Enter key not shown in UI, to be used to regain access to the node + +#define CUSTOM_EMERGENCY_FALLBACK_RESET_CREDENTIALS false +#define CUSTOM_EMERGENCY_FALLBACK_START_AP false + +#define CUSTOM_EMERGENCY_FALLBACK_ALLOW_MINUTES_UPTIME 10 + +// Allow for remote provisioning of a node. +// This is only allowed for custom builds. +// To setup the configuration of the provisioning file, one must also define FEATURE_SETTINGS_ARCHIVE +// Default setting is to not allow to configure a node remotely, unless explicitly enabled. +// #define FEATURE_CUSTOM_PROVISIONING 1 + +#define FEATURE_SSDP 1 + +#define FEATURE_EXT_RTC 1 // Support for external RTC clock modules like PCF8563/PCF8523/DS3231/DS1307 + +#define FEATURE_PLUGIN_STATS 1 // Support collecting historic data + computing stats on historic data +#ifdef ESP8266 +# define PLUGIN_STATS_NR_ELEMENTS 16 +#endif // ifdef ESP8266 +# ifdef ESP32 +# define PLUGIN_STATS_NR_ELEMENTS 64 +#endif // ifdef ESP32 +#define FEATURE_CHART_JS 1 // Support for drawing charts, like PluginStats historic data + +// Optional alternative CDN links: +// Chart.js: (only used when FEATURE_CHART_JS is enabled) +// #define CDN_URL_CHART_JS "https://cdn.jsdelivr.net/npm/chart.js@4.1.2/dist/chart.umd.min.js" +// JQuery: +// #define CDN_URL_JQUERY "https://code.jquery.com/jquery-3.6.0.min.js" + + +// #define FEATURE_SETTINGS_ARCHIVE 1 +// #define FEATURE_I2CMULTIPLEXER 1 +// #define FEATURE_TRIGONOMETRIC_FUNCTIONS_RULES 1 +// #define PLUGIN_USES_ADAFRUITGFX // Used by Display plugins using Adafruit GFX library +// #define ADAGFX_ARGUMENT_VALIDATION 0 // Disable argument validation in AdafruitGFX_helper +// #define ADAGFX_SUPPORT_7COLOR 0 // Disable the support of 7-color eInk displays by AdafruitGFX_helper +// #define FEATURE_SEND_TO_HTTP 1 // Enable availability of the SendToHTTP command +// #define FEATURE_POST_TO_HTTP 1 // Enable availability of the PostToHTTP command +// #define FEATURE_PUT_TO_HTTP 1 // Enable availability of the PutToHTTP command +// #define FEATURE_I2C_DEVICE_CHECK 0 // Disable the I2C Device check feature +// #define FEATURE_I2C_GET_ADDRESS 0 // Disable fetching the I2C address from I2C plugins. Will be enabled when FEATURE_I2C_DEVICE_CHECK is enabled +// #define FEATURE_RTTTL 1 // Enable rtttl command +// #define FEATURE_ANYRTTTL_LIB 1 // Use AnyRttl library for RTTTL handling +// #define FEATURE_ANYRTTTL_ASYNC 1 // When AnyRttl enabled, use Async (nonblocking) mode instead of the default Blocking mode +// #define FEATURE_RTTTL_EVENTS 1 // Enable RTTTL events for Async use, for blocking it doesn't make sense + +#if FEATURE_CUSTOM_PROVISIONING +// For device models, see src/src/DataTypes/DeviceModel.h +// #ifdef ESP32 +// #define DEFAULT_FACTORY_DEFAULT_DEVICE_MODEL 0 // DeviceModel_default +// #endif +// #ifdef ESP8266 +// #define DEFAULT_FACTORY_DEFAULT_DEVICE_MODEL 0 // DeviceModel_default +// #endif +// #define DEFAULT_PROVISIONING_FETCH_RULES1 false +// #define DEFAULT_PROVISIONING_FETCH_RULES2 false +// #define DEFAULT_PROVISIONING_FETCH_RULES3 false +// #define DEFAULT_PROVISIONING_FETCH_RULES4 false +// #define DEFAULT_PROVISIONING_FETCH_NOTIFICATIONS false +// #define DEFAULT_PROVISIONING_FETCH_SECURITY false +// #define DEFAULT_PROVISIONING_FETCH_CONFIG false +// #define DEFAULT_PROVISIONING_FETCH_PROVISIONING false +// #define DEFAULT_PROVISIONING_FETCH_FIRMWARE false +// #define DEFAULT_PROVISIONING_SAVE_URL false +// #define DEFAULT_PROVISIONING_SAVE_CREDENTIALS false +// #define DEFAULT_PROVISIONING_ALLOW_FETCH_COMMAND false +// #define DEFAULT_PROVISIONING_URL "" +// #define DEFAULT_PROVISIONING_USER "" +// #define DEFAULT_PROVISIONING_PASS "" +#endif + + + + +/* + ####################################################################################################### + Defining web interface + ####################################################################################################### + */ + +#define MENU_INDEX_MAIN_VISIBLE true +/* +#define MENU_INDEX_CONFIG_VISIBLE false +#define MENU_INDEX_CONTROLLERS_VISIBLE false +#define MENU_INDEX_HARDWARE_VISIBLE false +#define MENU_INDEX_DEVICES_VISIBLE false +#define MENU_INDEX_RULES_VISIBLE false +#define MENU_INDEX_NOTIFICATIONS_VISIBLE false +#define MENU_INDEX_TOOLS_VISIBLE false +*/ + +#define MAIN_PAGE_SHOW_SYSINFO_BUTTON true +#define MAIN_PAGE_SHOW_WiFi_SETUP_BUTTON true +#define MAIN_PAGE_SHOW_BASIC_INFO_NOT_LOGGED_IN false + +#define MAIN_PAGE_SHOW_NODE_LIST_BUILD true +#define MAIN_PAGE_SHOW_NODE_LIST_TYPE true + +#define SETUP_PAGE_SHOW_CONFIG_BUTTON true + +// #define FEATURE_AUTO_DARK_MODE 0 // 0 = Disable auto-dark mode +// #define FEATURE_EXTENDED_TASK_VALUE_TYPES 0 // 0 = Disable extra task value types like 64 bit ints, double, etc. in Dummy tasks +// #define FEATURE_USE_DOUBLE_AS_ESPEASY_RULES_FLOAT_TYPE 0 // 0 = switch to float as floating point type for rules/formula processing. + +//#define WEBPAGE_TEMPLATE_HIDE_HELP_BUTTON + +#define SHOW_SYSINFO_JSON 1 //Enables the sysinfo_json page (by default is enabled when WEBSERVER_NEW_UI is enabled too) + +/* + ####################################################################################################### + CSS / template + ####################################################################################################### + */ +/* +#define WEBPAGE_TEMPLATE_DEFAULT_HEADER "

ESP Easy Mega: {{title}}


" +#define WEBPAGE_TEMPLATE_DEFAULT_FOOTER "" +#define WEBPAGE_TEMPLATE_AP_HEADER "

Welcome to ESP Easy Mega AP

" +#define WEBPAGE_TEMPLATE_HIDE_HELP_BUTTON +*/ +// Embed Custom CSS in Custom.h: +/* +#define WEBSERVER_EMBED_CUSTOM_CSS +static const char DATA_ESPEASY_DEFAULT_MIN_CSS[] PROGMEM = { +... +,0}; +*/ + + +/* + ####################################################################################################### + Special settings (rendering settings incompatible with other builds) + ####################################################################################################### + */ + +// #define FEATURE_NON_STANDARD_24_TASKS 1 + +/* + ####################################################################################################### + Your Own selection of plugins and controllers + ####################################################################################################### + */ + +#define CONTROLLER_SET_NONE +#define NOTIFIER_SET_NONE +#define PLUGIN_SET_NONE + + +/* + ####################################################################################################### + ########### Plugins + ####################################################################################################### + */ + +// #define FEATURE_SERVO 1 // Uncomment and set to 0 to explicitly disable SERVO support + + +// #define USES_P001 // Switch +// #define USES_P002 // ADC +// #define USES_P003 // Pulse +// #define USES_P004 // 1-Wire Temperature (Dallas/Maxim DS18B20) +// #define USES_P005 // DHT11/12/22 SONOFF2301/7021/MS01 +// #define USES_P006 // BMP085/180 +// #define USES_P007 // PCF8591 +// #define USES_P008 // Wiegand (RFID) +// #define USES_P009 // MCP23017 + +// #define USES_P010 // BH1750 +// #define USES_P011 // ProMini Extender +// #define USES_P012 // LCD2004 +// #define USES_P013 // HC-SR04/RCW-0001 +// #define USES_P014 // SI70xx/HTU21D +// #define USES_P015 // TSL2561 +// #define USES_P017 // PN532 +// #define USES_P018 // GP2Y10 +// #define USES_P019 // PCF8574 + +// #define USES_P020 // Ser2Net +// #define USES_P021 // Level Control +// #define USES_P022 // PCA9685 +// #define USES_P023 // OLED SSD1306 +// #define USES_P024 // MLX90614 +// #define USES_P025 // ADS1x15 +// #define USES_P026 // SysInfo +// #define USES_P027 // INA219 +// #define USES_P028 // BMx280 +// #define USES_P029 // Domoticz MQTT Helper + +// #define USES_P031 // SHT1x +// #define USES_P032 // MS5611 (GY-63) +// #define USES_P033 // Dummy Device +// #define USES_P034 // DHT12 +// #define USES_P036 // OLED SSD1306/SH1106 Framed +// #define P036_FEATURE_DISPLAY_PREVIEW 1 // Enable Preview feature, shows on-display content on Devices overview page +// #define P036_FEATURE_ALIGN_PREVIEW 1 // Enable center/right-align feature when preview is enabled (auto-disabled for 1M builds) +// #define P036_ENABLE_TICKER 1 // Enable ticker function +// #define USES_P037 // MQTT Import +// #define P037_MAPPING_SUPPORT 1 // Enable Value mapping support +// #define P037_FILTER_SUPPORT 1 // Enable filtering support +// #define P037_JSON_SUPPORT 1 // Enable Json support +// #define USES_P038 // NeoPixel +// #define P038_FEATURE_NEOPIXELFOR 1 // Enable NeoPixelFor/NeoPixelForHSV commands (default enabled for ESP32) +// #define USES_P039 // Thermocouple + +// #define USES_P040 // RFID - ID12LA/RDM6300 +// #define USES_P041 // NeoPixel (Word Clock) +// #define USES_P042 // NeoPixel (Candle) +// #define USES_P043 // ClkOutput +// #define USES_P044 // P1 Wifi Gateway +// #define USES_P045 // MPU6050 +// #define USES_P046 // Ventus W266 +// #define USES_P047 // Soil moisture sensor +// #define USES_P048 // Motoshield v2 +// #define USES_P049 // MH-Z19 + +// #define USES_P050 // TCS34725 RGB Color Sensor with IR filter and White LED +// #define USES_P051 // AM2320 +// #define USES_P052 // SenseAir +// #define USES_P053 // PMSx003 / PMSx003ST +// #define USES_P054 // DMX512 +// #define USES_P055 // Chiming +// #define USES_P056 // SDS011/018/198 +// #define USES_P057 // HT16K33_LED +// #define USES_P058 // HT16K33_KeyPad +// #define USES_P059 // Rotary Encoder + +// #define USES_P060 // MCP3221 +// #define USES_P061 // PCF8574 / MCP23017 / PCA8575 +// #define USES_P062 // MPR121 +// #define USES_P063 // TTP229 +// #define USES_P064 // APDS9960 Gesture +// #define USES_P065 // DRF0299 +// #define USES_P066 // VEML6040 +// #define USES_P067 // HX711_Load_Cell +// #define USES_P068 // SHT3x +// #define USES_P069 // LM75A + +// #define USES_P070 // NeoPixel_Clock +// #define USES_P071 // Kamstrup401 +// #define USES_P072 // HDC1000/HDC1008/HDC1010/HDC1050/HDC1080 +// #define USES_P073 // 7-segment display +// #define USES_P074 // TSL2591 +// #define USES_P075 // Nextion +// #define USES_P076 // HLW8012/BL0937 (Shelly Plug S, Sonoff POW R1, Huafan SS, KMC 70011, Aplic WDP303075, SK03 Outdoor, BlitzWolf SHP, Teckin, Teckin US, Gosund SP1 v23) +// #define USES_P077 // CSE7766 (Sonoff S31, Sonoff POW R2, Sonoff POW R3xx(D), Sonoff Dual R3) +// #define USES_P078 // Eastron SDMxxx Modbus +// #define USES_P079 // Wemos / Lolin Motorshield + +// #define USES_P080 // iButton Sensor DS1990A +// #define USES_P081 // Cron +// #define USES_P082 // GPS +// #define USES_P083 // SGP30 TVOC +// #define USES_P084 // VEML6070 +// #define USES_P085 // AcuDC24x +// #define USES_P086 // Receiving values according Homie convention. Works together with C014 Homie controller +// #define USES_P087 // Serial Proxy +// #define USES_P088 // HeatpumpIR +// #define USES_P089 // Ping + +// #define USES_P090 // CCS811 TVOC +// #define USES_P091 // Serial MCU controlled switch +// #define USES_P092 // DLbus +// #define USES_P093 // Mitsubishi Heat Pump +// #define USES_P094 // CUL Reader +// #define USES_P095 // ILI934x / ILI948x +// #define USES_P096 // eInk +// #define USES_P097 // ESP32 Touch +// #define USES_P098 // PWM Motor +// #define USES_P099 // XPT2046 touchscreen + +// #define USES_P100 // DS2423 counter +// #define USES_P101 // Wake On Lan +// #define USES_P102 // PZEM-004Tv30-Multiple +// #define USES_P103 // Atlas Scientific EZO Sensors (pH, ORP, EZO, DO) +// #define USES_P104 // MAX7219 dot matrix +// #define USES_P105 // AHT10/AHT2x +// #define USES_P106 // BME68x +// #define USES_P107 // SI1145 +// #define USES_P108 // DDS238-x ZN Modbus energy meters +// #define USES_P109 // ThermoOLED + +// #define USES_P110 // VL53L0X Time of Flight sensor +// #define USES_P111 // MFRC522 RFID reader +// #define USES_P112 // AS7265x +// #define USES_P113 // VL53L1X ToF +// #define USES_P114 // VEML6075 +// #define USES_P115 // MAX1704x +// #define USES_P116 // ST77xx +// #define USES_P117 // SCD30 +// #define USES_P118 // Itho +// #define USES_P119 // ITG3205 Gyro + +// #define USES_P120 // ADXL345 I2C Acceleration / Gravity +// #define USES_P121 // HMC5883L +// #define USES_P122 // SHT2x +// #define USES_P123 // I2C Touchscreens +// #define USES_P124 // I2C Multi Relay +// #define USES_P125 // ADXL345 SPI Acceleration / Gravity +// #define USES_P126 // 74HC595 Shift register +// #define USES_P127 // CDM7160 +// #define USES_P128 // NeoPixel (BusFX) +// #define P128_USES_GRB // Default +// #define P128_USES_GRBW // Select 1 option, only first one enabled from this list will be used +// #define P128_USES_RGB +// #define P128_USES_RGBW +// #define P128_USES_BRG +// #define P128_USES_BGR +// #define P128_USES_RBG +// #define P128_ENABLE_FAKETV 1 // Enable(1)/Disable(0) FakeTV effect, disabled by default on ESP8266 (.bin size issue), enabled by default on ESP32 +// #define USES_P129 // 74HC165 Input shiftregisters +// #define USES_P130 // Current Sensor Irms - ADS1015 +// #define USES_P131 // NeoPixel Matrix +// #define USES_P132 // INA3221 +// #define USES_P133 // LTR390 UV +// #define USES_P134 // A02YYUW +// #define USES_P135 // SCD4x +// #define P135_FEATURE_RESET_COMMANDS 1 // Enable/Disable quite spacious (~950 bytes) 'selftest' and 'factoryreset' subcommands +// #define USES_P137 // AXP192 +// #define USES_P138 // IP5306 + +// #define USES_P141 // PCD8544 Nokia 5110 LCD +// #define USES_P142 // Position - AS5600 +// #define USES_P143 // I2C Rotary encoders +// #define P143_FEATURE_INCLUDE_M5STACK 0 // Enabled by default, can be turned off here +// #define P143_FEATURE_INCLUDE_DFROBOT 0 // Enabled by default, can be turned off here +// #define P143_FEATURE_COUNTER_COLORMAPPING 0 // Enabled by default, can be turned off here + +// #define USES_P144 // PM1006(K) (Vindriktning) +// #define USES_P145 // MQxxx (MQ135 CO2, MQ3 Alcohol) +// #define USES_P146 // Cache Reader +// #define USES_P147 // SGP4x +// #define P147_FEATURE_GASINDEXALGORITHM 0 // Enabled by default, can be turned off here + +// #define USES_P148 // POWR3xxD/THR3xxD +// #define USES_P150 // TMP117 Temperature +// #define USES_P151 // Honeywell Pressure +// #define USES_P152 // ESP32 DAC +// #define USES_P153 // SHT4x +// #define USES_P154 // BMP3xx I2C + +// #define USES_P159 // Presence - LD2410 Radar detection + +// #define USES_P162 // Output - MCP42xxx Digipot +// #define USES_P163 // Environment - RadSens I2C radiation counter +// #define USES_P164 // Gases - ENS16x TVOC/eCO2 +// #define USES_P166 // Output - GP8403 Dual channel DAC (Digital Analog Converter) +// #define USES_P167 // Environment - Sensirion SEN5x / Ikea Vindstyrka +// #define USES_P168 // Light - VEML6030/VEML7700 +// #define USES_P169 // Environment - AS3935 Lightning Detector +// #define USES_P170 // Input - I2C Liquid level sensor +// #define USES_P172 // BMP3xx SPI. +// #define USES_P173 // Environment - SHTC3 + +/* + ####################################################################################################### + ########### Controllers + ####################################################################################################### + */ + + +// #define USES_C001 // Domoticz HTTP +// #define USES_C002 // Domoticz MQTT +// #define USES_C003 // Nodo telnet +// #define USES_C004 // ThingSpeak +// #define USES_C005 // Home Assistant (openHAB) MQTT +// #define USES_C006 // PiDome MQTT +// #define USES_C007 // Emoncms +// #define USES_C008 // Generic HTTP +// #define USES_C009 // FHEM HTTP +// #define USES_C010 // Generic UDP +// #define USES_C011 // Generic HTTP Advanced +// #define USES_C012 // Blynk HTTP +// #define USES_C013 // ESPEasy P2P network +// #define USES_C014 // homie 3 & 4dev MQTT +// #define USES_C015 // Blynk +// #define USES_C016 // Cache controller +// #define USES_C017 // Zabbix +// #define USES_C018 // TTN/RN2483 + + +/* + ####################################################################################################### + ########### Notifiers + ####################################################################################################### + */ + + +// #define USES_N001 // Email +// #define USES_N002 // Buzzer + + +#endif // ESPEASY_CUSTOM_H diff --git a/src/_P130_IRMS_ADS1015.ino b/src/_P130_IRMS_ADS1015.ino new file mode 100644 index 0000000000..76001dde70 --- /dev/null +++ b/src/_P130_IRMS_ADS1015.ino @@ -0,0 +1,166 @@ +#include "_Plugin_Helper.h" +#ifdef USES_P130 + +// ####################################################################################################### +// ############################# Plugin 130: Irms ADS1015 I2C (base : 0x48) ############################# +// ####################################################################################################### + + +#include "src/PluginStructs/P130_data_struct.h" + +#define PLUGIN_130 +#define PLUGIN_ID_130 130 +#define PLUGIN_NAME_130 "Current Sensor Irms - ADS1015" +#define PLUGIN_VALUENAME1_130 "current1" +#define PLUGIN_VALUENAME2_130 "power1" +#define PLUGIN_VALUENAME3_130 "current2" +#define PLUGIN_VALUENAME4_130 "power2" + + +boolean Plugin_130(uint8_t function, struct EventStruct *event, String& string) +{ + boolean success = false; + + // static uint8_t portValue = 0; + switch (function) + { + case PLUGIN_DEVICE_ADD: + { + Device[++deviceCount].Number = PLUGIN_ID_130; + Device[deviceCount].Type = DEVICE_TYPE_I2C; + Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_SINGLE; + Device[deviceCount].Ports = 0; + Device[deviceCount].PullUpOption = false; + Device[deviceCount].InverseLogicOption = false; + Device[deviceCount].FormulaOption = true; + Device[deviceCount].ValueCount = 4; + Device[deviceCount].SendDataOption = true; + Device[deviceCount].TimerOption = true; + Device[deviceCount].GlobalSyncOption = true; + break; + } + + case PLUGIN_GET_DEVICENAME: + { + string = F(PLUGIN_NAME_130); + break; + } + + case PLUGIN_GET_DEVICEVALUENAMES: + { + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_130)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_130)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_130)); + strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[3], PSTR(PLUGIN_VALUENAME4_130)); + break; + } + + case PLUGIN_I2C_HAS_ADDRESS: + case PLUGIN_WEBFORM_SHOW_I2C_PARAMS: + { + #define ADS1015_I2C_ADDR_COUNT 4 + const uint8_t i2cAddressValues[] = { 0x48, 0x49, 0x4A, 0x4B }; + if (function == PLUGIN_WEBFORM_SHOW_I2C_PARAMS) { + addFormSelectorI2C(F("i2c_addr"), ADS1015_I2C_ADDR_COUNT, i2cAddressValues, PCONFIG(0)); + } else { + success = intArrayContains(ADS1015_I2C_ADDR_COUNT, i2cAddressValues, event->Par1); + } + break; + } + + case PLUGIN_WEBFORM_LOAD: + { + #define ADS1015_SPS_AVAILABLE_COUNT 3 + const String spsAvailableStr[] = {String(1600), String(2400), String(3300)}; + const int spsAvailableVal[] = {P130_ADS1015_RATE_1600SPS, + P130_ADS1015_RATE_2400SPS, + P130_ADS1015_RATE_3300SPS}; + addFormSubHeader(F("Calibration - General")); + addFormSelector(F("SPS"),F("p130_sps"), ADS1015_SPS_AVAILABLE_COUNT, spsAvailableStr,spsAvailableVal, PCONFIG_LONG(3)); + addFormNumericBox(F("Current Frequency"), F("p130_frequency"), PCONFIG_LONG(0), 50, 60); + addFormNumericBox(F("Nb Sinus to read"), F("p130_nb_sinus"), PCONFIG_LONG(1), 1, 25); + addFormNote("Take care! Reading sinus is a blocking process. With a SCT013 (60A/50A/30A - 1V), reading 2 sinus on 50Hz giving stable values."); + addFormCheckBox(F("ADC Conversion Mode Continous"), F("p130_adc_continous"), PCONFIG_LONG(2)); + addFormCheckBox(F("Small Debug to INFO Log"), F("p130_debug"), PCONFIG(3)); + addFormFloatNumberBox(F("Voltage Estimated"), F("p130_voltageEstimated"), PCONFIG_FLOAT(0), 0.0, 380.0, 2); + addFormSubHeader(F("Calibration")); + addFormNumericBox(F("Canal 1 - Max Current"), F("p130_calCurrent1"), PCONFIG(1), 1, 250); + addFormNumericBox(F("Canal 2 - Max Current"), F("p130_calCurrent2"), PCONFIG(2), 1, 250); + + success = true; + break; + } + + case PLUGIN_WEBFORM_SAVE: + { + PCONFIG(0) = getFormItemInt(F("i2c_addr")); + PCONFIG(1) = getFormItemInt(F("p130_calCurrent1")); + PCONFIG(2) = getFormItemInt(F("p130_calCurrent2")); + PCONFIG(3) = (true == isFormItemChecked(F("p130_debug")))?1:0; + + PCONFIG_LONG(0) = getFormItemInt(F("p130_frequency")); + PCONFIG_LONG(1) = getFormItemInt(F("p130_nb_sinus")); + PCONFIG_LONG(2) = (true == isFormItemChecked(F("p130_adc_continous")))?1:0; + PCONFIG_LONG(3) = getFormItemInt(F("p130_sps")); + + PCONFIG_FLOAT(0) = getFormItemFloat(F("p130_voltageEstimated")); + + success = true; + break; + } + + case PLUGIN_INIT: + { + const uint8_t address = PCONFIG(0); + const uint8_t calCurrent1 = PCONFIG(1); + const uint8_t calCurrent2 = PCONFIG(2); + const uint8_t debug = PCONFIG(3); + const uint8_t currentFreq = PCONFIG_LONG(0); + const uint8_t nbSinus = PCONFIG_LONG(1); + const uint8_t adc_continous = PCONFIG_LONG(2); + const uint8_t sps = PCONFIG_LONG(3); + const float_t voltageEstimated = PCONFIG_FLOAT(0); + + initPluginTaskData(event->TaskIndex, new (std::nothrow) P130_data_struct(address, calCurrent1, calCurrent2, voltageEstimated, currentFreq, nbSinus, adc_continous, sps)); + P130_data_struct *P130_data = + static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P130_data) { + P130_data->setDebug(debug); + success = true; + } + break; + } + + case PLUGIN_READ: + { + P130_data_struct *P130_data = + static_cast(getPluginTaskData(event->TaskIndex)); + + if (nullptr != P130_data) { + float_t value = 0.; + P130_data->readCurrent(1, value); + UserVar[event->BaseVarIndex+0] = value; + UserVar[event->BaseVarIndex+1] = P130_data->estimatePower(value); + P130_data->readCurrent(2, value); + UserVar[event->BaseVarIndex+2] = value; + UserVar[event->BaseVarIndex+3] = P130_data->estimatePower(value); + + { + String log; + log = F("Irms - ADS1015 : Canal1{ current="); log += UserVar[event->BaseVarIndex+0]; + log += F("; power="); log += UserVar[event->BaseVarIndex+1]; + log += F(";} Canal2{ current="); log += UserVar[event->BaseVarIndex+2]; + log += F("; power="); log += UserVar[event->BaseVarIndex+3]; + log += F(";}"); + addLog(LOG_LEVEL_INFO, log); + } + success = true; + } + break; + } + } + return success; +} + +#endif // USES_P130 diff --git a/src/src/CustomBuild/define_plugin_sets.h b/src/src/CustomBuild/define_plugin_sets.h index 14f6b5e813..8919c3f036 100644 --- a/src/src/CustomBuild/define_plugin_sets.h +++ b/src/src/CustomBuild/define_plugin_sets.h @@ -1439,7 +1439,6 @@ To create/register a plugin, you have to : #endif #endif - #ifdef CONTROLLER_SET_STABLE #if !FEATURE_NO_HTTP_CLIENT #define USES_C001 // Domoticz HTTP @@ -1605,6 +1604,8 @@ To create/register a plugin, you have to : #define USES_P125 // ADXL345 SPI #define USES_P126 // 74HC595 Shift register #define USES_P129 // 74HC165 Input shiftregisters + #define USES_P130 // Current Sensor Irms - ADS1015 + #define USES_P133 // LTR390 UV #define USES_P135 // SCD4x #define USES_P144 // Dust - PM1006(K) (Vindriktning) #define USES_P133 // LTR390 UV @@ -2148,7 +2149,7 @@ To create/register a plugin, you have to : //#define USES_P124 // Ventus_W266_RFM69 #define USES_P125 // ArduCAM #define USES_P127 // Teleinfo - #define USES_P130 // VEML6075 + #define USES_P130 // [Irms - ADS1015](https://github.com/letscontrolit/ESPEasy/issues/3839) #define USES_P131 // SHT3X #define USES_P133 // VL53L0X #define USES_P141 // LedStrip diff --git a/src/src/PluginStructs/P130_data_struct.cpp b/src/src/PluginStructs/P130_data_struct.cpp new file mode 100644 index 0000000000..f3adb2fb35 --- /dev/null +++ b/src/src/PluginStructs/P130_data_struct.cpp @@ -0,0 +1,283 @@ +#include "../PluginStructs/P130_data_struct.h" + +#ifdef USES_P130 + +#define P130_ADS1X15_REG_POINTER_CONVERT (0x00) +#define P130_ADS1X15_REG_POINTER_CONFIG (0x01) +#define P130_ADS1X15_REG_POINTER_THRESH_LO (0x02) +#define P130_ADS1X15_REG_POINTER_THRESH_HI (0x03) + +#define P130_ADS1015_MUX_DIFF_01 (0x0000) +#define P130_ADS1015_MUX_DIFF_23 (0x3000) +#define P130_ADS1015_PGA_1_024V (0x0600) //< +/-1.024V range = Gain 4 => datasheet says 1bit = 0.5mV +#define P130_ADS1015_CONFIG_CQUE_NONE (0x0003) // Disable the comparator (default val) +#define P130_ADS1015_CONFIG_CLAT_NONLAT (0x0000) // Non-latching (default val) +#define P130_ADS1015_CONFIG_CPOL_ACTVLOW (0x0000) // Alert/Rdy active low (default val) +#define P130_ADS1015_CONFIG_CMODE_TRAD (0x0000) // Traditional comparator (default val) +#define P130_ADS1015_CONV_MODE_CONTINUOUS (0x0000) // Single-shot mode (default) +#define P130_ADS1015_CONV_MODE_SINGLE (0x0100) // Single-shot mode (default) +#define P130_ADS1015_START_SINGLE_CONV (0x8000) // Start a single conversion + +P130_data_struct::P130_data_struct(uint8_t i2c_addr, uint8_t _calCurrent1, uint8_t _calCurrent2, float_t _calVoltage, uint8_t _currentFreq, uint8_t _nbSinus, uint8_t _convModeContinuous, uint8_t _sps) : + i2cAddress(i2c_addr), + calCurrent1(_calCurrent1), + calCurrent2(_calCurrent2), + calVoltage(_calVoltage), + currentFreq(_currentFreq), + nbSinus(_nbSinus), + convModeContinuous (_convModeContinuous), + sps (_sps) { + this->debug = 0; + } + +void P130_data_struct::setDebug(uint8_t _debug) { + this->debug = _debug; + if (this->debug) { + String log; + log = F("Irms - ADS1015 : Set internal plugin debug; _calCurrent1="); + log += this->calCurrent1; + log += F(" _calCurrent2="); + log += this->calCurrent2; + log += F(" voltEst.="); + log += String(this->calVoltage); + log += F(" frequency="); + log += this->currentFreq; + log += F(" nbSinus="); + log += this->nbSinus; + log += F(" SPS="); + log += this->sps; + addLog(LOG_LEVEL_INFO, log); + } +} + +uint8_t P130_data_struct::getDebug() { + return this->debug; +} + +boolean P130_data_struct::writeRegister(uint8_t registerAddr, uint16_t registerValue) { + boolean result = false; + uint8_t res = 0; + Wire.beginTransmission(this->i2cAddress); + Wire.write((uint8_t)(registerAddr)); + Wire.write((uint8_t)(registerValue >> 8)); + Wire.write((uint8_t)(registerValue & 0xFF)); + res = Wire.endTransmission(); + if ( 0 == res ) { + result = true; + } else { + String log = F("Irms - ADS1015 : writeRegister NOK, errcode= "); + log += res ; + addLog(LOG_LEVEL_INFO, log); + result = false; + } + return result; +} + +boolean P130_data_struct::readRegister(uint8_t registerAddr, uint16_t& registerValue) { + boolean result = false; + const uint8_t requestedByte = 2; + Wire.beginTransmission(this->i2cAddress); + Wire.write((uint8_t)(registerAddr)); + if ( 0 == Wire.endTransmission() ) { + if ( requestedByte == Wire.requestFrom(this->i2cAddress, requestedByte) ) { + result = true; + registerValue = ((Wire.read() << 8) | Wire.read()); + } + } + return result; +} + +uint16_t P130_data_struct::readRegisterFacility(uint8_t registerAddr) { + uint16_t registerValue = 0; + this->readRegister(registerAddr, registerValue); + return registerValue; +} + +uint16_t P130_data_struct::getDefaultADS1015ReadConfig(){ + return P130_ADS1015_CONFIG_CQUE_NONE | + P130_ADS1015_CONFIG_CLAT_NONLAT | + P130_ADS1015_CONFIG_CPOL_ACTVLOW | + P130_ADS1015_CONFIG_CMODE_TRAD | + P130_ADS1015_PGA_1_024V | + this->sps; +} + +boolean P130_data_struct::readAdcSingleValue(uint16_t muxConf, int16_t& adcValue) { + boolean result = false; + uint16_t registerValue = 0; + uint16_t configGlobal = P130_data_struct::getDefaultADS1015ReadConfig(); + configGlobal |= muxConf; + + uint16_t configStartSingle = configGlobal | + P130_ADS1015_CONV_MODE_SINGLE | + P130_ADS1015_START_SINGLE_CONV; + uint16_t configStartContinuous = configGlobal | + P130_ADS1015_CONV_MODE_CONTINUOUS | + P130_ADS1015_START_SINGLE_CONV; + uint16_t configStop = configGlobal | + P130_ADS1015_CONV_MODE_SINGLE; + + // write conf+ =>start reading + if ( false == this->writeRegister(P130_ADS1X15_REG_POINTER_CONFIG, configStartSingle) ) { + addLog(LOG_LEVEL_INFO, F("readadcsingle write register conf failed")); + result = false; + } else { + // delay(9); // See https://github.com/letscontrolit/ESPEasy/issues/3159#issuecomment-660546091 + // requesting if conversion ended + ulong readingLongUS = micros(); + while ( micros() < (readingLongUS + 1000) ) { + if ( ( this->readRegisterFacility(P130_ADS1X15_REG_POINTER_CONFIG) & 0x8000) != 0 ) { + if ( true == this->readRegister(P130_ADS1X15_REG_POINTER_CONVERT, registerValue) ) { + // Shift 12-bit results right 4 bits for the ADS1015, + // making sure we keep the sign bit intact + adcValue = ((int16_t)(registerValue >> 4)); + if (adcValue > 0x07FF) { + // negative number - extend the sign to 16th bit + adcValue |= 0xF000; + } + result = true; + } + break; + } + } + } + return result; +} + +boolean P130_data_struct::readAdcContinuousRmsValue(uint16_t muxConf, uint16_t period_ms, float_t& adcIrms, uint16_t& nbSample) { + boolean success = false; + boolean pbmWhileReading = false; + uint16_t registerValue = 0; + uint64_t sumI = 0, sqrI = 0; + adcIrms = 0.; + nbSample = 0; + uint16_t configGlobal = P130_data_struct::getDefaultADS1015ReadConfig(); + configGlobal |= muxConf; + + uint16_t configStartSingle = configGlobal | + P130_ADS1015_CONV_MODE_SINGLE | + P130_ADS1015_START_SINGLE_CONV; + uint16_t configStartContinuous = configGlobal | + P130_ADS1015_CONV_MODE_CONTINUOUS | + P130_ADS1015_START_SINGLE_CONV; + uint16_t configStop = configGlobal | + P130_ADS1015_CONV_MODE_SINGLE; + + // write conf+ =>start reading + if ( false == this->writeRegister(P130_ADS1X15_REG_POINTER_CONFIG, configStartContinuous) ) { + addLog(LOG_LEVEL_INFO, F("readadccontinuous write register conf failed")); + success = false; + } else { + // delay(9); // See https://github.com/letscontrolit/ESPEasy/issues/3159#issuecomment-660546091 + // requesting if conversion ended + pbmWhileReading = false; + ulong endPeriod = millis() + period_ms; + while ( millis() < endPeriod ) { + if ( true != this->readRegister(P130_ADS1X15_REG_POINTER_CONVERT, registerValue) ) { + pbmWhileReading = true; + break; + } else { + nbSample++; + // Shift 12-bit results right 4 bits for the ADS1015, + // making sure we keep the sign bit intact + int16_t adcValue = ((int16_t)(registerValue >> 4)); + if (adcValue > 0x07FF) { + // negative number - extend the sign to 16th bit + adcValue |= 0xF000; + } + sqrI = adcValue * adcValue; + sumI += sqrI; + #ifdef P130_DEBUG_DEV + String log = "readadccontinuous registerValue=" + String(registerValue); + log += " adcValue=" + String(adcValue); + log += " sqrI=" + String((unsigned long)(sqrI >>16), HEX) + String((unsigned long)(sqrI & 0x0000FFFF), HEX); + log += " sumI=" + String((unsigned long)(sumI >>16), HEX) + String((unsigned long)(sumI & 0x0000FFFF), HEX); + addLog(LOG_LEVEL_INFO, log); + #endif + } + } + if ( true == pbmWhileReading ) { + success = false; + } else { + adcIrms = sqrt(1. * sumI / nbSample); + success = true; + } + } + if ( false == this->writeRegister(P130_ADS1X15_REG_POINTER_CONFIG, configStop) ) { + addLog(LOG_LEVEL_INFO, F("readadccontinuous stop reading failed")); + } + return success; +} + +float_t P130_data_struct::estimatePower(float_t current) { + return calVoltage * current; +} + +boolean P130_data_struct::readCurrent(uint8_t canal, float_t& currentValue) { + boolean success = false; + boolean calculatingRMSSuccess = true; + uint16_t registerValue = 0; + int16_t adc = 0; + uint64_t sumI = 0; + float_t adcIrms = .0; + uint16_t nbSample = 0; + uint16_t durationSample = (this->nbSinus * (1000 / this->currentFreq)); + float_t voltage = .0; + float_t calCurrent =.0; + unsigned long endTime = 0; + if ( ( 1 != canal ) && ( 2 != canal ) ) + success = false; + else { + uint16_t muxConf = P130_ADS1015_MUX_DIFF_01; + if ( 1 == canal ) + muxConf = P130_ADS1015_MUX_DIFF_01; + else if ( 2 == canal ) + muxConf = P130_ADS1015_MUX_DIFF_23; + else + muxConf = P130_ADS1015_MUX_DIFF_01; //default value, should never happened + + if ( 1 != this->convModeContinuous ) { + // start loop + endTime = millis() + durationSample; // 2*20ms => 5sinus + calculatingRMSSuccess = true; + while ( millis() < endTime ) { + if ( false == this->readAdcSingleValue(muxConf, adc) ) { + currentValue = 0; + calculatingRMSSuccess = false; + break; + } else { + sumI += (adc * adc); + nbSample++; + } + } + if ( true == calculatingRMSSuccess ) { + adcIrms = sqrt(sumI / nbSample); + voltage = adcIrms * 0.0005; + calCurrent = (1==canal)?calCurrent1:calCurrent2; + currentValue = voltage * calCurrent; + success = true; + } + } else { + adcIrms = 0.; + nbSample = 0; + success = this->readAdcContinuousRmsValue(muxConf, durationSample, adcIrms, nbSample); + voltage = adcIrms * 0.0005; + calCurrent = (1==canal)?calCurrent1:calCurrent2; + currentValue = voltage * calCurrent; + } + if (false != this->debug) { + String log; + log = String("Irms - ADS1015 : "); log += ((true == success)?String("SUCCESS"):String("FAILED")); + log += String(" readCurrent canal = "); log += canal; addLog(LOG_LEVEL_INFO, log); + log = F("Irms - ADS1015 : Differential square/root: "); log += adcIrms; addLog(LOG_LEVEL_INFO, log); + log = F("Irms - ADS1015 : (voltage: "); log += voltage + String("mV )"); addLog(LOG_LEVEL_INFO, log); + log = F("Irms - ADS1015 : (SPS: "); log += this->sps + String(" )"); addLog(LOG_LEVEL_INFO, log); + log = F("Irms - ADS1015 : (sample duration: "); log += durationSample + String("ms )"); addLog(LOG_LEVEL_INFO, log); + log = F("Irms - ADS1015 : (sample count: "); log += nbSample + String(" )"); addLog(LOG_LEVEL_INFO, log); + log = F("Irms - ADS1015 : Current: "); log += currentValue; addLog(LOG_LEVEL_INFO, log); + } + } + return success; +} + +#endif // ifdef USES_P130 diff --git a/src/src/PluginStructs/P130_data_struct.h b/src/src/PluginStructs/P130_data_struct.h new file mode 100644 index 0000000000..8eb7a45858 --- /dev/null +++ b/src/src/PluginStructs/P130_data_struct.h @@ -0,0 +1,50 @@ +#ifndef PLUGINSTRUCTS_P130_DATA_STRUCT_H +#define PLUGINSTRUCTS_P130_DATA_STRUCT_H + +#include "../../_Plugin_Helper.h" +#ifdef USES_P130 + +#undef P130_DEBUG_DEV +#define P130_ADS1015_RATE_3300SPS (0x00C0) // < 3300 samples per second +#define P130_ADS1015_RATE_2400SPS (0x00A0) // < 2400 samples per second +#define P130_ADS1015_RATE_1600SPS (0x0080) // < 1600 samples per second + +struct P130_data_struct : public PluginTaskData_base { +public: + + P130_data_struct(uint8_t i2c_addr, + uint8_t _calCurrent1, + uint8_t _calCurrent2, + float_t _calVoltage, + uint8_t _currentFreq, + uint8_t _nbSinus, + uint8_t _convModeContinuous, + uint8_t _sps); + + void setDebug(uint8_t _debug); + uint8_t getDebug(); + boolean readCurrent(uint8_t canal, float_t& currentValue); + float_t estimatePower(float_t current); + +private: + + uint8_t i2cAddress; + uint8_t calCurrent1; + uint8_t calCurrent2; + float_t calVoltage; + uint8_t currentFreq; + uint8_t nbSinus; + uint8_t convModeContinuous; + uint8_t debug; + uint8_t sps; + + uint16_t getDefaultADS1015ReadConfig(); + boolean writeRegister(uint8_t registerAddr, uint16_t registerValue); + boolean readRegister(uint8_t registerAddr, uint16_t& registerValue); + uint16_t readRegisterFacility(uint8_t registerAddr); + boolean readAdcSingleValue(uint16_t muxConf, int16_t& adcValue); + boolean readAdcContinuousRmsValue(uint16_t muxConf, uint16_t period_ms, float_t& adcIrms, uint16_t& nbSample); +}; + +#endif // ifdef USES_P130 +#endif // ifndef PLUGINSTRUCTS_P130_DATA_STRUCT_H