mirror of https://github.com/arendst/Tasmota.git
v5.8.0m - Rewrite and Additions
5.8.0m * Rewrite code (partly) using Google C++ Style Guide (https://google.github.io/styleguide/cppguide.html) * Allow empty MqttHost name by using option 0 * Allow Mqtt server mDNS lookup only when MqttHost name is empty (#1026) * Change Ws2812 clock with more flexible version (#1019) * Add German language file (#1022) * Support connecting to MQTT brokers without userid and/or password (#1023) * Add commands PwmRange 1,255..1023 and PwmFrequency 1,100..4000 (#1025)
This commit is contained in:
parent
aa1d5b0342
commit
fc89330056
|
@ -1,7 +1,7 @@
|
|||
## Sonoff-Tasmota
|
||||
Provide ESP8266 based Sonoff by [iTead Studio](https://www.itead.cc/) and ElectroDragon IoT Relay with Serial, Web and MQTT control allowing 'Over the Air' or OTA firmware updates using Arduino IDE.
|
||||
|
||||
Current version is **5.8.0l** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
|
||||
Current version is **5.8.0m** - See [sonoff/_releasenotes.ino](https://github.com/arendst/Sonoff-Tasmota/blob/development/sonoff/_releasenotes.ino) for change information.
|
||||
|
||||
### ATTENTION All versions
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@ src_dir = sonoff
|
|||
; *** Uncomment one of the lines below to build/upload only one environment
|
||||
;env_default = sonoff
|
||||
;env_default = sonoff-NL
|
||||
;env_default = sonoff-DE
|
||||
;env_default = sonoff-minimal
|
||||
;env_default = sonoff-ds18x20
|
||||
|
||||
|
@ -62,6 +63,29 @@ monitor_baud = 115200
|
|||
;upload_port = domus1:80/api/upload-arduino.php
|
||||
;extra_scripts = pio/http-uploader.py
|
||||
|
||||
; *** Sonoff et al
|
||||
[env:sonoff-DE]
|
||||
platform = espressif8266
|
||||
framework = arduino
|
||||
board = esp01_1m
|
||||
board_flash_mode = dout
|
||||
build_flags = -Wl,-Tesp8266.flash.1m0.ld -DMQTT_MAX_PACKET_SIZE=512 -DMY_LANGUAGE=de-DE
|
||||
lib_deps = PubSubClient, NeoPixelBus, IRremoteESP8266, ArduinoJSON
|
||||
|
||||
; *** Serial Monitor options
|
||||
monitor_baud = 115200
|
||||
|
||||
; *** Upload Serial reset method for Wemos and NodeMCU
|
||||
;upload_resetmethod = nodemcu
|
||||
|
||||
; *** Upload file to OTA server using SCP
|
||||
;upload_port = user@host:/path
|
||||
;extra_scripts = pio/sftp-uploader.py
|
||||
|
||||
; *** Upload file to OTA server using HTTP
|
||||
;upload_port = domus1:80/api/upload-arduino.php
|
||||
;extra_scripts = pio/http-uploader.py
|
||||
|
||||
; Sonoff minimal
|
||||
[env:sonoff-minimal] ; Placeholder to be configured
|
||||
platform = espressif8266
|
||||
|
|
|
@ -1,4 +1,13 @@
|
|||
/* 5.8.0l
|
||||
/* 5.8.0m
|
||||
* Rewrite code (partly) using Google C++ Style Guide (https://google.github.io/styleguide/cppguide.html)
|
||||
* Allow empty MqttHost name by using option 0
|
||||
* Allow Mqtt server mDNS lookup only when MqttHost name is empty (#1026)
|
||||
* Change Ws2812 clock with more flexible version (#1019)
|
||||
* Add German language file (#1022)
|
||||
* Support connecting to MQTT brokers without userid and/or password (#1023)
|
||||
* Add commands PwmRange 1,255..1023 and PwmFrequency 1,100..4000 (#1025)
|
||||
*
|
||||
* 5.8.0l
|
||||
* Update HTML/CSS to enable nicer form field entry
|
||||
* Fix inverted relay status after restart or power on as regression from 5.8.0d (#909)
|
||||
* Add send protocol Panasonic to IRsend (#1014)
|
||||
|
@ -1018,7 +1027,7 @@
|
|||
* Add reset 2 option erasing flash
|
||||
* Add status 5 option displaying network info
|
||||
* Add syslog check for Wifi connection
|
||||
* Resize mqtt_publish log array
|
||||
* Resize MqttPublish log array
|
||||
* Change Wifi smartconfig active from 100 to 60 seconds
|
||||
* Update Wifi initialization
|
||||
*
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _I18N_H_
|
||||
#define _I18N_H_
|
||||
|
||||
#ifndef MY_LANGUAGE
|
||||
#include "language/en-GB.h"
|
||||
#else
|
||||
|
@ -38,20 +41,20 @@ const char S_OFFLINE[] PROGMEM = D_OFFLINE;
|
|||
|
||||
// sonoff.ino
|
||||
#define MAX_BUTTON_COMMANDS 5 // Max number of button commands supported
|
||||
const char commands[MAX_BUTTON_COMMANDS][14] PROGMEM = {
|
||||
const char kCommands[MAX_BUTTON_COMMANDS][14] PROGMEM = {
|
||||
D_CMND_WIFICONFIG " 1", // Press button three times
|
||||
D_CMND_WIFICONFIG " 2", // Press button four times
|
||||
D_CMND_WIFICONFIG " 3", // Press button five times
|
||||
D_CMND_RESTART " 1", // Press button six times
|
||||
D_CMND_UPGRADE " 1" }; // Press button seven times
|
||||
const char wificfg[MAX_WIFI_OPTION][WCFG_MAX_STRING_LENGTH] PROGMEM = {
|
||||
const char kWifiConfig[MAX_WIFI_OPTION][WCFG_MAX_STRING_LENGTH] PROGMEM = {
|
||||
D_WCFG_0_RESTART,
|
||||
D_WCFG_1_SMARTCONFIG,
|
||||
D_WCFG_2_WIFIMANAGER,
|
||||
D_WCFG_3_WPSCONFIG,
|
||||
D_WCFG_4_RETRY,
|
||||
D_WCFG_5_WAIT };
|
||||
const char PREFIXES[3][PRFX_MAX_STRING_LENGTH] PROGMEM = {
|
||||
const char kPrefixes[3][PRFX_MAX_STRING_LENGTH] PROGMEM = {
|
||||
D_CMND,
|
||||
D_STAT,
|
||||
D_TELE };
|
||||
|
@ -60,7 +63,7 @@ const char JSON_SNS_TEMPHUM[] PROGMEM =
|
|||
"%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s}";
|
||||
|
||||
// support.ino
|
||||
static const char monthNames[] = D_MONTH3LIST;
|
||||
static const char kMonthNames[] = D_MONTH3LIST;
|
||||
|
||||
// webserver.ino
|
||||
const char S_MAIN_MENU[] PROGMEM = D_MAIN_MENU;
|
||||
|
@ -78,3 +81,5 @@ const char S_FIRMWARE_UPGRADE[] PROGMEM = D_FIRMWARE_UPGRADE;
|
|||
const char S_CONSOLE[] PROGMEM = D_CONSOLE;
|
||||
const char S_INFORMATION[] PROGMEM = D_INFORMATION;
|
||||
const char S_RESTART[] PROGMEM = D_RESTART;
|
||||
|
||||
#endif // _I18N_H_
|
|
@ -0,0 +1,688 @@
|
|||
/*
|
||||
de-DE.h - localization for German - Germany for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 VinceMasuka
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _LANGUAGE_DE_DE_H_
|
||||
#define _LANGUAGE_DE_DE_H_
|
||||
|
||||
/*************************** ATTENTION *******************************\
|
||||
*
|
||||
* Due to memory constraints only UTF-8 is supported.
|
||||
* To save code space keep text as short as possible.
|
||||
* Time and Date provided by SDK can not be localized (yet).
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
*
|
||||
\*********************************************************************/
|
||||
|
||||
// "2017-03-07T11:08:02" - ISO8601:2004
|
||||
#define D_YEAR_MONTH_SEPARATOR "-"
|
||||
#define D_MONTH_DAY_SEPARATOR "-"
|
||||
#define D_DATE_TIME_SEPARATOR "T"
|
||||
#define D_HOUR_MINUTE_SEPARATOR ":"
|
||||
#define D_MINUTE_SECOND_SEPARATOR ":"
|
||||
|
||||
#define D_DAY3LIST "SonMonDieMitDonFriSam"
|
||||
#define D_MONTH3LIST "JanFebMaeAprMaiJunJulAugSepOktNovDez"
|
||||
|
||||
// Non JSON decimal separator
|
||||
#define D_DECIMAL_SEPARATOR "."
|
||||
|
||||
// Common
|
||||
#define D_ABORTED "abgebrochen"
|
||||
#define D_ACTIVE "aktiv"
|
||||
#define D_ADDRESS "Addresse"
|
||||
#define D_ADMIN "Admin"
|
||||
#define D_AIR_QUALITY "Ausschlagsqualität"
|
||||
#define D_AIRQUALITY "AusschlagsQualität"
|
||||
#define D_AP "AP" // Access Point
|
||||
#define D_APMAC_ADDRESS "APMac"
|
||||
#define D_APPENDED "angehängt"
|
||||
#define D_AS "wie"
|
||||
#define D_AUTO "AUTO"
|
||||
#define D_BAUDRATE "Baudrate"
|
||||
#define D_BLINK "Blinken"
|
||||
#define D_BLINKOFF "BlinkenAus"
|
||||
#define D_BOOTVERSION "Boot"
|
||||
#define D_BOOT_COUNT "Boot-Zähler"
|
||||
#define D_BOOTCOUNT "BootZähler"
|
||||
#define D_BRIGHTLIGHT "hell"
|
||||
#define D_BUILDDATETIME "BuildDatumUhrzeit"
|
||||
#define D_BUTTON "Taste"
|
||||
#define D_CELSIUS "Celsius"
|
||||
#define D_CODE "code" // Button code
|
||||
#define D_COLDLIGHT "kalt"
|
||||
#define D_COMMAND "Befehl"
|
||||
#define D_CONNECTED "verbunden"
|
||||
#define D_COREVERSION "Kern"
|
||||
#define D_COUNT "zählen"
|
||||
#define D_COUNTER "Zähler"
|
||||
#define D_CURRENT "Strom" // As in Voltage and Current
|
||||
#define D_DATA "Daten"
|
||||
#define D_DARKLIGHT "dunkel"
|
||||
#define D_DEBUG "debug"
|
||||
#define D_DISABLED "deaktiviert"
|
||||
#define D_DNS_SERVER "DNS Server"
|
||||
#define D_DNSSERVER "DNSServer"
|
||||
#define D_DONE "erledigt"
|
||||
#define D_DST_TIME "DST"
|
||||
#define D_EMPTY "leer"
|
||||
#define D_EMULATION "Emulierung"
|
||||
#define D_ENABLED "aktiviert"
|
||||
#define D_ENDDST "EndDST" // End Daylight Savings Time
|
||||
#define D_ERASE "löschen"
|
||||
#define D_ERROR "Fehler"
|
||||
#define D_EVERY "alle"
|
||||
#define D_FAHRENHEIT "Fahrenheit"
|
||||
#define D_FAILED "fehlgeschlagen"
|
||||
#define D_FALLBACK "Rückgriff"
|
||||
#define D_FALLBACK_TOPIC "Rückgriff topic"
|
||||
#define D_FALLBACKTOPIC "RückgriffTopic"
|
||||
#define D_FALSE "falsch"
|
||||
#define D_FILE "Datei"
|
||||
#define D_FLASHMODE "FlashMode"
|
||||
#define D_FLASHSIZE "FlashSize"
|
||||
#define D_FREE_MEMORY "freier Speicher"
|
||||
#define D_FREEMEMORY "frei"
|
||||
#define D_FROM "von"
|
||||
#define D_GATEWAY "gateway"
|
||||
#define D_GROUP "Gruppe"
|
||||
#define D_HEAPSIZE "Heap-Größe"
|
||||
#define D_HIGH "hoch"
|
||||
#define D_HOST "host"
|
||||
#define D_HOSTNAME "hostname"
|
||||
#define D_HUMIDITY "Feuchtigkeit"
|
||||
#define D_ILLUMINANCE "Beleuchtungsintensität"
|
||||
#define D_IMMEDIATE "direkt" // Button immediate
|
||||
#define D_INDEX "Index"
|
||||
#define D_INFO "Info"
|
||||
#define D_INITIALIZED "initialisiert"
|
||||
#define D_IP_ADDRESS "IP-Addresse"
|
||||
#define D_LIGHT "Licht"
|
||||
#define D_LOCAL_TIME "örtlich"
|
||||
#define D_LOW "niedrig"
|
||||
#define D_LWT "LWT"
|
||||
#define D_MAC "Mac"
|
||||
#define D_MASK "Maske"
|
||||
#define D_MODULE "Modul"
|
||||
#define D_MQTT "MQTT"
|
||||
#define D_MULTI_PRESS "Mehrfachdruck"
|
||||
#define D_NO "nein"
|
||||
#define D_NOISE "Lautstärke"
|
||||
#define D_NONE "keine"
|
||||
#define D_OFF "aus"
|
||||
#define D_OFFLINE "offline"
|
||||
#define D_OK "OK"
|
||||
#define D_ON "an"
|
||||
#define D_ONLINE "online"
|
||||
#define D_OR "oder"
|
||||
#define D_PASSWORD "Passwort"
|
||||
#define D_PERIOD "Punkt"
|
||||
#define D_PORT "port"
|
||||
#define D_POWER_FACTOR "Leistungsfaktor"
|
||||
#define D_POWERFACTOR "Faktor"
|
||||
#define D_POWERUSAGE "Leistung"
|
||||
#define D_PRESSURE "Druck"
|
||||
#define D_PRESSUREATSEALEVEL "MeeresDruck"
|
||||
#define D_PROGRAM_FLASH_SIZE "Programm-Flash-Größe"
|
||||
#define D_PROGRAMFLASHSIZE "ProgramFlashSize"
|
||||
#define D_PROGRAM_SIZE "Programmgröße"
|
||||
#define D_PROGRAMSIZE "ProgramSize"
|
||||
#define D_PROJECT "Projekt"
|
||||
#define D_RECEIVED "erhalten"
|
||||
#define D_RESTART "Neustart"
|
||||
#define D_RESTARTING "starte neu"
|
||||
#define D_RESTART_REASON "Grund für Neustart"
|
||||
#define D_RESTARTREASON "RestartReason"
|
||||
#define D_RESTORE "wiederherstellen"
|
||||
#define D_RETAINED "beibehalten"
|
||||
#define D_SAVE "speichern"
|
||||
#define D_SAVEADDRESS "SaveAddress"
|
||||
#define D_SAVECOUNT "SaveCount"
|
||||
#define D_SAVESTATE "SaveState"
|
||||
#define D_SDKVERSION "SDK"
|
||||
#define D_SELECTED "ausgewählt"
|
||||
#define D_SENSOR "Sensor"
|
||||
#define D_SERIAL "Serial"
|
||||
#define D_BYTES "Bytes"
|
||||
#define D_SSID "SSID"
|
||||
#define D_START "Start"
|
||||
#define D_STARTED "gestartet"
|
||||
#define D_STARTDST "StartDST" // Start Daylight Savings Time
|
||||
#define D_STD_TIME "STD"
|
||||
#define D_STOP "stopp"
|
||||
#define D_SUBNET_MASK "Subnetzmaske"
|
||||
#define D_SUBNETMASK "Subnetmaske"
|
||||
#define D_SUBSCRIBE_TO "subscribe to"
|
||||
#define D_SUCCESSFUL "erfolgreich"
|
||||
#define D_SWITCH "switch"
|
||||
#define D_SYNC "sync"
|
||||
#define D_SYS "sys" // Sys log
|
||||
#define D_TEMPERATURE "Temperatur"
|
||||
#define D_TEMPERATURE_UNIT "TempUnit"
|
||||
#define D_TIME "Zeit"
|
||||
#define D_TO "bis"
|
||||
#define D_TODAY "heute"
|
||||
#define D_TOGGLE "schalten"
|
||||
#define D_TOPIC "topic"
|
||||
#define D_TOTAL "Total"
|
||||
#define D_TRANSMIT "Übertragen"
|
||||
#define D_TRUE "wahr"
|
||||
#define D_TYPE "Typ"
|
||||
#define D_UNKNOWN "unbekannt"
|
||||
#define D_UPGRADE "upgrade"
|
||||
#define D_UPLOAD "upload"
|
||||
#define D_UPTIME "uptime"
|
||||
#define D_UTC_TIME "UTC"
|
||||
#define D_USER "Benutzer"
|
||||
#define D_VCC "VCC"
|
||||
#define D_VERSION "Version"
|
||||
#define D_VOLTAGE "Spannung"
|
||||
#define D_WARMLIGHT "warm"
|
||||
#define D_WEB "web" // Web log
|
||||
#define D_WEB_SERVER "Web-Server"
|
||||
#define D_WIFI "WLAN"
|
||||
#define D_WRONG "falsch"
|
||||
#define D_YESTERDAY "gestern"
|
||||
|
||||
// settings.ino
|
||||
#define D_SAVED_TO_FLASH_AT "in flash gespeichert am"
|
||||
#define D_LOADED_FROM_FLASH_AT "geladen aus flash am"
|
||||
#define D_USE_DEFAULTS "Standard verwenden"
|
||||
#define D_ERASED_SECTOR "gelöschter Sektor"
|
||||
|
||||
// sonoff.ino
|
||||
#define D_LEVEL_10 "level 1-0"
|
||||
#define D_LEVEL_01 "level 0-1"
|
||||
#define D_SERIAL_LOGGING_DISABLED "serielles logging deaktiviert"
|
||||
#define D_SYSLOG_LOGGING_REENABLED "syslog logging reaktiviert"
|
||||
|
||||
#define D_SET_BAUDRATE_TO "Baudrate eingestell auf"
|
||||
#define D_RECEIVED_TOPIC "erhaltenes topic"
|
||||
#define D_DATA_SIZE "Datengröße"
|
||||
#define D_ANALOG_INPUT0 "Analog0"
|
||||
|
||||
#define D_FINGERPRINT "TLS-Fingerabdruck wird verifiziert..."
|
||||
#define D_TLS_CONNECT_FAILED_TO "TLS-Verbindung fehlgeschlagen an"
|
||||
#define D_RETRY_IN "Wiederversuch in"
|
||||
#define D_VERIFIED "verifiziert"
|
||||
#define D_INSECURE "unsichere Verbindung aufgrund ungültigen Fingerabdrucks"
|
||||
#define D_CONNECT_FAILED_TO "Verbindung fehlgeschlagen aufgrund von"
|
||||
|
||||
// support.ino
|
||||
#define D_OSWATCH "osWatch"
|
||||
#define D_BLOCKED_LOOP "Blocked Loop"
|
||||
#define D_WPS_FAILED_WITH_STATUS "WPSconfig fehlgeschlagen mit Status"
|
||||
#define D_ACTIVE_FOR_1_MINUTE "aktiv für 1 Minute"
|
||||
#define D_FAILED_TO_START "Starten fehlgeschlagen"
|
||||
#define D_PATCH_ISSUE_2186 "Patch-Problem 2186"
|
||||
#define D_CONNECTING_TO_AP "verbinden mit AP"
|
||||
#define D_IN_MODE "in Modus"
|
||||
#define D_CONNECT_FAILED_NO_IP_ADDRESS "Verbindung fehlgeschlagen da keine IP-Adresse erhalten wurde"
|
||||
#define D_CONNECT_FAILED_AP_NOT_REACHED "Verbindung fehlgeschlagen da AP nicht erreicht werden konnte"
|
||||
#define D_CONNECT_FAILED_WRONG_PASSWORD "Verbindung fehlgeschlagen mit AP falschem Passwort"
|
||||
#define D_CONNECT_FAILED_AP_TIMEOUT "Verbindung fehlgeschlagen mit AP timeout"
|
||||
#define D_ATTEMPTING_CONNECTION "Verbindungsversuch..."
|
||||
#define D_CHECKING_CONNECTION "prüfe Verbindung..."
|
||||
#define D_QUERY_DONE "Suchanfrage abgeschlossen. MQTT-Services gefunden"
|
||||
#define D_MQTT_SERVICE_FOUND "MQTT-Service gefunden bei"
|
||||
#define D_I2CSCAN_DEVICES_FOUND_AT "Gerät(e) gefunden bei"
|
||||
#define D_FOUND_AT "gefunden bei"
|
||||
#define D_I2CSCAN_UNKNOWN_ERROR_AT "unbekannter Fehler bei"
|
||||
#define D_I2CSCAN_NO_DEVICES_FOUND "keine Geräte gefunden"
|
||||
#define D_SYSLOG_HOST_NOT_FOUND "syslog host nicht gefunden"
|
||||
|
||||
// webserver.ino
|
||||
#define D_MINIMAL_FIRMWARE_PLEASE_UPGRADE "MINIMUM-Firmware - bitte upgraden"
|
||||
#define D_WEBSERVER_ACTIVE_ON "Web-Server aktiv bei"
|
||||
#define D_WITH_IP_ADDRESS "mit IP-Adresse"
|
||||
#define D_WEBSERVER_STOPPED "Web-Server angehalten"
|
||||
#define D_FILE_NOT_FOUND "Datei nicht gefunden"
|
||||
#define D_REDIRECTED "umgeleitet zu captive portal"
|
||||
#define D_WIFIMANAGER_SET_ACCESSPOINT_AND_STATION "WLAN-Manager AccessPoint gesetzt und behält Station"
|
||||
#define D_WIFIMANAGER_SET_ACCESSPOINT "WLAN-Manager AccessPoint gesetzt"
|
||||
#define D_TRYING_TO_CONNECT "versuche Gerät mit Netzwerk zu verbinden"
|
||||
|
||||
#define D_RESTART_IN "Neustart in"
|
||||
#define D_SECONDS "Sekunden"
|
||||
#define D_DEVICE_WILL_RESTART "Gerät wird in wenigen Sekunden neu starten"
|
||||
#define D_BUTTON_TOGGLE "schalten"
|
||||
#define D_CONFIGURATION "Einstellungen"
|
||||
#define D_INFORMATION "Informationen"
|
||||
#define D_FIRMWARE_UPGRADE "Firmware-Upgrade"
|
||||
#define D_CONSOLE "Konsole"
|
||||
#define D_CONFIRM_RESTART "Neustart bestätigen"
|
||||
|
||||
#define D_CONFIGURE_MODULE "Modul konfigurieren"
|
||||
#define D_CONFIGURE_WIFI "WLAN konfigurieren"
|
||||
#define D_CONFIGURE_MQTT "MQTT konfigurieren"
|
||||
#define D_CONFIGURE_DOMOTICZ "Domoticz konfigurieren"
|
||||
#define D_CONFIGURE_LOGGING "Logging konfigurieren"
|
||||
#define D_CONFIGURE_OTHER "Andere konfigurieren"
|
||||
#define D_CONFIRM_RESET_CONFIGURATION "Zurücksetzen der Konfiguration bestätigen"
|
||||
#define D_RESET_CONFIGURATION "Konfiguration zurücksetzen"
|
||||
#define D_BACKUP_CONFIGURATION "Konfiguration sichern"
|
||||
#define D_RESTORE_CONFIGURATION "Konfiguration wiederherstellen"
|
||||
#define D_MAIN_MENU "Hauptmenü"
|
||||
|
||||
#define D_MODULE_PARAMETERS "Modul-Parameter"
|
||||
#define D_MODULE_TYPE "Module-Typ"
|
||||
#define D_GPIO "GPIO"
|
||||
#define D_SERIAL_IN "serieller Eingang [serial in]"
|
||||
#define D_SERIAL_OUT "serieller Ausgang [serial out]"
|
||||
|
||||
#define D_WIFI_PARAMETERS "WLAN-Parameter"
|
||||
#define D_SCAN_FOR_WIFI_NETWORKS "Suche nach WLAN-Netzwerke"
|
||||
#define D_SCAN_DONE "scan abgeschlossen"
|
||||
#define D_NO_NETWORKS_FOUND "keine Netzwerke gefunden"
|
||||
#define D_REFRESH_TO_SCAN_AGAIN "Aktualisieren um erneut zu suchen"
|
||||
#define D_DUPLICATE_ACCESSPOINT "AccessPoint duplizieren"
|
||||
#define D_SKIPPING_LOW_QUALITY "überspringe wegen niedriger Qualität"
|
||||
#define D_RSSI "RSSI"
|
||||
#define D_WEP "WEP"
|
||||
#define D_WPA_PSK "WPA PSK"
|
||||
#define D_WPA2_PSK "WPA2 PSK"
|
||||
#define D_AP1_SSID "AP1 SSID"
|
||||
#define D_AP1_PASSWORD "AP1 Password"
|
||||
#define D_AP2_SSID "AP2 SSID"
|
||||
#define D_AP2_PASSWORD "AP2 Password"
|
||||
|
||||
#define D_MQTT_PARAMETERS "MQTT-Parameter"
|
||||
#define D_CLIENT "client"
|
||||
#define D_FULL_TOPIC "full topic"
|
||||
|
||||
#define D_LOGGING_PARAMETERS "Logging-Parameter"
|
||||
#define D_LOG_LEVEL "log level"
|
||||
#define D_MORE_DEBUG "More debug"
|
||||
#define D_SYSLOG_HOST "Syslog host"
|
||||
#define D_SYSLOG_PORT "Syslog port"
|
||||
#define D_TELEMETRY_PERIOD "Telemetry period"
|
||||
|
||||
#define D_OTHER_PARAMETERS "andere Parameter"
|
||||
#define D_WEB_ADMIN_PASSWORD "Web-Admin-Passwort"
|
||||
#define D_MQTT_ENABLE "MQTT aktivieren"
|
||||
#define D_FRIENDLY_NAME "Name [friendly name]"
|
||||
#define D_BELKIN_WEMO "Belkin WeMo"
|
||||
#define D_HUE_BRIDGE "Hue Bridge"
|
||||
#define D_SINGLE_DEVICE "einzelnes Gerät"
|
||||
#define D_MULTI_DEVICE "Mehrfachgerät"
|
||||
|
||||
#define D_SAVE_CONFIGURATION "Konfiguration speichern"
|
||||
#define D_CONFIGURATION_SAVED "Konfiguration gespeichert"
|
||||
#define D_CONFIGURATION_RESET "Konfiguration zurücksetzen"
|
||||
|
||||
#define D_PROGRAM_VERSION "Programmversion"
|
||||
#define D_BUILD_DATE_AND_TIME "Build-Datum & -Uhrzeit"
|
||||
#define D_CORE_AND_SDK_VERSION "Core-/SDK-Version"
|
||||
#define D_FLASH_WRITE_COUNT "Flash-Schreibzähler"
|
||||
#define D_MAC_ADDRESS "MAC-Adresse"
|
||||
#define D_MQTT_HOST "MQTT host"
|
||||
#define D_MQTT_PORT "MQTT port"
|
||||
#define D_MQTT_CLIENT "MQTT client"
|
||||
#define D_MQTT_USER "MQTT-Benutzer"
|
||||
#define D_MQTT_TOPIC "MQTT topic"
|
||||
#define D_MQTT_GROUP_TOPIC "MQTT group topic"
|
||||
#define D_MQTT_FULL_TOPIC "MQTT full topic"
|
||||
#define D_MDNS_DISCOVERY "mDNS-Ermittlung"
|
||||
#define D_MDNS_ADVERTISE "mDNS-Bekanntmachung"
|
||||
#define D_ESP_CHIP_ID "ESP Chip ID"
|
||||
#define D_FLASH_CHIP_ID "Flash Chip ID"
|
||||
#define D_FLASH_CHIP_SIZE "Flash-Größe"
|
||||
#define D_FREE_PROGRAM_SPACE "freier Programmspeicherplatz"
|
||||
|
||||
#define D_UPGRADE_BY_WEBSERVER "Upgrade über Web-Server"
|
||||
#define D_OTA_URL "OTA-URL"
|
||||
#define D_START_UPGRADE "Upgrade starten"
|
||||
#define D_UPGRADE_BY_FILE_UPLOAD "Upgrade per Datei-Upload"
|
||||
#define D_UPLOAD_STARTED "Upload gestartet"
|
||||
#define D_UPGRADE_STARTED "Upgrade gestartet"
|
||||
#define D_UPLOAD_DONE "Upload abgeschlossen"
|
||||
#define D_UPLOAD_ERR_1 "keine Datei ausgewählt"
|
||||
#define D_UPLOAD_ERR_2 "ungenügend Speicherplatz"
|
||||
#define D_UPLOAD_ERR_3 "magic byte ist nicht 0xE9"
|
||||
#define D_UPLOAD_ERR_4 "Flash-Größe des Programmes ist größer als die reale Flash-Größe"
|
||||
#define D_UPLOAD_ERR_5 "Upload-buffer-Vergleich weicht ab"
|
||||
#define D_UPLOAD_ERR_6 "Upload fehlgeschlagen. Aktiviere logging 3"
|
||||
#define D_UPLOAD_ERR_7 "Upload abgebrochen"
|
||||
#define D_UPLOAD_ERR_8 "Datei ungültig"
|
||||
#define D_UPLOAD_ERR_9 "Datei zu groß"
|
||||
#define D_UPLOAD_ERROR_CODE "Upload-Fehler-Code"
|
||||
|
||||
#define D_ENTER_COMMAND "Befehl eingeben"
|
||||
#define D_ENABLE_WEBLOG_FOR_RESPONSE "aktivere weblog 2 falls Reaktion erwartet"
|
||||
#define D_NEED_USER_AND_PASSWORD "Benutzer benötigt=<Benutzername>&password=<Passwort>"
|
||||
|
||||
// xdrv_domoticz.ino
|
||||
#define D_DOMOTICZ_PARAMETERS "Domoticz parameters"
|
||||
#define D_DOMOTICZ_IDX "Idx"
|
||||
#define D_DOMOTICZ_KEY_IDX "Key idx"
|
||||
#define D_DOMOTICZ_SWITCH_IDX "Switch idx"
|
||||
#define D_DOMOTICZ_SENSOR_IDX "Sensor idx"
|
||||
#define DOMOTICZ_SENSORS_MAX_STRING_LENGTH 14
|
||||
#define D_DOMOTICZ_TEMP "Temp"
|
||||
#define D_DOMOTICZ_TEMP_HUM "Temp,Hum"
|
||||
#define D_DOMOTICZ_TEMP_HUM_BARO "Temp,Hum,Baro"
|
||||
#define D_DOMOTICZ_POWER_ENERGY "Power,Energy"
|
||||
#define D_DOMOTICZ_ILLUMINANCE "Illuminance"
|
||||
#define D_DOMOTICZ_COUNT "Count"
|
||||
#define D_DOMOTICZ_VOLTAGE "Voltage"
|
||||
#define D_DOMOTICZ_CURRENT "Current"
|
||||
#define D_DOMOTICZ_UPDATE_TIMER "Update timer"
|
||||
|
||||
// xdrv_ir-send.ino
|
||||
#define D_INVALID_JSON "ungültiger JSON"
|
||||
#define D_PROTOCOL_NOT_SUPPORTED "Protokoll nicht unterstützt"
|
||||
#define D_IR_PROTOCOL "PROTOKOLL"
|
||||
#define D_IR_BITS "BITS"
|
||||
#define D_IR_DATA "DATEN"
|
||||
#define D_IRHVAC_VENDOR "HERSTELLER"
|
||||
#define D_IRHVAC_POWER "STROM"
|
||||
#define D_IRHVAC_MODE "MODUS"
|
||||
#define D_IRHVAC_FANSPEED "LÜFTERGESCHWINDIGKEIT"
|
||||
#define D_IRHVAC_TEMP "TEMPERATUR"
|
||||
#define D_IRRECEIVED "IrReceived"
|
||||
|
||||
// xdrv_snfbridge.ino
|
||||
#define D_RFRECEIVED "RfReceived"
|
||||
#define D_START_LEARNING "starte Anlernen"
|
||||
#define D_SET_TO_DEFAULT "auf Standard zurücksetzen"
|
||||
#define D_DEFAULT_SENT "Standard gesendet"
|
||||
#define D_LEARNED_SENT "Anlernen gesendet"
|
||||
#define D_LEARNING_ACTIVE "Anlernen aktiv"
|
||||
#define D_LEARN_FAILED "Anlernen fehlgeschlagen"
|
||||
#define D_LEARNED "angelernt"
|
||||
|
||||
// xdrv_wemohue.ino
|
||||
#define D_MULTICAST_DISABLED "Multicast deaktiviert"
|
||||
#define D_MULTICAST_REJOINED "Multicast (wieder-)verbunden"
|
||||
#define D_MULTICAST_JOIN_FAILED "Multicast-Verbinden fehlgeschlagen"
|
||||
#define D_FAILED_TO_SEND_RESPONSE "Antwort senden fehlgeschlagen"
|
||||
|
||||
#define D_WEMO "WeMo"
|
||||
#define D_WEMO_BASIC_EVENT "WeMo basic event"
|
||||
#define D_WEMO_EVENT_SERVICE "WeMo event service"
|
||||
#define D_WEMO_SETUP "WeMo-Setup"
|
||||
#define D_RESPONSE_SENT "Antwort gesendet"
|
||||
|
||||
#define D_HUE "Hue"
|
||||
#define D_HUE_BRIDGE_SETUP "Hue-Setup"
|
||||
#define D_HUE_API_NOT_IMPLEMENTED "Hue API nicht implementiert"
|
||||
#define D_HUE_API "Hue API"
|
||||
#define D_HUE_POST_ARGS "Hue POST args"
|
||||
#define D_3_RESPONSE_PACKETS_SENT "3 Antwortpakete gesendet"
|
||||
|
||||
// xsns_dht.ino
|
||||
#define D_TIMEOUT_WAITING_FOR "Timeout wartet auf"
|
||||
#define D_START_SIGNAL_LOW "Startausschlag niedrig"
|
||||
#define D_START_SIGNAL_HIGH "Startausschlag hoch"
|
||||
#define D_PULSE "pulse"
|
||||
#define D_CHECKSUM_FAILURE "Checksum-Fehler"
|
||||
|
||||
// xsns_ds18b20.ino
|
||||
#define D_SENSOR_BUSY "Sensor beschäftigt"
|
||||
#define D_SENSOR_CRC_ERROR "Sensor CRC-Fehler"
|
||||
|
||||
// xsns_hlw8012.ino
|
||||
#define D_MAXPOWERREACHED "MaxPowerReached"
|
||||
#define D_MAXPOWERREACHEDRETRY "MaxPowerReachedRetry"
|
||||
#define D_POWERMONITOR "PowerMonitor"
|
||||
#define D_ENERGYMONITOR "EnergyMonitor"
|
||||
#define D_MAXENERGYREACHED "MaxEnergyReached"
|
||||
#define D_ENERGY_TODAY "Strom heute"
|
||||
#define D_ENERGY_YESTERDAY "Strom gestern"
|
||||
#define D_ENERGY_TOTAL "Stromtotal"
|
||||
|
||||
// xsns_sht1x.ino
|
||||
#define D_SENSOR_DID_NOT_ACK_COMMAND "Sensor hat ACK-Befehl nicht ausgeführt"
|
||||
#define D_SHT1X_FOUND "SHT1X gefunden"
|
||||
|
||||
// sonoff_template.h
|
||||
// Max string length is 8 characters including suffixes
|
||||
#define D_SENSOR_NONE "None"
|
||||
#define D_SENSOR_DHT11 "DHT11"
|
||||
#define D_SENSOR_AM2301 "AM2301"
|
||||
#define D_SENSOR_DHT22 "DHT22"
|
||||
#define D_SENSOR_DS18X20 "DS18x20"
|
||||
#define D_SENSOR_I2C_SCL "I2C SCL"
|
||||
#define D_SENSOR_I2C_SDA "I2C SDA"
|
||||
#define D_SENSOR_WS2812 "WS2812"
|
||||
#define D_SENSOR_IRSEND "IRsend"
|
||||
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
|
||||
#define D_SENSOR_BUTTON "Button" // Suffix "1"
|
||||
#define D_SENSOR_RELAY "Relay" // Suffix "1i"
|
||||
#define D_SENSOR_LED "Led" // Suffix "1i"
|
||||
#define D_SENSOR_PWM "PWM" // Suffix "1"
|
||||
#define D_SENSOR_COUNTER "Counter" // Suffix "1"
|
||||
#define D_SENSOR_IRRECV "IRrecv"
|
||||
#define D_SENSOR_SPI_CS "SPI CS"
|
||||
#define D_SENSOR_SPI_DC "SPI DC"
|
||||
#define D_SENSOR_BACKLIGHT "BLight"
|
||||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
#define D_UNIT_HOUR "h"
|
||||
#define D_UNIT_KILOWATTHOUR "kWh"
|
||||
#define D_UNIT_LUX "lx"
|
||||
#define D_UNIT_MICROSECOND "us"
|
||||
#define D_UNIT_MILLIAMPERE "mA"
|
||||
#define D_UNIT_MILLISECOND "ms"
|
||||
#define D_UNIT_MINUTE "min"
|
||||
#define D_UNIT_PRESSURE "hPa"
|
||||
#define D_UNIT_SECOND "sec"
|
||||
#define D_UNIT_SECTORS "Sektoren"
|
||||
#define D_UNIT_VOLT "V"
|
||||
#define D_UNIT_WATT "W"
|
||||
#define D_UNIT_WATTHOUR "Wh"
|
||||
|
||||
// Log message prefix
|
||||
#define D_LOG_APPLICATION "APP: "
|
||||
#define D_LOG_BRIDGE "BRG: "
|
||||
#define D_LOG_CONFIG "CFG: "
|
||||
#define D_LOG_COMMAND "CMD: "
|
||||
#define D_LOG_DHT "DHT: "
|
||||
#define D_LOG_DOMOTICZ "DOM: "
|
||||
#define D_LOG_DSB "DSB: "
|
||||
#define D_LOG_HTTP "HTP: "
|
||||
#define D_LOG_I2C "I2C: "
|
||||
#define D_LOG_IRR "IRR: "
|
||||
#define D_LOG_LOG "LOG: "
|
||||
#define D_LOG_MODULE "MOD: "
|
||||
#define D_LOG_MDNS "DNS: "
|
||||
#define D_LOG_MQTT "MQT: "
|
||||
#define D_LOG_OTHER "OTH: "
|
||||
#define D_LOG_RESULT "RSL: "
|
||||
#define D_LOG_SERIAL "SER: "
|
||||
#define D_LOG_SHT1 "SHT: "
|
||||
#define D_LOG_UPLOAD "UPL: "
|
||||
#define D_LOG_UPNP "UPP: "
|
||||
#define D_LOG_WIFI "WIF: "
|
||||
|
||||
// Result
|
||||
#define D_RSLT_RESULT "ERGEBNIS"
|
||||
#define D_RSLT_INFO "INFO"
|
||||
#define D_RSLT_STATE "STATUS"
|
||||
#define D_RSLT_SENSOR "SENSOR"
|
||||
#define D_RSLT_UPTIME "LAUFZEIT"
|
||||
#define D_RSLT_MARGINS "TOLERANZ"
|
||||
#define D_RSLT_WARNING "WARNUNG"
|
||||
#define D_RSLT_ENERGY "ENERGIE"
|
||||
|
||||
// Commands
|
||||
#define D_CMND_MQTTHOST "MqttHost"
|
||||
#define D_CMND_MQTTPORT "MqttPort"
|
||||
#define D_CMND_MQTTRETRY "MqttRetry"
|
||||
#define D_CMND_STATETEXT "StateText"
|
||||
#define D_CMND_MQTTFINGERPRINT "MqttFingerprint"
|
||||
#define D_CMND_MQTTCLIENT "MqttClient"
|
||||
#define D_CMND_MQTTUSER "MqttUser"
|
||||
#define D_CMND_MQTTPASSWORD "MqttPassword"
|
||||
#define D_CMND_FULLTOPIC "FullTopic"
|
||||
#define D_CMND_PREFIX "Prefix"
|
||||
#define PRFX_MAX_STRING_LENGTH 5
|
||||
#define D_CMND "cmnd"
|
||||
#define D_STAT "stat"
|
||||
#define D_TELE "tele"
|
||||
#define D_CMND_GROUPTOPIC "GroupTopic"
|
||||
#define D_CMND_TOPIC "Topic"
|
||||
#define D_CMND_BUTTONTOPIC "ButtonTopic"
|
||||
#define D_CMND_SWITCHTOPIC "SwitchTopic"
|
||||
#define D_CMND_BUTTONRETAIN "ButtonRetain"
|
||||
#define D_CMND_SWITCHRETAIN "SwitchRetain"
|
||||
#define D_CMND_POWERRETAIN "PowerRetain"
|
||||
#define D_CMND_SENSORRETAIN "SensorRetain"
|
||||
#define D_CMND_BACKLOG "Backlog"
|
||||
#define D_CMND_DELAY "Delay"
|
||||
#define D_CMND_STATUS "Status"
|
||||
#define D_STATUS1_PARAMETER "PRM"
|
||||
#define D_STATUS2_FIRMWARE "FWR"
|
||||
#define D_STATUS3_LOGGING "LOG"
|
||||
#define D_STATUS4_MEMORY "MEM"
|
||||
#define D_STATUS5_NETWORK "NET"
|
||||
#define D_STATUS6_MQTT "MQT"
|
||||
#define D_STATUS7_TIME "TIM"
|
||||
#define D_STATUS8_POWER "PWR"
|
||||
#define D_STATUS9_MARGIN "PTH"
|
||||
#define D_STATUS10_SENSOR "SNS"
|
||||
#define D_STATUS11_STATUS "STS"
|
||||
#define D_CMND_POWER "Power"
|
||||
#define D_RSLT_POWER "POWER"
|
||||
#define D_CMND_POWERONSTATE "PowerOnState"
|
||||
#define D_CMND_PULSETIME "PulseTime"
|
||||
#define D_CMND_BLINKTIME "BlinkTime"
|
||||
#define D_CMND_BLINKCOUNT "BlinkCount"
|
||||
#define D_CMND_SAVEDATA "SaveData"
|
||||
#define D_CMND_SETOPTION "SetOption"
|
||||
#define D_CMND_TEMPERATURE_RESOLUTION "TempRes"
|
||||
#define D_CMND_HUMIDITY_RESOLUTION "HumRes"
|
||||
#define D_CMND_PRESSURE_RESOLUTION "PressRes"
|
||||
#define D_CMND_POWER_RESOLUTION "WattRes"
|
||||
#define D_CMND_VOLTAGE_RESOLUTION "VoltRes"
|
||||
#define D_CMND_ENERGY_RESOLUTION "EnergyRes"
|
||||
#define D_CMND_MODULE "Module"
|
||||
#define D_CMND_MODULES "Modules"
|
||||
#define D_CMND_GPIO "GPIO"
|
||||
#define D_NOT_SUPPORTED "Not supported"
|
||||
#define D_CMND_GPIOS "GPIOs"
|
||||
#define D_CMND_PWM "PWM"
|
||||
#define D_CMND_PWMFREQUENCY "PWMFrequency"
|
||||
#define D_CMND_PWMRANGE "PWMRange"
|
||||
#define D_CMND_COUNTER "Counter"
|
||||
#define D_CMND_COUNTERTYPE "CounterType"
|
||||
#define D_CMND_COUNTERDEBOUNCE "CounterDebounce"
|
||||
#define D_CMND_SLEEP "Sleep"
|
||||
#define D_CMND_UPLOAD "Upload"
|
||||
#define D_CMND_UPGRADE "Upgrade"
|
||||
#define D_ONE_OR_GT "1 or >%s to upgrade"
|
||||
#define D_CMND_OTAURL "OtaUrl"
|
||||
#define D_CMND_SERIALLOG "SerialLog"
|
||||
#define D_CMND_SYSLOG "SysLog"
|
||||
#define D_CMND_LOGHOST "LogHost"
|
||||
#define D_CMND_LOGPORT "LogPort"
|
||||
#define D_CMND_IPADDRESS "IPAddress"
|
||||
#define D_CMND_NTPSERVER "NtpServer"
|
||||
#define D_CMND_AP "Ap"
|
||||
#define D_CMND_SSID "SSId"
|
||||
#define D_CMND_PASSWORD "Password"
|
||||
#define D_CMND_HOSTNAME "Hostname"
|
||||
#define D_CMND_WIFICONFIG "WifiConfig"
|
||||
#define WCFG_MAX_STRING_LENGTH 12
|
||||
#define D_WCFG_0_RESTART "Restart"
|
||||
#define D_WCFG_1_SMARTCONFIG "SmartConfig"
|
||||
#define D_WCFG_2_WIFIMANAGER "WifiManager"
|
||||
#define D_WCFG_3_WPSCONFIG "WPSConfig"
|
||||
#define D_WCFG_4_RETRY "Retry"
|
||||
#define D_WCFG_5_WAIT "Wait"
|
||||
#define D_CMND_FRIENDLYNAME "FriendlyName"
|
||||
#define D_CMND_SWITCHMODE "SwitchMode"
|
||||
#define D_CMND_WEBSERVER "Webserver"
|
||||
#define D_WEBSERVER_MODE "WebServerMode"
|
||||
#define D_ACTIVE_FOR "Active for"
|
||||
#define D_ON_DEVICE "on"
|
||||
#define D_CMND_WEBPASSWORD "WebPassword"
|
||||
#define D_CMND_WEBLOG "WebLog"
|
||||
#define D_CMND_EMULATION "Emulation"
|
||||
#define D_CMND_TELEPERIOD "TelePeriod"
|
||||
#define D_CMND_RESTART "Restart"
|
||||
#define D_ONE_TO_RESTART "1 to restart"
|
||||
#define D_CMND_RESET "Reset"
|
||||
#define D_RESET_AND_RESTARTING "Reset and Restarting"
|
||||
#define D_ONE_TO_RESET "1 to reset"
|
||||
#define D_CMND_TIMEZONE "Timezone"
|
||||
#define D_CMND_ALTITUDE "Altitude"
|
||||
#define D_CMND_LEDPOWER "LedPower"
|
||||
#define D_CMND_LEDSTATE "LedState"
|
||||
#define D_CMND_CFGDUMP "CfgDump"
|
||||
#define D_CMND_I2CSCAN "I2CScan"
|
||||
#define D_CMND_EXCEPTION "Exception"
|
||||
|
||||
// Commands xdrv_domoticz.ino
|
||||
#define D_CMND_DOMOTICZ "Domoticz"
|
||||
#define D_CMND_IDX "Idx"
|
||||
#define D_CMND_KEYIDX "KeyIdx"
|
||||
#define D_CMND_SWITCHIDX "SwitchIdx"
|
||||
#define D_CMND_SENSORIDX "SensorIdx"
|
||||
#define D_CMND_UPDATETIMER "UpdateTimer"
|
||||
|
||||
// Commands xdrv_ir_send.ino
|
||||
#define D_CMND_IRSEND "IRSend"
|
||||
#define D_CMND_IRHVAC "IRHVAC"
|
||||
|
||||
// Commands xdrv_snfbridge.ino
|
||||
#define D_CMND_RFKEY "RfKey"
|
||||
#define D_CMND_RFDEFAULT "RfDefault"
|
||||
|
||||
// Commands xdrv_snfled.ino
|
||||
#define D_CMND_COLOR "Color"
|
||||
#define D_CMND_COLORTEMPERATURE "CT"
|
||||
#define D_CMND_DIMMER "Dimmer"
|
||||
#define D_CMND_LEDTABLE "LedTable"
|
||||
#define D_CMND_FADE "Fade"
|
||||
#define D_CMND_SPEED "Speed"
|
||||
#define D_CMND_WAKEUPDURATION "WakeUpDuration"
|
||||
#define D_CMND_WAKEUP "Wakeup"
|
||||
|
||||
// Commands xdrv_ws2812.ino
|
||||
#define D_CMND_PIXELS "Pixels"
|
||||
#define D_CMND_LED "Led"
|
||||
#define D_CMND_WIDTH "Width"
|
||||
#define D_CMND_SCHEME "Scheme"
|
||||
|
||||
// Commands xsns_hlw8012.ino
|
||||
#define D_CMND_POWERLOW "PowerLow"
|
||||
#define D_CMND_POWERHIGH "PowerHigh"
|
||||
#define D_CMND_VOLTAGELOW "VoltageLow"
|
||||
#define D_CMND_VOLTAGEHIGH "VoltageHigh"
|
||||
#define D_CMND_CURRENTLOW "CurrentLow"
|
||||
#define D_CMND_CURRENTHIGH "CurrentHigh"
|
||||
#define D_CMND_ENERGYRESET "EnergyReset"
|
||||
#define D_CMND_HLWPCAL "HlwPcal"
|
||||
#define D_CMND_HLWPSET "HlwPset"
|
||||
#define D_CMND_HLWUCAL "HlwUcal"
|
||||
#define D_CMND_HLWUSET "HlwUset"
|
||||
#define D_CMND_HLWICAL "HlwIcal"
|
||||
#define D_CMND_HLWISET "HlwIset"
|
||||
#define D_CMND_MAXPOWER "MaxPower"
|
||||
#define D_CMND_MAXPOWERHOLD "MaxPowerHold"
|
||||
#define D_CMND_MAXPOWERWINDOW "MaxPowerWindow"
|
||||
#define D_CMND_SAFEPOWER "SafePower"
|
||||
#define D_CMND_SAFEPOWERHOLD "SafePowerHold"
|
||||
#define D_CMND_SAFEPOWERWINDOW "SafePowerWindow"
|
||||
#define D_CMND_MAXENERGY "MaxEnergy"
|
||||
#define D_CMND_MAXENERGYSTART "MaxEnergyStart"
|
||||
|
||||
#endif // _LANGUAGE_DE_DE_H_
|
|
@ -17,9 +17,13 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LANGUAGE_EN_GB_H_
|
||||
#define _LANGUAGE_EN_GB_H_
|
||||
|
||||
/*************************** ATTENTION *******************************\
|
||||
*
|
||||
* Due to memory constraints only UTF-8 is supported.
|
||||
* To save code space keep text as short as possible.
|
||||
* Time and Date provided by SDK can not be localized (yet).
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
|
@ -379,7 +383,6 @@
|
|||
#define D_DOMOTICZ_VOLTAGE "Voltage"
|
||||
#define D_DOMOTICZ_CURRENT "Current"
|
||||
#define D_DOMOTICZ_UPDATE_TIMER "Update timer"
|
||||
#define D_CONFIGURE_DOMOTICZ "Configure Domoticz"
|
||||
|
||||
// xdrv_ir-send.ino
|
||||
#define D_INVALID_JSON "Invalid JSON"
|
||||
|
@ -461,8 +464,8 @@
|
|||
#define D_SENSOR_IRSEND "IRsend"
|
||||
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
|
||||
#define D_SENSOR_BUTTON "Button" // Suffix "1"
|
||||
#define D_SENSOR_RELAY "Relay" // Suffix "1I"
|
||||
#define D_SENSOR_LED "Led" // Suffix "1I"
|
||||
#define D_SENSOR_RELAY "Relay" // Suffix "1i"
|
||||
#define D_SENSOR_LED "Led" // Suffix "1i"
|
||||
#define D_SENSOR_PWM "PWM" // Suffix "1"
|
||||
#define D_SENSOR_COUNTER "Counter" // Suffix "1"
|
||||
#define D_SENSOR_IRRECV "IRrecv"
|
||||
|
@ -576,6 +579,8 @@
|
|||
#define D_NOT_SUPPORTED "Not supported"
|
||||
#define D_CMND_GPIOS "GPIOs"
|
||||
#define D_CMND_PWM "PWM"
|
||||
#define D_CMND_PWMFREQUENCY "PWMFrequency"
|
||||
#define D_CMND_PWMRANGE "PWMRange"
|
||||
#define D_CMND_COUNTER "Counter"
|
||||
#define D_CMND_COUNTERTYPE "CounterType"
|
||||
#define D_CMND_COUNTERDEBOUNCE "CounterDebounce"
|
||||
|
@ -679,3 +684,5 @@
|
|||
#define D_CMND_SAFEPOWERWINDOW "SafePowerWindow"
|
||||
#define D_CMND_MAXENERGY "MaxEnergy"
|
||||
#define D_CMND_MAXENERGYSTART "MaxEnergyStart"
|
||||
|
||||
#endif // _LANGUAGE_EN_GB_H_
|
|
@ -17,9 +17,13 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _LANGUAGE_NL_NL_H_
|
||||
#define _LANGUAGE_NL_NL_H_
|
||||
|
||||
/*************************** ATTENTION *******************************\
|
||||
*
|
||||
* Due to memory constraints only UTF-8 is supported.
|
||||
* To save code space keep text as short as possible.
|
||||
* Time and Date provided by SDK can not be localized (yet).
|
||||
* Use online command StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||
* Use online command Prefix to translate cmnd, stat and tele.
|
||||
|
@ -379,7 +383,6 @@
|
|||
#define D_DOMOTICZ_VOLTAGE "Spanning"
|
||||
#define D_DOMOTICZ_CURRENT "Stroom"
|
||||
#define D_DOMOTICZ_UPDATE_TIMER "Bijwerk timer"
|
||||
#define D_CONFIGURE_DOMOTICZ "Configureer Domoticz"
|
||||
|
||||
// xdrv_ir-send.ino
|
||||
#define D_INVALID_JSON "Ongeldig JSON"
|
||||
|
@ -461,8 +464,8 @@
|
|||
#define D_SENSOR_IRSEND "IRsend"
|
||||
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
|
||||
#define D_SENSOR_BUTTON "Button" // Suffix "1"
|
||||
#define D_SENSOR_RELAY "Relais" // Suffix "1I"
|
||||
#define D_SENSOR_LED "Led" // Suffix "1I"
|
||||
#define D_SENSOR_RELAY "Relais" // Suffix "1i"
|
||||
#define D_SENSOR_LED "Led" // Suffix "1i"
|
||||
#define D_SENSOR_PWM "PWM" // Suffix "1"
|
||||
#define D_SENSOR_COUNTER "Teller" // Suffix "1"
|
||||
#define D_SENSOR_IRRECV "IRrecv"
|
||||
|
@ -472,7 +475,7 @@
|
|||
|
||||
// Units
|
||||
#define D_UNIT_AMPERE "A"
|
||||
#define D_UNIT_HOUR "Hr"
|
||||
#define D_UNIT_HOUR "h"
|
||||
#define D_UNIT_KILOWATTHOUR "kWh"
|
||||
#define D_UNIT_LUX "lx"
|
||||
#define D_UNIT_MICROSECOND "us"
|
||||
|
@ -576,6 +579,8 @@
|
|||
#define D_NOT_SUPPORTED "Not supported"
|
||||
#define D_CMND_GPIOS "GPIOs"
|
||||
#define D_CMND_PWM "PWM"
|
||||
#define D_CMND_PWMFREQUENCY "PWMFrequency"
|
||||
#define D_CMND_PWMRANGE "PWMRange"
|
||||
#define D_CMND_COUNTER "Counter"
|
||||
#define D_CMND_COUNTERTYPE "CounterType"
|
||||
#define D_CMND_COUNTERDEBOUNCE "CounterDebounce"
|
||||
|
@ -679,3 +684,5 @@
|
|||
#define D_CMND_SAFEPOWERWINDOW "SafePowerWindow"
|
||||
#define D_CMND_MAXENERGY "MaxEnergy"
|
||||
#define D_CMND_MAXENERGYSTART "MaxEnergyStart"
|
||||
|
||||
#endif // _LANGUAGE_NL_NL_H_
|
|
@ -17,12 +17,15 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SETTINGS_H_
|
||||
#define _SETTINGS_H_
|
||||
|
||||
#define PARAM8_SIZE 23 // Number of param bytes
|
||||
|
||||
typedef union { // Restricted by MISRA-C Rule 18.4 but so usefull...
|
||||
uint32_t data; // Allow bit manipulation using SetOption
|
||||
struct {
|
||||
uint32_t savestate : 1; // bit 0
|
||||
uint32_t save_state : 1; // bit 0
|
||||
uint32_t button_restrict : 1; // bit 1
|
||||
uint32_t value_units : 1; // bit 2
|
||||
uint32_t mqtt_enabled : 1; // bit 3
|
||||
|
@ -49,17 +52,17 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu
|
|||
uint32_t humidity_resolution : 2;
|
||||
uint32_t temperature_resolution : 2;
|
||||
};
|
||||
} sysBitfield;
|
||||
} SysBitfield;
|
||||
|
||||
struct SYSCFG {
|
||||
unsigned long cfg_holder; // 000
|
||||
unsigned long saveFlag; // 004
|
||||
unsigned long save_flag; // 004
|
||||
unsigned long version; // 008
|
||||
unsigned long bootcount; // 00C
|
||||
sysBitfield flag; // 010 Add flag since 5.0.2
|
||||
int16_t savedata; // 014
|
||||
SysBitfield flag; // 010 Add flag since 5.0.2
|
||||
int16_t save_data; // 014
|
||||
int8_t timezone; // 016
|
||||
char otaUrl[101]; // 017
|
||||
char ota_url[101]; // 017
|
||||
char mqtt_prefix[3][11]; // 07C
|
||||
|
||||
byte free_09D[1]; // 09D
|
||||
|
@ -89,11 +92,9 @@ struct SYSCFG {
|
|||
char mqtt_grptopic[33]; // 2B1
|
||||
uint8_t mqtt_fingerprinth[20]; // 2D2 Reserved for binary fingerprint
|
||||
|
||||
byte free_2E6[2]; // 2E6
|
||||
|
||||
uint16_t pwm_frequency; // 2E6
|
||||
power_t power; // 2E8
|
||||
uint16_t pwmvalue[MAX_PWMS]; // 2EC
|
||||
// byte free_2EC[10]; // 2EC
|
||||
uint16_t pwm_value[MAX_PWMS]; // 2EC
|
||||
|
||||
int16_t altitude; // 2F6 Add since 5.8.0i
|
||||
uint16_t tele_period; // 2F8
|
||||
|
@ -105,15 +106,14 @@ struct SYSCFG {
|
|||
byte free_33F[1]; // 33F
|
||||
|
||||
uint16_t domoticz_update_timer; // 340
|
||||
|
||||
byte free_342[2]; // 342
|
||||
uint16_t pwm_range; // 342
|
||||
|
||||
unsigned long domoticz_relay_idx[MAX_DOMOTICZ_IDX]; // 344
|
||||
unsigned long domoticz_key_idx[MAX_DOMOTICZ_IDX]; // 354
|
||||
|
||||
unsigned long hlw_pcal; // 364
|
||||
unsigned long hlw_ucal; // 368
|
||||
unsigned long hlw_ical; // 36C
|
||||
unsigned long hlw_power_calibration; // 364
|
||||
unsigned long hlw_voltage_calibration; // 368
|
||||
unsigned long hlw_current_calibration; // 36C
|
||||
unsigned long hlw_kWhtoday; // 370
|
||||
unsigned long hlw_kWhyesterday; // 374
|
||||
uint16_t hlw_kWhdoy; // 378
|
||||
|
@ -189,8 +189,8 @@ struct SYSCFG {
|
|||
|
||||
byte free_531[1]; // 531
|
||||
|
||||
uint16_t pulsetime[MAX_PULSETIMERS]; // 532
|
||||
//uint16_t ex_pwmvalue[MAX_PWMS]; // 53A
|
||||
uint16_t pulse_timer[MAX_PULSETIMERS]; // 532
|
||||
//uint16_t ex_pwm_value[MAX_PWMS]; // 53A
|
||||
|
||||
byte free_542[2]; // 542
|
||||
|
||||
|
@ -200,24 +200,52 @@ struct SYSCFG {
|
|||
|
||||
byte free_5BD[3]; // 5BD
|
||||
|
||||
unsigned long pCounter[MAX_COUNTERS]; // 5C0
|
||||
uint16_t pCounterType; // 5D0
|
||||
uint16_t pCounterDebounce; // 5D2
|
||||
uint8_t sfb_code[17][9]; // 5D4
|
||||
unsigned long pulse_counter[MAX_COUNTERS]; // 5C0
|
||||
uint16_t pulse_counter_type; // 5D0
|
||||
uint16_t pulse_counter_debounce; // 5D2
|
||||
uint8_t rf_code[17][9]; // 5D4
|
||||
|
||||
} sysCfg;
|
||||
} Settings;
|
||||
|
||||
struct RTCMEM {
|
||||
uint16_t valid; // 000
|
||||
byte osw_flag; // 002
|
||||
byte oswatch_blocked_loop; // 002
|
||||
uint8_t unused; // 003
|
||||
unsigned long hlw_kWhtoday; // 004
|
||||
unsigned long hlw_kWhtotal; // 008
|
||||
unsigned long pCounter[MAX_COUNTERS]; // 00C
|
||||
unsigned long pulse_counter[MAX_COUNTERS]; // 00C
|
||||
power_t power; // 01C
|
||||
} rtcMem;
|
||||
} RtcSettings;
|
||||
|
||||
struct TIME_T {
|
||||
uint8_t second;
|
||||
uint8_t minute;
|
||||
uint8_t hour;
|
||||
uint8_t day_of_week; // sunday is day 1
|
||||
uint8_t day_of_month;
|
||||
uint8_t month;
|
||||
char name_of_month[4];
|
||||
uint16_t day_of_year;
|
||||
uint16_t year;
|
||||
unsigned long valid;
|
||||
} RtcTime;
|
||||
|
||||
struct TimeChangeRule
|
||||
{
|
||||
uint8_t hemis; // 0-Northern, 1=Southern Hemisphere (=Opposite DST/STD)
|
||||
uint8_t week; // 1=First, 2=Second, 3=Third, 4=Fourth, or 0=Last week of the month
|
||||
uint8_t dow; // day of week, 1=Sun, 2=Mon, ... 7=Sat
|
||||
uint8_t month; // 1=Jan, 2=Feb, ... 12=Dec
|
||||
uint8_t hour; // 0-23
|
||||
int offset; // offset from UTC in minutes
|
||||
};
|
||||
|
||||
TimeChangeRule DaylightSavingTime = { TIME_DST }; // Daylight Saving Time
|
||||
TimeChangeRule StandardTime = { TIME_STD }; // Standard Time
|
||||
|
||||
// See issue https://github.com/esp8266/Arduino/issues/2913
|
||||
#ifdef USE_ADC_VCC
|
||||
ADC_MODE(ADC_VCC); // Set ADC input for Power Supply Voltage usage
|
||||
#endif
|
||||
|
||||
#endif // _SETTINGS_H_
|
|
@ -21,7 +21,7 @@
|
|||
#define DOMOTICZ_UPDATE_TIMER 0 // [DomoticzUpdateTimer] Send relay status (0 = disable, 1 - 3600 seconds) (Optional)
|
||||
#endif
|
||||
|
||||
const uint8_t sfb_codeDefault[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };
|
||||
const uint8_t kDefaultRfCode[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48, 0x2E, 0x1A, 0x00 };
|
||||
|
||||
/*********************************************************************************************\
|
||||
* RTC memory
|
||||
|
@ -29,12 +29,12 @@ const uint8_t sfb_codeDefault[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48,
|
|||
|
||||
#define RTC_MEM_VALID 0xA55A
|
||||
|
||||
uint32_t _rtcHash = 0;
|
||||
uint32_t rtc_settings_hash = 0;
|
||||
|
||||
uint32_t getRtcHash()
|
||||
uint32_t GetRtcSettingsHash()
|
||||
{
|
||||
uint32_t hash = 0;
|
||||
uint8_t *bytes = (uint8_t*)&rtcMem;
|
||||
uint8_t *bytes = (uint8_t*)&RtcSettings;
|
||||
|
||||
for (uint16_t i = 0; i < sizeof(RTCMEM); i++) {
|
||||
hash += bytes[i]*(i+1);
|
||||
|
@ -42,47 +42,47 @@ uint32_t getRtcHash()
|
|||
return hash;
|
||||
}
|
||||
|
||||
void RTC_Save()
|
||||
void RtcSettingsSave()
|
||||
{
|
||||
if (getRtcHash() != _rtcHash) {
|
||||
rtcMem.valid = RTC_MEM_VALID;
|
||||
ESP.rtcUserMemoryWrite(100, (uint32_t*)&rtcMem, sizeof(RTCMEM));
|
||||
_rtcHash = getRtcHash();
|
||||
if (GetRtcSettingsHash() != rtc_settings_hash) {
|
||||
RtcSettings.valid = RTC_MEM_VALID;
|
||||
ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RTCMEM));
|
||||
rtc_settings_hash = GetRtcSettingsHash();
|
||||
#ifdef DEBUG_THEO
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Save"));
|
||||
RTC_Dump();
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Save"));
|
||||
RtcSettingsDump();
|
||||
#endif // DEBUG_THEO
|
||||
}
|
||||
}
|
||||
|
||||
void RTC_Load()
|
||||
void RtcSettingsLoad()
|
||||
{
|
||||
ESP.rtcUserMemoryRead(100, (uint32_t*)&rtcMem, sizeof(RTCMEM));
|
||||
ESP.rtcUserMemoryRead(100, (uint32_t*)&RtcSettings, sizeof(RTCMEM));
|
||||
#ifdef DEBUG_THEO
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Load"));
|
||||
RTC_Dump();
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Load"));
|
||||
RtcSettingsDump();
|
||||
#endif // DEBUG_THEO
|
||||
if (rtcMem.valid != RTC_MEM_VALID) {
|
||||
memset(&rtcMem, 0, sizeof(RTCMEM));
|
||||
rtcMem.valid = RTC_MEM_VALID;
|
||||
rtcMem.hlw_kWhtoday = sysCfg.hlw_kWhtoday;
|
||||
rtcMem.hlw_kWhtotal = sysCfg.hlw_kWhtotal;
|
||||
if (RtcSettings.valid != RTC_MEM_VALID) {
|
||||
memset(&RtcSettings, 0, sizeof(RTCMEM));
|
||||
RtcSettings.valid = RTC_MEM_VALID;
|
||||
RtcSettings.hlw_kWhtoday = Settings.hlw_kWhtoday;
|
||||
RtcSettings.hlw_kWhtotal = Settings.hlw_kWhtotal;
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
rtcMem.pCounter[i] = sysCfg.pCounter[i];
|
||||
RtcSettings.pulse_counter[i] = Settings.pulse_counter[i];
|
||||
}
|
||||
rtcMem.power = sysCfg.power;
|
||||
RTC_Save();
|
||||
RtcSettings.power = Settings.power;
|
||||
RtcSettingsSave();
|
||||
}
|
||||
_rtcHash = getRtcHash();
|
||||
rtc_settings_hash = GetRtcSettingsHash();
|
||||
}
|
||||
|
||||
boolean RTC_Valid()
|
||||
boolean RtcSettingsValid()
|
||||
{
|
||||
return (RTC_MEM_VALID == rtcMem.valid);
|
||||
return (RTC_MEM_VALID == RtcSettings.valid);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_THEO
|
||||
void RTC_Dump()
|
||||
void RtcSettingsDump()
|
||||
{
|
||||
#define CFG_COLS 16
|
||||
|
||||
|
@ -91,7 +91,7 @@ void RTC_Dump()
|
|||
uint16_t row;
|
||||
uint16_t col;
|
||||
|
||||
uint8_t *buffer = (uint8_t *) &rtcMem;
|
||||
uint8_t *buffer = (uint8_t *) &RtcSettings;
|
||||
maxrow = ((sizeof(RTCMEM)+CFG_COLS)/CFG_COLS);
|
||||
|
||||
for (row = 0; row < maxrow; row++) {
|
||||
|
@ -111,7 +111,7 @@ void RTC_Dump()
|
|||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
||||
addLog(LOG_LEVEL_INFO);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_THEO
|
||||
|
@ -130,21 +130,21 @@ extern "C" uint32_t _SPIFFS_end;
|
|||
#define SPIFFS_END ((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE
|
||||
|
||||
// Version 3.x config
|
||||
#define CFG_LOCATION_3 SPIFFS_END - 4
|
||||
#define SETTINGS_LOCATION_3 SPIFFS_END - 4
|
||||
|
||||
// Version 4.2 config = eeprom area
|
||||
#define CFG_LOCATION SPIFFS_END // No need for SPIFFS as it uses EEPROM area
|
||||
#define SETTINGS_LOCATION SPIFFS_END // No need for SPIFFS as it uses EEPROM area
|
||||
// Version 5.2 allow for more flash space
|
||||
#define CFG_ROTATES 8 // Number of flash sectors used (handles uploads)
|
||||
|
||||
uint32_t _cfgHash = 0;
|
||||
uint32_t _cfgLocation = CFG_LOCATION;
|
||||
uint32_t settings_hash = 0;
|
||||
uint32_t settings_location = SETTINGS_LOCATION;
|
||||
|
||||
/********************************************************************************************/
|
||||
/*
|
||||
* Based on cores/esp8266/Updater.cpp
|
||||
*/
|
||||
void setFlashModeDout()
|
||||
void SetFlashModeDout()
|
||||
{
|
||||
uint8_t *_buffer;
|
||||
uint32_t address;
|
||||
|
@ -166,10 +166,10 @@ void setFlashModeDout()
|
|||
delete[] _buffer;
|
||||
}
|
||||
|
||||
uint32_t getHash()
|
||||
uint32_t GetSettingsHash()
|
||||
{
|
||||
uint32_t hash = 0;
|
||||
uint8_t *bytes = (uint8_t*)&sysCfg;
|
||||
uint8_t *bytes = (uint8_t*)&Settings;
|
||||
|
||||
for (uint16_t i = 0; i < sizeof(SYSCFG); i++) {
|
||||
hash += bytes[i]*(i+1);
|
||||
|
@ -181,12 +181,12 @@ uint32_t getHash()
|
|||
* Config Save - Save parameters to Flash ONLY if any parameter has changed
|
||||
\*********************************************************************************************/
|
||||
|
||||
uint32_t CFG_Address()
|
||||
uint32_t GetSettingsAddress()
|
||||
{
|
||||
return _cfgLocation * SPI_FLASH_SEC_SIZE;
|
||||
return settings_location * SPI_FLASH_SEC_SIZE;
|
||||
}
|
||||
|
||||
void CFG_Save(byte rotate)
|
||||
void SettingsSave(byte rotate)
|
||||
{
|
||||
/* Save configuration in eeprom or one of 7 slots below
|
||||
*
|
||||
|
@ -197,90 +197,90 @@ void CFG_Save(byte rotate)
|
|||
* stop_flash_rotate 1 = Allow only eeprom flash slot use (SetOption12 1)
|
||||
*/
|
||||
#ifndef BE_MINIMAL
|
||||
if ((getHash() != _cfgHash) || rotate) {
|
||||
if ((GetSettingsHash() != settings_hash) || rotate) {
|
||||
if (1 == rotate) { // Use eeprom flash slot only and disable flash rotate from now on (upgrade)
|
||||
stop_flash_rotate = 1;
|
||||
}
|
||||
if (2 == rotate) { // Use eeprom flash slot and erase next flash slots if stop_flash_rotate is off (default)
|
||||
_cfgLocation = CFG_LOCATION +1;
|
||||
settings_location = SETTINGS_LOCATION +1;
|
||||
}
|
||||
if (stop_flash_rotate) {
|
||||
_cfgLocation = CFG_LOCATION;
|
||||
settings_location = SETTINGS_LOCATION;
|
||||
} else {
|
||||
_cfgLocation--;
|
||||
if (_cfgLocation <= (CFG_LOCATION - CFG_ROTATES)) {
|
||||
_cfgLocation = CFG_LOCATION;
|
||||
settings_location--;
|
||||
if (settings_location <= (SETTINGS_LOCATION - CFG_ROTATES)) {
|
||||
settings_location = SETTINGS_LOCATION;
|
||||
}
|
||||
}
|
||||
sysCfg.saveFlag++;
|
||||
Settings.save_flag++;
|
||||
noInterrupts();
|
||||
spi_flash_erase_sector(_cfgLocation);
|
||||
spi_flash_write(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
spi_flash_erase_sector(settings_location);
|
||||
spi_flash_write(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
||||
interrupts();
|
||||
if (!stop_flash_rotate && rotate) {
|
||||
for (byte i = 1; i < CFG_ROTATES; i++) {
|
||||
noInterrupts();
|
||||
spi_flash_erase_sector(_cfgLocation -i); // Delete previous configurations by resetting to 0xFF
|
||||
spi_flash_erase_sector(settings_location -i); // Delete previous configurations by resetting to 0xFF
|
||||
interrupts();
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_CONFIG D_SAVED_TO_FLASH_AT " %X, " D_COUNT " %d, " D_BYTES " %d"),
|
||||
_cfgLocation, sysCfg.saveFlag, sizeof(SYSCFG));
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
_cfgHash = getHash();
|
||||
settings_location, Settings.save_flag, sizeof(SYSCFG));
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
settings_hash = GetSettingsHash();
|
||||
}
|
||||
#endif // BE_MINIMAL
|
||||
RTC_Save();
|
||||
RtcSettingsSave();
|
||||
}
|
||||
|
||||
void CFG_Load()
|
||||
void SettingsLoad()
|
||||
{
|
||||
/* Load configuration from eeprom or one of 7 slots below if first load does not stop_flash_rotate
|
||||
*/
|
||||
struct SYSCFGH {
|
||||
unsigned long cfg_holder;
|
||||
unsigned long saveFlag;
|
||||
} _sysCfgH;
|
||||
unsigned long save_flag;
|
||||
} _SettingsH;
|
||||
|
||||
_cfgLocation = CFG_LOCATION +1;
|
||||
settings_location = SETTINGS_LOCATION +1;
|
||||
for (byte i = 0; i < CFG_ROTATES; i++) {
|
||||
_cfgLocation--;
|
||||
settings_location--;
|
||||
noInterrupts();
|
||||
spi_flash_read(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
spi_flash_read((_cfgLocation -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
||||
spi_flash_read(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
||||
spi_flash_read((settings_location -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_SettingsH, sizeof(SYSCFGH));
|
||||
interrupts();
|
||||
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("Cnfg: Check at %X with count %d and holder %X"), _cfgLocation -1, _sysCfgH.saveFlag, _sysCfgH.cfg_holder);
|
||||
// addLog(LOG_LEVEL_DEBUG);
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("Cnfg: Check at %X with count %d and holder %X"), settings_location -1, _SettingsH.save_flag, _SettingsH.cfg_holder);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
if (((sysCfg.version > 0x05000200) && sysCfg.flag.stop_flash_rotate) || (sysCfg.cfg_holder != _sysCfgH.cfg_holder) || (sysCfg.saveFlag > _sysCfgH.saveFlag)) {
|
||||
if (((Settings.version > 0x05000200) && Settings.flag.stop_flash_rotate) || (Settings.cfg_holder != _SettingsH.cfg_holder) || (Settings.save_flag > _SettingsH.save_flag)) {
|
||||
break;
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %d"),
|
||||
_cfgLocation, sysCfg.saveFlag);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
if (sysCfg.cfg_holder != CFG_HOLDER) {
|
||||
settings_location, Settings.save_flag);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
if (Settings.cfg_holder != CFG_HOLDER) {
|
||||
// Auto upgrade
|
||||
noInterrupts();
|
||||
spi_flash_read((CFG_LOCATION_3) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
||||
if (sysCfg.saveFlag < _sysCfgH.saveFlag)
|
||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
||||
spi_flash_read((SETTINGS_LOCATION_3) * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
||||
spi_flash_read((SETTINGS_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_SettingsH, sizeof(SYSCFGH));
|
||||
if (Settings.save_flag < _SettingsH.save_flag)
|
||||
spi_flash_read((SETTINGS_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
||||
interrupts();
|
||||
if ((sysCfg.cfg_holder != CFG_HOLDER) || (sysCfg.version >= 0x04020000)) {
|
||||
CFG_Default();
|
||||
if ((Settings.cfg_holder != CFG_HOLDER) || (Settings.version >= 0x04020000)) {
|
||||
SettingsDefault();
|
||||
}
|
||||
}
|
||||
|
||||
_cfgHash = getHash();
|
||||
settings_hash = GetSettingsHash();
|
||||
|
||||
RTC_Load();
|
||||
RtcSettingsLoad();
|
||||
}
|
||||
|
||||
void CFG_Erase()
|
||||
void SettingsErase()
|
||||
{
|
||||
SpiFlashOpResult result;
|
||||
|
||||
|
@ -289,7 +289,7 @@ void CFG_Erase()
|
|||
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION D_ERASE " %d " D_UNIT_SECTORS), _sectorEnd - _sectorStart);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
|
||||
noInterrupts();
|
||||
|
@ -305,11 +305,11 @@ void CFG_Erase()
|
|||
}
|
||||
delay(10);
|
||||
}
|
||||
osw_loop();
|
||||
OsWatchLoop();
|
||||
}
|
||||
}
|
||||
|
||||
void CFG_Dump(char* parms)
|
||||
void SettingsDump(char* parms)
|
||||
{
|
||||
#define CFG_COLS 16
|
||||
|
||||
|
@ -319,14 +319,14 @@ void CFG_Dump(char* parms)
|
|||
uint16_t col;
|
||||
char *p;
|
||||
|
||||
uint8_t *buffer = (uint8_t *) &sysCfg;
|
||||
uint8_t *buffer = (uint8_t *) &Settings;
|
||||
maxrow = ((sizeof(SYSCFG)+CFG_COLS)/CFG_COLS);
|
||||
|
||||
uint16_t srow = strtol(parms, &p, 16) / CFG_COLS;
|
||||
uint16_t mrow = strtol(p, &p, 10);
|
||||
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("Cnfg: Parms %s, Start row %d, rows %d"), parms, srow, mrow);
|
||||
// addLog(LOG_LEVEL_DEBUG);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
if (0 == mrow) { // Default only 8 lines
|
||||
mrow = 8;
|
||||
|
@ -355,399 +355,403 @@ void CFG_Dump(char* parms)
|
|||
snprintf_P(log_data, sizeof(log_data), PSTR("%s%c"), log_data, ((buffer[idx + col] > 0x20) && (buffer[idx + col] < 0x7F)) ? (char)buffer[idx + col] : ' ');
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
||||
addLog(LOG_LEVEL_INFO);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
delay(1);
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void CFG_Default()
|
||||
void SettingsDefault()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_USE_DEFAULTS));
|
||||
CFG_DefaultSet1();
|
||||
CFG_DefaultSet2();
|
||||
CFG_Save(2);
|
||||
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_USE_DEFAULTS));
|
||||
SettingsDefaultSet1();
|
||||
SettingsDefaultSet2();
|
||||
SettingsSave(2);
|
||||
}
|
||||
|
||||
void CFG_DefaultSet1()
|
||||
void SettingsDefaultSet1()
|
||||
{
|
||||
memset(&sysCfg, 0x00, sizeof(SYSCFG));
|
||||
memset(&Settings, 0x00, sizeof(SYSCFG));
|
||||
|
||||
sysCfg.cfg_holder = CFG_HOLDER;
|
||||
// sysCfg.saveFlag = 0;
|
||||
sysCfg.version = VERSION;
|
||||
// sysCfg.bootcount = 0;
|
||||
Settings.cfg_holder = CFG_HOLDER;
|
||||
// Settings.save_flag = 0;
|
||||
Settings.version = VERSION;
|
||||
// Settings.bootcount = 0;
|
||||
}
|
||||
|
||||
void CFG_DefaultSet2()
|
||||
void SettingsDefaultSet2()
|
||||
{
|
||||
memset((char*)&sysCfg +16, 0x00, sizeof(SYSCFG) -16);
|
||||
memset((char*)&Settings +16, 0x00, sizeof(SYSCFG) -16);
|
||||
|
||||
sysCfg.flag.savestate = SAVE_STATE;
|
||||
//sysCfg.flag.button_restrict = 0;
|
||||
//sysCfg.flag.value_units = 0;
|
||||
sysCfg.flag.mqtt_enabled = MQTT_USE;
|
||||
//sysCfg.flag.mqtt_response = 0;
|
||||
sysCfg.flag.mqtt_power_retain = MQTT_POWER_RETAIN;
|
||||
sysCfg.flag.mqtt_button_retain = MQTT_BUTTON_RETAIN;
|
||||
sysCfg.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
||||
Settings.flag.save_state = SAVE_STATE;
|
||||
//Settings.flag.button_restrict = 0;
|
||||
//Settings.flag.value_units = 0;
|
||||
Settings.flag.mqtt_enabled = MQTT_USE;
|
||||
//Settings.flag.mqtt_response = 0;
|
||||
Settings.flag.mqtt_power_retain = MQTT_POWER_RETAIN;
|
||||
Settings.flag.mqtt_button_retain = MQTT_BUTTON_RETAIN;
|
||||
Settings.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
||||
|
||||
sysCfg.flag.emulation = EMULATION;
|
||||
Settings.flag.emulation = EMULATION;
|
||||
|
||||
sysCfg.savedata = SAVE_DATA;
|
||||
sysCfg.timezone = APP_TIMEZONE;
|
||||
strlcpy(sysCfg.otaUrl, OTA_URL, sizeof(sysCfg.otaUrl));
|
||||
Settings.save_data = SAVE_DATA;
|
||||
Settings.timezone = APP_TIMEZONE;
|
||||
strlcpy(Settings.ota_url, OTA_URL, sizeof(Settings.ota_url));
|
||||
|
||||
sysCfg.seriallog_level = SERIAL_LOG_LEVEL;
|
||||
// sysCfg.sta_active = 0;
|
||||
strlcpy(sysCfg.sta_ssid[0], STA_SSID1, sizeof(sysCfg.sta_ssid[0]));
|
||||
strlcpy(sysCfg.sta_pwd[0], STA_PASS1, sizeof(sysCfg.sta_pwd[0]));
|
||||
strlcpy(sysCfg.sta_ssid[1], STA_SSID2, sizeof(sysCfg.sta_ssid[1]));
|
||||
strlcpy(sysCfg.sta_pwd[1], STA_PASS2, sizeof(sysCfg.sta_pwd[1]));
|
||||
strlcpy(sysCfg.hostname, WIFI_HOSTNAME, sizeof(sysCfg.hostname));
|
||||
sysCfg.sta_config = WIFI_CONFIG_TOOL;
|
||||
strlcpy(sysCfg.syslog_host, SYS_LOG_HOST, sizeof(sysCfg.syslog_host));
|
||||
sysCfg.syslog_port = SYS_LOG_PORT;
|
||||
sysCfg.syslog_level = SYS_LOG_LEVEL;
|
||||
sysCfg.webserver = WEB_SERVER;
|
||||
sysCfg.weblog_level = WEB_LOG_LEVEL;
|
||||
Settings.seriallog_level = SERIAL_LOG_LEVEL;
|
||||
// Settings.sta_active = 0;
|
||||
strlcpy(Settings.sta_ssid[0], STA_SSID1, sizeof(Settings.sta_ssid[0]));
|
||||
strlcpy(Settings.sta_pwd[0], STA_PASS1, sizeof(Settings.sta_pwd[0]));
|
||||
strlcpy(Settings.sta_ssid[1], STA_SSID2, sizeof(Settings.sta_ssid[1]));
|
||||
strlcpy(Settings.sta_pwd[1], STA_PASS2, sizeof(Settings.sta_pwd[1]));
|
||||
strlcpy(Settings.hostname, WIFI_HOSTNAME, sizeof(Settings.hostname));
|
||||
Settings.sta_config = WIFI_CONFIG_TOOL;
|
||||
strlcpy(Settings.syslog_host, SYS_LOG_HOST, sizeof(Settings.syslog_host));
|
||||
Settings.syslog_port = SYS_LOG_PORT;
|
||||
Settings.syslog_level = SYS_LOG_LEVEL;
|
||||
Settings.webserver = WEB_SERVER;
|
||||
Settings.weblog_level = WEB_LOG_LEVEL;
|
||||
|
||||
strlcpy(sysCfg.mqtt_fingerprint, MQTT_FINGERPRINT, sizeof(sysCfg.mqtt_fingerprint));
|
||||
strlcpy(sysCfg.mqtt_host, MQTT_HOST, sizeof(sysCfg.mqtt_host));
|
||||
sysCfg.mqtt_port = MQTT_PORT;
|
||||
strlcpy(sysCfg.mqtt_client, MQTT_CLIENT_ID, sizeof(sysCfg.mqtt_client));
|
||||
strlcpy(sysCfg.mqtt_user, MQTT_USER, sizeof(sysCfg.mqtt_user));
|
||||
strlcpy(sysCfg.mqtt_pwd, MQTT_PASS, sizeof(sysCfg.mqtt_pwd));
|
||||
strlcpy(sysCfg.mqtt_topic, MQTT_TOPIC, sizeof(sysCfg.mqtt_topic));
|
||||
strlcpy(sysCfg.button_topic, "0", sizeof(sysCfg.button_topic));
|
||||
strlcpy(sysCfg.mqtt_grptopic, MQTT_GRPTOPIC, sizeof(sysCfg.mqtt_grptopic));
|
||||
sysCfg.tele_period = TELE_PERIOD;
|
||||
strlcpy(Settings.mqtt_fingerprint, MQTT_FINGERPRINT, sizeof(Settings.mqtt_fingerprint));
|
||||
strlcpy(Settings.mqtt_host, MQTT_HOST, sizeof(Settings.mqtt_host));
|
||||
Settings.mqtt_port = MQTT_PORT;
|
||||
strlcpy(Settings.mqtt_client, MQTT_CLIENT_ID, sizeof(Settings.mqtt_client));
|
||||
strlcpy(Settings.mqtt_user, MQTT_USER, sizeof(Settings.mqtt_user));
|
||||
strlcpy(Settings.mqtt_pwd, MQTT_PASS, sizeof(Settings.mqtt_pwd));
|
||||
strlcpy(Settings.mqtt_topic, MQTT_TOPIC, sizeof(Settings.mqtt_topic));
|
||||
strlcpy(Settings.button_topic, "0", sizeof(Settings.button_topic));
|
||||
strlcpy(Settings.mqtt_grptopic, MQTT_GRPTOPIC, sizeof(Settings.mqtt_grptopic));
|
||||
Settings.tele_period = TELE_PERIOD;
|
||||
|
||||
sysCfg.power = APP_POWER;
|
||||
sysCfg.poweronstate = APP_POWERON_STATE;
|
||||
sysCfg.ledstate = APP_LEDSTATE;
|
||||
sysCfg.blinktime = APP_BLINKTIME;
|
||||
sysCfg.blinkcount = APP_BLINKCOUNT;
|
||||
sysCfg.sleep = APP_SLEEP;
|
||||
Settings.power = APP_POWER;
|
||||
Settings.poweronstate = APP_POWERON_STATE;
|
||||
Settings.ledstate = APP_LEDSTATE;
|
||||
Settings.blinktime = APP_BLINKTIME;
|
||||
Settings.blinkcount = APP_BLINKCOUNT;
|
||||
Settings.sleep = APP_SLEEP;
|
||||
|
||||
sysCfg.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER;
|
||||
Settings.domoticz_update_timer = DOMOTICZ_UPDATE_TIMER;
|
||||
for (byte i = 0; i < MAX_SWITCHES; i++) {
|
||||
sysCfg.switchmode[i] = SWITCH_MODE;
|
||||
// sysCfg.domoticz_relay_idx[i] = 0;
|
||||
// sysCfg.domoticz_key_idx[i] = 0;
|
||||
// sysCfg.domoticz_switch_idx[i] = 0;
|
||||
Settings.switchmode[i] = SWITCH_MODE;
|
||||
// Settings.domoticz_relay_idx[i] = 0;
|
||||
// Settings.domoticz_key_idx[i] = 0;
|
||||
// Settings.domoticz_switch_idx[i] = 0;
|
||||
}
|
||||
|
||||
sysCfg.hlw_pcal = HLW_PREF_PULSE;
|
||||
sysCfg.hlw_ucal = HLW_UREF_PULSE;
|
||||
sysCfg.hlw_ical = HLW_IREF_PULSE;
|
||||
// sysCfg.hlw_kWhtoday = 0;
|
||||
// sysCfg.hlw_kWhyesterday = 0;
|
||||
// sysCfg.hlw_kWhdoy = 0;
|
||||
// sysCfg.hlw_pmin = 0;
|
||||
// sysCfg.hlw_pmax = 0;
|
||||
// sysCfg.hlw_umin = 0;
|
||||
// sysCfg.hlw_umax = 0;
|
||||
// sysCfg.hlw_imin = 0;
|
||||
// sysCfg.hlw_imax = 0;
|
||||
// sysCfg.hlw_mpl = 0; // MaxPowerLimit
|
||||
sysCfg.hlw_mplh = MAX_POWER_HOLD;
|
||||
sysCfg.hlw_mplw = MAX_POWER_WINDOW;
|
||||
// sysCfg.hlw_mspl = 0; // MaxSafePowerLimit
|
||||
sysCfg.hlw_msplh = SAFE_POWER_HOLD;
|
||||
sysCfg.hlw_msplw = SAFE_POWER_WINDOW;
|
||||
// sysCfg.hlw_mkwh = 0; // MaxEnergy
|
||||
// sysCfg.hlw_mkwhs = 0; // MaxEnergyStart
|
||||
Settings.hlw_power_calibration = HLW_PREF_PULSE;
|
||||
Settings.hlw_voltage_calibration = HLW_UREF_PULSE;
|
||||
Settings.hlw_current_calibration = HLW_IREF_PULSE;
|
||||
// Settings.hlw_kWhtoday = 0;
|
||||
// Settings.hlw_kWhyesterday = 0;
|
||||
// Settings.hlw_kWhdoy = 0;
|
||||
// Settings.hlw_pmin = 0;
|
||||
// Settings.hlw_pmax = 0;
|
||||
// Settings.hlw_umin = 0;
|
||||
// Settings.hlw_umax = 0;
|
||||
// Settings.hlw_imin = 0;
|
||||
// Settings.hlw_imax = 0;
|
||||
// Settings.hlw_mpl = 0; // MaxPowerLimit
|
||||
Settings.hlw_mplh = MAX_POWER_HOLD;
|
||||
Settings.hlw_mplw = MAX_POWER_WINDOW;
|
||||
// Settings.hlw_mspl = 0; // MaxSafePowerLimit
|
||||
Settings.hlw_msplh = SAFE_POWER_HOLD;
|
||||
Settings.hlw_msplw = SAFE_POWER_WINDOW;
|
||||
// Settings.hlw_mkwh = 0; // MaxEnergy
|
||||
// Settings.hlw_mkwhs = 0; // MaxEnergyStart
|
||||
|
||||
CFG_DefaultSet_3_2_4();
|
||||
SettingsDefaultSet_3_2_4();
|
||||
|
||||
strlcpy(sysCfg.friendlyname[0], FRIENDLY_NAME, sizeof(sysCfg.friendlyname[0]));
|
||||
strlcpy(sysCfg.friendlyname[1], FRIENDLY_NAME"2", sizeof(sysCfg.friendlyname[1]));
|
||||
strlcpy(sysCfg.friendlyname[2], FRIENDLY_NAME"3", sizeof(sysCfg.friendlyname[2]));
|
||||
strlcpy(sysCfg.friendlyname[3], FRIENDLY_NAME"4", sizeof(sysCfg.friendlyname[3]));
|
||||
strlcpy(Settings.friendlyname[0], FRIENDLY_NAME, sizeof(Settings.friendlyname[0]));
|
||||
strlcpy(Settings.friendlyname[1], FRIENDLY_NAME"2", sizeof(Settings.friendlyname[1]));
|
||||
strlcpy(Settings.friendlyname[2], FRIENDLY_NAME"3", sizeof(Settings.friendlyname[2]));
|
||||
strlcpy(Settings.friendlyname[3], FRIENDLY_NAME"4", sizeof(Settings.friendlyname[3]));
|
||||
|
||||
CFG_DefaultSet_3_9_3();
|
||||
SettingsDefaultSet_3_9_3();
|
||||
|
||||
strlcpy(sysCfg.switch_topic, "0", sizeof(sysCfg.switch_topic));
|
||||
strlcpy(Settings.switch_topic, "0", sizeof(Settings.switch_topic));
|
||||
|
||||
strlcpy(sysCfg.web_password, WEB_PASSWORD, sizeof(sysCfg.web_password));
|
||||
strlcpy(Settings.web_password, WEB_PASSWORD, sizeof(Settings.web_password));
|
||||
|
||||
CFG_DefaultSet_4_0_4();
|
||||
sysCfg.pulsetime[0] = APP_PULSETIME;
|
||||
SettingsDefaultSet_4_0_4();
|
||||
Settings.pulse_timer[0] = APP_PULSETIME;
|
||||
|
||||
// 4.0.7
|
||||
// for (byte i = 0; i < MAX_PWMS; i++) sysCfg.pwmvalue[i] = 0;
|
||||
// for (byte i = 0; i < MAX_PWMS; i++) Settings.pwm_value[i] = 0;
|
||||
|
||||
// 4.0.9
|
||||
CFG_DefaultSet_4_0_9();
|
||||
SettingsDefaultSet_4_0_9();
|
||||
|
||||
// 4.1.1 + 5.1.6
|
||||
CFG_DefaultSet_4_1_1();
|
||||
SettingsDefaultSet_4_1_1();
|
||||
|
||||
// 5.0.2
|
||||
CFG_DefaultSet_5_0_2();
|
||||
SettingsDefaultSet_5_0_2();
|
||||
|
||||
// 5.0.4
|
||||
// sysCfg.hlw_kWhtotal = 0;
|
||||
rtcMem.hlw_kWhtotal = 0;
|
||||
// Settings.hlw_kWhtotal = 0;
|
||||
RtcSettings.hlw_kWhtotal = 0;
|
||||
|
||||
// 5.0.5
|
||||
strlcpy(sysCfg.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(sysCfg.mqtt_fulltopic));
|
||||
strlcpy(Settings.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(Settings.mqtt_fulltopic));
|
||||
|
||||
// 5.0.6
|
||||
sysCfg.mqtt_retry = MQTT_RETRY_SECS;
|
||||
Settings.mqtt_retry = MQTT_RETRY_SECS;
|
||||
|
||||
// 5.1.7
|
||||
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||
Settings.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||
|
||||
// 5.2.0
|
||||
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||
Settings.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||
|
||||
// 5.4.1
|
||||
memcpy_P(sysCfg.sfb_code[0], sfb_codeDefault, 9);
|
||||
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
|
||||
|
||||
// 5.8.0
|
||||
sysCfg.led_pixels = WS2812_LEDS;
|
||||
Settings.led_pixels = WS2812_LEDS;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void CFG_DefaultSet_3_2_4()
|
||||
void SettingsDefaultSet_3_2_4()
|
||||
{
|
||||
sysCfg.ws_pixels = WS2812_LEDS;
|
||||
sysCfg.ws_red = 255;
|
||||
sysCfg.ws_green = 0;
|
||||
sysCfg.ws_blue = 0;
|
||||
sysCfg.ws_ledtable = 0;
|
||||
sysCfg.ws_dimmer = 8;
|
||||
sysCfg.ws_fade = 0;
|
||||
sysCfg.ws_speed = 1;
|
||||
sysCfg.ws_scheme = 0;
|
||||
sysCfg.ws_width = 1;
|
||||
sysCfg.ws_wakeup = 0;
|
||||
Settings.ws_pixels = WS2812_LEDS;
|
||||
Settings.ws_red = 255;
|
||||
Settings.ws_green = 0;
|
||||
Settings.ws_blue = 0;
|
||||
Settings.ws_ledtable = 0;
|
||||
Settings.ws_dimmer = 8;
|
||||
Settings.ws_fade = 0;
|
||||
Settings.ws_speed = 1;
|
||||
Settings.ws_scheme = 0;
|
||||
Settings.ws_width = 1;
|
||||
Settings.ws_wakeup = 0;
|
||||
}
|
||||
|
||||
void CFG_DefaultSet_3_9_3()
|
||||
void SettingsDefaultSet_3_9_3()
|
||||
{
|
||||
for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
||||
sysCfg.domoticz_switch_idx[i] = 0;
|
||||
Settings.domoticz_switch_idx[i] = 0;
|
||||
}
|
||||
for (byte i = 0; i < 12; i++) {
|
||||
sysCfg.domoticz_sensor_idx[i] = 0;
|
||||
Settings.domoticz_sensor_idx[i] = 0;
|
||||
}
|
||||
|
||||
sysCfg.module = MODULE;
|
||||
Settings.module = MODULE;
|
||||
for (byte i = 0; i < MAX_GPIO_PIN; i++){
|
||||
sysCfg.my_gp.io[i] = 0;
|
||||
Settings.my_gp.io[i] = 0;
|
||||
}
|
||||
|
||||
sysCfg.led_pixels = WS2812_LEDS;
|
||||
Settings.led_pixels = WS2812_LEDS;
|
||||
for (byte i = 0; i < MAX_PWMS; i++) {
|
||||
sysCfg.led_color[i] = 255;
|
||||
Settings.led_color[i] = 255;
|
||||
}
|
||||
sysCfg.led_table = 0;
|
||||
sysCfg.led_dimmer = 10;
|
||||
sysCfg.led_fade = 0;
|
||||
sysCfg.led_speed = 1;
|
||||
sysCfg.led_scheme = 0;
|
||||
sysCfg.led_width = 1;
|
||||
sysCfg.led_wakeup = 0;
|
||||
Settings.led_table = 0;
|
||||
Settings.led_dimmer = 10;
|
||||
Settings.led_fade = 0;
|
||||
Settings.led_speed = 1;
|
||||
Settings.led_scheme = 0;
|
||||
Settings.led_width = 1;
|
||||
Settings.led_wakeup = 0;
|
||||
}
|
||||
|
||||
void CFG_DefaultSet_4_0_4()
|
||||
void SettingsDefaultSet_4_0_4()
|
||||
{
|
||||
strlcpy(sysCfg.ntp_server[0], NTP_SERVER1, sizeof(sysCfg.ntp_server[0]));
|
||||
strlcpy(sysCfg.ntp_server[1], NTP_SERVER2, sizeof(sysCfg.ntp_server[1]));
|
||||
strlcpy(sysCfg.ntp_server[2], NTP_SERVER3, sizeof(sysCfg.ntp_server[2]));
|
||||
strlcpy(Settings.ntp_server[0], NTP_SERVER1, sizeof(Settings.ntp_server[0]));
|
||||
strlcpy(Settings.ntp_server[1], NTP_SERVER2, sizeof(Settings.ntp_server[1]));
|
||||
strlcpy(Settings.ntp_server[2], NTP_SERVER3, sizeof(Settings.ntp_server[2]));
|
||||
for (byte j = 0; j < 3; j++) {
|
||||
for (byte i = 0; i < strlen(sysCfg.ntp_server[j]); i++) {
|
||||
if (sysCfg.ntp_server[j][i] == ',') {
|
||||
sysCfg.ntp_server[j][i] = '.';
|
||||
for (byte i = 0; i < strlen(Settings.ntp_server[j]); i++) {
|
||||
if (Settings.ntp_server[j][i] == ',') {
|
||||
Settings.ntp_server[j][i] = '.';
|
||||
}
|
||||
}
|
||||
}
|
||||
sysCfg.pulsetime[0] = APP_PULSETIME;
|
||||
Settings.pulse_timer[0] = APP_PULSETIME;
|
||||
for (byte i = 1; i < MAX_PULSETIMERS; i++) {
|
||||
sysCfg.pulsetime[i] = 0;
|
||||
Settings.pulse_timer[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void CFG_DefaultSet_4_0_9()
|
||||
void SettingsDefaultSet_4_0_9()
|
||||
{
|
||||
strlcpy(sysCfg.mqtt_prefix[0], SUB_PREFIX, sizeof(sysCfg.mqtt_prefix[0]));
|
||||
strlcpy(sysCfg.mqtt_prefix[1], PUB_PREFIX, sizeof(sysCfg.mqtt_prefix[1]));
|
||||
strlcpy(sysCfg.mqtt_prefix[2], PUB_PREFIX2, sizeof(sysCfg.mqtt_prefix[2]));
|
||||
parseIP(&sysCfg.ip_address[0], WIFI_IP_ADDRESS);
|
||||
parseIP(&sysCfg.ip_address[1], WIFI_GATEWAY);
|
||||
parseIP(&sysCfg.ip_address[2], WIFI_SUBNETMASK);
|
||||
parseIP(&sysCfg.ip_address[3], WIFI_DNS);
|
||||
strlcpy(Settings.mqtt_prefix[0], SUB_PREFIX, sizeof(Settings.mqtt_prefix[0]));
|
||||
strlcpy(Settings.mqtt_prefix[1], PUB_PREFIX, sizeof(Settings.mqtt_prefix[1]));
|
||||
strlcpy(Settings.mqtt_prefix[2], PUB_PREFIX2, sizeof(Settings.mqtt_prefix[2]));
|
||||
ParseIp(&Settings.ip_address[0], WIFI_IP_ADDRESS);
|
||||
ParseIp(&Settings.ip_address[1], WIFI_GATEWAY);
|
||||
ParseIp(&Settings.ip_address[2], WIFI_SUBNETMASK);
|
||||
ParseIp(&Settings.ip_address[3], WIFI_DNS);
|
||||
}
|
||||
|
||||
void CFG_DefaultSet_4_1_1()
|
||||
void SettingsDefaultSet_4_1_1()
|
||||
{
|
||||
strlcpy(sysCfg.state_text[0], MQTT_STATUS_OFF, sizeof(sysCfg.state_text[0]));
|
||||
strlcpy(sysCfg.state_text[1], MQTT_STATUS_ON, sizeof(sysCfg.state_text[1]));
|
||||
strlcpy(sysCfg.state_text[2], MQTT_CMND_TOGGLE, sizeof(sysCfg.state_text[2]));
|
||||
strlcpy(sysCfg.state_text[3], MQTT_CMND_HOLD, sizeof(sysCfg.state_text[3])); // v5.1.6
|
||||
strlcpy(Settings.state_text[0], MQTT_STATUS_OFF, sizeof(Settings.state_text[0]));
|
||||
strlcpy(Settings.state_text[1], MQTT_STATUS_ON, sizeof(Settings.state_text[1]));
|
||||
strlcpy(Settings.state_text[2], MQTT_CMND_TOGGLE, sizeof(Settings.state_text[2]));
|
||||
strlcpy(Settings.state_text[3], MQTT_CMND_HOLD, sizeof(Settings.state_text[3])); // v5.1.6
|
||||
}
|
||||
|
||||
void CFG_DefaultSet_5_0_2()
|
||||
void SettingsDefaultSet_5_0_2()
|
||||
{
|
||||
sysCfg.flag.temperature_conversion = TEMP_CONVERSION;
|
||||
sysCfg.flag.temperature_resolution = TEMP_RESOLUTION;
|
||||
sysCfg.flag.humidity_resolution = HUMIDITY_RESOLUTION;
|
||||
sysCfg.flag.pressure_resolution = PRESSURE_RESOLUTION;
|
||||
sysCfg.flag.energy_resolution = ENERGY_RESOLUTION;
|
||||
Settings.flag.temperature_conversion = TEMP_CONVERSION;
|
||||
Settings.flag.temperature_resolution = TEMP_RESOLUTION;
|
||||
Settings.flag.humidity_resolution = HUMIDITY_RESOLUTION;
|
||||
Settings.flag.pressure_resolution = PRESSURE_RESOLUTION;
|
||||
Settings.flag.energy_resolution = ENERGY_RESOLUTION;
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void CFG_Delta()
|
||||
void SettingsDelta()
|
||||
{
|
||||
if (sysCfg.version != VERSION) { // Fix version dependent changes
|
||||
if (sysCfg.version < 0x03010200) { // 3.1.2 - Add parameter
|
||||
sysCfg.poweronstate = APP_POWERON_STATE;
|
||||
if (Settings.version != VERSION) { // Fix version dependent changes
|
||||
if (Settings.version < 0x03010200) { // 3.1.2 - Add parameter
|
||||
Settings.poweronstate = APP_POWERON_STATE;
|
||||
}
|
||||
if (sysCfg.version < 0x03010600) { // 3.1.6 - Add parameter
|
||||
sysCfg.blinktime = APP_BLINKTIME;
|
||||
sysCfg.blinkcount = APP_BLINKCOUNT;
|
||||
if (Settings.version < 0x03010600) { // 3.1.6 - Add parameter
|
||||
Settings.blinktime = APP_BLINKTIME;
|
||||
Settings.blinkcount = APP_BLINKCOUNT;
|
||||
}
|
||||
if (sysCfg.version < 0x03020400) { // 3.2.4 - Add parameter
|
||||
CFG_DefaultSet_3_2_4();
|
||||
if (Settings.version < 0x03020400) { // 3.2.4 - Add parameter
|
||||
SettingsDefaultSet_3_2_4();
|
||||
}
|
||||
if (sysCfg.version < 0x03020500) { // 3.2.5 - Add parameter
|
||||
getClient(sysCfg.friendlyname[0], sysCfg.mqtt_client, sizeof(sysCfg.friendlyname[0]));
|
||||
strlcpy(sysCfg.friendlyname[1], FRIENDLY_NAME"2", sizeof(sysCfg.friendlyname[1]));
|
||||
strlcpy(sysCfg.friendlyname[2], FRIENDLY_NAME"3", sizeof(sysCfg.friendlyname[2]));
|
||||
strlcpy(sysCfg.friendlyname[3], FRIENDLY_NAME"4", sizeof(sysCfg.friendlyname[3]));
|
||||
if (Settings.version < 0x03020500) { // 3.2.5 - Add parameter
|
||||
GetMqttClient(Settings.friendlyname[0], Settings.mqtt_client, sizeof(Settings.friendlyname[0]));
|
||||
strlcpy(Settings.friendlyname[1], FRIENDLY_NAME"2", sizeof(Settings.friendlyname[1]));
|
||||
strlcpy(Settings.friendlyname[2], FRIENDLY_NAME"3", sizeof(Settings.friendlyname[2]));
|
||||
strlcpy(Settings.friendlyname[3], FRIENDLY_NAME"4", sizeof(Settings.friendlyname[3]));
|
||||
}
|
||||
if (sysCfg.version < 0x03020800) { // 3.2.8 - Add parameter
|
||||
strlcpy(sysCfg.switch_topic, sysCfg.button_topic, sizeof(sysCfg.switch_topic));
|
||||
if (Settings.version < 0x03020800) { // 3.2.8 - Add parameter
|
||||
strlcpy(Settings.switch_topic, Settings.button_topic, sizeof(Settings.switch_topic));
|
||||
}
|
||||
if (sysCfg.version < 0x03020C00) { // 3.2.12 - Add parameter
|
||||
sysCfg.sleep = APP_SLEEP;
|
||||
if (Settings.version < 0x03020C00) { // 3.2.12 - Add parameter
|
||||
Settings.sleep = APP_SLEEP;
|
||||
}
|
||||
if (sysCfg.version < 0x03090300) { // 3.9.2d - Add parameter
|
||||
CFG_DefaultSet_3_9_3();
|
||||
if (Settings.version < 0x03090300) { // 3.9.2d - Add parameter
|
||||
SettingsDefaultSet_3_9_3();
|
||||
}
|
||||
if (sysCfg.version < 0x03091400) {
|
||||
strlcpy(sysCfg.web_password, WEB_PASSWORD, sizeof(sysCfg.web_password));
|
||||
if (Settings.version < 0x03091400) {
|
||||
strlcpy(Settings.web_password, WEB_PASSWORD, sizeof(Settings.web_password));
|
||||
}
|
||||
if (sysCfg.version < 0x03091500) {
|
||||
if (Settings.version < 0x03091500) {
|
||||
for (byte i = 0; i < MAX_SWITCHES; i++) {
|
||||
sysCfg.switchmode[i] = SWITCH_MODE;
|
||||
Settings.switchmode[i] = SWITCH_MODE;
|
||||
}
|
||||
}
|
||||
if (sysCfg.version < 0x04000400) {
|
||||
CFG_DefaultSet_4_0_4();
|
||||
if (Settings.version < 0x04000400) {
|
||||
SettingsDefaultSet_4_0_4();
|
||||
}
|
||||
if (sysCfg.version < 0x04000500) {
|
||||
memmove(sysCfg.my_gp.io, sysCfg.my_gp.io +1, MAX_GPIO_PIN -1); // move myio 1 byte to front
|
||||
sysCfg.my_gp.io[MAX_GPIO_PIN -1] = 0; // Clear ADC0
|
||||
if (Settings.version < 0x04000500) {
|
||||
memmove(Settings.my_gp.io, Settings.my_gp.io +1, MAX_GPIO_PIN -1); // move myio 1 byte to front
|
||||
Settings.my_gp.io[MAX_GPIO_PIN -1] = 0; // Clear ADC0
|
||||
}
|
||||
if (sysCfg.version < 0x04000700) {
|
||||
if (Settings.version < 0x04000700) {
|
||||
for (byte i = 0; i < MAX_PWMS; i++) {
|
||||
sysCfg.pwmvalue[i] = 0;
|
||||
Settings.pwm_value[i] = 0;
|
||||
}
|
||||
}
|
||||
if (sysCfg.version < 0x04000804) {
|
||||
CFG_DefaultSet_4_0_9();
|
||||
if (Settings.version < 0x04000804) {
|
||||
SettingsDefaultSet_4_0_9();
|
||||
}
|
||||
if (sysCfg.version < 0x04010100) {
|
||||
CFG_DefaultSet_4_1_1();
|
||||
if (Settings.version < 0x04010100) {
|
||||
SettingsDefaultSet_4_1_1();
|
||||
}
|
||||
if (sysCfg.version < 0x05000105) {
|
||||
sysCfg.flag = { 0 };
|
||||
sysCfg.flag.savestate = SAVE_STATE;
|
||||
// sysCfg.flag.button_restrict = 0;
|
||||
// sysCfg.flag.value_units = 0;
|
||||
sysCfg.flag.mqtt_enabled = MQTT_USE;
|
||||
// sysCfg.flag.mqtt_response = 0;
|
||||
// sysCfg.flag.mqtt_power_retain = 0;
|
||||
// sysCfg.flag.mqtt_button_retain = 0;
|
||||
sysCfg.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
||||
sysCfg.flag.emulation = EMULATION;
|
||||
if (Settings.version < 0x05000105) {
|
||||
Settings.flag = { 0 };
|
||||
Settings.flag.save_state = SAVE_STATE;
|
||||
// Settings.flag.button_restrict = 0;
|
||||
// Settings.flag.value_units = 0;
|
||||
Settings.flag.mqtt_enabled = MQTT_USE;
|
||||
// Settings.flag.mqtt_response = 0;
|
||||
// Settings.flag.mqtt_power_retain = 0;
|
||||
// Settings.flag.mqtt_button_retain = 0;
|
||||
Settings.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
||||
Settings.flag.emulation = EMULATION;
|
||||
|
||||
CFG_DefaultSet_5_0_2();
|
||||
SettingsDefaultSet_5_0_2();
|
||||
|
||||
sysCfg.savedata = SAVE_DATA;
|
||||
Settings.save_data = SAVE_DATA;
|
||||
}
|
||||
if (sysCfg.version < 0x05000400) {
|
||||
sysCfg.hlw_kWhtotal = 0;
|
||||
rtcMem.hlw_kWhtotal = 0;
|
||||
if (Settings.version < 0x05000400) {
|
||||
Settings.hlw_kWhtotal = 0;
|
||||
RtcSettings.hlw_kWhtotal = 0;
|
||||
}
|
||||
if (sysCfg.version < 0x05000500) {
|
||||
strlcpy(sysCfg.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(sysCfg.mqtt_fulltopic));
|
||||
if (Settings.version < 0x05000500) {
|
||||
strlcpy(Settings.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(Settings.mqtt_fulltopic));
|
||||
}
|
||||
if (sysCfg.version < 0x05000600) {
|
||||
sysCfg.mqtt_retry = MQTT_RETRY_SECS;
|
||||
if (Settings.version < 0x05000600) {
|
||||
Settings.mqtt_retry = MQTT_RETRY_SECS;
|
||||
}
|
||||
if (sysCfg.version < 0x05010100) {
|
||||
sysCfg.pCounterType = 0;
|
||||
sysCfg.pCounterDebounce = 0;
|
||||
if (Settings.version < 0x05010100) {
|
||||
Settings.pulse_counter_type = 0;
|
||||
Settings.pulse_counter_debounce = 0;
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
sysCfg.pCounter[i] = 0;
|
||||
rtcMem.pCounter[i] = 0;
|
||||
Settings.pulse_counter[i] = 0;
|
||||
RtcSettings.pulse_counter[i] = 0;
|
||||
}
|
||||
}
|
||||
if (sysCfg.version < 0x05010600) {
|
||||
CFG_DefaultSet_4_1_1();
|
||||
if (Settings.version < 0x05010600) {
|
||||
SettingsDefaultSet_4_1_1();
|
||||
}
|
||||
if (sysCfg.version < 0x05010700) {
|
||||
sysCfg.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||
if (Settings.version < 0x05010700) {
|
||||
Settings.param[P_HOLD_TIME] = KEY_HOLD_TIME; // Default 4 seconds hold time
|
||||
}
|
||||
if (sysCfg.version < 0x05020000) {
|
||||
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||
if (Settings.version < 0x05020000) {
|
||||
Settings.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||
}
|
||||
if (sysCfg.version < 0x05050000) {
|
||||
if (Settings.version < 0x05050000) {
|
||||
for (byte i = 0; i < 17; i++) {
|
||||
sysCfg.sfb_code[i][0] = 0;
|
||||
Settings.rf_code[i][0] = 0;
|
||||
}
|
||||
memcpy_P(sysCfg.sfb_code[0], sfb_codeDefault, 9);
|
||||
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
|
||||
}
|
||||
if (sysCfg.version < 0x05080000) {
|
||||
if (Settings.version < 0x05080000) {
|
||||
uint8_t cfg_wsflg = 0;
|
||||
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
|
||||
if (GPIO_WS2812 == sysCfg.my_gp.io[i]) {
|
||||
if (GPIO_WS2812 == Settings.my_gp.io[i]) {
|
||||
cfg_wsflg = 1;
|
||||
}
|
||||
}
|
||||
if (!sysCfg.led_pixels && cfg_wsflg) {
|
||||
sysCfg.led_pixels = sysCfg.ws_pixels;
|
||||
sysCfg.led_color[0] = sysCfg.ws_red;
|
||||
sysCfg.led_color[1] = sysCfg.ws_green;
|
||||
sysCfg.led_color[2] = sysCfg.ws_blue;
|
||||
sysCfg.led_dimmer = sysCfg.ws_dimmer;
|
||||
sysCfg.led_table = sysCfg.ws_ledtable;
|
||||
sysCfg.led_fade = sysCfg.ws_fade;
|
||||
sysCfg.led_speed = sysCfg.ws_speed;
|
||||
sysCfg.led_scheme = sysCfg.ws_scheme;
|
||||
sysCfg.led_width = sysCfg.ws_width;
|
||||
sysCfg.led_wakeup = sysCfg.ws_wakeup;
|
||||
if (!Settings.led_pixels && cfg_wsflg) {
|
||||
Settings.led_pixels = Settings.ws_pixels;
|
||||
Settings.led_color[0] = Settings.ws_red;
|
||||
Settings.led_color[1] = Settings.ws_green;
|
||||
Settings.led_color[2] = Settings.ws_blue;
|
||||
Settings.led_dimmer = Settings.ws_dimmer;
|
||||
Settings.led_table = Settings.ws_ledtable;
|
||||
Settings.led_fade = Settings.ws_fade;
|
||||
Settings.led_speed = Settings.ws_speed;
|
||||
Settings.led_scheme = Settings.ws_scheme;
|
||||
Settings.led_width = Settings.ws_width;
|
||||
Settings.led_wakeup = Settings.ws_wakeup;
|
||||
} else {
|
||||
sysCfg.led_pixels = WS2812_LEDS;
|
||||
sysCfg.led_width = 1;
|
||||
Settings.led_pixels = WS2812_LEDS;
|
||||
Settings.led_width = 1;
|
||||
}
|
||||
}
|
||||
if (sysCfg.version < 0x0508000A) {
|
||||
sysCfg.power = sysCfg.ex_power;
|
||||
sysCfg.altitude = 0;
|
||||
if (Settings.version < 0x0508000A) {
|
||||
Settings.power = Settings.ex_power;
|
||||
Settings.altitude = 0;
|
||||
}
|
||||
if (sysCfg.version < 0x0508000B) {
|
||||
if (Settings.version < 0x0508000B) {
|
||||
for (byte i = 0; i < MAX_GPIO_PIN; i++) { // Move GPIO_LEDs
|
||||
if ((sysCfg.my_gp.io[i] >= 25) && (sysCfg.my_gp.io[i] <= 32)) { // Was GPIO_LED1
|
||||
sysCfg.my_gp.io[i] += 23; // Move GPIO_LED1
|
||||
if ((Settings.my_gp.io[i] >= 25) && (Settings.my_gp.io[i] <= 32)) { // Was GPIO_LED1
|
||||
Settings.my_gp.io[i] += 23; // Move GPIO_LED1
|
||||
}
|
||||
}
|
||||
for (byte i = 0; i < MAX_PWMS; i++) { // Move pwmvalue and reset additional pulsetimers
|
||||
sysCfg.pwmvalue[i] = sysCfg.pulsetime[4 +i];
|
||||
sysCfg.pulsetime[4 +i] = 0;
|
||||
for (byte i = 0; i < MAX_PWMS; i++) { // Move pwm_value and reset additional pulse_timerrs
|
||||
Settings.pwm_value[i] = Settings.pulse_timer[4 +i];
|
||||
Settings.pulse_timer[4 +i] = 0;
|
||||
}
|
||||
}
|
||||
if (Settings.version < 0x0508000D) {
|
||||
Settings.pwm_frequency = PWM_FREQ;
|
||||
Settings.pwm_range = PWM_RANGE;
|
||||
}
|
||||
|
||||
sysCfg.version = VERSION;
|
||||
CFG_Save(1);
|
||||
Settings.version = VERSION;
|
||||
SettingsSave(1);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
sonoff.h - Sonoff-Tasmota master header
|
||||
sonoff.h - Master header file for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
|
@ -17,6 +17,9 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SONOFF_H_
|
||||
#define _SONOFF_H_
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Power Type
|
||||
\*********************************************************************************************/
|
||||
|
@ -81,7 +84,7 @@ typedef unsigned long power_t; // Power (Relay) type
|
|||
#else
|
||||
#define MAX_LOG_LINES 20 // Max number of lines in weblog
|
||||
#endif
|
||||
#define MAX_BACKLOG 16 // Max number of commands in backlog (chk blogidx and blogptr code)
|
||||
#define MAX_BACKLOG 16 // Max number of commands in backlog (chk backlog_index and backlog_pointer code)
|
||||
#define MIN_BACKLOG_DELAY 2 // Minimal backlog delay in 0.1 seconds
|
||||
|
||||
#define APP_BAUDRATE 115200 // Default serial baudrate
|
||||
|
@ -91,15 +94,16 @@ typedef unsigned long power_t; // Power (Relay) type
|
|||
* Enumeration
|
||||
\*********************************************************************************************/
|
||||
|
||||
enum week_t {Last, First, Second, Third, Fourth};
|
||||
enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
|
||||
enum month_t {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
|
||||
enum hemis_t {North, South};
|
||||
enum log_t {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL}; // SerialLog, Syslog, Weblog
|
||||
enum wifi_t {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; // WifiConfig
|
||||
enum swtch_t {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION}; // SwitchMode
|
||||
enum led_t {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION}; // LedState
|
||||
enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; // Emulation
|
||||
enum WeekInMonthOptions {Last, First, Second, Third, Fourth};
|
||||
enum DayOfTheWeekOptions {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
|
||||
enum MonthNamesOptions {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
|
||||
enum HemisphereOptions {North, South};
|
||||
enum LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
||||
enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION};
|
||||
enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION};
|
||||
enum LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION};
|
||||
enum EmulationOptions {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX};
|
||||
enum ButtonStates {PRESSED, NOT_PRESSED};
|
||||
enum SettingsParmaIndex {P_HOLD_TIME, P_MAX_POWER_RETRY, P_MAX_PARAM8};
|
||||
|
||||
enum butt_t {PRESSED, NOT_PRESSED};
|
||||
enum opt_t {P_HOLD_TIME, P_MAX_POWER_RETRY, P_MAX_PARAM8}; // Index in sysCfg.param
|
||||
#endif // _SONOFF_H_
|
1870
sonoff/sonoff.ino
1870
sonoff/sonoff.ino
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,102 @@
|
|||
/*
|
||||
sonoff_post.h - Post header file for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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/>.
|
||||
*/
|
||||
|
||||
#ifndef _SONOFF_POST_H_
|
||||
#define _SONOFF_POST_H_
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "user_interface.h"
|
||||
|
||||
// Function prototypes
|
||||
void WifiWpsStatusCallback(wps_cb_status status);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#define USE_DHT // Default DHT11 sensor needs no external library
|
||||
#ifndef USE_DS18x20
|
||||
#define USE_DS18B20 // Default DS18B20 sensor needs no external library
|
||||
#endif
|
||||
//#define DEBUG_THEO // Add debug code
|
||||
|
||||
#ifdef BE_MINIMAL
|
||||
#ifdef USE_MQTT_TLS
|
||||
#undef USE_MQTT_TLS // Disable TLS support won't work as the MQTTHost is not set
|
||||
#endif
|
||||
#ifdef USE_DISCOVERY
|
||||
#undef USE_DISCOVERY // Disable Discovery services for both MQTT and web server
|
||||
#endif
|
||||
#ifdef USE_DOMOTICZ
|
||||
#undef USE_DOMOTICZ // Disable Domoticz
|
||||
#endif
|
||||
//#ifdef USE_WEBSERVER
|
||||
//#undef USE_WEBSERVER // Disable Webserver
|
||||
//#endif
|
||||
#ifdef USE_EMULATION
|
||||
#undef USE_EMULATION // Disable Wemo or Hue emulation
|
||||
#endif
|
||||
#ifdef USE_DS18x20
|
||||
#undef USE_DS18x20 // Disable DS18x20 sensor
|
||||
#endif
|
||||
#ifdef USE_I2C
|
||||
#undef USE_I2C // Disable all I2C sensors and devices
|
||||
#endif
|
||||
#ifdef USE_SPI
|
||||
#undef USE_SPI // Disable all SPI devices
|
||||
#endif
|
||||
#ifdef USE_WS2812
|
||||
#undef USE_WS2812 // Disable WS2812 Led string
|
||||
#endif
|
||||
#ifdef USE_DS18B20
|
||||
#undef USE_DS18B20 // Disable internal DS18B20 sensor
|
||||
#endif
|
||||
#ifdef USE_DHT
|
||||
#undef USE_DHT // Disable internal DHT sensor
|
||||
#endif
|
||||
#ifdef USE_IR_REMOTE
|
||||
#undef USE_IR_REMOTE // Disable IR driver
|
||||
#endif
|
||||
#ifdef DEBUG_THEO
|
||||
#undef DEBUG_THEO // Disable debug code
|
||||
#endif
|
||||
#endif // BE_MINIMAL
|
||||
|
||||
#ifndef SWITCH_MODE
|
||||
#define SWITCH_MODE TOGGLE // TOGGLE, FOLLOW or FOLLOW_INV (the wall switch state)
|
||||
#endif
|
||||
|
||||
#ifndef MQTT_FINGERPRINT
|
||||
#define MQTT_FINGERPRINT "A5 02 FF 13 99 9F 8B 39 8E F1 83 4F 11 23 65 0B 32 36 FC 07"
|
||||
#endif
|
||||
|
||||
#ifndef WS2812_LEDS
|
||||
#define WS2812_LEDS 30 // [Pixels] Number of LEDs
|
||||
#endif
|
||||
|
||||
#ifndef MESSZ
|
||||
#define MESSZ 405 // Max number of characters in JSON message string (4 x DS18x20 sensors)
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif // _SONOFF_POST_H_
|
|
@ -17,8 +17,11 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _SONOFF_TEMPLATE_H_
|
||||
#define _SONOFF_TEMPLATE_H_
|
||||
|
||||
// User selectable GPIO functionality
|
||||
enum upins_t {
|
||||
enum UserSelectablePins {
|
||||
GPIO_NONE, // Not used
|
||||
GPIO_DHT11, // DHT11
|
||||
GPIO_DHT21, // DHT21, AM2301
|
||||
|
@ -78,7 +81,7 @@ enum upins_t {
|
|||
GPIO_SENSOR_END };
|
||||
|
||||
// Text in webpage Module Parameters and commands GPIOS and GPIO
|
||||
const char sensors[GPIO_SENSOR_END][9] PROGMEM = {
|
||||
const char kSensors[GPIO_SENSOR_END][9] PROGMEM = {
|
||||
D_SENSOR_NONE,
|
||||
D_SENSOR_DHT11,
|
||||
D_SENSOR_AM2301,
|
||||
|
@ -138,7 +141,7 @@ const char sensors[GPIO_SENSOR_END][9] PROGMEM = {
|
|||
};
|
||||
|
||||
// Programmer selectable GPIO functionality offset by user selectable GPIOs
|
||||
enum fpins_t {
|
||||
enum ProgramSelectablePins {
|
||||
GPIO_RXD = GPIO_SENSOR_END, // Serial interface
|
||||
GPIO_TXD, // Serial interface
|
||||
GPIO_HLW_SEL, // HLW8012 Sel output (Sonoff Pow)
|
||||
|
@ -153,7 +156,7 @@ enum fpins_t {
|
|||
/********************************************************************************************/
|
||||
|
||||
// Supported hardware modules
|
||||
enum module_t {
|
||||
enum SupportedModules {
|
||||
SONOFF_BASIC,
|
||||
SONOFF_RF,
|
||||
SONOFF_SV,
|
||||
|
@ -206,7 +209,7 @@ typedef struct MYTMPLT {
|
|||
myio gp;
|
||||
} mytmplt;
|
||||
|
||||
const uint8_t nicelist[MAXMODULE] PROGMEM = {
|
||||
const uint8_t kNiceList[MAXMODULE] PROGMEM = {
|
||||
SONOFF_BASIC,
|
||||
SONOFF_RF,
|
||||
SONOFF_TH,
|
||||
|
@ -245,7 +248,7 @@ const uint8_t nicelist[MAXMODULE] PROGMEM = {
|
|||
};
|
||||
|
||||
// Default module settings
|
||||
const mytmplt modules[MAXMODULE] PROGMEM = {
|
||||
const mytmplt kModules[MAXMODULE] PROGMEM = {
|
||||
{ "Sonoff Basic", // Sonoff Basic (ESP8266)
|
||||
GPIO_KEY1, // GPIO00 Button
|
||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
||||
|
@ -714,3 +717,4 @@ const mytmplt modules[MAXMODULE] PROGMEM = {
|
|||
}
|
||||
};
|
||||
|
||||
#endif // _SONOFF_TEMPLATE_H_
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
support.h - parameters used by platformio for Sonoff-Tasmota
|
||||
|
||||
Copyright (C) 2017 Theo Arends
|
||||
|
||||
This program 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.
|
||||
|
||||
This program 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/>.
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef __SUPPORT_H__
|
||||
#define __SUPPORT_H__
|
||||
|
||||
#include "user_interface.h"
|
||||
|
||||
/* Function prototypes. */
|
||||
void WIFI_wps_status_cb(wps_cb_status status);
|
||||
|
||||
#endif // ifndef __SUPPORT_H__
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
File diff suppressed because it is too large
Load Diff
|
@ -17,6 +17,9 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _USER_CONFIG_H_
|
||||
#define _USER_CONFIG_H_
|
||||
|
||||
/*********************************************************************************************\
|
||||
* ATTENTION: Changes to most PARAMETER defines will only override flash settings if you change
|
||||
* define CFG_HOLDER.
|
||||
|
@ -28,6 +31,7 @@
|
|||
// -- Localization --------------------------------
|
||||
//#define MY_LANGUAGE en-GB // Enabled by Default
|
||||
//#define MY_LANGUAGE nl-NL
|
||||
//#define MY_LANGUAGE de-DE
|
||||
|
||||
// -- Project -------------------------------------
|
||||
#define PROJECT "sonoff" // PROJECT is used as the default topic delimiter and OTA file name
|
||||
|
@ -172,8 +176,14 @@
|
|||
|
||||
#define USE_WS2812 // WS2812 Led string using library NeoPixelBus (+5k code, +1k mem) - Disable by //
|
||||
#define USE_WS2812_CTYPE 1 // WS2812 Color type (0 - RGB, 1 - GRB)
|
||||
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial RXD) (+1k mem)
|
||||
// When USE_WS2812_DMA is enabled expect Exceptions on Pow
|
||||
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial RXD) (+1k mem). When USE_WS2812_DMA is enabled expect Exceptions on Pow
|
||||
#define CLOCK_REVERSE 0 // WS2812 Clock display (0 - Normal, 1 - Reverse)
|
||||
#define CLOCK_SECOND_WIDTH 1 // WS2812 Clock second hand pixel width
|
||||
#define CLOCK_MINUTE_WIDTH 3 // WS2812 Clock minute hand pixel width
|
||||
#define CLOCK_HOUR_WIDTH 5 // WS2812 Clock hour hand pixel width
|
||||
#define CLOCK_SECOND_COLOR (255, 0, 255) // WS2812 Clock second pixel color
|
||||
#define CLOCK_MINUTE_COLOR (0, 255, 0) // WS2812 Clock minute pixel color
|
||||
#define CLOCK_HOUR_COLOR (255, 0,0 ) // WS2812 Clock hour pixel color
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Compile a minimal version if upgrade memory gets tight ONLY TO BE USED FOR UPGRADE STEP 1!
|
||||
|
@ -196,3 +206,4 @@
|
|||
#error "This software is supported with Arduino IDE starting from 1.6.10 and ESP8266 Release 2.3.0"
|
||||
#endif
|
||||
|
||||
#endif // _USER_CONFIG_H_
|
|
@ -17,6 +17,9 @@
|
|||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef _USER_CONFIG_OVERRIDE_H_
|
||||
#define _USER_CONFIG_OVERRIDE_H_
|
||||
|
||||
/*****************************************************************************************************\
|
||||
* ATTENTION: - Changes to most PARAMETER defines will only override flash settings if you change
|
||||
* define CFG_HOLDER.
|
||||
|
@ -38,3 +41,4 @@
|
|||
//#endif
|
||||
//#define STA_SSID1 "yourssid1"
|
||||
|
||||
#endif // _USER_CONFIG_OVERRIDE_H_
|
File diff suppressed because it is too large
Load Diff
|
@ -35,7 +35,7 @@ const char HTTP_FORM_DOMOTICZ_TIMER[] PROGMEM =
|
|||
"<tr><td width='260'><b>" D_DOMOTICZ_UPDATE_TIMER "</b> (" STR(DOMOTICZ_UPDATE_TIMER) ")</td><td width='70'><input id='ut' name='ut' placeholder='" STR(DOMOTICZ_UPDATE_TIMER) "' value='{6'</td></tr>";
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
enum domoticz_sensors_t {
|
||||
enum DomoticzSensors {
|
||||
DZ_TEMP,
|
||||
DZ_TEMP_HUM,
|
||||
DZ_TEMP_HUM_BARO,
|
||||
|
@ -46,7 +46,7 @@ enum domoticz_sensors_t {
|
|||
DZ_CURRENT,
|
||||
DZ_MAX_SENSORS };
|
||||
|
||||
const char domoticz_sensors[DZ_MAX_SENSORS][DOMOTICZ_SENSORS_MAX_STRING_LENGTH] PROGMEM = {
|
||||
const char kDomoticzSensors[DZ_MAX_SENSORS][DOMOTICZ_SENSORS_MAX_STRING_LENGTH] PROGMEM = {
|
||||
D_DOMOTICZ_TEMP,
|
||||
D_DOMOTICZ_TEMP_HUM,
|
||||
D_DOMOTICZ_TEMP_HUM_BARO,
|
||||
|
@ -63,67 +63,62 @@ boolean domoticz_subscribe = false;
|
|||
int domoticz_update_timer = 0;
|
||||
byte domoticz_update_flag = 1;
|
||||
|
||||
void mqtt_publishDomoticzPowerState(byte device)
|
||||
void MqttPublishDomoticzPowerState(byte device)
|
||||
{
|
||||
char sdimmer[8];
|
||||
|
||||
if ((device < 1) || (device > Maxdevice)) {
|
||||
if ((device < 1) || (device > devices_present)) {
|
||||
device = 1;
|
||||
}
|
||||
if (sysCfg.flag.mqtt_enabled && sysCfg.domoticz_relay_idx[device -1]) {
|
||||
snprintf_P(sdimmer, sizeof(sdimmer), PSTR("%d"), sysCfg.led_dimmer);
|
||||
if (Settings.flag.mqtt_enabled && Settings.domoticz_relay_idx[device -1]) {
|
||||
snprintf_P(sdimmer, sizeof(sdimmer), PSTR("%d"), Settings.led_dimmer);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"%s\"}"),
|
||||
sysCfg.domoticz_relay_idx[device -1], (power & (1 << (device -1))) ? 1 : 0, (sfl_flg) ? sdimmer : "");
|
||||
mqtt_publish(domoticz_in_topic);
|
||||
Settings.domoticz_relay_idx[device -1], (power & (1 << (device -1))) ? 1 : 0, (light_type) ? sdimmer : "");
|
||||
MqttPublish(domoticz_in_topic);
|
||||
}
|
||||
}
|
||||
|
||||
void domoticz_updatePowerState(byte device)
|
||||
void DomoticzUpdatePowerState(byte device)
|
||||
{
|
||||
if (domoticz_update_flag) {
|
||||
mqtt_publishDomoticzPowerState(device);
|
||||
MqttPublishDomoticzPowerState(device);
|
||||
}
|
||||
domoticz_update_flag = 1;
|
||||
}
|
||||
|
||||
void domoticz_mqttUpdate()
|
||||
void DomoticzMqttUpdate()
|
||||
{
|
||||
if (domoticz_subscribe && (sysCfg.domoticz_update_timer || domoticz_update_timer)) {
|
||||
if (domoticz_subscribe && (Settings.domoticz_update_timer || domoticz_update_timer)) {
|
||||
domoticz_update_timer--;
|
||||
if (domoticz_update_timer <= 0) {
|
||||
domoticz_update_timer = sysCfg.domoticz_update_timer;
|
||||
for (byte i = 1; i <= Maxdevice; i++) {
|
||||
mqtt_publishDomoticzPowerState(i);
|
||||
domoticz_update_timer = Settings.domoticz_update_timer;
|
||||
for (byte i = 1; i <= devices_present; i++) {
|
||||
MqttPublishDomoticzPowerState(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void domoticz_setUpdateTimer(uint16_t value)
|
||||
void DomoticzSetUpdateTimer(uint16_t value)
|
||||
{
|
||||
domoticz_update_timer = value;
|
||||
}
|
||||
|
||||
void domoticz_mqttSubscribe()
|
||||
void DomoticzMqttSubscribe()
|
||||
{
|
||||
uint8_t maxdev = (Maxdevice > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : Maxdevice;
|
||||
uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present;
|
||||
for (byte i = 0; i < maxdev; i++) {
|
||||
if (sysCfg.domoticz_relay_idx[i]) {
|
||||
if (Settings.domoticz_relay_idx[i]) {
|
||||
domoticz_subscribe = true;
|
||||
}
|
||||
}
|
||||
if (domoticz_subscribe) {
|
||||
char stopic[TOPSZ];
|
||||
snprintf_P(stopic, sizeof(stopic), PSTR("%s/#"), domoticz_out_topic); // domoticz topic
|
||||
mqtt_subscribe(stopic);
|
||||
MqttSubscribe(stopic);
|
||||
}
|
||||
}
|
||||
|
||||
boolean domoticz_update()
|
||||
{
|
||||
return domoticz_update_flag;
|
||||
}
|
||||
|
||||
/*
|
||||
* ArduinoJSON Domoticz Switch entry used to calculate jsonBuf: JSON_OBJECT_SIZE(11) + 129 = 313
|
||||
{
|
||||
|
@ -141,7 +136,7 @@ boolean domoticz_update()
|
|||
}
|
||||
*/
|
||||
|
||||
boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
|
||||
boolean DomoticzMqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uint16_t sdataBuf)
|
||||
{
|
||||
char stemp1[10];
|
||||
char scommand[10];
|
||||
|
@ -166,16 +161,16 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
|||
nvalue = domoticz["nvalue"];
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, nvalue);
|
||||
addLog(LOG_LEVEL_DEBUG_MORE);
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE);
|
||||
|
||||
if ((idx > 0) && (nvalue >= 0) && (nvalue <= 2)) {
|
||||
uint8_t maxdev = (Maxdevice > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : Maxdevice;
|
||||
uint8_t maxdev = (devices_present > MAX_DOMOTICZ_IDX) ? MAX_DOMOTICZ_IDX : devices_present;
|
||||
for (byte i = 0; i < maxdev; i++) {
|
||||
if (idx == sysCfg.domoticz_relay_idx[i]) {
|
||||
if (idx == Settings.domoticz_relay_idx[i]) {
|
||||
snprintf_P(stemp1, sizeof(stemp1), PSTR("%d"), i +1);
|
||||
if (2 == nvalue) {
|
||||
nvalue = domoticz["svalue1"];
|
||||
if (sfl_flg && (sysCfg.led_dimmer == nvalue) && ((power >> i) &1)) {
|
||||
if (light_type && (Settings.led_dimmer == nvalue) && ((power >> i) &1)) {
|
||||
return 1;
|
||||
}
|
||||
snprintf_P(topicBuf, stopicBuf, PSTR("/" D_CMND_DIMMER));
|
||||
|
@ -185,7 +180,7 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
|||
if (((power >> i) &1) == nvalue) {
|
||||
return 1;
|
||||
}
|
||||
snprintf_P(topicBuf, stopicBuf, PSTR("/" D_CMND_POWER "%s"), (Maxdevice > 1) ? stemp1 : "");
|
||||
snprintf_P(topicBuf, stopicBuf, PSTR("/" D_CMND_POWER "%s"), (devices_present > 1) ? stemp1 : "");
|
||||
snprintf_P(dataBuf, sdataBuf, PSTR("%d"), nvalue);
|
||||
found = 1;
|
||||
}
|
||||
|
@ -198,7 +193,7 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
|||
}
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_RECEIVED_TOPIC " %s, " D_DATA " %s"), topicBuf, dataBuf);
|
||||
addLog(LOG_LEVEL_DEBUG_MORE);
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE);
|
||||
|
||||
domoticz_update_flag = 0;
|
||||
}
|
||||
|
@ -209,7 +204,7 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
|||
* Commands
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
boolean DomoticzCommand(const char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
{
|
||||
boolean serviced = true;
|
||||
uint8_t dmtcz_len = strlen(D_CMND_DOMOTICZ); // Prep for string length change
|
||||
|
@ -217,34 +212,34 @@ boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16
|
|||
if (!strncasecmp_P(type, PSTR(D_CMND_DOMOTICZ), dmtcz_len)) { // Prefix
|
||||
if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_IDX)) && (index > 0) && (index <= MAX_DOMOTICZ_IDX)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_relay_idx[index -1] = payload;
|
||||
restartflag = 2;
|
||||
Settings.domoticz_relay_idx[index -1] = payload;
|
||||
restart_flag = 2;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_IDX "%d\":%d}"), index, sysCfg.domoticz_relay_idx[index -1]);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_IDX "%d\":%d}"), index, Settings.domoticz_relay_idx[index -1]);
|
||||
}
|
||||
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_KEYIDX)) && (index > 0) && (index <= MAX_DOMOTICZ_IDX)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_key_idx[index -1] = payload;
|
||||
Settings.domoticz_key_idx[index -1] = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_KEYIDX "%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_KEYIDX "%d\":%d}"), index, Settings.domoticz_key_idx[index -1]);
|
||||
}
|
||||
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_SWITCHIDX)) && (index > 0) && (index <= MAX_DOMOTICZ_IDX)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_switch_idx[index -1] = payload;
|
||||
Settings.domoticz_switch_idx[index -1] = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SWITCHIDX "%d\":%d}"), index, sysCfg.domoticz_key_idx[index -1]);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SWITCHIDX "%d\":%d}"), index, Settings.domoticz_key_idx[index -1]);
|
||||
}
|
||||
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_SENSORIDX)) && (index > 0) && (index <= DZ_MAX_SENSORS)) {
|
||||
if (payload >= 0) {
|
||||
sysCfg.domoticz_sensor_idx[index -1] = payload;
|
||||
Settings.domoticz_sensor_idx[index -1] = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SENSORIDX "%d\":%d}"), index, sysCfg.domoticz_sensor_idx[index -1]);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_SENSORIDX "%d\":%d}"), index, Settings.domoticz_sensor_idx[index -1]);
|
||||
}
|
||||
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_UPDATETIMER))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.domoticz_update_timer = payload;
|
||||
Settings.domoticz_update_timer = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_UPDATETIMER "\":%d}"), sysCfg.domoticz_update_timer);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DOMOTICZ D_CMND_UPDATETIMER "\":%d}"), Settings.domoticz_update_timer);
|
||||
}
|
||||
else serviced = false;
|
||||
}
|
||||
|
@ -252,12 +247,12 @@ boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16
|
|||
return serviced;
|
||||
}
|
||||
|
||||
boolean domoticz_button(byte key, byte device, byte state, byte svalflg)
|
||||
boolean DomoticzButton(byte key, byte device, byte state, byte svalflg)
|
||||
{
|
||||
if ((sysCfg.domoticz_key_idx[device -1] || sysCfg.domoticz_switch_idx[device -1]) && (svalflg)) {
|
||||
if ((Settings.domoticz_key_idx[device -1] || Settings.domoticz_switch_idx[device -1]) && (svalflg)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"command\":\"switchlight\",\"idx\":%d,\"switchcmd\":\"%s\"}"),
|
||||
(key) ? sysCfg.domoticz_switch_idx[device -1] : sysCfg.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off");
|
||||
mqtt_publish(domoticz_in_topic);
|
||||
(key) ? Settings.domoticz_switch_idx[device -1] : Settings.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off");
|
||||
MqttPublish(domoticz_in_topic);
|
||||
return 1;
|
||||
} else {
|
||||
return 0;
|
||||
|
@ -268,51 +263,51 @@ boolean domoticz_button(byte key, byte device, byte state, byte svalflg)
|
|||
* Sensors
|
||||
\*********************************************************************************************/
|
||||
|
||||
uint8_t dom_hum_stat(char *hum)
|
||||
uint8_t DomoticzHumidityState(char *hum)
|
||||
{
|
||||
uint8_t h = atoi(hum);
|
||||
return (!h) ? 0 : (h < 40) ? 2 : (h > 70) ? 3 : 1;
|
||||
}
|
||||
|
||||
void domoticz_sensor(byte idx, char *data)
|
||||
void DomoticzSensor(byte idx, char *data)
|
||||
{
|
||||
if (sysCfg.domoticz_sensor_idx[idx]) {
|
||||
if (Settings.domoticz_sensor_idx[idx]) {
|
||||
char dmess[64];
|
||||
|
||||
memcpy(dmess, mqtt_data, sizeof(dmess));
|
||||
snprintf_P(mqtt_data, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"),
|
||||
sysCfg.domoticz_sensor_idx[idx], data);
|
||||
mqtt_publish(domoticz_in_topic);
|
||||
Settings.domoticz_sensor_idx[idx], data);
|
||||
MqttPublish(domoticz_in_topic);
|
||||
memcpy(mqtt_data, dmess, sizeof(dmess));
|
||||
}
|
||||
}
|
||||
|
||||
void domoticz_sensor(byte idx, uint32_t value)
|
||||
void DomoticzSensor(byte idx, uint32_t value)
|
||||
{
|
||||
char data[16];
|
||||
snprintf_P(data, sizeof(data), PSTR("%d"), value);
|
||||
domoticz_sensor(idx, data);
|
||||
DomoticzSensor(idx, data);
|
||||
}
|
||||
|
||||
void domoticz_sensor2(char *temp, char *hum)
|
||||
void DomoticzTempHumSensor(char *temp, char *hum)
|
||||
{
|
||||
char data[16];
|
||||
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d"), temp, hum, dom_hum_stat(hum));
|
||||
domoticz_sensor(DZ_TEMP_HUM, data);
|
||||
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d"), temp, hum, DomoticzHumidityState(hum));
|
||||
DomoticzSensor(DZ_TEMP_HUM, data);
|
||||
}
|
||||
|
||||
void domoticz_sensor3(char *temp, char *hum, char *baro)
|
||||
void DomoticzTempHumPressureSensor(char *temp, char *hum, char *baro)
|
||||
{
|
||||
char data[32];
|
||||
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d;%s;5"), temp, hum, dom_hum_stat(hum), baro);
|
||||
domoticz_sensor(DZ_TEMP_HUM_BARO, data);
|
||||
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d;%s;5"), temp, hum, DomoticzHumidityState(hum), baro);
|
||||
DomoticzSensor(DZ_TEMP_HUM_BARO, data);
|
||||
}
|
||||
|
||||
void domoticz_sensor4(uint16_t power, char *energy)
|
||||
void DomoticzSensorPowerEnergy(uint16_t power, char *energy)
|
||||
{
|
||||
char data[16];
|
||||
snprintf_P(data, sizeof(data), PSTR("%d;%s"), power, energy);
|
||||
domoticz_sensor(DZ_POWER_ENERGY, data);
|
||||
DomoticzSensor(DZ_POWER_ENERGY, data);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -322,13 +317,13 @@ void domoticz_sensor4(uint16_t power, char *energy)
|
|||
#ifdef USE_WEBSERVER
|
||||
const char S_CONFIGURE_DOMOTICZ[] PROGMEM = D_CONFIGURE_DOMOTICZ;
|
||||
|
||||
void handleDomoticz()
|
||||
void HandleDomoticzConfiguration()
|
||||
{
|
||||
if (HTTP_USER == _httpflag) {
|
||||
handleRoot();
|
||||
if (HTTP_USER == webserver_state) {
|
||||
HandleRoot();
|
||||
return;
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_DOMOTICZ);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, S_CONFIGURE_DOMOTICZ);
|
||||
|
||||
char stemp[20];
|
||||
|
||||
|
@ -336,59 +331,59 @@ void handleDomoticz()
|
|||
page.replace(F("{v}"), FPSTR(S_CONFIGURE_DOMOTICZ));
|
||||
page += FPSTR(HTTP_FORM_DOMOTICZ);
|
||||
for (int i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
||||
if (i < Maxdevice) {
|
||||
if (i < devices_present) {
|
||||
page += FPSTR(HTTP_FORM_DOMOTICZ_RELAY);
|
||||
page.replace("{2", String((int)sysCfg.domoticz_relay_idx[i]));
|
||||
page.replace("{3", String((int)sysCfg.domoticz_key_idx[i]));
|
||||
page.replace("{2", String((int)Settings.domoticz_relay_idx[i]));
|
||||
page.replace("{3", String((int)Settings.domoticz_key_idx[i]));
|
||||
}
|
||||
if (pin[GPIO_SWT1 +i] < 99) {
|
||||
page += FPSTR(HTTP_FORM_DOMOTICZ_SWITCH);
|
||||
page.replace("{4", String((int)sysCfg.domoticz_switch_idx[i]));
|
||||
page.replace("{4", String((int)Settings.domoticz_switch_idx[i]));
|
||||
}
|
||||
page.replace("{1", String(i +1));
|
||||
}
|
||||
for (int i = 0; i < DZ_MAX_SENSORS; i++) {
|
||||
page += FPSTR(HTTP_FORM_DOMOTICZ_SENSOR);
|
||||
page.replace("{1", String(i +1));
|
||||
snprintf_P(stemp, sizeof(stemp), domoticz_sensors[i]);
|
||||
snprintf_P(stemp, sizeof(stemp), kDomoticzSensors[i]);
|
||||
page.replace("{2", stemp);
|
||||
page.replace("{5", String((int)sysCfg.domoticz_sensor_idx[i]));
|
||||
page.replace("{5", String((int)Settings.domoticz_sensor_idx[i]));
|
||||
}
|
||||
page += FPSTR(HTTP_FORM_DOMOTICZ_TIMER);
|
||||
page.replace("{6", String((int)sysCfg.domoticz_update_timer));
|
||||
page.replace("{6", String((int)Settings.domoticz_update_timer));
|
||||
page += F("</table>");
|
||||
page += FPSTR(HTTP_FORM_END);
|
||||
page += FPSTR(HTTP_BTN_CONF);
|
||||
showPage(page);
|
||||
ShowPage(page);
|
||||
}
|
||||
|
||||
void domoticz_saveSettings()
|
||||
void DomoticzSaveSettings()
|
||||
{
|
||||
char stemp[20];
|
||||
|
||||
for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("r%d"), i +1);
|
||||
sysCfg.domoticz_relay_idx[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
|
||||
Settings.domoticz_relay_idx[i] = (!strlen(WebServer->arg(stemp).c_str())) ? 0 : atoi(WebServer->arg(stemp).c_str());
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("k%d"), i +1);
|
||||
sysCfg.domoticz_key_idx[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
|
||||
Settings.domoticz_key_idx[i] = (!strlen(WebServer->arg(stemp).c_str())) ? 0 : atoi(WebServer->arg(stemp).c_str());
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("s%d"), i +1);
|
||||
sysCfg.domoticz_switch_idx[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
|
||||
Settings.domoticz_switch_idx[i] = (!strlen(WebServer->arg(stemp).c_str())) ? 0 : atoi(WebServer->arg(stemp).c_str());
|
||||
}
|
||||
for (byte i = 0; i < DZ_MAX_SENSORS; i++) {
|
||||
snprintf_P(stemp, sizeof(stemp), PSTR("l%d"), i +1);
|
||||
sysCfg.domoticz_sensor_idx[i] = (!strlen(webServer->arg(stemp).c_str())) ? 0 : atoi(webServer->arg(stemp).c_str());
|
||||
Settings.domoticz_sensor_idx[i] = (!strlen(WebServer->arg(stemp).c_str())) ? 0 : atoi(WebServer->arg(stemp).c_str());
|
||||
}
|
||||
sysCfg.domoticz_update_timer = (!strlen(webServer->arg("ut").c_str())) ? DOMOTICZ_UPDATE_TIMER : atoi(webServer->arg("ut").c_str());
|
||||
Settings.domoticz_update_timer = (!strlen(WebServer->arg("ut").c_str())) ? DOMOTICZ_UPDATE_TIMER : atoi(WebServer->arg("ut").c_str());
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_IDX " %d, %d, %d, %d, " D_CMND_UPDATETIMER " %d"),
|
||||
sysCfg.domoticz_relay_idx[0], sysCfg.domoticz_relay_idx[1], sysCfg.domoticz_relay_idx[2], sysCfg.domoticz_relay_idx[3],
|
||||
sysCfg.domoticz_update_timer);
|
||||
addLog(LOG_LEVEL_INFO);
|
||||
Settings.domoticz_relay_idx[0], Settings.domoticz_relay_idx[1], Settings.domoticz_relay_idx[2], Settings.domoticz_relay_idx[3],
|
||||
Settings.domoticz_update_timer);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ D_CMND_KEYIDX " %d, %d, %d, %d, " D_CMND_SWITCHIDX " %d, %d, %d, %d, " D_CMND_SENSORIDX " %d, %d, %d, %d, %d, %d, %d, %d"),
|
||||
sysCfg.domoticz_key_idx[0], sysCfg.domoticz_key_idx[1], sysCfg.domoticz_key_idx[2], sysCfg.domoticz_key_idx[3],
|
||||
sysCfg.domoticz_switch_idx[0], sysCfg.domoticz_switch_idx[1], sysCfg.domoticz_switch_idx[2], sysCfg.domoticz_switch_idx[3],
|
||||
sysCfg.domoticz_sensor_idx[0], sysCfg.domoticz_sensor_idx[1], sysCfg.domoticz_sensor_idx[2], sysCfg.domoticz_sensor_idx[3],
|
||||
sysCfg.domoticz_sensor_idx[4], sysCfg.domoticz_sensor_idx[5], sysCfg.domoticz_sensor_idx[6], sysCfg.domoticz_sensor_idx[7]);
|
||||
addLog(LOG_LEVEL_INFO);
|
||||
Settings.domoticz_key_idx[0], Settings.domoticz_key_idx[1], Settings.domoticz_key_idx[2], Settings.domoticz_key_idx[3],
|
||||
Settings.domoticz_switch_idx[0], Settings.domoticz_switch_idx[1], Settings.domoticz_switch_idx[2], Settings.domoticz_switch_idx[3],
|
||||
Settings.domoticz_sensor_idx[0], Settings.domoticz_sensor_idx[1], Settings.domoticz_sensor_idx[2], Settings.domoticz_sensor_idx[3],
|
||||
Settings.domoticz_sensor_idx[4], Settings.domoticz_sensor_idx[5], Settings.domoticz_sensor_idx[6], Settings.domoticz_sensor_idx[7]);
|
||||
AddLog(LOG_LEVEL_INFO);
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
#endif // USE_DOMOTICZ
|
||||
|
|
|
@ -39,8 +39,8 @@
|
|||
|
||||
IRMitsubishiAC *mitsubir = NULL;
|
||||
|
||||
const char FANSPEED[] = "A12345S";
|
||||
const char HVACMODE[] = "HDCA";
|
||||
const char kFanSpeedOptions[] = "A12345S";
|
||||
const char kHvacModeOptions[] = "HDCA";
|
||||
#endif
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -49,7 +49,7 @@ const char HVACMODE[] = "HDCA";
|
|||
|
||||
IRsend *irsend = NULL;
|
||||
|
||||
void ir_send_init(void)
|
||||
void IrSendInit(void)
|
||||
{
|
||||
irsend = new IRsend(pin[GPIO_IRSEND]); // an IR led is at GPIO_IRSEND
|
||||
irsend->begin();
|
||||
|
@ -69,15 +69,15 @@ void ir_send_init(void)
|
|||
IRrecv *irrecv = NULL;
|
||||
unsigned long ir_lasttime = 0;
|
||||
|
||||
void ir_recv_init(void)
|
||||
void IrReceiveInit(void)
|
||||
{
|
||||
irrecv = new IRrecv(pin[GPIO_IRRECV]); // an IR led is at GPIO_IRRECV
|
||||
irrecv->enableIRIn(); // Start the receiver
|
||||
|
||||
// addLog_P(LOG_LEVEL_DEBUG, PSTR("IrReceive initialized"));
|
||||
// AddLog_P(LOG_LEVEL_DEBUG, PSTR("IrReceive initialized"));
|
||||
}
|
||||
|
||||
void ir_recv_check()
|
||||
void IrReceiveCheck()
|
||||
{
|
||||
char sirtype[100];
|
||||
char *protocol;
|
||||
|
@ -90,7 +90,7 @@ void ir_recv_check()
|
|||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_IRR "RawLen %d, Bits %d, Value %08X, Decode %d"),
|
||||
results.rawlen, results.bits, results.value, results.decode_type);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
unsigned long now = millis();
|
||||
if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) {
|
||||
|
@ -111,10 +111,10 @@ void ir_recv_check()
|
|||
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_IRRECEIVED "\":{\"" D_IR_PROTOCOL "\":\"%s\", \"" D_IR_BITS "\":%d, \"" D_IR_DATA "\":\"%X\"}}"),
|
||||
protocol, results.bits, results.value);
|
||||
mqtt_publish_topic_P(6, PSTR(D_IRRECEIVED));
|
||||
MqttPublishPrefixTopic_P(6, PSTR(D_IRRECEIVED));
|
||||
#ifdef USE_DOMOTICZ
|
||||
unsigned long value = results.value | (diridx << 28); // [Protocol:4, Data:28]
|
||||
domoticz_sensor(DZ_COUNT, value); // Send data as Domoticz Counter value
|
||||
DomoticzSensor(DZ_COUNT, value); // Send data as Domoticz Counter value
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
||||
|
@ -128,7 +128,7 @@ void ir_recv_check()
|
|||
* IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
|
||||
boolean IrHvacToshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
|
||||
{
|
||||
unsigned int rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2];
|
||||
byte data[HVAC_TOSHIBA_DATALEN] = {0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00};
|
||||
|
@ -138,30 +138,30 @@ boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean
|
|||
uint8_t mode;
|
||||
|
||||
if (HVAC_Mode == NULL) {
|
||||
p = (char *)HVACMODE; // default HVAC_HOT
|
||||
p = (char *)kHvacModeOptions; // default HVAC_HOT
|
||||
}
|
||||
else {
|
||||
p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
|
||||
p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0]));
|
||||
}
|
||||
if (!p) {
|
||||
return true;
|
||||
}
|
||||
data[6] = (p - HVACMODE) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00
|
||||
data[6] = (p - kHvacModeOptions) ^ 0x03; // HOT = 0x03, DRY = 0x02, COOL = 0x01, AUTO = 0x00
|
||||
|
||||
if (!HVAC_Power) {
|
||||
data[6] = (byte)0x07; // Turn OFF HVAC
|
||||
}
|
||||
|
||||
if (HVAC_FanMode == NULL) {
|
||||
p = (char *)FANSPEED; // default FAN_SPEED_AUTO
|
||||
p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO
|
||||
}
|
||||
else {
|
||||
p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
|
||||
p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0]));
|
||||
}
|
||||
if (!p) {
|
||||
return true;
|
||||
}
|
||||
mode = p - FANSPEED + 1;
|
||||
mode = p - kFanSpeedOptions + 1;
|
||||
if ((1 == mode) || (7 == mode)) {
|
||||
mode = 0;
|
||||
}
|
||||
|
@ -218,7 +218,7 @@ boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean
|
|||
return false;
|
||||
}
|
||||
|
||||
boolean ir_hvac_mitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
|
||||
boolean IrHvacMitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, boolean HVAC_Power, int HVAC_Temp)
|
||||
{
|
||||
char *p;
|
||||
char *token;
|
||||
|
@ -227,29 +227,29 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, bool
|
|||
mitsubir->stateReset();
|
||||
|
||||
if (HVAC_Mode == NULL) {
|
||||
p = (char *)HVACMODE; // default HVAC_HOT
|
||||
p = (char *)kHvacModeOptions; // default HVAC_HOT
|
||||
}
|
||||
else {
|
||||
p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
|
||||
p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0]));
|
||||
}
|
||||
if (!p) {
|
||||
return true;
|
||||
}
|
||||
mode = (p - HVACMODE + 1) << 3; // HOT = 0x08, DRY = 0x10, COOL = 0x18, AUTO = 0x20
|
||||
mode = (p - kHvacModeOptions + 1) << 3; // HOT = 0x08, DRY = 0x10, COOL = 0x18, AUTO = 0x20
|
||||
mitsubir->setMode(mode);
|
||||
|
||||
mitsubir->setPower(HVAC_Power);
|
||||
|
||||
if (HVAC_FanMode == NULL) {
|
||||
p = (char *)FANSPEED; // default FAN_SPEED_AUTO
|
||||
p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO
|
||||
}
|
||||
else {
|
||||
p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
|
||||
p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0]));
|
||||
}
|
||||
if (!p) {
|
||||
return true;
|
||||
}
|
||||
mode = p - FANSPEED; // AUTO = 0, SPEED = 1 .. 5, SILENT = 6
|
||||
mode = p - kFanSpeedOptions; // AUTO = 0, SPEED = 1 .. 5, SILENT = 6
|
||||
mitsubir->setFan(mode);
|
||||
|
||||
mitsubir->setTemp(HVAC_Temp);
|
||||
|
@ -258,7 +258,7 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, bool
|
|||
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: Mitsubishi Power %d, Mode %d, FanSpeed %d, Temp %d, VaneMode %d"),
|
||||
// mitsubir->getPower(), mitsubir->getMode(), mitsubir->getFan(), mitsubir->getTemp(), mitsubir->getVane());
|
||||
// addLog(LOG_LEVEL_DEBUG);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -277,7 +277,7 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, bool
|
|||
{ "Vendor": "<Toshiba|Mitsubishi>", "Power": <0|1>, "Mode": "<Hot|Cold|Dry|Auto>", "FanSpeed": "<1|2|3|4|5|Auto|Silence>", "Temp": <17..30> }
|
||||
*/
|
||||
|
||||
boolean ir_send_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
boolean IrSendCommand(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
{
|
||||
boolean serviced = true;
|
||||
boolean error = false;
|
||||
|
@ -358,13 +358,13 @@ boolean ir_send_command(char *type, uint16_t index, char *dataBuf, uint16_t data
|
|||
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("IRHVAC: Received Vendor %s, Power %d, Mode %s, FanSpeed %s, Temp %d"),
|
||||
// HVAC_Vendor, HVAC_Power, HVAC_Mode, HVAC_FanMode, HVAC_Temp);
|
||||
// addLog(LOG_LEVEL_DEBUG);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
if (HVAC_Vendor == NULL || !strcasecmp_P(HVAC_Vendor, PSTR("TOSHIBA"))) {
|
||||
error = ir_hvac_toshiba(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
|
||||
error = IrHvacToshiba(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
|
||||
}
|
||||
else if (!strcasecmp_P(HVAC_Vendor, PSTR("MITSUBISHI"))) {
|
||||
error = ir_hvac_mitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
|
||||
error = IrHvacMitsubishi(HVAC_Mode, HVAC_FanMode, HVAC_Power, HVAC_Temp);
|
||||
}
|
||||
else {
|
||||
error = true;
|
||||
|
|
|
@ -23,108 +23,106 @@
|
|||
|
||||
#define SFB_TIME_AVOID_DUPLICATE 2000 // Milliseconds
|
||||
|
||||
uint8_t sfb_rcvflg = 0;
|
||||
uint8_t sfb_learnKey = 1;
|
||||
uint8_t sfb_learnFlg = 0;
|
||||
uint32_t sfb_lastrid = 0;
|
||||
unsigned long sfb_lasttime = 0;
|
||||
uint8_t sonoff_bridge_receive_flag = 0;
|
||||
uint8_t sonoff_bridge_learn_key = 1;
|
||||
uint8_t sonoff_bridge_learn_active = 0;
|
||||
uint32_t sonoff_bridge_last_received_id = 0;
|
||||
unsigned long sonoff_bridge_last_time = 0;
|
||||
|
||||
void sb_received()
|
||||
void SonoffBridgeReceived()
|
||||
{
|
||||
uint8_t i = 0;
|
||||
uint32_t sid = 0;
|
||||
uint32_t rid = 0;
|
||||
uint16_t rsy = 0;
|
||||
uint16_t rlo = 0;
|
||||
uint16_t rhi = 0;
|
||||
uint16_t sync_time = 0;
|
||||
uint16_t low_time = 0;
|
||||
uint16_t high_time = 0;
|
||||
uint32_t received_id = 0;
|
||||
char svalue[90];
|
||||
char rfkey[8];
|
||||
|
||||
svalue[0] = '\0';
|
||||
for (i = 0; i < SerialInByteCounter; i++) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s%02X "), svalue, serialInBuf[i]);
|
||||
for (byte i = 0; i < serial_in_byte_counter; i++) {
|
||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s%02X "), svalue, serial_in_buffer[i]);
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_BRIDGE D_RECEIVED " %s"), svalue);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
if (0xA2 == serialInBuf[0]) { // Learn timeout
|
||||
sfb_learnFlg = 0;
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sfb_learnKey);
|
||||
mqtt_publish_topic_P(5, PSTR(D_CMND_RFKEY));
|
||||
if (0xA2 == serial_in_buffer[0]) { // Learn timeout
|
||||
sonoff_bridge_learn_active = 0;
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sonoff_bridge_learn_key);
|
||||
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_RFKEY));
|
||||
}
|
||||
else if (0xA3 == serialInBuf[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
|
||||
sfb_learnFlg = 0;
|
||||
rlo = serialInBuf[3] << 8 | serialInBuf[4]; // Low time in uSec
|
||||
rhi = serialInBuf[5] << 8 | serialInBuf[6]; // High time in uSec
|
||||
if (rlo && rhi) {
|
||||
for (i = 0; i < 9; i++) {
|
||||
sysCfg.sfb_code[sfb_learnKey][i] = serialInBuf[i +1];
|
||||
else if (0xA3 == serial_in_buffer[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
|
||||
sonoff_bridge_learn_active = 0;
|
||||
low_time = serial_in_buffer[3] << 8 | serial_in_buffer[4]; // Low time in uSec
|
||||
high_time = serial_in_buffer[5] << 8 | serial_in_buffer[6]; // High time in uSec
|
||||
if (low_time && high_time) {
|
||||
for (byte i = 0; i < 9; i++) {
|
||||
Settings.rf_code[sonoff_bridge_learn_key][i] = serial_in_buffer[i +1];
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED "\"}"), sfb_learnKey);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED "\"}"), sonoff_bridge_learn_key);
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sfb_learnKey);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARN_FAILED "\"}"), sonoff_bridge_learn_key);
|
||||
}
|
||||
mqtt_publish_topic_P(5, PSTR(D_CMND_RFKEY));
|
||||
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_RFKEY));
|
||||
}
|
||||
else if (0xA4 == serialInBuf[0]) { // Received RF data A4 20 EE 01 18 03 3E 2E 1A 22 55
|
||||
rsy = serialInBuf[1] << 8 | serialInBuf[2]; // Sync time in uSec
|
||||
rlo = serialInBuf[3] << 8 | serialInBuf[4]; // Low time in uSec
|
||||
rhi = serialInBuf[5] << 8 | serialInBuf[6]; // High time in uSec
|
||||
rid = serialInBuf[7] << 16 | serialInBuf[8] << 8 | serialInBuf[9];
|
||||
else if (0xA4 == serial_in_buffer[0]) { // Received RF data A4 20 EE 01 18 03 3E 2E 1A 22 55
|
||||
sync_time = serial_in_buffer[1] << 8 | serial_in_buffer[2]; // Sync time in uSec
|
||||
low_time = serial_in_buffer[3] << 8 | serial_in_buffer[4]; // Low time in uSec
|
||||
high_time = serial_in_buffer[5] << 8 | serial_in_buffer[6]; // High time in uSec
|
||||
received_id = serial_in_buffer[7] << 16 | serial_in_buffer[8] << 8 | serial_in_buffer[9];
|
||||
|
||||
unsigned long now = millis();
|
||||
if (!((rid == sfb_lastrid) && (now - sfb_lasttime < SFB_TIME_AVOID_DUPLICATE))) {
|
||||
sfb_lastrid = rid;
|
||||
sfb_lasttime = now;
|
||||
if (!((received_id == sonoff_bridge_last_received_id) && (now - sonoff_bridge_last_time < SFB_TIME_AVOID_DUPLICATE))) {
|
||||
sonoff_bridge_last_received_id = received_id;
|
||||
sonoff_bridge_last_time = now;
|
||||
strncpy_P(rfkey, PSTR("\"" D_NONE "\""), sizeof(rfkey));
|
||||
for (i = 1; i <= 16; i++) {
|
||||
if (sysCfg.sfb_code[i][0]) {
|
||||
sid = sysCfg.sfb_code[i][6] << 16 | sysCfg.sfb_code[i][7] << 8 | sysCfg.sfb_code[i][8];
|
||||
if (sid == rid) {
|
||||
for (byte i = 1; i <= 16; i++) {
|
||||
if (Settings.rf_code[i][0]) {
|
||||
uint32_t send_id = Settings.rf_code[i][6] << 16 | Settings.rf_code[i][7] << 8 | Settings.rf_code[i][8];
|
||||
if (send_id == received_id) {
|
||||
snprintf_P(rfkey, sizeof(rfkey), PSTR("%d"), i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_RFRECEIVED "\":{\"" D_SYNC "\":%d, \"" D_LOW "\":%d, \"" D_HIGH "\":%d, \"" D_DATA "\":\"%06X\", \"" D_CMND_RFKEY "\":%s}}"),
|
||||
rsy, rlo, rhi, rid, rfkey);
|
||||
mqtt_publish_topic_P(6, PSTR(D_RFRECEIVED));
|
||||
sync_time, low_time, high_time, received_id, rfkey);
|
||||
MqttPublishPrefixTopic_P(6, PSTR(D_RFRECEIVED));
|
||||
#ifdef USE_DOMOTICZ
|
||||
domoticz_sensor(DZ_COUNT, rid); // Send rid as Domoticz Counter value
|
||||
DomoticzSensor(DZ_COUNT, received_id); // Send rid as Domoticz Counter value
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean sb_serial()
|
||||
boolean SonoffBridgeSerialInput()
|
||||
{
|
||||
if (sfb_rcvflg) {
|
||||
if (!((SerialInByteCounter == 0) && (SerialInByte == 0))) { // Skip leading 0
|
||||
serialInBuf[SerialInByteCounter++] = SerialInByte;
|
||||
if (0x55 == SerialInByte) { // 0x55 - End of text
|
||||
sb_received();
|
||||
sfb_rcvflg = 0;
|
||||
if (sonoff_bridge_receive_flag) {
|
||||
if (!((serial_in_byte_counter == 0) && (serial_in_byte == 0))) { // Skip leading 0
|
||||
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
|
||||
if (0x55 == serial_in_byte) { // 0x55 - End of text
|
||||
SonoffBridgeReceived();
|
||||
sonoff_bridge_receive_flag = 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
SerialInByte = 0;
|
||||
serial_in_byte = 0;
|
||||
}
|
||||
if (0xAA == SerialInByte) { // 0xAA - Start of text
|
||||
SerialInByteCounter = 0;
|
||||
SerialInByte = 0;
|
||||
sfb_rcvflg = 1;
|
||||
if (0xAA == serial_in_byte) { // 0xAA - Start of text
|
||||
serial_in_byte_counter = 0;
|
||||
serial_in_byte = 0;
|
||||
sonoff_bridge_receive_flag = 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void sb_sendAck()
|
||||
void SonoffBridgeSendAck()
|
||||
{
|
||||
Serial.write(0xAA); // Start of Text
|
||||
Serial.write(0xA0); // Acknowledge
|
||||
Serial.write(0x55); // End of Text
|
||||
}
|
||||
|
||||
void sb_send(uint8_t idx, uint8_t key)
|
||||
void SonoffBridgeSend(uint8_t idx, uint8_t key)
|
||||
{
|
||||
uint8_t code;
|
||||
|
||||
|
@ -132,26 +130,26 @@ void sb_send(uint8_t idx, uint8_t key)
|
|||
Serial.write(0xAA); // Start of Text
|
||||
Serial.write(0xA5); // Send following code
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
Serial.write(sysCfg.sfb_code[idx][i]);
|
||||
Serial.write(Settings.rf_code[idx][i]);
|
||||
}
|
||||
if (0 == idx) {
|
||||
code = (0x10 << (key >> 2)) | (1 << (key & 3)); // 11,12,14,18,21,22,24,28,41,42,44,48,81,82,84,88
|
||||
} else {
|
||||
code = sysCfg.sfb_code[idx][8];
|
||||
code = Settings.rf_code[idx][8];
|
||||
}
|
||||
Serial.write(code);
|
||||
Serial.write(0x55); // End of Text
|
||||
Serial.flush();
|
||||
#ifdef USE_DOMOTICZ
|
||||
// uint32_t rid = sysCfg.sfb_code[idx][6] << 16 | sysCfg.sfb_code[idx][7] << 8 | code;
|
||||
// domoticz_sensor(DZ_COUNT, rid); // Send rid as Domoticz Counter value
|
||||
// uint32_t rid = Settings.rf_code[idx][6] << 16 | Settings.rf_code[idx][7] << 8 | code;
|
||||
// DomoticzSensor(DZ_COUNT, rid); // Send rid as Domoticz Counter value
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
||||
void sb_learn(uint8_t key)
|
||||
void SonoffBridgeLearn(uint8_t key)
|
||||
{
|
||||
sfb_learnKey = key;
|
||||
sfb_learnFlg = 1;
|
||||
sonoff_bridge_learn_key = key;
|
||||
sonoff_bridge_learn_active = 1;
|
||||
Serial.write(0xAA); // Start of Text
|
||||
Serial.write(0xA1); // Start learning
|
||||
Serial.write(0x55); // End of Text
|
||||
|
@ -161,7 +159,7 @@ void sb_learn(uint8_t key)
|
|||
* Commands
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean sb_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
boolean SonoffBridgeCommand(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
{
|
||||
boolean serviced = true;
|
||||
char *p;
|
||||
|
@ -172,32 +170,32 @@ boolean sb_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len,
|
|||
uint8_t msb = hexcode >> 8;
|
||||
uint8_t lsb = hexcode & 0xFF;
|
||||
if ((hexcode > 0) && (hexcode < 0x7FFF) && (msb != 0x55) && (lsb != 0x55)) {
|
||||
sysCfg.sfb_code[0][6] = msb;
|
||||
sysCfg.sfb_code[0][7] = lsb;
|
||||
Settings.rf_code[0][6] = msb;
|
||||
Settings.rf_code[0][7] = lsb;
|
||||
}
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFDEFAULT "\":\"%0X%0X\"}"), sysCfg.sfb_code[0][6], sysCfg.sfb_code[0][7]);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFDEFAULT "\":\"%0X%0X\"}"), Settings.rf_code[0][6], Settings.rf_code[0][7]);
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_RFKEY)) && (index > 0) && (index <= 16)) {
|
||||
if (!sfb_learnFlg) {
|
||||
if (!sonoff_bridge_learn_active) {
|
||||
if (2 == payload) {
|
||||
sb_learn(index);
|
||||
SonoffBridgeLearn(index);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_START_LEARNING "\"}"), index);
|
||||
}
|
||||
else if (3 == payload) {
|
||||
sysCfg.sfb_code[index][0] = 0;
|
||||
Settings.rf_code[index][0] = 0;
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_SET_TO_DEFAULT "\"}"), index);
|
||||
} else {
|
||||
if ((1 == payload) || (0 == sysCfg.sfb_code[index][0])) {
|
||||
sb_send(0, index);
|
||||
if ((1 == payload) || (0 == Settings.rf_code[index][0])) {
|
||||
SonoffBridgeSend(0, index);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_DEFAULT_SENT "\"}"), index);
|
||||
} else {
|
||||
sb_send(index, 0);
|
||||
SonoffBridgeSend(index, 0);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED_SENT "\"}"), index);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNING_ACTIVE "\"}"), sfb_learnKey);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNING_ACTIVE "\"}"), sonoff_bridge_learn_key);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -20,7 +20,7 @@
|
|||
/*********************************************************************************************\
|
||||
* PWM, WS2812, Sonoff B1, AiLight, Sonoff Led and BN-SZ01
|
||||
*
|
||||
* sfl_flg Module Color ColorTemp
|
||||
* light_type Module Color ColorTemp
|
||||
* 1 PWM1 W no (Sonoff BN-SZ)
|
||||
* 2 PWM2 CW yes (Sonoff Led)
|
||||
* 3 PWM3 RGB no (H801 and MagicHome)
|
||||
|
@ -87,7 +87,7 @@ extern "C" {
|
|||
uint8_t sl_pdi;
|
||||
uint8_t sl_pdcki;
|
||||
|
||||
void sl_di_pulse(uint8_t times)
|
||||
void LightDiPulse(uint8_t times)
|
||||
{
|
||||
for (uint8_t i = 0; i < times; i++) {
|
||||
digitalWrite(sl_pdi, HIGH);
|
||||
|
@ -95,7 +95,7 @@ void sl_di_pulse(uint8_t times)
|
|||
}
|
||||
}
|
||||
|
||||
void sl_dcki_pulse(uint8_t times)
|
||||
void LightDckiPulse(uint8_t times)
|
||||
{
|
||||
for (uint8_t i = 0; i < times; i++) {
|
||||
digitalWrite(sl_pdcki, HIGH);
|
||||
|
@ -103,7 +103,7 @@ void sl_dcki_pulse(uint8_t times)
|
|||
}
|
||||
}
|
||||
|
||||
void sl_my92x1_write(uint8_t data)
|
||||
void LightMy92x1Write(uint8_t data)
|
||||
{
|
||||
for (uint8_t i = 0; i < 4; i++) { // Send 8bit Data
|
||||
digitalWrite(sl_pdcki, LOW);
|
||||
|
@ -117,56 +117,56 @@ void sl_my92x1_write(uint8_t data)
|
|||
}
|
||||
}
|
||||
|
||||
void sl_my92x1_init()
|
||||
void LightMy92x1Init()
|
||||
{
|
||||
uint8_t chips = sfl_flg -11; // 1 (AiLight) or 2 (Sonoff B1)
|
||||
uint8_t chips = light_type -11; // 1 (AiLight) or 2 (Sonoff B1)
|
||||
|
||||
sl_dcki_pulse(chips * 32); // Clear all duty register
|
||||
LightDckiPulse(chips * 32); // Clear all duty register
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
// Send 12 DI pulse, after 6 pulse's falling edge store duty data, and 12
|
||||
// pulse's rising edge convert to command mode.
|
||||
sl_di_pulse(12);
|
||||
LightDiPulse(12);
|
||||
os_delay_us(12); // Delay >12us, begin send CMD data
|
||||
for (uint8_t n = 0; n < chips; n++) { // Send CMD data
|
||||
sl_my92x1_write(0x18); // ONE_SHOT_DISABLE, REACTION_FAST, BIT_WIDTH_8, FREQUENCY_DIVIDE_1, SCATTER_APDM
|
||||
LightMy92x1Write(0x18); // ONE_SHOT_DISABLE, REACTION_FAST, BIT_WIDTH_8, FREQUENCY_DIVIDE_1, SCATTER_APDM
|
||||
}
|
||||
os_delay_us(12); // TStart > 12us. Delay 12 us.
|
||||
// Send 16 DI pulse, at 14 pulse's falling edge store CMD data, and
|
||||
// at 16 pulse's falling edge convert to duty mode.
|
||||
sl_di_pulse(16);
|
||||
LightDiPulse(16);
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
}
|
||||
|
||||
void sl_my92x1_duty(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b, uint8_t duty_w, uint8_t duty_c)
|
||||
void LightMy92x1Duty(uint8_t duty_r, uint8_t duty_g, uint8_t duty_b, uint8_t duty_w, uint8_t duty_c)
|
||||
{
|
||||
uint8_t channels[2] = { 4, 6 };
|
||||
|
||||
uint8_t didx = sfl_flg -12; // 0 or 1
|
||||
uint8_t didx = light_type -12; // 0 or 1
|
||||
|
||||
uint8_t duty[2][6] = {{ duty_r, duty_g, duty_b, duty_w, 0, 0 }, // Definition for RGBW channels
|
||||
{ duty_w, duty_c, 0, duty_g, duty_r, duty_b }}; // Definition for RGBWC channels
|
||||
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
for (uint8_t channel = 0; channel < channels[didx]; channel++) {
|
||||
sl_my92x1_write(duty[didx][channel]); // Send 8bit Data
|
||||
LightMy92x1Write(duty[didx][channel]); // Send 8bit Data
|
||||
}
|
||||
os_delay_us(12); // TStart > 12us. Ready for send DI pulse.
|
||||
sl_di_pulse(8); // Send 8 DI pulse. After 8 pulse falling edge, store old data.
|
||||
LightDiPulse(8); // Send 8 DI pulse. After 8 pulse falling edge, store old data.
|
||||
os_delay_us(12); // TStop > 12us.
|
||||
}
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void sl_init(void)
|
||||
void LightInit(void)
|
||||
{
|
||||
if (sfl_flg < 6) { // PWM
|
||||
for (byte i = 0; i < sfl_flg; i++) {
|
||||
sysCfg.pwmvalue[i] = 0; // Disable direct PWM control
|
||||
if (light_type < 6) { // PWM
|
||||
for (byte i = 0; i < light_type; i++) {
|
||||
Settings.pwm_value[i] = 0; // Disable direct PWM control
|
||||
}
|
||||
if (1 == sfl_flg) {
|
||||
sysCfg.led_color[0] = 255; // One PWM channel only supports Dimmer but needs max color
|
||||
if (1 == light_type) {
|
||||
Settings.led_color[0] = 255; // One PWM channel only supports Dimmer but needs max color
|
||||
}
|
||||
if (SONOFF_LED == sysCfg.module) { // Fix Sonoff Led instabilities
|
||||
if (SONOFF_LED == Settings.module) { // Fix Sonoff Led instabilities
|
||||
if (!my_module.gp.io[4]) {
|
||||
pinMode(4, OUTPUT); // Stop floating outputs
|
||||
digitalWrite(4, LOW);
|
||||
|
@ -180,13 +180,13 @@ void sl_init(void)
|
|||
digitalWrite(14, LOW);
|
||||
}
|
||||
}
|
||||
sysCfg.led_scheme = 0;
|
||||
Settings.led_scheme = 0;
|
||||
}
|
||||
#ifdef USE_WS2812 // ************************************************************************
|
||||
else if (11 == sfl_flg) {
|
||||
ws2812_init();
|
||||
if (1 == sysCfg.led_scheme) {
|
||||
sysCfg.led_scheme = 0;
|
||||
else if (11 == light_type) {
|
||||
Ws2812Init();
|
||||
if (1 == Settings.led_scheme) {
|
||||
Settings.led_scheme = 0;
|
||||
}
|
||||
}
|
||||
#endif // USE_WS2812 ************************************************************************
|
||||
|
@ -199,8 +199,8 @@ void sl_init(void)
|
|||
digitalWrite(sl_pdi, LOW);
|
||||
digitalWrite(sl_pdcki, LOW);
|
||||
|
||||
sl_my92x1_init();
|
||||
sysCfg.led_scheme = 0;
|
||||
LightMy92x1Init();
|
||||
Settings.led_scheme = 0;
|
||||
}
|
||||
|
||||
sl_power = 0;
|
||||
|
@ -208,7 +208,7 @@ void sl_init(void)
|
|||
sl_wakeupActive = 0;
|
||||
}
|
||||
|
||||
void sl_setColorTemp(uint16_t ct)
|
||||
void LightSetColorTemp(uint16_t ct)
|
||||
{
|
||||
/* Color Temperature (https://developers.meethue.com/documentation/core-concepts)
|
||||
*
|
||||
|
@ -221,115 +221,115 @@ void sl_setColorTemp(uint16_t ct)
|
|||
}
|
||||
uint16_t icold = (100 * (347 - my_ct)) / 136;
|
||||
uint16_t iwarm = (100 * my_ct) / 136;
|
||||
if (5 == (sfl_flg &7)) {
|
||||
sysCfg.led_color[0] = 0;
|
||||
sysCfg.led_color[1] = 0;
|
||||
sysCfg.led_color[2] = 0;
|
||||
sysCfg.led_color[3] = (uint8_t)icold;
|
||||
sysCfg.led_color[4] = (uint8_t)iwarm;
|
||||
if (5 == (light_type &7)) {
|
||||
Settings.led_color[0] = 0;
|
||||
Settings.led_color[1] = 0;
|
||||
Settings.led_color[2] = 0;
|
||||
Settings.led_color[3] = (uint8_t)icold;
|
||||
Settings.led_color[4] = (uint8_t)iwarm;
|
||||
} else {
|
||||
sysCfg.led_color[0] = (uint8_t)icold;
|
||||
sysCfg.led_color[1] = (uint8_t)iwarm;
|
||||
Settings.led_color[0] = (uint8_t)icold;
|
||||
Settings.led_color[1] = (uint8_t)iwarm;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t sl_getColorTemp()
|
||||
uint16_t LightGetColorTemp()
|
||||
{
|
||||
uint8_t ct_idx = 0;
|
||||
if (5 == (sfl_flg &7)) {
|
||||
if (5 == (light_type &7)) {
|
||||
ct_idx = 3;
|
||||
}
|
||||
uint16_t my_ct = sysCfg.led_color[ct_idx +1];
|
||||
uint16_t my_ct = Settings.led_color[ct_idx +1];
|
||||
if (my_ct > 0) {
|
||||
return ((my_ct * 136) / 100) + 154;
|
||||
} else {
|
||||
my_ct = sysCfg.led_color[ct_idx];
|
||||
my_ct = Settings.led_color[ct_idx];
|
||||
return 499 - ((my_ct * 136) / 100);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setDim(uint8_t myDimmer)
|
||||
void LightSetDimmer(uint8_t myDimmer)
|
||||
{
|
||||
float temp;
|
||||
|
||||
if ((SONOFF_BN == sysCfg.module) && (100 == myDimmer)) {
|
||||
if ((SONOFF_BN == Settings.module) && (100 == myDimmer)) {
|
||||
myDimmer = 99; // BN-SZ01 starts flickering at dimmer = 100
|
||||
}
|
||||
float newDim = 100 / (float)myDimmer;
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
temp = (float)sysCfg.led_color[i] / newDim;
|
||||
float dimmer = 100 / (float)myDimmer;
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
temp = (float)Settings.led_color[i] / dimmer;
|
||||
sl_dcolor[i] = (uint8_t)temp;
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setColor()
|
||||
void LightSetColor()
|
||||
{
|
||||
uint8_t highest = 0;
|
||||
float temp;
|
||||
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
if (highest < sl_dcolor[i]) {
|
||||
highest = sl_dcolor[i];
|
||||
}
|
||||
}
|
||||
float mDim = (float)highest / 2.55;
|
||||
sysCfg.led_dimmer = (uint8_t)mDim;
|
||||
float newDim = 100 / mDim;
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
temp = (float)sl_dcolor[i] * newDim;
|
||||
sysCfg.led_color[i] = (uint8_t)temp;
|
||||
Settings.led_dimmer = (uint8_t)mDim;
|
||||
float dimmer = 100 / mDim;
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
temp = (float)sl_dcolor[i] * dimmer;
|
||||
Settings.led_color[i] = (uint8_t)temp;
|
||||
}
|
||||
}
|
||||
|
||||
char* sl_getColor(char* scolor)
|
||||
char* LightGetColor(char* scolor)
|
||||
{
|
||||
sl_setDim(sysCfg.led_dimmer);
|
||||
LightSetDimmer(Settings.led_dimmer);
|
||||
scolor[0] = '\0';
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
snprintf_P(scolor, 11, PSTR("%s%02X"), scolor, sl_dcolor[i]);
|
||||
}
|
||||
return scolor;
|
||||
}
|
||||
|
||||
void sl_prepPower()
|
||||
void LightPreparePower()
|
||||
{
|
||||
char scolor[11];
|
||||
char scommand[16];
|
||||
|
||||
if (sysCfg.led_dimmer && !(sl_power)) {
|
||||
do_cmnd_power(Maxdevice, 7); // No publishPowerState
|
||||
if (Settings.led_dimmer && !(sl_power)) {
|
||||
ExecuteCommandPower(devices_present, 7); // No publishPowerState
|
||||
}
|
||||
else if (!sysCfg.led_dimmer && sl_power) {
|
||||
do_cmnd_power(Maxdevice, 6); // No publishPowerState
|
||||
else if (!Settings.led_dimmer && sl_power) {
|
||||
ExecuteCommandPower(devices_present, 6); // No publishPowerState
|
||||
}
|
||||
#ifdef USE_DOMOTICZ
|
||||
// mqtt_publishDomoticzPowerState(1);
|
||||
domoticz_updatePowerState(Maxdevice);
|
||||
// MqttPublishDomoticzPowerState(1);
|
||||
DomoticzUpdatePowerState(devices_present);
|
||||
#endif // USE_DOMOTICZ
|
||||
|
||||
getPowerDevice(scommand, Maxdevice, sizeof(scommand));
|
||||
if ((sfl_flg &7) > 1) {
|
||||
GetPowerDevice(scommand, devices_present, sizeof(scommand));
|
||||
if ((light_type &7) > 1) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\", \"" D_CMND_DIMMER "\":%d, \"" D_CMND_COLOR "\":\"%s\"}"),
|
||||
scommand, getStateText(sl_power), sysCfg.led_dimmer, sl_getColor(scolor));
|
||||
scommand, GetStateText(sl_power), Settings.led_dimmer, LightGetColor(scolor));
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\", \"" D_CMND_DIMMER "\":%d}"),
|
||||
scommand, getStateText(sl_power), sysCfg.led_dimmer);
|
||||
scommand, GetStateText(sl_power), Settings.led_dimmer);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setPower(power_t mpower)
|
||||
void LightSetPower(uint8_t mpower)
|
||||
{
|
||||
sl_power = ((mpower & (1 << (Maxdevice -1))) != 0);
|
||||
sl_power = mpower;
|
||||
if (sl_wakeupActive) {
|
||||
sl_wakeupActive--;
|
||||
}
|
||||
if (sl_power) {
|
||||
sl_any = 1;
|
||||
}
|
||||
sl_animate();
|
||||
LightAnimate();
|
||||
}
|
||||
|
||||
void sl_animate()
|
||||
void LightAnimate()
|
||||
{
|
||||
// {"Wakeup":"Done"}
|
||||
uint8_t fadeValue;
|
||||
|
@ -337,29 +337,29 @@ void sl_animate()
|
|||
|
||||
stripTimerCntr++;
|
||||
if (!sl_power) { // Power Off
|
||||
sleep = sysCfg.sleep;
|
||||
sleep = Settings.sleep;
|
||||
stripTimerCntr = 0;
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
sl_tcolor[i] = 0;
|
||||
}
|
||||
}
|
||||
else {
|
||||
sleep = 0;
|
||||
switch (sysCfg.led_scheme) {
|
||||
switch (Settings.led_scheme) {
|
||||
case 0: // Power On
|
||||
sl_setDim(sysCfg.led_dimmer); // Power On
|
||||
if (0 == sysCfg.led_fade) {
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
LightSetDimmer(Settings.led_dimmer); // Power On
|
||||
if (0 == Settings.led_fade) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
sl_tcolor[i] = sl_dcolor[i];
|
||||
}
|
||||
} else {
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
if (sl_tcolor[i] != sl_dcolor[i]) {
|
||||
if (sl_tcolor[i] < sl_dcolor[i]) {
|
||||
sl_tcolor[i] += ((sl_dcolor[i] - sl_tcolor[i]) >> sysCfg.led_speed) +1;
|
||||
sl_tcolor[i] += ((sl_dcolor[i] - sl_tcolor[i]) >> Settings.led_speed) +1;
|
||||
}
|
||||
if (sl_tcolor[i] > sl_dcolor[i]) {
|
||||
sl_tcolor[i] -= ((sl_tcolor[i] - sl_dcolor[i]) >> sysCfg.led_speed) +1;
|
||||
sl_tcolor[i] -= ((sl_tcolor[i] - sl_dcolor[i]) >> Settings.led_speed) +1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -368,65 +368,65 @@ void sl_animate()
|
|||
case 1: // Power On using wake up duration
|
||||
if (2 == sl_wakeupActive) {
|
||||
sl_wakeupActive = 1;
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
sl_tcolor[i] = 0;
|
||||
}
|
||||
sl_wakeupCntr = 0;
|
||||
sl_wakeupDimmer = 0;
|
||||
}
|
||||
sl_wakeupCntr++;
|
||||
if (sl_wakeupCntr > ((sysCfg.led_wakeup * STATES) / sysCfg.led_dimmer)) {
|
||||
if (sl_wakeupCntr > ((Settings.led_wakeup * STATES) / Settings.led_dimmer)) {
|
||||
sl_wakeupCntr = 0;
|
||||
sl_wakeupDimmer++;
|
||||
if (sl_wakeupDimmer <= sysCfg.led_dimmer) {
|
||||
sl_setDim(sl_wakeupDimmer);
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
if (sl_wakeupDimmer <= Settings.led_dimmer) {
|
||||
LightSetDimmer(sl_wakeupDimmer);
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
sl_tcolor[i] = sl_dcolor[i];
|
||||
}
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_DONE "\"}"));
|
||||
mqtt_publish_topic_P(2, PSTR(D_CMND_WAKEUP));
|
||||
MqttPublishPrefixTopic_P(2, PSTR(D_CMND_WAKEUP));
|
||||
sl_wakeupActive = 0;
|
||||
sysCfg.led_scheme = 0;
|
||||
Settings.led_scheme = 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#ifdef USE_WS2812 // ************************************************************************
|
||||
default:
|
||||
if (11 == sfl_flg) {
|
||||
ws2812_showScheme(sysCfg.led_scheme -2);
|
||||
if (11 == light_type) {
|
||||
Ws2812ShowScheme(Settings.led_scheme -2);
|
||||
}
|
||||
#endif // USE_WS2812 ************************************************************************
|
||||
}
|
||||
}
|
||||
|
||||
if ((sysCfg.led_scheme < 2) || !sl_power) {
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
if ((Settings.led_scheme < 2) || !sl_power) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
if (sl_lcolor[i] != sl_tcolor[i]) {
|
||||
sl_any = 1;
|
||||
}
|
||||
}
|
||||
if (sl_any) {
|
||||
sl_any = 0;
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
sl_lcolor[i] = sl_tcolor[i];
|
||||
cur_col[i] = (sysCfg.led_table) ? ledTable[sl_lcolor[i]] : sl_lcolor[i];
|
||||
if (sfl_flg < 6) {
|
||||
cur_col[i] = (Settings.led_table) ? ledTable[sl_lcolor[i]] : sl_lcolor[i];
|
||||
if (light_type < 6) {
|
||||
if (pin[GPIO_PWM1 +i] < 99) {
|
||||
uint16_t curcol = cur_col[i] * (PWM_RANGE / 255);
|
||||
uint16_t curcol = cur_col[i] * (Settings.pwm_range / 255);
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_APPLICATION "Cur_Col%d %d, CurCol %d"), i, cur_col[i], curcol);
|
||||
// addLog(LOG_LEVEL_DEBUG);
|
||||
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? PWM_RANGE - curcol : curcol);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? Settings.pwm_range - curcol : curcol);
|
||||
}
|
||||
}
|
||||
}
|
||||
#ifdef USE_WS2812 // ************************************************************************
|
||||
if (11 == sfl_flg) {
|
||||
ws2812_setColor(0, cur_col[0], cur_col[1], cur_col[2]);
|
||||
if (11 == light_type) {
|
||||
Ws2812SetColor(0, cur_col[0], cur_col[1], cur_col[2]);
|
||||
}
|
||||
#endif // USE_ES2812 ************************************************************************
|
||||
if (sfl_flg > 11) {
|
||||
sl_my92x1_duty(cur_col[0], cur_col[1], cur_col[2], cur_col[3], cur_col[4]);
|
||||
if (light_type > 11) {
|
||||
LightMy92x1Duty(cur_col[0], cur_col[1], cur_col[2], cur_col[3], cur_col[4]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -440,9 +440,9 @@ float sl_Hue = 0.0;
|
|||
float sl_Sat = 0.0;
|
||||
float sl_Bri = 0.0;
|
||||
|
||||
void sl_rgb2hsb()
|
||||
void LightRgbToHsb()
|
||||
{
|
||||
sl_setDim(sysCfg.led_dimmer);
|
||||
LightSetDimmer(Settings.led_dimmer);
|
||||
|
||||
// convert colors to float between (0.0 - 1.0)
|
||||
float r = sl_dcolor[0] / 255.0f;
|
||||
|
@ -471,7 +471,7 @@ void sl_rgb2hsb()
|
|||
}
|
||||
}
|
||||
|
||||
void sl_hsb2rgb()
|
||||
void LightHsbToRgb()
|
||||
{
|
||||
float r;
|
||||
float g;
|
||||
|
@ -537,37 +537,37 @@ void sl_hsb2rgb()
|
|||
|
||||
/********************************************************************************************/
|
||||
|
||||
void sl_replaceHSB(String *response)
|
||||
void LightReplaceHsb(String *response)
|
||||
{
|
||||
if ((sfl_flg &7) > 2) {
|
||||
sl_rgb2hsb();
|
||||
if ((light_type &7) > 2) {
|
||||
LightRgbToHsb();
|
||||
response->replace("{h}", String((uint16_t)(65535.0f * sl_Hue)));
|
||||
response->replace("{s}", String((uint8_t)(254.0f * sl_Sat)));
|
||||
response->replace("{b}", String((uint8_t)(254.0f * sl_Bri)));
|
||||
} else {
|
||||
response->replace("{h}", "0");
|
||||
response->replace("{s}", "0");
|
||||
// response->replace("{b}", String((uint8_t)(2.54f * (float)sysCfg.led_dimmer)));
|
||||
response->replace("{b}", String((uint8_t)(0.01f * (float)sysCfg.led_dimmer)));
|
||||
// response->replace("{b}", String((uint8_t)(2.54f * (float)Settings.led_dimmer)));
|
||||
response->replace("{b}", String((uint8_t)(0.01f * (float)Settings.led_dimmer)));
|
||||
}
|
||||
}
|
||||
|
||||
void sl_getHSB(float *hue, float *sat, float *bri)
|
||||
void LightGetHsb(float *hue, float *sat, float *bri)
|
||||
{
|
||||
if ((sfl_flg &7) > 2) {
|
||||
sl_rgb2hsb();
|
||||
if ((light_type &7) > 2) {
|
||||
LightRgbToHsb();
|
||||
*hue = sl_Hue;
|
||||
*sat = sl_Sat;
|
||||
*bri = sl_Bri;
|
||||
} else {
|
||||
*hue = 0;
|
||||
*sat = 0;
|
||||
// *bri = (2.54f * (float)sysCfg.led_dimmer);
|
||||
*bri = (0.01f * (float)sysCfg.led_dimmer);
|
||||
// *bri = (2.54f * (float)Settings.led_dimmer);
|
||||
*bri = (0.01f * (float)Settings.led_dimmer);
|
||||
}
|
||||
}
|
||||
|
||||
void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
|
||||
void LightSetHsb(float hue, float sat, float bri, uint16_t ct)
|
||||
{
|
||||
/*
|
||||
char stemp1[10];
|
||||
|
@ -577,33 +577,33 @@ void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
|
|||
dtostrfi(sat, 3, stemp2);
|
||||
dtostrfi(bri, 3, stemp3);
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR("HUE: Set Hue %s, Sat %s, Bri %s, Ct %d"), stemp1, stemp2, stemp3, ct);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
*/
|
||||
|
||||
if (sfl_flg > 2) {
|
||||
if ((5 == (sfl_flg &7)) && (ct > 0)) {
|
||||
sl_setColorTemp(ct);
|
||||
if (light_type > 2) {
|
||||
if ((5 == (light_type &7)) && (ct > 0)) {
|
||||
LightSetColorTemp(ct);
|
||||
} else {
|
||||
sl_Hue = hue;
|
||||
sl_Sat = sat;
|
||||
sl_Bri = bri;
|
||||
sl_hsb2rgb();
|
||||
sl_setColor();
|
||||
LightHsbToRgb();
|
||||
LightSetColor();
|
||||
}
|
||||
sl_prepPower();
|
||||
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR));
|
||||
LightPreparePower();
|
||||
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_COLOR));
|
||||
} else {
|
||||
uint8_t tmp = (uint8_t)(bri * 100);
|
||||
sysCfg.led_dimmer = tmp;
|
||||
if (2 == (sfl_flg &7)) {
|
||||
Settings.led_dimmer = tmp;
|
||||
if (2 == (light_type &7)) {
|
||||
if (ct > 0) {
|
||||
sl_setColorTemp(ct);
|
||||
LightSetColorTemp(ct);
|
||||
}
|
||||
sl_prepPower();
|
||||
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR));
|
||||
LightPreparePower();
|
||||
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_COLOR));
|
||||
} else {
|
||||
sl_prepPower();
|
||||
mqtt_publish_topic_P(5, PSTR(D_CMND_DIMMER));
|
||||
LightPreparePower();
|
||||
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_DIMMER));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -612,94 +612,94 @@ void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
|
|||
* Commands
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean sl_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
boolean LightCommand(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
{
|
||||
boolean serviced = true;
|
||||
boolean coldim = false;
|
||||
char scolor[11];
|
||||
char *p;
|
||||
|
||||
if (((sfl_flg &7) > 1) && !strcasecmp_P(type, PSTR(D_CMND_COLOR))) {
|
||||
if (((light_type &7) > 1) && !strcasecmp_P(type, PSTR(D_CMND_COLOR))) {
|
||||
if (dataBuf[0] == '#') {
|
||||
dataBuf++;
|
||||
data_len--;
|
||||
}
|
||||
if ((2 * (sfl_flg &7)) == data_len) {
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
if ((2 * (light_type &7)) == data_len) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
strlcpy(scolor, dataBuf + (i *2), 3);
|
||||
sl_dcolor[i] = (uint8_t)strtol(scolor, &p, 16);
|
||||
}
|
||||
sl_setColor();
|
||||
LightSetColor();
|
||||
coldim = true;
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_COLOR "\":\"%s\"}"), sl_getColor(scolor));
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_COLOR "\":\"%s\"}"), LightGetColor(scolor));
|
||||
}
|
||||
}
|
||||
#ifdef USE_WS2812 // ***********************************************************************
|
||||
else if ((11 == sfl_flg) && !strcasecmp_P(type, PSTR(D_CMND_LED)) && (index > 0) && (index <= sysCfg.led_pixels)) {
|
||||
else if ((11 == light_type) && !strcasecmp_P(type, PSTR(D_CMND_LED)) && (index > 0) && (index <= Settings.led_pixels)) {
|
||||
if (dataBuf[0] == '#') {
|
||||
dataBuf++;
|
||||
data_len--;
|
||||
}
|
||||
uint8_t sl_ledcolor[3];
|
||||
if ((2 * (sfl_flg &7)) == data_len) {
|
||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
||||
if ((2 * (light_type &7)) == data_len) {
|
||||
for (byte i = 0; i < (light_type &7); i++) {
|
||||
strlcpy(scolor, dataBuf + (i *2), 3);
|
||||
sl_ledcolor[i] = (uint8_t)strtol(scolor, &p, 16);
|
||||
}
|
||||
ws2812_setColor(index, sl_ledcolor[0], sl_ledcolor[1], sl_ledcolor[2]);
|
||||
Ws2812SetColor(index, sl_ledcolor[0], sl_ledcolor[1], sl_ledcolor[2]);
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_LED "%d\":\"%s\"}"), index, ws2812_getColor(index, scolor));
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_LED "%d\":\"%s\"}"), index, Ws2812GetColor(index, scolor));
|
||||
}
|
||||
else if ((11 == sfl_flg) && !strcasecmp_P(type, PSTR(D_CMND_PIXELS))) {
|
||||
else if ((11 == light_type) && !strcasecmp_P(type, PSTR(D_CMND_PIXELS))) {
|
||||
if ((payload > 0) && (payload <= WS2812_MAX_LEDS)) {
|
||||
sysCfg.led_pixels = payload;
|
||||
ws2812_clear();
|
||||
Settings.led_pixels = payload;
|
||||
Ws2812Clear();
|
||||
sl_any = 1;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_PIXELS "\":%d}"), sysCfg.led_pixels);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_PIXELS "\":%d}"), Settings.led_pixels);
|
||||
}
|
||||
else if ((11 == sfl_flg) && !strcasecmp_P(type, PSTR(D_CMND_WIDTH))) {
|
||||
else if ((11 == light_type) && !strcasecmp_P(type, PSTR(D_CMND_WIDTH))) {
|
||||
if ((payload >= 0) && (payload <= 4)) {
|
||||
sysCfg.led_width = payload;
|
||||
Settings.led_width = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WIDTH "\":%d}"), sysCfg.led_width);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WIDTH "\":%d}"), Settings.led_width);
|
||||
}
|
||||
else if ((11 == sfl_flg) && !strcasecmp_P(type, PSTR(D_CMND_SCHEME))) {
|
||||
else if ((11 == light_type) && !strcasecmp_P(type, PSTR(D_CMND_SCHEME))) {
|
||||
if ((payload >= 0) && (payload <= 9)) {
|
||||
sysCfg.led_scheme = payload;
|
||||
if (1 == sysCfg.led_scheme) {
|
||||
Settings.led_scheme = payload;
|
||||
if (1 == Settings.led_scheme) {
|
||||
sl_wakeupActive = 3;
|
||||
}
|
||||
do_cmnd_power(Maxdevice, 1);
|
||||
ExecuteCommandPower(devices_present, 1);
|
||||
stripTimerCntr = 0;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SCHEME "\":%d}"), sysCfg.led_scheme);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SCHEME "\":%d}"), Settings.led_scheme);
|
||||
}
|
||||
#endif // USE_WS2812 ************************************************************************
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUP))) {
|
||||
if ((payload >= 0) && (payload <= 100)) {
|
||||
sysCfg.led_dimmer = payload;
|
||||
Settings.led_dimmer = payload;
|
||||
}
|
||||
sl_wakeupActive = 3;
|
||||
sysCfg.led_scheme = 1;
|
||||
do_cmnd_power(Maxdevice, 1);
|
||||
Settings.led_scheme = 1;
|
||||
ExecuteCommandPower(devices_present, 1);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_STARTED "\"}"));
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_COLORTEMPERATURE)) && ((2 == (sfl_flg &7)) || (5 == (sfl_flg &7)))) { // ColorTemp
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_COLORTEMPERATURE)) && ((2 == (light_type &7)) || (5 == (light_type &7)))) { // ColorTemp
|
||||
if ((payload >= 153) && (payload <= 500)) { // https://developers.meethue.com/documentation/core-concepts
|
||||
sl_setColorTemp(payload);
|
||||
LightSetColorTemp(payload);
|
||||
coldim = true;
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_COLORTEMPERATURE "\":%d}"), sl_getColorTemp());
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_COLORTEMPERATURE "\":%d}"), LightGetColorTemp());
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_DIMMER))) {
|
||||
if ((payload >= 0) && (payload <= 100)) {
|
||||
sysCfg.led_dimmer = payload;
|
||||
Settings.led_dimmer = payload;
|
||||
coldim = true;
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DIMMER "\":%d}"), sysCfg.led_dimmer);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_DIMMER "\":%d}"), Settings.led_dimmer);
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_LEDTABLE))) {
|
||||
|
@ -707,54 +707,54 @@ boolean sl_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len,
|
|||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
sysCfg.led_table = payload;
|
||||
Settings.led_table = payload;
|
||||
break;
|
||||
case 2: // Toggle
|
||||
sysCfg.led_table ^= 1;
|
||||
Settings.led_table ^= 1;
|
||||
break;
|
||||
}
|
||||
sl_any = 1;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_LEDTABLE "\":\"%s\"}"), getStateText(sysCfg.led_table));
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_LEDTABLE "\":\"%s\"}"), GetStateText(Settings.led_table));
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_FADE))) {
|
||||
switch (payload) {
|
||||
case 0: // Off
|
||||
case 1: // On
|
||||
sysCfg.led_fade = payload;
|
||||
Settings.led_fade = payload;
|
||||
break;
|
||||
case 2: // Toggle
|
||||
sysCfg.led_fade ^= 1;
|
||||
Settings.led_fade ^= 1;
|
||||
break;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_FADE "\":\"%s\"}"), getStateText(sysCfg.led_fade));
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_FADE "\":\"%s\"}"), GetStateText(Settings.led_fade));
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_SPEED))) { // 1 - fast, 8 - slow
|
||||
if ((payload > 0) && (payload <= 8)) {
|
||||
sysCfg.led_speed = payload;
|
||||
Settings.led_speed = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SPEED "\":%d}"), sysCfg.led_speed);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SPEED "\":%d}"), Settings.led_speed);
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUPDURATION))) {
|
||||
if ((payload > 0) && (payload < 3001)) {
|
||||
sysCfg.led_wakeup = payload;
|
||||
Settings.led_wakeup = payload;
|
||||
sl_wakeupActive = 0;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUPDURATION "\":%d}"), sysCfg.led_wakeup);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUPDURATION "\":%d}"), Settings.led_wakeup);
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR("UNDOCA"))) { // Theos legacy status
|
||||
sl_getColor(scolor);
|
||||
LightGetColor(scolor);
|
||||
scolor[6] = '\0'; // RGB only
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, %d, %d, %d, %d, %d"),
|
||||
scolor, sysCfg.led_fade, sysCfg.led_table, sysCfg.led_scheme, sysCfg.led_speed, sysCfg.led_width);
|
||||
mqtt_publish_topic_P(1, type);
|
||||
scolor, Settings.led_fade, Settings.led_table, Settings.led_scheme, Settings.led_speed, Settings.led_width);
|
||||
MqttPublishPrefixTopic_P(1, type);
|
||||
mqtt_data[0] = '\0';
|
||||
}
|
||||
else {
|
||||
serviced = false; // Unknown command
|
||||
}
|
||||
if (coldim) {
|
||||
sl_prepPower();
|
||||
LightPreparePower();
|
||||
}
|
||||
return serviced;
|
||||
}
|
||||
|
|
|
@ -55,29 +55,29 @@
|
|||
|
||||
uint16_t sc_value[5] = { 0 };
|
||||
|
||||
void sc_send(const char *data)
|
||||
void SonoffScSend(const char *data)
|
||||
{
|
||||
Serial.write(data);
|
||||
Serial.write('\x1B');
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SERIAL D_TRANSMIT " %s"), data);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
}
|
||||
|
||||
void sc_init()
|
||||
void SonoffScInit()
|
||||
{
|
||||
// sc_send("AT+DEVCONFIG=\"uploadFreq\":1800");
|
||||
sc_send("AT+START");
|
||||
// sc_send("AT+STATUS");
|
||||
// SonoffScSend("AT+DEVCONFIG=\"uploadFreq\":1800");
|
||||
SonoffScSend("AT+START");
|
||||
// SonoffScSend("AT+STATUS");
|
||||
}
|
||||
|
||||
void sc_rcvstat(char *rcvstat)
|
||||
void SonoffScSerialInput(char *rcvstat)
|
||||
{
|
||||
char *p;
|
||||
char *str;
|
||||
uint16_t value[5] = { 0 };
|
||||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SERIAL D_RECEIVED " %s"), rcvstat);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
if (!strncasecmp_P(rcvstat, PSTR("AT+UPDATE="), 10)) {
|
||||
int8_t i = -1;
|
||||
|
@ -91,13 +91,13 @@ void sc_rcvstat(char *rcvstat)
|
|||
sc_value[2] = (11 - sc_value[2]) * 10; // Invert light level
|
||||
sc_value[3] *= 10;
|
||||
sc_value[4] = (11 - sc_value[4]) * 10; // Invert dust level
|
||||
sc_send("AT+SEND=ok");
|
||||
SonoffScSend("AT+SEND=ok");
|
||||
} else {
|
||||
sc_send("AT+SEND=fail");
|
||||
SonoffScSend("AT+SEND=fail");
|
||||
}
|
||||
}
|
||||
else if (!strcasecmp_P(rcvstat, PSTR("AT+STATUS?"))) {
|
||||
sc_send("AT+STATUS=4");
|
||||
SonoffScSend("AT+STATUS=4");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -105,28 +105,28 @@ void sc_rcvstat(char *rcvstat)
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void sc_mqttPresent(uint8_t* djson)
|
||||
void MqttShowSonoffSC(uint8_t* djson)
|
||||
{
|
||||
if (sc_value[0] > 0) {
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
|
||||
float t = convertTemp(sc_value[1]);
|
||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
||||
float t = ConvertTemp(sc_value[1]);
|
||||
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||
float h = sc_value[0];
|
||||
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
|
||||
dtostrfd(h, Settings.flag.humidity_resolution, stemp2);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_LIGHT "\":%d, \"" D_NOISE "\":%d, \"" D_AIRQUALITY "\":%d"),
|
||||
mqtt_data, stemp1, stemp2, sc_value[2], sc_value[3], sc_value[4]);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
domoticz_sensor2(stemp1, stemp2);
|
||||
domoticz_sensor(DZ_ILLUMINANCE, sc_value[2]);
|
||||
DomoticzTempHumSensor(stemp1, stemp2);
|
||||
DomoticzSensor(DZ_ILLUMINANCE, sc_value[2]);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
String sc_webPresent()
|
||||
String WebShowSonoffSc()
|
||||
{
|
||||
String page = "";
|
||||
|
||||
|
@ -135,12 +135,12 @@ String sc_webPresent()
|
|||
char sensor[80];
|
||||
char scstype[] = "";
|
||||
|
||||
float t = convertTemp(sc_value[1]);
|
||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, scstype, stemp, tempUnit());
|
||||
float t = ConvertTemp(sc_value[1]);
|
||||
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, scstype, stemp, TempUnit());
|
||||
page += sensor;
|
||||
float h = sc_value[0];
|
||||
dtostrfi(h, sysCfg.flag.humidity_resolution, stemp);
|
||||
dtostrfi(h, Settings.flag.humidity_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, scstype, stemp);
|
||||
page += sensor;
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_LIGHT, scstype, sc_value[2]);
|
||||
|
|
|
@ -25,11 +25,11 @@
|
|||
|
||||
#define UDP_BUFFER_SIZE 200 // Max UDP buffer size needed for M-SEARCH message
|
||||
|
||||
boolean udpConnected = false;
|
||||
boolean udp_connected = false;
|
||||
|
||||
char packetBuffer[UDP_BUFFER_SIZE]; // buffer to hold incoming UDP packet
|
||||
char packet_buffer[UDP_BUFFER_SIZE]; // buffer to hold incoming UDP packet
|
||||
IPAddress ipMulticast(239, 255, 255, 250); // Simple Service Discovery Protocol (SSDP)
|
||||
uint32_t portMulticast = 1900; // Multicast address and port
|
||||
uint32_t port_multicast = 1900; // Multicast address and port
|
||||
|
||||
/*********************************************************************************************\
|
||||
* WeMo UPNP support routines
|
||||
|
@ -49,7 +49,7 @@ const char WEMO_MSEARCH[] PROGMEM =
|
|||
"X-User-Agent: redsonic\r\n"
|
||||
"\r\n";
|
||||
|
||||
String wemo_serial()
|
||||
String WemoSerialnumber()
|
||||
{
|
||||
char serial[16];
|
||||
|
||||
|
@ -57,31 +57,31 @@ String wemo_serial()
|
|||
return String(serial);
|
||||
}
|
||||
|
||||
String wemo_UUID()
|
||||
String WemoUuid()
|
||||
{
|
||||
char uuid[27];
|
||||
|
||||
snprintf_P(uuid, sizeof(uuid), PSTR("Socket-1_0-%s"), wemo_serial().c_str());
|
||||
snprintf_P(uuid, sizeof(uuid), PSTR("Socket-1_0-%s"), WemoSerialnumber().c_str());
|
||||
return String(uuid);
|
||||
}
|
||||
|
||||
void wemo_respondToMSearch()
|
||||
void WemoRespondToMSearch()
|
||||
{
|
||||
char message[TOPSZ];
|
||||
|
||||
if (portUDP.beginPacket(portUDP.remoteIP(), portUDP.remotePort())) {
|
||||
if (PortUdp.beginPacket(PortUdp.remoteIP(), PortUdp.remotePort())) {
|
||||
String response = FPSTR(WEMO_MSEARCH);
|
||||
response.replace("{r1}", WiFi.localIP().toString());
|
||||
response.replace("{r2}", wemo_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
response.replace("{r2}", WemoUuid());
|
||||
PortUdp.write(response.c_str());
|
||||
PortUdp.endPacket();
|
||||
snprintf_P(message, sizeof(message), PSTR(D_RESPONSE_SENT));
|
||||
} else {
|
||||
snprintf_P(message, sizeof(message), PSTR(D_FAILED_TO_SEND_RESPONSE));
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPNP D_WEMO " %s " D_TO " %s:%d"),
|
||||
message, portUDP.remoteIP().toString().c_str(), portUDP.remotePort());
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
message, PortUdp.remoteIP().toString().c_str(), PortUdp.remotePort());
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -113,7 +113,7 @@ const char HUE_ST3[] PROGMEM =
|
|||
"USN: uuid:{r3}\r\n"
|
||||
"\r\n";
|
||||
|
||||
String hue_bridgeid()
|
||||
String HueBridgeId()
|
||||
{
|
||||
String temp = WiFi.macAddress();
|
||||
temp.replace(":", "");
|
||||
|
@ -121,7 +121,7 @@ String hue_bridgeid()
|
|||
return bridgeid; // 5CCF7FFFFE139F3D
|
||||
}
|
||||
|
||||
String hue_serial()
|
||||
String HueSerialnumber()
|
||||
{
|
||||
String serial = WiFi.macAddress();
|
||||
serial.replace(":", "");
|
||||
|
@ -129,106 +129,106 @@ String hue_serial()
|
|||
return serial; // 5ccf7f139f3d
|
||||
}
|
||||
|
||||
String hue_UUID()
|
||||
String HueUuid()
|
||||
{
|
||||
String uuid = F("f6543a06-da50-11ba-8d8f-");
|
||||
uuid += hue_serial();
|
||||
uuid += HueSerialnumber();
|
||||
return uuid; // f6543a06-da50-11ba-8d8f-5ccf7f139f3d
|
||||
}
|
||||
|
||||
void hue_respondToMSearch()
|
||||
void HueRespondToMSearch()
|
||||
{
|
||||
char message[TOPSZ];
|
||||
|
||||
if (portUDP.beginPacket(portUDP.remoteIP(), portUDP.remotePort())) {
|
||||
if (PortUdp.beginPacket(PortUdp.remoteIP(), PortUdp.remotePort())) {
|
||||
String response1 = FPSTR(HUE_RESPONSE);
|
||||
response1.replace("{r1}", WiFi.localIP().toString());
|
||||
response1.replace("{r2}", hue_bridgeid());
|
||||
response1.replace("{r2}", HueBridgeId());
|
||||
|
||||
String response = response1;
|
||||
response += FPSTR(HUE_ST1);
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
response.replace("{r3}", HueUuid());
|
||||
PortUdp.write(response.c_str());
|
||||
PortUdp.endPacket();
|
||||
|
||||
response = response1;
|
||||
response += FPSTR(HUE_ST2);
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
response.replace("{r3}", HueUuid());
|
||||
PortUdp.write(response.c_str());
|
||||
PortUdp.endPacket();
|
||||
|
||||
response = response1;
|
||||
response += FPSTR(HUE_ST3);
|
||||
response.replace("{r3}", hue_UUID());
|
||||
portUDP.write(response.c_str());
|
||||
portUDP.endPacket();
|
||||
response.replace("{r3}", HueUuid());
|
||||
PortUdp.write(response.c_str());
|
||||
PortUdp.endPacket();
|
||||
|
||||
snprintf_P(message, sizeof(message), PSTR(D_3_RESPONSE_PACKETS_SENT));
|
||||
} else {
|
||||
snprintf_P(message, sizeof(message), PSTR(D_FAILED_TO_SEND_RESPONSE));
|
||||
}
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_UPNP D_HUE " %s " D_TO " %s:%d"),
|
||||
message, portUDP.remoteIP().toString().c_str(), portUDP.remotePort());
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
message, PortUdp.remoteIP().toString().c_str(), PortUdp.remotePort());
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Belkin WeMo and Philips Hue bridge UDP multicast support
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean UDP_Disconnect()
|
||||
boolean UdpDisconnect()
|
||||
{
|
||||
if (udpConnected) {
|
||||
if (udp_connected) {
|
||||
WiFiUDP::stopAll();
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP D_MULTICAST_DISABLED));
|
||||
udpConnected = false;
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP D_MULTICAST_DISABLED));
|
||||
udp_connected = false;
|
||||
}
|
||||
return udpConnected;
|
||||
return udp_connected;
|
||||
}
|
||||
|
||||
boolean UDP_Connect()
|
||||
boolean UdpConnect()
|
||||
{
|
||||
if (!udpConnected) {
|
||||
if (portUDP.beginMulticast(WiFi.localIP(), ipMulticast, portMulticast)) {
|
||||
addLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_REJOINED));
|
||||
udpConnected = true;
|
||||
if (!udp_connected) {
|
||||
if (PortUdp.beginMulticast(WiFi.localIP(), ipMulticast, port_multicast)) {
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_REJOINED));
|
||||
udp_connected = true;
|
||||
} else {
|
||||
addLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_JOIN_FAILED));
|
||||
udpConnected = false;
|
||||
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_JOIN_FAILED));
|
||||
udp_connected = false;
|
||||
}
|
||||
}
|
||||
return udpConnected;
|
||||
return udp_connected;
|
||||
}
|
||||
|
||||
void pollUDP()
|
||||
void PollUdp()
|
||||
{
|
||||
if (udpConnected) {
|
||||
if (portUDP.parsePacket()) {
|
||||
int len = portUDP.read(packetBuffer, UDP_BUFFER_SIZE -1);
|
||||
if (udp_connected) {
|
||||
if (PortUdp.parsePacket()) {
|
||||
int len = PortUdp.read(packet_buffer, UDP_BUFFER_SIZE -1);
|
||||
if (len > 0) {
|
||||
packetBuffer[len] = 0;
|
||||
packet_buffer[len] = 0;
|
||||
}
|
||||
String request = packetBuffer;
|
||||
String request = packet_buffer;
|
||||
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet received"));
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, packetBuffer);
|
||||
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: Packet received"));
|
||||
// AddLog_P(LOG_LEVEL_DEBUG_MORE, packet_buffer);
|
||||
|
||||
if (request.indexOf("M-SEARCH") >= 0) {
|
||||
request.toLowerCase();
|
||||
request.replace(" ", "");
|
||||
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: M-SEARCH Packet received"));
|
||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, request.c_str());
|
||||
// AddLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: M-SEARCH Packet received"));
|
||||
// AddLog_P(LOG_LEVEL_DEBUG_MORE, request.c_str());
|
||||
|
||||
if ((EMUL_WEMO == sysCfg.flag.emulation) && (request.indexOf(F("urn:belkin:device:**")) > 0)) {
|
||||
wemo_respondToMSearch();
|
||||
if ((EMUL_WEMO == Settings.flag.emulation) && (request.indexOf(F("urn:belkin:device:**")) > 0)) {
|
||||
WemoRespondToMSearch();
|
||||
}
|
||||
else if ((EMUL_HUE == sysCfg.flag.emulation) &&
|
||||
else if ((EMUL_HUE == Settings.flag.emulation) &&
|
||||
((request.indexOf(F("st:urn:schemas-upnp-org:device:basic:1")) > 0) ||
|
||||
(request.indexOf(F("st:upnp:rootdevice")) > 0) ||
|
||||
(request.indexOf(F("st:ssdpsearch:all")) > 0) ||
|
||||
(request.indexOf(F("st:ssdp:all")) > 0))) {
|
||||
hue_respondToMSearch();
|
||||
HueRespondToMSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -295,36 +295,36 @@ const char WEMO_SETUP_XML[] PROGMEM =
|
|||
|
||||
/********************************************************************************************/
|
||||
|
||||
void handleUPnPevent()
|
||||
void HandleUpnpEvent()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT));
|
||||
String request = webServer->arg(0);
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT));
|
||||
String request = WebServer->arg(0);
|
||||
if (request.indexOf(F("State>1</Binary")) > 0) {
|
||||
// do_cmnd_power(1, 1);
|
||||
do_cmnd_power(Maxdevice, 1);
|
||||
// ExecuteCommandPower(1, 1);
|
||||
ExecuteCommandPower(devices_present, 1);
|
||||
}
|
||||
if (request.indexOf(F("State>0</Binary")) > 0) {
|
||||
// do_cmnd_power(1, 0);
|
||||
do_cmnd_power(Maxdevice, 0);
|
||||
// ExecuteCommandPower(1, 0);
|
||||
ExecuteCommandPower(devices_present, 0);
|
||||
}
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_PLAIN), "");
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_PLAIN), "");
|
||||
}
|
||||
|
||||
void handleUPnPservice()
|
||||
void HandleUpnpService()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_EVENT_SERVICE));
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_PLAIN), FPSTR(WEMO_EVENTSERVICE_XML));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_EVENT_SERVICE));
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_PLAIN), FPSTR(WEMO_EVENTSERVICE_XML));
|
||||
}
|
||||
|
||||
void handleUPnPsetupWemo()
|
||||
void HandleUpnpSetupWemo()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_SETUP));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_SETUP));
|
||||
|
||||
String setup_xml = FPSTR(WEMO_SETUP_XML);
|
||||
setup_xml.replace("{x1}", sysCfg.friendlyname[0]);
|
||||
setup_xml.replace("{x2}", wemo_UUID());
|
||||
setup_xml.replace("{x3}", wemo_serial());
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_XML), setup_xml);
|
||||
setup_xml.replace("{x1}", Settings.friendlyname[0]);
|
||||
setup_xml.replace("{x2}", WemoUuid());
|
||||
setup_xml.replace("{x3}", WemoSerialnumber());
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_XML), setup_xml);
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
|
@ -353,7 +353,7 @@ const char HUE_DESCRIPTION_XML[] PROGMEM =
|
|||
"</device>"
|
||||
"</root>\r\n"
|
||||
"\r\n";
|
||||
const char HUE_LIGHT_STATUS_JSON[] PROGMEM =
|
||||
const char HueLightStatus_JSON[] PROGMEM =
|
||||
"\"on\":{state},"
|
||||
"\"bri\":{b},"
|
||||
"\"hue\":{h},"
|
||||
|
@ -377,7 +377,7 @@ const char HUE_GROUP0_STATUS_JSON[] PROGMEM =
|
|||
"\"type\":\"LightGroup\","
|
||||
"\"action\":{";
|
||||
// "\"scene\":\"none\",";
|
||||
const char HUE_CONFIG_RESPONSE_JSON[] PROGMEM =
|
||||
const char HueConfigResponse_JSON[] PROGMEM =
|
||||
"{\"name\":\"Philips hue\","
|
||||
"\"mac\":\"{mac}\","
|
||||
"\"dhcp\":true,"
|
||||
|
@ -405,14 +405,14 @@ const char HUE_ERROR_JSON[] PROGMEM =
|
|||
|
||||
/********************************************************************************************/
|
||||
|
||||
String hue_deviceId(uint8_t id)
|
||||
String GetHueDeviceId(uint8_t id)
|
||||
{
|
||||
String deviceid = WiFi.macAddress() + F(":00:11-") + String(id);
|
||||
deviceid.toLowerCase();
|
||||
return deviceid; // 5c:cf:7f:13:9f:3d:00:11-1
|
||||
}
|
||||
|
||||
String hue_userId()
|
||||
String GetHueUserId()
|
||||
{
|
||||
char userid[7];
|
||||
|
||||
|
@ -420,50 +420,50 @@ String hue_userId()
|
|||
return String(userid);
|
||||
}
|
||||
|
||||
void handleUPnPsetupHue()
|
||||
void HandleUpnpSetupHue()
|
||||
{
|
||||
addLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_HUE_BRIDGE_SETUP));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_HUE_BRIDGE_SETUP));
|
||||
String description_xml = FPSTR(HUE_DESCRIPTION_XML);
|
||||
description_xml.replace("{x1}", WiFi.localIP().toString());
|
||||
description_xml.replace("{x2}", hue_UUID());
|
||||
description_xml.replace("{x3}", hue_serial());
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_XML), description_xml);
|
||||
description_xml.replace("{x2}", HueUuid());
|
||||
description_xml.replace("{x3}", HueSerialnumber());
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_XML), description_xml);
|
||||
}
|
||||
|
||||
void hue_todo(String *path)
|
||||
void HueNotImplemented(String *path)
|
||||
{
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_API_NOT_IMPLEMENTED " (%s)"), path->c_str());
|
||||
addLog(LOG_LEVEL_DEBUG_MORE);
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE);
|
||||
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), "{}");
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), "{}");
|
||||
}
|
||||
|
||||
void hue_config_response(String *response)
|
||||
void HueConfigResponse(String *response)
|
||||
{
|
||||
*response += FPSTR(HUE_CONFIG_RESPONSE_JSON);
|
||||
*response += FPSTR(HueConfigResponse_JSON);
|
||||
response->replace("{mac}", WiFi.macAddress());
|
||||
response->replace("{ip}", WiFi.localIP().toString());
|
||||
response->replace("{mask}", WiFi.subnetMask().toString());
|
||||
response->replace("{gw}", WiFi.gatewayIP().toString());
|
||||
response->replace("{bid}", hue_bridgeid());
|
||||
response->replace("{dt}", getUTCDateTime());
|
||||
response->replace("{id}", hue_userId());
|
||||
response->replace("{bid}", HueBridgeId());
|
||||
response->replace("{dt}", GetUtcDateAndTime());
|
||||
response->replace("{id}", GetHueUserId());
|
||||
}
|
||||
|
||||
void hue_config(String *path)
|
||||
void HueConfig(String *path)
|
||||
{
|
||||
String response = "";
|
||||
hue_config_response(&response);
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
HueConfigResponse(&response);
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void hue_light_status(byte device, String *response)
|
||||
void HueLightStatus(byte device, String *response)
|
||||
{
|
||||
*response += FPSTR(HUE_LIGHT_STATUS_JSON);
|
||||
*response += FPSTR(HueLightStatus_JSON);
|
||||
response->replace("{state}", (power & (1 << (device-1))) ? "true" : "false");
|
||||
|
||||
if (sfl_flg) {
|
||||
sl_replaceHSB(response);
|
||||
if (light_type) {
|
||||
LightReplaceHsb(response);
|
||||
} else {
|
||||
response->replace("{h}", "0");
|
||||
response->replace("{s}", "0");
|
||||
|
@ -471,40 +471,40 @@ void hue_light_status(byte device, String *response)
|
|||
}
|
||||
}
|
||||
|
||||
void hue_global_cfg(String *path)
|
||||
void HueGlobalConfig(String *path)
|
||||
{
|
||||
String response;
|
||||
uint8_t maxhue = (Maxdevice > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : Maxdevice;
|
||||
uint8_t maxhue = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;
|
||||
|
||||
path->remove(0,1); // cut leading / to get <id>
|
||||
response = F("{\"lights\":{\"");
|
||||
for (uint8_t i = 1; i <= maxhue; i++) {
|
||||
response += i;
|
||||
response += F("\":{\"state\":{");
|
||||
hue_light_status(i, &response);
|
||||
HueLightStatus(i, &response);
|
||||
response += "},";
|
||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
||||
response.replace("{j2}", hue_deviceId(i));
|
||||
response.replace("{j1}", Settings.friendlyname[i-1]);
|
||||
response.replace("{j2}", GetHueDeviceId(i));
|
||||
if (i < maxhue) {
|
||||
response += ",\"";
|
||||
}
|
||||
}
|
||||
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
|
||||
hue_config_response(&response);
|
||||
HueConfigResponse(&response);
|
||||
response += "}";
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void hue_auth(String *path)
|
||||
void HueAuthentication(String *path)
|
||||
{
|
||||
char response[38];
|
||||
|
||||
snprintf_P(response, sizeof(response), PSTR("[{\"success\":{\"username\":\"%s\"}}]"), hue_userId().c_str());
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
snprintf_P(response, sizeof(response), PSTR("[{\"success\":{\"username\":\"%s\"}}]"), GetHueUserId().c_str());
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void hue_lights(String *path)
|
||||
void HueLights(String *path)
|
||||
{
|
||||
/*
|
||||
* http://sonoff/api/username/lights/1/state?1={"on":true,"hue":56100,"sat":254,"bri":254,"alert":"none","transitiontime":40}
|
||||
|
@ -521,7 +521,7 @@ void hue_lights(String *path)
|
|||
bool on = false;
|
||||
bool change = false;
|
||||
char id[4];
|
||||
uint8_t maxhue = (Maxdevice > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : Maxdevice;
|
||||
uint8_t maxhue = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;
|
||||
|
||||
path->remove(0,path->indexOf("/lights")); // Remove until /lights
|
||||
if (path->endsWith("/lights")) { // Got /lights
|
||||
|
@ -529,17 +529,17 @@ void hue_lights(String *path)
|
|||
for (uint8_t i = 1; i <= maxhue; i++) {
|
||||
response += i;
|
||||
response += F("\":{\"state\":{");
|
||||
hue_light_status(i, &response);
|
||||
HueLightStatus(i, &response);
|
||||
response += "},";
|
||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
||||
response.replace("{j2}", hue_deviceId(i));
|
||||
response.replace("{j1}", Settings.friendlyname[i-1]);
|
||||
response.replace("{j2}", GetHueDeviceId(i));
|
||||
if (i < maxhue) {
|
||||
response += ",\"";
|
||||
}
|
||||
}
|
||||
response += "}";
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
else if (path->endsWith("/state")) { // Got ID/state
|
||||
path->remove(0,8); // Remove /lights/
|
||||
|
@ -548,11 +548,11 @@ void hue_lights(String *path)
|
|||
if ((device < 1) || (device > maxhue)) {
|
||||
device = 1;
|
||||
}
|
||||
if (1 == webServer->args()) {
|
||||
if (1 == WebServer->args()) {
|
||||
response = "[";
|
||||
|
||||
StaticJsonBuffer<400> jsonBuffer;
|
||||
JsonObject &hue_json = jsonBuffer.parseObject(webServer->arg(0));
|
||||
JsonObject &hue_json = jsonBuffer.parseObject(WebServer->arg(0));
|
||||
if (hue_json.containsKey("on")) {
|
||||
|
||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||
|
@ -562,10 +562,10 @@ void hue_lights(String *path)
|
|||
on = hue_json["on"];
|
||||
switch(on)
|
||||
{
|
||||
case false : do_cmnd_power(device, 0);
|
||||
case false : ExecuteCommandPower(device, 0);
|
||||
response.replace("{res}", "false");
|
||||
break;
|
||||
case true : do_cmnd_power(device, 1);
|
||||
case true : ExecuteCommandPower(device, 1);
|
||||
response.replace("{res}", "true");
|
||||
break;
|
||||
default : response.replace("{res}", (power & (1 << (device-1))) ? "true" : "false");
|
||||
|
@ -574,8 +574,8 @@ void hue_lights(String *path)
|
|||
resp = true;
|
||||
}
|
||||
|
||||
if (sfl_flg) {
|
||||
sl_getHSB(&hue,&sat,&bri);
|
||||
if (light_type) {
|
||||
LightGetHsb(&hue,&sat,&bri);
|
||||
}
|
||||
|
||||
if (hue_json.containsKey("bri")) {
|
||||
|
@ -628,8 +628,8 @@ void hue_lights(String *path)
|
|||
change = true;
|
||||
}
|
||||
if (change) {
|
||||
if (sfl_flg) {
|
||||
sl_setHSB(hue, sat, bri, ct);
|
||||
if (light_type) {
|
||||
LightSetHsb(hue, sat, bri, ct);
|
||||
}
|
||||
change = false;
|
||||
}
|
||||
|
@ -642,7 +642,7 @@ void hue_lights(String *path)
|
|||
response = FPSTR(HUE_ERROR_JSON);
|
||||
}
|
||||
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
else if(path->indexOf("/lights/") >= 0) { // Got /lights/ID
|
||||
path->remove(0,8); // Remove /lights/
|
||||
|
@ -651,25 +651,25 @@ void hue_lights(String *path)
|
|||
device = 1;
|
||||
}
|
||||
response += F("{\"state\":{");
|
||||
hue_light_status(device, &response);
|
||||
HueLightStatus(device, &response);
|
||||
response += "},";
|
||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||
response.replace("{j1}", sysCfg.friendlyname[device-1]);
|
||||
response.replace("{j2}", hue_deviceId(device));
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
response.replace("{j1}", Settings.friendlyname[device-1]);
|
||||
response.replace("{j2}", GetHueDeviceId(device));
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
else {
|
||||
webServer->send(406, FPSTR(HDR_CTYPE_JSON), "{}");
|
||||
WebServer->send(406, FPSTR(HDR_CTYPE_JSON), "{}");
|
||||
}
|
||||
}
|
||||
|
||||
void hue_groups(String *path)
|
||||
void HueGroups(String *path)
|
||||
{
|
||||
/*
|
||||
* http://sonoff/api/username/groups?1={"name":"Woonkamer","lights":[],"type":"Room","class":"Living room"})
|
||||
*/
|
||||
String response = "{}";
|
||||
uint8_t maxhue = (Maxdevice > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : Maxdevice;
|
||||
uint8_t maxhue = (devices_present > MAX_FRIENDLYNAMES) ? MAX_FRIENDLYNAMES : devices_present;
|
||||
|
||||
if (path->endsWith("/0")) {
|
||||
response = FPSTR(HUE_GROUP0_STATUS_JSON);
|
||||
|
@ -678,14 +678,14 @@ void hue_groups(String *path)
|
|||
lights += ",\"" + String(i) + "\"";
|
||||
}
|
||||
response.replace("{l1}", lights);
|
||||
hue_light_status(1, &response);
|
||||
HueLightStatus(1, &response);
|
||||
response += F("}}");
|
||||
}
|
||||
|
||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||
}
|
||||
|
||||
void handle_hue_api(String *path)
|
||||
void HandleHueApi(String *path)
|
||||
{
|
||||
/* HUE API uses /api/<userid>/<command> syntax. The userid is created by the echo device and
|
||||
* on original HUE the pressed button allows for creation of this user. We simply ignore the
|
||||
|
@ -699,24 +699,24 @@ void handle_hue_api(String *path)
|
|||
path->remove(0, 4); // remove /api
|
||||
uint16_t apilen = path->length();
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_API " (%s)"), path->c_str());
|
||||
addLog(LOG_LEVEL_DEBUG_MORE); // HTP: Hue API (//lights/1/state)
|
||||
for (args = 0; args < webServer->args(); args++) {
|
||||
String json = webServer->arg(args);
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE); // HTP: Hue API (//lights/1/state)
|
||||
for (args = 0; args < WebServer->args(); args++) {
|
||||
String json = WebServer->arg(args);
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_POST_ARGS " (%s)"), json.c_str());
|
||||
addLog(LOG_LEVEL_DEBUG_MORE); // HTP: Hue POST args ({"on":false})
|
||||
AddLog(LOG_LEVEL_DEBUG_MORE); // HTP: Hue POST args ({"on":false})
|
||||
}
|
||||
|
||||
if (path->endsWith("/invalid/")) {} // Just ignore
|
||||
else if (!apilen) hue_auth(path); // New HUE App setup
|
||||
else if (path->endsWith("/")) hue_auth(path); // New HUE App setup
|
||||
else if (path->endsWith("/config")) hue_config(path);
|
||||
else if (path->indexOf("/lights") >= 0) hue_lights(path);
|
||||
else if (path->indexOf("/groups") >= 0) hue_groups(path);
|
||||
else if (path->endsWith("/schedules")) hue_todo(path);
|
||||
else if (path->endsWith("/sensors")) hue_todo(path);
|
||||
else if (path->endsWith("/scenes")) hue_todo(path);
|
||||
else if (path->endsWith("/rules")) hue_todo(path);
|
||||
else hue_global_cfg(path);
|
||||
else if (!apilen) HueAuthentication(path); // New HUE App setup
|
||||
else if (path->endsWith("/")) HueAuthentication(path); // New HUE App setup
|
||||
else if (path->endsWith("/config")) HueConfig(path);
|
||||
else if (path->indexOf("/lights") >= 0) HueLights(path);
|
||||
else if (path->indexOf("/groups") >= 0) HueGroups(path);
|
||||
else if (path->endsWith("/schedules")) HueNotImplemented(path);
|
||||
else if (path->endsWith("/sensors")) HueNotImplemented(path);
|
||||
else if (path->endsWith("/scenes")) HueNotImplemented(path);
|
||||
else if (path->endsWith("/rules")) HueNotImplemented(path);
|
||||
else HueGlobalConfig(path);
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
#endif // USE_EMULATION
|
||||
|
|
|
@ -38,45 +38,44 @@
|
|||
#endif // USE_WS2812_CTYPE
|
||||
#endif // USE_WS2812_DMA
|
||||
|
||||
struct wsColor {
|
||||
struct WsColor {
|
||||
uint8_t red, green, blue;
|
||||
};
|
||||
|
||||
struct ColorScheme {
|
||||
wsColor* colors;
|
||||
WsColor* colors;
|
||||
uint8_t count;
|
||||
};
|
||||
|
||||
wsColor incandescent[2] = { 255, 140, 20, 0, 0, 0 };
|
||||
wsColor rgb[3] = { 255, 0, 0, 0, 255, 0, 0, 0, 255 };
|
||||
wsColor christmas[2] = { 255, 0, 0, 0, 255, 0 };
|
||||
wsColor hanukkah[2] = { 0, 0, 255, 255, 255, 255 };
|
||||
wsColor kwanzaa[3] = { 255, 0, 0, 0, 0, 0, 0, 255, 0 };
|
||||
wsColor rainbow[7] = { 255, 0, 0, 255, 128, 0, 255, 255, 0, 0, 255, 0, 0, 0, 255, 128, 0, 255, 255, 0, 255 };
|
||||
wsColor fire[3] = { 255, 0, 0, 255, 102, 0, 255, 192, 0 };
|
||||
ColorScheme schemes[7] = {
|
||||
incandescent, 2,
|
||||
rgb, 3,
|
||||
christmas, 2,
|
||||
hanukkah, 2,
|
||||
WsColor kIncandescent[2] = { 255, 140, 20, 0, 0, 0 };
|
||||
WsColor kRgb[3] = { 255, 0, 0, 0, 255, 0, 0, 0, 255 };
|
||||
WsColor kChristmas[2] = { 255, 0, 0, 0, 255, 0 };
|
||||
WsColor kHanukkah[2] = { 0, 0, 255, 255, 255, 255 };
|
||||
WsColor kwanzaa[3] = { 255, 0, 0, 0, 0, 0, 0, 255, 0 };
|
||||
WsColor kRainbow[7] = { 255, 0, 0, 255, 128, 0, 255, 255, 0, 0, 255, 0, 0, 0, 255, 128, 0, 255, 255, 0, 255 };
|
||||
WsColor kFire[3] = { 255, 0, 0, 255, 102, 0, 255, 192, 0 };
|
||||
ColorScheme kSchemes[7] = {
|
||||
kIncandescent, 2,
|
||||
kRgb, 3,
|
||||
kChristmas, 2,
|
||||
kHanukkah, 2,
|
||||
kwanzaa, 3,
|
||||
rainbow, 7,
|
||||
fire, 3 };
|
||||
kRainbow, 7,
|
||||
kFire, 3 };
|
||||
|
||||
uint8_t widthValues[5] = {
|
||||
uint8_t kWidth[5] = {
|
||||
1, // Small
|
||||
2, // Medium
|
||||
4, // Large
|
||||
8, // Largest
|
||||
255 }; // All
|
||||
uint8_t repeatValues[5] = {
|
||||
uint8_t kRepeat[5] = {
|
||||
8, // Small
|
||||
6, // Medium
|
||||
4, // Large
|
||||
2, // Largest
|
||||
1 }; // All
|
||||
|
||||
uint8_t speedValues[9] = {
|
||||
uint8_t kSpeed[9] = {
|
||||
0, // None
|
||||
1 * (STATES / 10), // Fastest
|
||||
3 * (STATES / 10),
|
||||
|
@ -87,16 +86,16 @@ uint8_t speedValues[9] = {
|
|||
13 * (STATES / 10),
|
||||
15 * (STATES / 10) }; // Slowest
|
||||
|
||||
uint8_t ws2812_showNext = 1;
|
||||
uint8_t ws_show_next = 1;
|
||||
|
||||
/********************************************************************************************/
|
||||
|
||||
void ws2812_stripShow()
|
||||
void Ws2812StripShow()
|
||||
{
|
||||
RgbColor c;
|
||||
|
||||
if (sysCfg.led_table) {
|
||||
for (uint16_t i = 0; i < sysCfg.led_pixels; i++) {
|
||||
if (Settings.led_table) {
|
||||
for (uint16_t i = 0; i < Settings.led_pixels; i++) {
|
||||
c = strip->GetPixelColor(i);
|
||||
strip->SetPixelColor(i, RgbColor(ledTable[c.R], ledTable[c.G], ledTable[c.B]));
|
||||
}
|
||||
|
@ -113,44 +112,64 @@ int mod(int a, int b)
|
|||
return ret;
|
||||
}
|
||||
|
||||
void ws2812_clock()
|
||||
#define cmin(a,b) ((a)<(b)?(a):(b))
|
||||
|
||||
void Ws2812UpdatePixelColor(int position, struct RgbColor hand_color, uint8_t hand)
|
||||
{
|
||||
RgbColor color;
|
||||
|
||||
uint16_t mod_position = mod(position, (int)Settings.led_pixels);
|
||||
|
||||
color = strip->GetPixelColor(mod_position);
|
||||
float dimmer = 100 / (float)Settings.led_dimmer;
|
||||
uint8_t offset = 1 << hand;
|
||||
color.R = cmin(color.R + ((hand_color.R / dimmer) / offset), 255);
|
||||
color.G = cmin(color.G + ((hand_color.G / dimmer) / offset), 255);
|
||||
color.B = cmin(color.B + ((hand_color.B / dimmer) / offset), 255);
|
||||
strip->SetPixelColor(mod_position, color);
|
||||
}
|
||||
|
||||
void Ws2812UpdateHand(int position, uint8_t width, struct RgbColor hand_color)
|
||||
{
|
||||
boolean clock_reverse = CLOCK_REVERSE;
|
||||
|
||||
if (clock_reverse) {
|
||||
position = Settings.led_pixels -position;
|
||||
}
|
||||
Ws2812UpdatePixelColor(position, hand_color, 0);
|
||||
for (uint8_t h = 1; h <= ((width -1) / 2); h++) {
|
||||
Ws2812UpdatePixelColor(position -h, hand_color, h);
|
||||
Ws2812UpdatePixelColor(position +h, hand_color, h);
|
||||
}
|
||||
}
|
||||
|
||||
void Ws2812Clock()
|
||||
{
|
||||
RgbColor c;
|
||||
|
||||
uint8_t hand_second_width = CLOCK_SECOND_WIDTH;
|
||||
uint8_t hand_minute_width = CLOCK_MINUTE_WIDTH;
|
||||
uint8_t hand_hour_width = CLOCK_HOUR_WIDTH;
|
||||
RgbColor hand_second_color CLOCK_SECOND_COLOR;
|
||||
RgbColor hand_minute_color CLOCK_MINUTE_COLOR;
|
||||
RgbColor hand_hour_color CLOCK_HOUR_COLOR;
|
||||
|
||||
strip->ClearTo(0); // Reset strip
|
||||
float newDim = 100 / (float)sysCfg.led_dimmer;
|
||||
float f1 = 255 / newDim;
|
||||
uint8_t i1 = (uint8_t)f1;
|
||||
float f2 = 127 / newDim;
|
||||
uint8_t i2 = (uint8_t)f2;
|
||||
float f3 = 63 / newDim;
|
||||
uint8_t i3 = (uint8_t)f3;
|
||||
int clksize = 600 / (int)Settings.led_pixels;
|
||||
Ws2812UpdateHand((RtcTime.second * 10) / clksize, hand_second_width, hand_second_color);
|
||||
Ws2812UpdateHand((RtcTime.minute * 10) / clksize, hand_minute_width, hand_minute_color);
|
||||
Ws2812UpdateHand((RtcTime.hour % 12) * (50 / clksize), hand_hour_width, hand_hour_color);
|
||||
|
||||
int j = sysCfg.led_pixels;
|
||||
int clksize = 600 / j;
|
||||
int i = (rtcTime.Second * 10) / clksize;
|
||||
|
||||
c = strip->GetPixelColor(mod(i, j)); c.B = i1; strip->SetPixelColor(mod(i, j), c);
|
||||
i = (rtcTime.Minute * 10) / clksize;
|
||||
c = strip->GetPixelColor(mod(i -1, j)); c.G = i3; strip->SetPixelColor(mod(i -1, j), c);
|
||||
c = strip->GetPixelColor(mod(i, j)); c.G = i1; strip->SetPixelColor(mod(i, j), c);
|
||||
c = strip->GetPixelColor(mod(i +1, j)); c.G = i3; strip->SetPixelColor(mod(i +1, j), c);
|
||||
i = (rtcTime.Hour % 12 * 5 + rtcTime.Minute / 12 ) * 10 / clksize;
|
||||
c = strip->GetPixelColor(mod(i -2, j)); c.R = i3; strip->SetPixelColor(mod(i -2, j), c);
|
||||
c = strip->GetPixelColor(mod(i -1, j)); c.R = i2; strip->SetPixelColor(mod(i -1, j), c);
|
||||
c = strip->GetPixelColor(mod(i, j)); c.R = i1; strip->SetPixelColor(mod(i, j), c);
|
||||
c = strip->GetPixelColor(mod(i +1, j)); c.R = i2; strip->SetPixelColor(mod(i +1, j), c);
|
||||
c = strip->GetPixelColor(mod(i +2, j)); c.R = i3; strip->SetPixelColor(mod(i +2, j), c);
|
||||
ws2812_stripShow();
|
||||
Ws2812StripShow();
|
||||
}
|
||||
|
||||
void ws2812_gradientColor(uint8_t schemenr, struct wsColor* mColor, uint16_t range, uint16_t gradRange, uint16_t i)
|
||||
void Ws2812GradientColor(uint8_t schemenr, struct WsColor* mColor, uint16_t range, uint16_t gradRange, uint16_t i)
|
||||
{
|
||||
/*
|
||||
* Compute the color of a pixel at position i using a gradient of the color scheme.
|
||||
* This function is used internally by the gradient function.
|
||||
*/
|
||||
ColorScheme scheme = schemes[schemenr];
|
||||
ColorScheme scheme = kSchemes[schemenr];
|
||||
uint16_t curRange = i / range;
|
||||
uint16_t rangeIndex = i % range;
|
||||
uint16_t colorIndex = rangeIndex / gradRange;
|
||||
|
@ -160,16 +179,16 @@ void ws2812_gradientColor(uint8_t schemenr, struct wsColor* mColor, uint16_t ran
|
|||
start = (scheme.count -1) - start;
|
||||
end = (scheme.count -1) - end;
|
||||
}
|
||||
float newDim = 100 / (float)sysCfg.led_dimmer;
|
||||
float fmyRed = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].red, scheme.colors[end].red) / newDim;
|
||||
float fmyGrn = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].green, scheme.colors[end].green) / newDim;
|
||||
float fmyBlu = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].blue, scheme.colors[end].blue) / newDim;
|
||||
float dimmer = 100 / (float)Settings.led_dimmer;
|
||||
float fmyRed = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].red, scheme.colors[end].red) / dimmer;
|
||||
float fmyGrn = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].green, scheme.colors[end].green) / dimmer;
|
||||
float fmyBlu = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].blue, scheme.colors[end].blue) / dimmer;
|
||||
mColor->red = (uint8_t)fmyRed;
|
||||
mColor->green = (uint8_t)fmyGrn;
|
||||
mColor->blue = (uint8_t)fmyBlu;
|
||||
}
|
||||
|
||||
void ws2812_gradient(uint8_t schemenr)
|
||||
void Ws2812Gradient(uint8_t schemenr)
|
||||
{
|
||||
/*
|
||||
* This routine courtesy Tony DiCola (Adafruit)
|
||||
|
@ -178,28 +197,28 @@ void ws2812_gradient(uint8_t schemenr)
|
|||
*/
|
||||
RgbColor c;
|
||||
|
||||
ColorScheme scheme = schemes[schemenr];
|
||||
ColorScheme scheme = kSchemes[schemenr];
|
||||
if (scheme.count < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t repeat = repeatValues[sysCfg.led_width]; // number of scheme.count per ledcount
|
||||
uint16_t range = (uint16_t)ceil((float)sysCfg.led_pixels / (float)repeat);
|
||||
uint8_t repeat = kRepeat[Settings.led_width]; // number of scheme.count per ledcount
|
||||
uint16_t range = (uint16_t)ceil((float)Settings.led_pixels / (float)repeat);
|
||||
uint16_t gradRange = (uint16_t)ceil((float)range / (float)(scheme.count - 1));
|
||||
uint16_t offset = speedValues[sysCfg.led_speed] > 0 ? stripTimerCntr / speedValues[sysCfg.led_speed] : 0;
|
||||
uint16_t offset = kSpeed[Settings.led_speed] > 0 ? stripTimerCntr / kSpeed[Settings.led_speed] : 0;
|
||||
|
||||
wsColor oldColor, currentColor;
|
||||
ws2812_gradientColor(schemenr, &oldColor, range, gradRange, offset);
|
||||
WsColor oldColor, currentColor;
|
||||
Ws2812GradientColor(schemenr, &oldColor, range, gradRange, offset);
|
||||
currentColor = oldColor;
|
||||
for (uint16_t i = 0; i < sysCfg.led_pixels; i++) {
|
||||
if (repeatValues[sysCfg.led_width] > 1) {
|
||||
ws2812_gradientColor(schemenr, ¤tColor, range, gradRange, i +offset);
|
||||
for (uint16_t i = 0; i < Settings.led_pixels; i++) {
|
||||
if (kRepeat[Settings.led_width] > 1) {
|
||||
Ws2812GradientColor(schemenr, ¤tColor, range, gradRange, i +offset);
|
||||
}
|
||||
if (sysCfg.led_speed > 0) {
|
||||
if (Settings.led_speed > 0) {
|
||||
// Blend old and current color based on time for smooth movement.
|
||||
c.R = map(stripTimerCntr % speedValues[sysCfg.led_speed], 0, speedValues[sysCfg.led_speed], oldColor.red, currentColor.red);
|
||||
c.G = map(stripTimerCntr % speedValues[sysCfg.led_speed], 0, speedValues[sysCfg.led_speed], oldColor.green, currentColor.green);
|
||||
c.B = map(stripTimerCntr % speedValues[sysCfg.led_speed], 0, speedValues[sysCfg.led_speed], oldColor.blue, currentColor.blue);
|
||||
c.R = map(stripTimerCntr % kSpeed[Settings.led_speed], 0, kSpeed[Settings.led_speed], oldColor.red, currentColor.red);
|
||||
c.G = map(stripTimerCntr % kSpeed[Settings.led_speed], 0, kSpeed[Settings.led_speed], oldColor.green, currentColor.green);
|
||||
c.B = map(stripTimerCntr % kSpeed[Settings.led_speed], 0, kSpeed[Settings.led_speed], oldColor.blue, currentColor.blue);
|
||||
}
|
||||
else {
|
||||
// No animation, just use the current color.
|
||||
|
@ -210,10 +229,10 @@ void ws2812_gradient(uint8_t schemenr)
|
|||
strip->SetPixelColor(i, c);
|
||||
oldColor = currentColor;
|
||||
}
|
||||
ws2812_stripShow();
|
||||
Ws2812StripShow();
|
||||
}
|
||||
|
||||
void ws2812_bars(uint8_t schemenr)
|
||||
void Ws2812Bars(uint8_t schemenr)
|
||||
{
|
||||
/*
|
||||
* This routine courtesy Tony DiCola (Adafruit)
|
||||
|
@ -223,44 +242,44 @@ void ws2812_bars(uint8_t schemenr)
|
|||
RgbColor c;
|
||||
uint16_t i;
|
||||
|
||||
ColorScheme scheme = schemes[schemenr];
|
||||
ColorScheme scheme = kSchemes[schemenr];
|
||||
|
||||
uint16_t maxSize = sysCfg.led_pixels / scheme.count;
|
||||
if (widthValues[sysCfg.led_width] > maxSize) {
|
||||
uint16_t maxSize = Settings.led_pixels / scheme.count;
|
||||
if (kWidth[Settings.led_width] > maxSize) {
|
||||
maxSize = 0;
|
||||
}
|
||||
|
||||
uint8_t offset = speedValues[sysCfg.led_speed] > 0 ? stripTimerCntr / speedValues[sysCfg.led_speed] : 0;
|
||||
uint8_t offset = kSpeed[Settings.led_speed] > 0 ? stripTimerCntr / kSpeed[Settings.led_speed] : 0;
|
||||
|
||||
wsColor mcolor[scheme.count];
|
||||
WsColor mcolor[scheme.count];
|
||||
memcpy(mcolor, scheme.colors, sizeof(mcolor));
|
||||
float newDim = 100 / (float)sysCfg.led_dimmer;
|
||||
float dimmer = 100 / (float)Settings.led_dimmer;
|
||||
for (i = 0; i < scheme.count; i++) {
|
||||
float fmyRed = (float)mcolor[i].red / newDim;
|
||||
float fmyGrn = (float)mcolor[i].green / newDim;
|
||||
float fmyBlu = (float)mcolor[i].blue / newDim;
|
||||
float fmyRed = (float)mcolor[i].red / dimmer;
|
||||
float fmyGrn = (float)mcolor[i].green / dimmer;
|
||||
float fmyBlu = (float)mcolor[i].blue / dimmer;
|
||||
mcolor[i].red = (uint8_t)fmyRed;
|
||||
mcolor[i].green = (uint8_t)fmyGrn;
|
||||
mcolor[i].blue = (uint8_t)fmyBlu;
|
||||
}
|
||||
uint8_t colorIndex = offset % scheme.count;
|
||||
for (i = 0; i < sysCfg.led_pixels; i++) {
|
||||
for (i = 0; i < Settings.led_pixels; i++) {
|
||||
if (maxSize) {
|
||||
colorIndex = ((i + offset) % (scheme.count * widthValues[sysCfg.led_width])) / widthValues[sysCfg.led_width];
|
||||
colorIndex = ((i + offset) % (scheme.count * kWidth[Settings.led_width])) / kWidth[Settings.led_width];
|
||||
}
|
||||
c.R = mcolor[colorIndex].red;
|
||||
c.G = mcolor[colorIndex].green;
|
||||
c.B = mcolor[colorIndex].blue;
|
||||
strip->SetPixelColor(i, c);
|
||||
}
|
||||
ws2812_stripShow();
|
||||
Ws2812StripShow();
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Public
|
||||
\*********************************************************************************************/
|
||||
|
||||
void ws2812_init()
|
||||
void Ws2812Init()
|
||||
{
|
||||
#ifdef USE_WS2812_DMA
|
||||
#if (USE_WS2812_CTYPE == 1)
|
||||
|
@ -276,17 +295,17 @@ void ws2812_init()
|
|||
#endif // USE_WS2812_CTYPE
|
||||
#endif // USE_WS2812_DMA
|
||||
strip->Begin();
|
||||
ws2812_clear();
|
||||
Ws2812Clear();
|
||||
}
|
||||
|
||||
void ws2812_clear()
|
||||
void Ws2812Clear()
|
||||
{
|
||||
strip->ClearTo(0);
|
||||
strip->Show();
|
||||
ws2812_showNext = 1;
|
||||
ws_show_next = 1;
|
||||
}
|
||||
|
||||
void ws2812_setColor(uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
|
||||
void Ws2812SetColor(uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
|
||||
{
|
||||
RgbColor lcolor;
|
||||
lcolor.R = red;
|
||||
|
@ -296,15 +315,15 @@ void ws2812_setColor(uint16_t led, uint8_t red, uint8_t green, uint8_t blue)
|
|||
strip->SetPixelColor(led -1, lcolor); // Led 1 is strip Led 0 -> substract offset 1
|
||||
} else {
|
||||
// strip->ClearTo(lcolor); // Set WS2812_MAX_LEDS pixels
|
||||
for (uint16_t i = 0; i < sysCfg.led_pixels; i++) {
|
||||
for (uint16_t i = 0; i < Settings.led_pixels; i++) {
|
||||
strip->SetPixelColor(i, lcolor);
|
||||
}
|
||||
}
|
||||
strip->Show();
|
||||
ws2812_showNext = 1;
|
||||
ws_show_next = 1;
|
||||
}
|
||||
|
||||
char* ws2812_getColor(uint16_t led, char* scolor)
|
||||
char* Ws2812GetColor(uint16_t led, char* scolor)
|
||||
{
|
||||
uint8_t sl_ledcolor[3];
|
||||
|
||||
|
@ -319,22 +338,22 @@ char* ws2812_getColor(uint16_t led, char* scolor)
|
|||
return scolor;
|
||||
}
|
||||
|
||||
void ws2812_showScheme(uint8_t scheme)
|
||||
void Ws2812ShowScheme(uint8_t scheme)
|
||||
{
|
||||
switch (scheme) {
|
||||
case 0: // Clock
|
||||
if (((STATES/10)*2 == state) || (ws2812_showNext)) {
|
||||
ws2812_clock();
|
||||
ws2812_showNext = 0;
|
||||
if (((STATES/10)*2 == state) || (ws_show_next)) {
|
||||
Ws2812Clock();
|
||||
ws_show_next = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (1 == sysCfg.led_fade) {
|
||||
ws2812_gradient(scheme -1);
|
||||
if (1 == Settings.led_fade) {
|
||||
Ws2812Gradient(scheme -1);
|
||||
} else {
|
||||
ws2812_bars(scheme -1);
|
||||
Ws2812Bars(scheme -1);
|
||||
}
|
||||
ws2812_showNext = 1;
|
||||
ws_show_next = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,48 +28,48 @@
|
|||
|
||||
#define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10 // Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||
|
||||
uint8_t bh1750addr;
|
||||
uint8_t bh1750type = 0;
|
||||
char bh1750stype[7];
|
||||
uint8_t bh1750_address;
|
||||
uint8_t bh1750_type = 0;
|
||||
char bh1750_types[7];
|
||||
|
||||
uint16_t bh1750_readLux(void)
|
||||
uint16_t Bh1750ReadLux()
|
||||
{
|
||||
Wire.requestFrom(bh1750addr, (uint8_t)2);
|
||||
Wire.requestFrom(bh1750_address, (uint8_t)2);
|
||||
byte msb = Wire.read();
|
||||
byte lsb = Wire.read();
|
||||
uint16_t value = ((msb << 8) | lsb) / 1.2;
|
||||
return value;
|
||||
}
|
||||
|
||||
boolean bh1750_detect()
|
||||
boolean Bh1750Detect()
|
||||
{
|
||||
if (bh1750type) {
|
||||
if (bh1750_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
uint8_t status;
|
||||
boolean success = false;
|
||||
|
||||
bh1750addr = BH1750_ADDR1;
|
||||
Wire.beginTransmission(bh1750addr);
|
||||
bh1750_address = BH1750_ADDR1;
|
||||
Wire.beginTransmission(bh1750_address);
|
||||
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||
status = Wire.endTransmission();
|
||||
if (status) {
|
||||
bh1750addr = BH1750_ADDR2;
|
||||
Wire.beginTransmission(bh1750addr);
|
||||
bh1750_address = BH1750_ADDR2;
|
||||
Wire.beginTransmission(bh1750_address);
|
||||
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||
status = Wire.endTransmission();
|
||||
}
|
||||
if (!status) {
|
||||
success = true;
|
||||
bh1750type = 1;
|
||||
strcpy_P(bh1750stype, PSTR("BH1750"));
|
||||
bh1750_type = 1;
|
||||
strcpy_P(bh1750_types, PSTR("BH1750"));
|
||||
}
|
||||
if (success) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bh1750stype, bh1750addr);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bh1750_types, bh1750_address);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
} else {
|
||||
bh1750type = 0;
|
||||
bh1750_type = 0;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -78,17 +78,17 @@ boolean bh1750_detect()
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void bh1750_mqttPresent(uint8_t* djson)
|
||||
void MqttShowBh1750(uint8_t* djson)
|
||||
{
|
||||
if (!bh1750type) {
|
||||
if (!bh1750_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint16_t l = bh1750_readLux();
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_ILLUMINANCE "\":%d}"), mqtt_data, bh1750stype, l);
|
||||
uint16_t l = Bh1750ReadLux();
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_ILLUMINANCE "\":%d}"), mqtt_data, bh1750_types, l);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
domoticz_sensor(DZ_ILLUMINANCE, l);
|
||||
DomoticzSensor(DZ_ILLUMINANCE, l);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
||||
|
@ -96,12 +96,12 @@ void bh1750_mqttPresent(uint8_t* djson)
|
|||
const char HTTP_SNS_ILLUMINANCE[] PROGMEM =
|
||||
"<tr><th>BH1750 " D_ILLUMINANCE "</th><td>%d " D_UNIT_LUX "</td></tr>";
|
||||
|
||||
String bh1750_webPresent()
|
||||
String WebShowBh1750()
|
||||
{
|
||||
String page = "";
|
||||
if (bh1750type) {
|
||||
if (bh1750_type) {
|
||||
char sensor[80];
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_ILLUMINANCE, bh1750_readLux());
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_ILLUMINANCE, Bh1750ReadLux());
|
||||
page += sensor;
|
||||
}
|
||||
return page;
|
||||
|
|
|
@ -34,9 +34,9 @@
|
|||
#define BMP_REGISTER_CHIPID 0xD0
|
||||
|
||||
double bmp_sealevel = 0.0;
|
||||
uint8_t bmpaddr;
|
||||
uint8_t bmptype = 0;
|
||||
char bmpstype[7];
|
||||
uint8_t bmp_address;
|
||||
uint8_t bmp_type = 0;
|
||||
char bmp_types[7];
|
||||
|
||||
/*********************************************************************************************\
|
||||
* BMP085 and BME180
|
||||
|
@ -73,18 +73,18 @@ uint16_t cal_ac5;
|
|||
uint16_t cal_ac6;
|
||||
int32_t bmp180_b5 = 0;
|
||||
|
||||
boolean bmp180_calibration()
|
||||
boolean Bmp180Calibration()
|
||||
{
|
||||
cal_ac1 = i2c_read16(bmpaddr, BMP180_AC1);
|
||||
cal_ac2 = i2c_read16(bmpaddr, BMP180_AC2);
|
||||
cal_ac3 = i2c_read16(bmpaddr, BMP180_AC3);
|
||||
cal_ac4 = i2c_read16(bmpaddr, BMP180_AC4);
|
||||
cal_ac5 = i2c_read16(bmpaddr, BMP180_AC5);
|
||||
cal_ac6 = i2c_read16(bmpaddr, BMP180_AC6);
|
||||
cal_b1 = i2c_read16(bmpaddr, BMP180_VB1);
|
||||
cal_b2 = i2c_read16(bmpaddr, BMP180_VB2);
|
||||
cal_mc = i2c_read16(bmpaddr, BMP180_MC);
|
||||
cal_md = i2c_read16(bmpaddr, BMP180_MD);
|
||||
cal_ac1 = I2cRead16(bmp_address, BMP180_AC1);
|
||||
cal_ac2 = I2cRead16(bmp_address, BMP180_AC2);
|
||||
cal_ac3 = I2cRead16(bmp_address, BMP180_AC3);
|
||||
cal_ac4 = I2cRead16(bmp_address, BMP180_AC4);
|
||||
cal_ac5 = I2cRead16(bmp_address, BMP180_AC5);
|
||||
cal_ac6 = I2cRead16(bmp_address, BMP180_AC6);
|
||||
cal_b1 = I2cRead16(bmp_address, BMP180_VB1);
|
||||
cal_b2 = I2cRead16(bmp_address, BMP180_VB2);
|
||||
cal_mc = I2cRead16(bmp_address, BMP180_MC);
|
||||
cal_md = I2cRead16(bmp_address, BMP180_MD);
|
||||
|
||||
// Check for Errors in calibration data. Value never is 0x0000 or 0xFFFF
|
||||
if (!cal_ac1 | !cal_ac2 | !cal_ac3 | !cal_ac4 | !cal_ac5 | !cal_ac6 | !cal_b1 | !cal_b2 | !cal_mc | !cal_md) {
|
||||
|
@ -106,11 +106,11 @@ boolean bmp180_calibration()
|
|||
return true;
|
||||
}
|
||||
|
||||
double bmp180_readTemperature()
|
||||
double Bmp180ReadTemperature()
|
||||
{
|
||||
i2c_write8(bmpaddr, BMP180_REG_CONTROL, BMP180_TEMPERATURE);
|
||||
I2cWrite8(bmp_address, BMP180_REG_CONTROL, BMP180_TEMPERATURE);
|
||||
delay(5); // 5ms conversion time
|
||||
int ut = i2c_read16(bmpaddr, BMP180_REG_RESULT);
|
||||
int ut = I2cRead16(bmp_address, BMP180_REG_RESULT);
|
||||
int32_t x1 = (ut - (int32_t)cal_ac6) * ((int32_t)cal_ac5) >> 15;
|
||||
int32_t x2 = ((int32_t)cal_mc << 11) / (x1 + (int32_t)cal_md);
|
||||
bmp180_b5 = x1 + x2;
|
||||
|
@ -118,16 +118,16 @@ double bmp180_readTemperature()
|
|||
return ((bmp180_b5 + 8) >> 4) / 10.0;
|
||||
}
|
||||
|
||||
double bmp180_readPressure()
|
||||
double Bmp180ReadPressure()
|
||||
{
|
||||
int32_t p;
|
||||
uint8_t msb;
|
||||
uint8_t lsb;
|
||||
uint8_t xlsb;
|
||||
|
||||
i2c_write8(bmpaddr, BMP180_REG_CONTROL, BMP180_PRESSURE3); // Highest resolution
|
||||
I2cWrite8(bmp_address, BMP180_REG_CONTROL, BMP180_PRESSURE3); // Highest resolution
|
||||
delay(2 + (4 << BMP180_OSS)); // 26ms conversion time at ultra high resolution
|
||||
uint32_t up = i2c_read24(bmpaddr, BMP180_REG_RESULT);
|
||||
uint32_t up = I2cRead24(bmp_address, BMP180_REG_RESULT);
|
||||
up >>= (8 - BMP180_OSS);
|
||||
|
||||
int32_t b6 = bmp180_b5 - 4000;
|
||||
|
@ -157,12 +157,6 @@ double bmp180_readPressure()
|
|||
return p / 100.0; // convert to mbar
|
||||
}
|
||||
|
||||
double bmp180_calcSealevelPressure(float pAbs, float altitude_meters)
|
||||
{
|
||||
double pressure = pAbs * 100.0;
|
||||
return (double)(pressure / pow(1.0 - altitude_meters / 44330, 5.255)) / 100.0;
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* BMP280 and BME280
|
||||
*
|
||||
|
@ -194,7 +188,7 @@ double bmp180_calcSealevelPressure(float pAbs, float altitude_meters)
|
|||
#define BME280_REGISTER_DIG_H5 0xE5
|
||||
#define BME280_REGISTER_DIG_H6 0xE7
|
||||
|
||||
struct bme280_calib_data
|
||||
struct BME280CALIBDATA
|
||||
{
|
||||
uint16_t dig_T1;
|
||||
int16_t dig_T2;
|
||||
|
@ -214,133 +208,112 @@ struct bme280_calib_data
|
|||
int16_t dig_H4;
|
||||
int16_t dig_H5;
|
||||
int8_t dig_H6;
|
||||
} _bme280_calib;
|
||||
} Bme280CalibrationData;
|
||||
|
||||
int32_t t_fine;
|
||||
|
||||
boolean bmp280_calibrate()
|
||||
boolean Bmx280Calibrate()
|
||||
{
|
||||
// if (i2c_read8(bmpaddr, BMP_REGISTER_CHIPID) != BMP280_CHIPID) return false;
|
||||
// if (I2cRead8(bmp_address, BMP_REGISTER_CHIPID) != BME280_CHIPID) return false;
|
||||
|
||||
_bme280_calib.dig_T1 = i2c_read16_LE(bmpaddr, BME280_REGISTER_DIG_T1);
|
||||
_bme280_calib.dig_T2 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_T2);
|
||||
_bme280_calib.dig_T3 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_T3);
|
||||
_bme280_calib.dig_P1 = i2c_read16_LE(bmpaddr, BME280_REGISTER_DIG_P1);
|
||||
_bme280_calib.dig_P2 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P2);
|
||||
_bme280_calib.dig_P3 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P3);
|
||||
_bme280_calib.dig_P4 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P4);
|
||||
_bme280_calib.dig_P5 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P5);
|
||||
_bme280_calib.dig_P6 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P6);
|
||||
_bme280_calib.dig_P7 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P7);
|
||||
_bme280_calib.dig_P8 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P8);
|
||||
_bme280_calib.dig_P9 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P9);
|
||||
|
||||
// i2c_write8(bmpaddr, BME280_REGISTER_CONTROL, 0x3F); // Temp 1x oversampling, Press 16x oversampling, normal mode (Adafruit)
|
||||
i2c_write8(bmpaddr, BME280_REGISTER_CONTROL, 0xB7); // 16x oversampling, normal mode (Adafruit)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean bme280_calibrate()
|
||||
{
|
||||
// if (i2c_read8(bmpaddr, BMP_REGISTER_CHIPID) != BME280_CHIPID) return false;
|
||||
|
||||
_bme280_calib.dig_T1 = i2c_read16_LE(bmpaddr, BME280_REGISTER_DIG_T1);
|
||||
_bme280_calib.dig_T2 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_T2);
|
||||
_bme280_calib.dig_T3 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_T3);
|
||||
_bme280_calib.dig_P1 = i2c_read16_LE(bmpaddr, BME280_REGISTER_DIG_P1);
|
||||
_bme280_calib.dig_P2 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P2);
|
||||
_bme280_calib.dig_P3 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P3);
|
||||
_bme280_calib.dig_P4 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P4);
|
||||
_bme280_calib.dig_P5 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P5);
|
||||
_bme280_calib.dig_P6 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P6);
|
||||
_bme280_calib.dig_P7 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P7);
|
||||
_bme280_calib.dig_P8 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P8);
|
||||
_bme280_calib.dig_P9 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P9);
|
||||
_bme280_calib.dig_H1 = i2c_read8(bmpaddr, BME280_REGISTER_DIG_H1);
|
||||
_bme280_calib.dig_H2 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_H2);
|
||||
_bme280_calib.dig_H3 = i2c_read8(bmpaddr, BME280_REGISTER_DIG_H3);
|
||||
_bme280_calib.dig_H4 = (i2c_read8(bmpaddr, BME280_REGISTER_DIG_H4) << 4) | (i2c_read8(bmpaddr, BME280_REGISTER_DIG_H4 + 1) & 0xF);
|
||||
_bme280_calib.dig_H5 = (i2c_read8(bmpaddr, BME280_REGISTER_DIG_H5 + 1) << 4) | (i2c_read8(bmpaddr, BME280_REGISTER_DIG_H5) >> 4);
|
||||
_bme280_calib.dig_H6 = (int8_t)i2c_read8(bmpaddr, BME280_REGISTER_DIG_H6);
|
||||
Bme280CalibrationData.dig_T1 = I2cRead16LE(bmp_address, BME280_REGISTER_DIG_T1);
|
||||
Bme280CalibrationData.dig_T2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_T2);
|
||||
Bme280CalibrationData.dig_T3 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_T3);
|
||||
Bme280CalibrationData.dig_P1 = I2cRead16LE(bmp_address, BME280_REGISTER_DIG_P1);
|
||||
Bme280CalibrationData.dig_P2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P2);
|
||||
Bme280CalibrationData.dig_P3 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P3);
|
||||
Bme280CalibrationData.dig_P4 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P4);
|
||||
Bme280CalibrationData.dig_P5 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P5);
|
||||
Bme280CalibrationData.dig_P6 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P6);
|
||||
Bme280CalibrationData.dig_P7 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P7);
|
||||
Bme280CalibrationData.dig_P8 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P8);
|
||||
Bme280CalibrationData.dig_P9 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P9);
|
||||
if (BME280_CHIPID == bmp_type) {
|
||||
Bme280CalibrationData.dig_H1 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H1);
|
||||
Bme280CalibrationData.dig_H2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_H2);
|
||||
Bme280CalibrationData.dig_H3 = I2cRead8(bmp_address, BME280_REGISTER_DIG_H3);
|
||||
Bme280CalibrationData.dig_H4 = (I2cRead8(bmp_address, BME280_REGISTER_DIG_H4) << 4) | (I2cRead8(bmp_address, BME280_REGISTER_DIG_H4 + 1) & 0xF);
|
||||
Bme280CalibrationData.dig_H5 = (I2cRead8(bmp_address, BME280_REGISTER_DIG_H5 + 1) << 4) | (I2cRead8(bmp_address, BME280_REGISTER_DIG_H5) >> 4);
|
||||
Bme280CalibrationData.dig_H6 = (int8_t)I2cRead8(bmp_address, BME280_REGISTER_DIG_H6);
|
||||
|
||||
// Set before CONTROL_meas (DS 5.4.3)
|
||||
i2c_write8(bmpaddr, BME280_REGISTER_CONTROLHUMID, 0x05); // 16x oversampling (Adafruit)
|
||||
i2c_write8(bmpaddr, BME280_REGISTER_CONTROL, 0xB7); // 16x oversampling, normal mode (Adafruit)
|
||||
I2cWrite8(bmp_address, BME280_REGISTER_CONTROLHUMID, 0x05); // 16x oversampling (Adafruit)
|
||||
}
|
||||
I2cWrite8(bmp_address, BME280_REGISTER_CONTROL, 0xB7); // 16x oversampling, normal mode (Adafruit)
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
double bmp280_readTemperature(void)
|
||||
double Bme280ReadTemperature(void)
|
||||
{
|
||||
int32_t var1;
|
||||
int32_t var2;
|
||||
|
||||
int32_t adc_T = i2c_read24(bmpaddr, BME280_REGISTER_TEMPDATA);
|
||||
int32_t adc_T = I2cRead24(bmp_address, BME280_REGISTER_TEMPDATA);
|
||||
adc_T >>= 4;
|
||||
|
||||
var1 = ((((adc_T >> 3) - ((int32_t)_bme280_calib.dig_T1 << 1))) * ((int32_t)_bme280_calib.dig_T2)) >> 11;
|
||||
var2 = (((((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1)) * ((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1))) >> 12) *
|
||||
((int32_t)_bme280_calib.dig_T3)) >>
|
||||
var1 = ((((adc_T >> 3) - ((int32_t)Bme280CalibrationData.dig_T1 << 1))) * ((int32_t)Bme280CalibrationData.dig_T2)) >> 11;
|
||||
var2 = (((((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1)) * ((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1))) >> 12) *
|
||||
((int32_t)Bme280CalibrationData.dig_T3)) >>
|
||||
14;
|
||||
t_fine = var1 + var2;
|
||||
double T = (t_fine * 5 + 128) >> 8;
|
||||
return T / 100.0;
|
||||
}
|
||||
|
||||
double bmp280_readPressure(void)
|
||||
double Bme280ReadPressure(void)
|
||||
{
|
||||
int64_t var1;
|
||||
int64_t var2;
|
||||
int64_t p;
|
||||
|
||||
// Must be done first to get the t_fine variable set up
|
||||
// bmp280_readTemperature();
|
||||
// Bme280ReadTemperature();
|
||||
|
||||
int32_t adc_P = i2c_read24(bmpaddr, BME280_REGISTER_PRESSUREDATA);
|
||||
int32_t adc_P = I2cRead24(bmp_address, BME280_REGISTER_PRESSUREDATA);
|
||||
adc_P >>= 4;
|
||||
|
||||
var1 = ((int64_t)t_fine) - 128000;
|
||||
var2 = var1 * var1 * (int64_t)_bme280_calib.dig_P6;
|
||||
var2 = var2 + ((var1 * (int64_t)_bme280_calib.dig_P5) << 17);
|
||||
var2 = var2 + (((int64_t)_bme280_calib.dig_P4) << 35);
|
||||
var1 = ((var1 * var1 * (int64_t)_bme280_calib.dig_P3) >> 8) + ((var1 * (int64_t)_bme280_calib.dig_P2) << 12);
|
||||
var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)_bme280_calib.dig_P1) >> 33;
|
||||
var2 = var1 * var1 * (int64_t)Bme280CalibrationData.dig_P6;
|
||||
var2 = var2 + ((var1 * (int64_t)Bme280CalibrationData.dig_P5) << 17);
|
||||
var2 = var2 + (((int64_t)Bme280CalibrationData.dig_P4) << 35);
|
||||
var1 = ((var1 * var1 * (int64_t)Bme280CalibrationData.dig_P3) >> 8) + ((var1 * (int64_t)Bme280CalibrationData.dig_P2) << 12);
|
||||
var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)Bme280CalibrationData.dig_P1) >> 33;
|
||||
if (0 == var1) {
|
||||
return 0; // avoid exception caused by division by zero
|
||||
}
|
||||
p = 1048576 - adc_P;
|
||||
p = (((p << 31) - var2) * 3125) / var1;
|
||||
var1 = (((int64_t)_bme280_calib.dig_P9) * (p >> 13) * (p >> 13)) >> 25;
|
||||
var2 = (((int64_t)_bme280_calib.dig_P8) * p) >> 19;
|
||||
p = ((p + var1 + var2) >> 8) + (((int64_t)_bme280_calib.dig_P7) << 4);
|
||||
var1 = (((int64_t)Bme280CalibrationData.dig_P9) * (p >> 13) * (p >> 13)) >> 25;
|
||||
var2 = (((int64_t)Bme280CalibrationData.dig_P8) * p) >> 19;
|
||||
p = ((p + var1 + var2) >> 8) + (((int64_t)Bme280CalibrationData.dig_P7) << 4);
|
||||
return (double)p / 25600.0;
|
||||
}
|
||||
|
||||
double bme280_readHumidity(void)
|
||||
double Bme280ReadHumidity(void)
|
||||
{
|
||||
int32_t v_x1_u32r;
|
||||
|
||||
// Must be done first to get the t_fine variable set up
|
||||
// bmp280_readTemperature();
|
||||
// Bme280ReadTemperature();
|
||||
|
||||
int32_t adc_H = i2c_read16(bmpaddr, BME280_REGISTER_HUMIDDATA);
|
||||
int32_t adc_H = I2cRead16(bmp_address, BME280_REGISTER_HUMIDDATA);
|
||||
|
||||
v_x1_u32r = (t_fine - ((int32_t)76800));
|
||||
|
||||
v_x1_u32r = (((((adc_H << 14) - (((int32_t)_bme280_calib.dig_H4) << 20) -
|
||||
(((int32_t)_bme280_calib.dig_H5) * v_x1_u32r)) +
|
||||
v_x1_u32r = (((((adc_H << 14) - (((int32_t)Bme280CalibrationData.dig_H4) << 20) -
|
||||
(((int32_t)Bme280CalibrationData.dig_H5) * v_x1_u32r)) +
|
||||
((int32_t)16384)) >>
|
||||
15) *
|
||||
(((((((v_x1_u32r * ((int32_t)_bme280_calib.dig_H6)) >> 10) *
|
||||
(((v_x1_u32r * ((int32_t)_bme280_calib.dig_H3)) >> 11) + ((int32_t)32768))) >>
|
||||
(((((((v_x1_u32r * ((int32_t)Bme280CalibrationData.dig_H6)) >> 10) *
|
||||
(((v_x1_u32r * ((int32_t)Bme280CalibrationData.dig_H3)) >> 11) + ((int32_t)32768))) >>
|
||||
10) +
|
||||
((int32_t)2097152)) *
|
||||
((int32_t)_bme280_calib.dig_H2) +
|
||||
((int32_t)Bme280CalibrationData.dig_H2) +
|
||||
8192) >>
|
||||
14));
|
||||
v_x1_u32r = (v_x1_u32r - (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7) *
|
||||
((int32_t)_bme280_calib.dig_H1)) >>
|
||||
((int32_t)Bme280CalibrationData.dig_H1)) >>
|
||||
4));
|
||||
v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r;
|
||||
v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r;
|
||||
|
@ -352,116 +325,92 @@ double bme280_readHumidity(void)
|
|||
* BMP
|
||||
\*********************************************************************************************/
|
||||
|
||||
double fastPrecisePow(double a, double b)
|
||||
{
|
||||
// https://martin.ankerl.com/2012/01/25/optimized-approximative-pow-in-c-and-cpp/
|
||||
// calculate approximation with fraction of the exponent
|
||||
int e = (int)b;
|
||||
union {
|
||||
double d;
|
||||
int x[2];
|
||||
} u = { a };
|
||||
u.x[1] = (int)((b - e) * (u.x[1] - 1072632447) + 1072632447);
|
||||
u.x[0] = 0;
|
||||
// exponentiation by squaring with the exponent's integer part
|
||||
// double r = u.d makes everything much slower, not sure why
|
||||
double r = 1.0;
|
||||
while (e) {
|
||||
if (e & 1) {
|
||||
r *= a;
|
||||
}
|
||||
a *= a;
|
||||
e >>= 1;
|
||||
}
|
||||
return r * u.d;
|
||||
}
|
||||
|
||||
double bmp_readTemperature(void)
|
||||
double BmpReadTemperature(void)
|
||||
{
|
||||
double t = NAN;
|
||||
|
||||
switch (bmptype)
|
||||
switch (bmp_type)
|
||||
{
|
||||
case BMP180_CHIPID:
|
||||
t = bmp180_readTemperature();
|
||||
t = Bmp180ReadTemperature();
|
||||
break;
|
||||
case BMP280_CHIPID:
|
||||
case BME280_CHIPID:
|
||||
t = bmp280_readTemperature();
|
||||
t = Bme280ReadTemperature();
|
||||
}
|
||||
if (!isnan(t))
|
||||
{
|
||||
t = convertTemp(t);
|
||||
t = ConvertTemp(t);
|
||||
return t;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
double bmp_readPressure(void)
|
||||
double BmpReadPressure(void)
|
||||
{
|
||||
double pressure = 0.0;
|
||||
|
||||
switch (bmptype) {
|
||||
switch (bmp_type) {
|
||||
case BMP180_CHIPID:
|
||||
pressure = bmp180_readPressure();
|
||||
pressure = Bmp180ReadPressure();
|
||||
break;
|
||||
case BMP280_CHIPID:
|
||||
case BME280_CHIPID:
|
||||
pressure = bmp280_readPressure();
|
||||
pressure = Bme280ReadPressure();
|
||||
}
|
||||
if (pressure != 0.0) {
|
||||
// bmp_sealevel = pressure / pow(1.0 - ((float)sysCfg.altitude / 44330.0), 5.255); // Adds 8k to the code
|
||||
bmp_sealevel = (pressure / fastPrecisePow(1.0 - ((float)sysCfg.altitude / 44330.0), 5.255)) - 21.6;
|
||||
// bmp_sealevel = pressure / pow(1.0 - ((float)Settings.altitude / 44330.0), 5.255); // Adds 8k to the code
|
||||
bmp_sealevel = (pressure / FastPrecisePow(1.0 - ((float)Settings.altitude / 44330.0), 5.255)) - 21.6;
|
||||
}
|
||||
return pressure;
|
||||
}
|
||||
|
||||
double bmp_readHumidity(void)
|
||||
double BmpReadHumidity(void)
|
||||
{
|
||||
switch (bmptype) {
|
||||
switch (bmp_type) {
|
||||
case BMP180_CHIPID:
|
||||
case BMP280_CHIPID:
|
||||
break;
|
||||
case BME280_CHIPID:
|
||||
return bme280_readHumidity();
|
||||
return Bme280ReadHumidity();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
boolean bmp_detect()
|
||||
boolean BmpDetect()
|
||||
{
|
||||
if (bmptype) {
|
||||
if (bmp_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
|
||||
bmpaddr = BMP_ADDR;
|
||||
bmptype = i2c_read8(bmpaddr, BMP_REGISTER_CHIPID);
|
||||
if (!bmptype) {
|
||||
bmpaddr--;
|
||||
bmptype = i2c_read8(bmpaddr, BMP_REGISTER_CHIPID);
|
||||
bmp_address = BMP_ADDR;
|
||||
bmp_type = I2cRead8(bmp_address, BMP_REGISTER_CHIPID);
|
||||
if (!bmp_type) {
|
||||
bmp_address--;
|
||||
bmp_type = I2cRead8(bmp_address, BMP_REGISTER_CHIPID);
|
||||
}
|
||||
strcpy_P(bmpstype, PSTR("BMP"));
|
||||
switch (bmptype) {
|
||||
strcpy_P(bmp_types, PSTR("BMP"));
|
||||
switch (bmp_type) {
|
||||
case BMP180_CHIPID:
|
||||
success = bmp180_calibration();
|
||||
strcpy_P(bmpstype, PSTR("BMP180"));
|
||||
success = Bmp180Calibration();
|
||||
strcpy_P(bmp_types, PSTR("BMP180"));
|
||||
break;
|
||||
case BMP280_CHIPID:
|
||||
success = bmp280_calibrate();
|
||||
strcpy_P(bmpstype, PSTR("BMP280"));
|
||||
success = Bmx280Calibrate();
|
||||
strcpy_P(bmp_types, PSTR("BMP280"));
|
||||
break;
|
||||
case BME280_CHIPID:
|
||||
success = bme280_calibrate();
|
||||
strcpy_P(bmpstype, PSTR("BME280"));
|
||||
success = Bmx280Calibrate();
|
||||
strcpy_P(bmp_types, PSTR("BME280"));
|
||||
}
|
||||
if (success) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmpstype, bmpaddr);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmp_types, bmp_address);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
}
|
||||
else {
|
||||
bmptype = 0;
|
||||
bmp_type = 0;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -470,66 +419,66 @@ boolean bmp_detect()
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void bmp_mqttPresent(uint8_t *djson)
|
||||
void MqttShowBmp(uint8_t *djson)
|
||||
{
|
||||
if (!bmptype) {
|
||||
if (!bmp_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
char stemp3[10];
|
||||
char stemp4[10];
|
||||
char temperature[10];
|
||||
char pressure[10];
|
||||
char humidity[10];
|
||||
char sea_pressure[10];
|
||||
char sealevel[40];
|
||||
|
||||
double t = bmp_readTemperature();
|
||||
double p = bmp_readPressure();
|
||||
double h = bmp_readHumidity();
|
||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
||||
dtostrfd(p, sysCfg.flag.pressure_resolution, stemp2);
|
||||
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp3);
|
||||
double t = BmpReadTemperature();
|
||||
double p = BmpReadPressure();
|
||||
double h = BmpReadHumidity();
|
||||
dtostrfd(t, Settings.flag.temperature_resolution, temperature);
|
||||
dtostrfd(p, Settings.flag.pressure_resolution, pressure);
|
||||
dtostrfd(h, Settings.flag.humidity_resolution, humidity);
|
||||
|
||||
dtostrfd(bmp_sealevel, sysCfg.flag.pressure_resolution, stemp4);
|
||||
snprintf_P(sealevel, sizeof(sealevel), PSTR(", \"" D_PRESSUREATSEALEVEL "\":%s"), stemp4);
|
||||
if (!strcmp(bmpstype, "BME280")) {
|
||||
dtostrfd(bmp_sealevel, Settings.flag.pressure_resolution, sea_pressure);
|
||||
snprintf_P(sealevel, sizeof(sealevel), PSTR(", \"" D_PRESSUREATSEALEVEL "\":%s"), sea_pressure);
|
||||
if (BME280_CHIPID == bmp_type) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s, \"" D_PRESSURE "\":%s%s}"),
|
||||
mqtt_data, bmpstype, stemp1, stemp3, stemp2, (sysCfg.altitude != 0) ? sealevel : "");
|
||||
mqtt_data, bmp_types, temperature, humidity, pressure, (Settings.altitude != 0) ? sealevel : "");
|
||||
}
|
||||
else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_PRESSURE "\":%s%s}"),
|
||||
mqtt_data, bmpstype, stemp1, stemp2, (sysCfg.altitude != 0) ? sealevel : "");
|
||||
mqtt_data, bmp_types, temperature, pressure, (Settings.altitude != 0) ? sealevel : "");
|
||||
}
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
domoticz_sensor3(stemp1, stemp3, stemp2);
|
||||
DomoticzTempHumPressureSensor(temperature, humidity, pressure);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
String bmp_webPresent()
|
||||
String WebShowBmp()
|
||||
{
|
||||
String page = "";
|
||||
if (bmptype) {
|
||||
if (bmp_type) {
|
||||
char stemp[10];
|
||||
char sensor[80];
|
||||
|
||||
double t_bmp = bmp_readTemperature();
|
||||
double p_bmp = bmp_readPressure();
|
||||
double h_bmp = bmp_readHumidity();
|
||||
dtostrfi(t_bmp, sysCfg.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, bmpstype, stemp, tempUnit());
|
||||
double t = BmpReadTemperature();
|
||||
double p = BmpReadPressure();
|
||||
double h = BmpReadHumidity();
|
||||
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, bmp_types, stemp, TempUnit());
|
||||
page += sensor;
|
||||
if (!strcmp(bmpstype, "BME280")) {
|
||||
dtostrfi(h_bmp, sysCfg.flag.humidity_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, bmpstype, stemp);
|
||||
if (BME280_CHIPID == bmp_type) {
|
||||
dtostrfi(h, Settings.flag.humidity_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, bmp_types, stemp);
|
||||
page += sensor;
|
||||
}
|
||||
dtostrfi(p_bmp, sysCfg.flag.pressure_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSURE, bmpstype, stemp);
|
||||
dtostrfi(p, Settings.flag.pressure_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSURE, bmp_types, stemp);
|
||||
page += sensor;
|
||||
if (sysCfg.altitude != 0) {
|
||||
dtostrfi(bmp_sealevel, sysCfg.flag.pressure_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSUREATSEALEVEL, bmpstype, stemp);
|
||||
if (Settings.altitude != 0) {
|
||||
dtostrfi(bmp_sealevel, Settings.flag.pressure_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSUREATSEALEVEL, bmp_types, stemp);
|
||||
page += sensor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,57 +21,57 @@
|
|||
* Counter sensors (water meters, electricity meters etc.)
|
||||
\*********************************************************************************************/
|
||||
|
||||
unsigned long pTimeLast[MAX_COUNTERS]; // Last counter time in milli seconds
|
||||
unsigned long last_counter_timer[MAX_COUNTERS]; // Last counter time in milli seconds
|
||||
|
||||
void counter_update(byte index)
|
||||
void CounterUpdate(byte index)
|
||||
{
|
||||
unsigned long pTime = millis() - pTimeLast[index -1];
|
||||
if (pTime > sysCfg.pCounterDebounce) {
|
||||
pTimeLast[index -1] = millis();
|
||||
if (bitRead(sysCfg.pCounterType, index -1)) {
|
||||
rtcMem.pCounter[index -1] = pTime;
|
||||
unsigned long counter_debounce_time = millis() - last_counter_timer[index -1];
|
||||
if (counter_debounce_time > Settings.pulse_counter_debounce) {
|
||||
last_counter_timer[index -1] = millis();
|
||||
if (bitRead(Settings.pulse_counter_type, index -1)) {
|
||||
RtcSettings.pulse_counter[index -1] = counter_debounce_time;
|
||||
} else {
|
||||
rtcMem.pCounter[index -1]++;
|
||||
RtcSettings.pulse_counter[index -1]++;
|
||||
}
|
||||
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("CNTR: Interrupt %d"), index);
|
||||
// addLog(LOG_LEVEL_DEBUG);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
void counter_update1()
|
||||
void CounterUpdate1()
|
||||
{
|
||||
counter_update(1);
|
||||
CounterUpdate(1);
|
||||
}
|
||||
|
||||
void counter_update2()
|
||||
void CounterUpdate2()
|
||||
{
|
||||
counter_update(2);
|
||||
CounterUpdate(2);
|
||||
}
|
||||
|
||||
void counter_update3()
|
||||
void CounterUpdate3()
|
||||
{
|
||||
counter_update(3);
|
||||
CounterUpdate(3);
|
||||
}
|
||||
|
||||
void counter_update4()
|
||||
void CounterUpdate4()
|
||||
{
|
||||
counter_update(4);
|
||||
CounterUpdate(4);
|
||||
}
|
||||
|
||||
void counter_savestate()
|
||||
void CounterSaveState()
|
||||
{
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
sysCfg.pCounter[i] = rtcMem.pCounter[i];
|
||||
Settings.pulse_counter[i] = RtcSettings.pulse_counter[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void counter_init()
|
||||
void CounterInit()
|
||||
{
|
||||
typedef void (*function) () ;
|
||||
function counter_callbacks[] = { counter_update1, counter_update2, counter_update3, counter_update4 };
|
||||
function counter_callbacks[] = { CounterUpdate1, CounterUpdate2, CounterUpdate3, CounterUpdate4 };
|
||||
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
|
@ -85,24 +85,24 @@ void counter_init()
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void counter_mqttPresent(uint8_t* djson)
|
||||
void MqttShowCounter(uint8_t* djson)
|
||||
{
|
||||
char stemp[16];
|
||||
|
||||
byte dsxflg = 0;
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
if (bitRead(sysCfg.pCounterType, i)) {
|
||||
dtostrfd((double)rtcMem.pCounter[i] / 1000, 3, stemp);
|
||||
if (bitRead(Settings.pulse_counter_type, i)) {
|
||||
dtostrfd((double)RtcSettings.pulse_counter[i] / 1000, 3, stemp);
|
||||
} else {
|
||||
dsxflg++;
|
||||
dtostrfd(rtcMem.pCounter[i], 0, stemp);
|
||||
dtostrfd(RtcSettings.pulse_counter[i], 0, stemp);
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_COUNTER "%d\":%s"), mqtt_data, i +1, stemp);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (1 == dsxflg) {
|
||||
domoticz_sensor(DZ_COUNT, rtcMem.pCounter[i]);
|
||||
DomoticzSensor(DZ_COUNT, RtcSettings.pulse_counter[i]);
|
||||
dsxflg++;
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
|
@ -114,7 +114,7 @@ void counter_mqttPresent(uint8_t* djson)
|
|||
const char HTTP_SNS_COUNTER[] PROGMEM =
|
||||
"<tr><th>" D_COUNTER "%d</th><td>%s%s</td></tr>";
|
||||
|
||||
String counter_webPresent()
|
||||
String WebShowCounter()
|
||||
{
|
||||
String page = "";
|
||||
char stemp[16];
|
||||
|
@ -122,12 +122,12 @@ String counter_webPresent()
|
|||
|
||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||
if (bitRead(sysCfg.pCounterType, i)) {
|
||||
dtostrfi((double)rtcMem.pCounter[i] / 1000, 3, stemp);
|
||||
if (bitRead(Settings.pulse_counter_type, i)) {
|
||||
dtostrfi((double)RtcSettings.pulse_counter[i] / 1000, 3, stemp);
|
||||
} else {
|
||||
dtostrfi(rtcMem.pCounter[i], 0, stemp);
|
||||
dtostrfi(RtcSettings.pulse_counter[i], 0, stemp);
|
||||
}
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_COUNTER, i+1, stemp, (bitRead(sysCfg.pCounterType, i)) ? " " D_UNIT_SECOND : "");
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_COUNTER, i+1, stemp, (bitRead(Settings.pulse_counter_type, i)) ? " " D_UNIT_SECOND : "");
|
||||
page += sensor;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#define DHT_MAX_SENSORS 3
|
||||
#define MIN_INTERVAL 2000
|
||||
|
||||
uint32_t dht_maxcycles;
|
||||
uint32_t dht_max_cycles;
|
||||
uint8_t dht_data[5];
|
||||
byte dht_sensors = 0;
|
||||
|
||||
|
@ -43,26 +43,26 @@ struct DHTSTRUCT {
|
|||
float h = 0;
|
||||
} dht[DHT_MAX_SENSORS];
|
||||
|
||||
void dht_readPrep()
|
||||
void DhtReadPrep()
|
||||
{
|
||||
for (byte i = 0; i < dht_sensors; i++) {
|
||||
digitalWrite(dht[i].pin, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t dht_expectPulse(byte sensor, bool level)
|
||||
uint32_t DhtExpectPulse(byte sensor, bool level)
|
||||
{
|
||||
uint32_t count = 0;
|
||||
|
||||
while (digitalRead(dht[sensor].pin) == level) {
|
||||
if (count++ >= dht_maxcycles) {
|
||||
if (count++ >= dht_max_cycles) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
void dht_read(byte sensor)
|
||||
void DhtRead(byte sensor)
|
||||
{
|
||||
uint32_t cycles[80];
|
||||
uint32_t currenttime = millis();
|
||||
|
@ -86,19 +86,19 @@ void dht_read(byte sensor)
|
|||
delayMicroseconds(40);
|
||||
pinMode(dht[sensor].pin, INPUT_PULLUP);
|
||||
delayMicroseconds(10);
|
||||
if (0 == dht_expectPulse(sensor, LOW)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE));
|
||||
if (0 == DhtExpectPulse(sensor, LOW)) {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE));
|
||||
dht[sensor].lastresult++;
|
||||
return;
|
||||
}
|
||||
if (0 == dht_expectPulse(sensor, HIGH)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_HIGH " " D_PULSE));
|
||||
if (0 == DhtExpectPulse(sensor, HIGH)) {
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_HIGH " " D_PULSE));
|
||||
dht[sensor].lastresult++;
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < 80; i += 2) {
|
||||
cycles[i] = dht_expectPulse(sensor, LOW);
|
||||
cycles[i+1] = dht_expectPulse(sensor, HIGH);
|
||||
cycles[i] = DhtExpectPulse(sensor, LOW);
|
||||
cycles[i+1] = DhtExpectPulse(sensor, HIGH);
|
||||
}
|
||||
interrupts();
|
||||
|
||||
|
@ -106,7 +106,7 @@ void dht_read(byte sensor)
|
|||
uint32_t lowCycles = cycles[2*i];
|
||||
uint32_t highCycles = cycles[2*i+1];
|
||||
if ((0 == lowCycles) || (0 == highCycles)) {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_PULSE));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_PULSE));
|
||||
dht[sensor].lastresult++;
|
||||
return;
|
||||
}
|
||||
|
@ -118,17 +118,17 @@ void dht_read(byte sensor)
|
|||
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DHT D_RECEIVED " %02X, %02X, %02X, %02X, %02X =? %02X"),
|
||||
dht_data[0], dht_data[1], dht_data[2], dht_data[3], dht_data[4], (dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
if (dht_data[4] == ((dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF)) {
|
||||
dht[sensor].lastresult = 0;
|
||||
} else {
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_CHECKSUM_FAILURE));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_CHECKSUM_FAILURE));
|
||||
dht[sensor].lastresult++;
|
||||
}
|
||||
}
|
||||
|
||||
boolean dht_readTempHum(byte sensor, float &t, float &h)
|
||||
boolean DhtReadTempHum(byte sensor, float &t, float &h)
|
||||
{
|
||||
if (!dht[sensor].h) {
|
||||
t = NAN;
|
||||
|
@ -142,12 +142,12 @@ boolean dht_readTempHum(byte sensor, float &t, float &h)
|
|||
h = dht[sensor].h;
|
||||
}
|
||||
|
||||
dht_read(sensor);
|
||||
DhtRead(sensor);
|
||||
if (!dht[sensor].lastresult) {
|
||||
switch (dht[sensor].type) {
|
||||
case GPIO_DHT11:
|
||||
h = dht_data[0];
|
||||
t = convertTemp(dht_data[2]);
|
||||
t = ConvertTemp(dht_data[2]);
|
||||
break;
|
||||
case GPIO_DHT22:
|
||||
case GPIO_DHT21:
|
||||
|
@ -162,7 +162,7 @@ boolean dht_readTempHum(byte sensor, float &t, float &h)
|
|||
if (dht_data[2] & 0x80) {
|
||||
t *= -1;
|
||||
}
|
||||
t = convertTemp(t);
|
||||
t = ConvertTemp(t);
|
||||
break;
|
||||
}
|
||||
if (!isnan(t)) {
|
||||
|
@ -175,7 +175,7 @@ boolean dht_readTempHum(byte sensor, float &t, float &h)
|
|||
return (!isnan(t) && !isnan(h));
|
||||
}
|
||||
|
||||
boolean dht_setup(byte pin, byte type)
|
||||
boolean DhtSetup(byte pin, byte type)
|
||||
{
|
||||
boolean success = false;
|
||||
|
||||
|
@ -188,9 +188,9 @@ boolean dht_setup(byte pin, byte type)
|
|||
return success;
|
||||
}
|
||||
|
||||
void dht_init()
|
||||
void DhtInit()
|
||||
{
|
||||
dht_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for reading pulses from DHT sensor.
|
||||
dht_max_cycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for reading pulses from DHT sensor.
|
||||
|
||||
for (byte i = 0; i < dht_sensors; i++) {
|
||||
pinMode(dht[i].pin, INPUT_PULLUP);
|
||||
|
@ -216,7 +216,7 @@ void dht_init()
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void dht_mqttPresent(uint8_t* djson)
|
||||
void MqttShowDht(uint8_t* djson)
|
||||
{
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
|
@ -225,14 +225,14 @@ void dht_mqttPresent(uint8_t* djson)
|
|||
|
||||
byte dsxflg = 0;
|
||||
for (byte i = 0; i < dht_sensors; i++) {
|
||||
if (dht_readTempHum(i, t, h)) { // Read temperature
|
||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
||||
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
|
||||
if (DhtReadTempHum(i, t, h)) { // Read temperature
|
||||
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||
dtostrfd(h, Settings.flag.humidity_resolution, stemp2);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, dht[i].stype, stemp1, stemp2);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (!dsxflg) {
|
||||
domoticz_sensor2(stemp1, stemp2);
|
||||
DomoticzTempHumSensor(stemp1, stemp2);
|
||||
dsxflg++;
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
|
@ -241,7 +241,7 @@ void dht_mqttPresent(uint8_t* djson)
|
|||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
String dht_webPresent()
|
||||
String WebShowDht()
|
||||
{
|
||||
String page = "";
|
||||
char stemp[10];
|
||||
|
@ -250,11 +250,11 @@ String dht_webPresent()
|
|||
float h;
|
||||
|
||||
for (byte i = 0; i < dht_sensors; i++) {
|
||||
if (dht_readTempHum(i, t, h)) {
|
||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, dht[i].stype, stemp, tempUnit());
|
||||
if (DhtReadTempHum(i, t, h)) {
|
||||
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, dht[i].stype, stemp, TempUnit());
|
||||
page += sensor;
|
||||
dtostrfi(h, sysCfg.flag.humidity_resolution, stemp);
|
||||
dtostrfi(h, Settings.flag.humidity_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, dht[i].stype, stemp);
|
||||
page += sensor;
|
||||
}
|
||||
|
|
|
@ -24,10 +24,10 @@
|
|||
* Source: Marinus vd Broek https://github.com/ESP8266nu/ESPEasy and AlexTransit (CRC)
|
||||
\*********************************************************************************************/
|
||||
|
||||
float dsb_mt = 0;
|
||||
uint16_t dsb_lastresult = 0;
|
||||
float ds18b20_last_temperature = 0;
|
||||
uint16_t ds18b20_last_result = 0;
|
||||
|
||||
uint8_t dsb_reset()
|
||||
uint8_t Ds18b20Reset()
|
||||
{
|
||||
uint8_t r;
|
||||
uint8_t retries = 125;
|
||||
|
@ -49,7 +49,7 @@ uint8_t dsb_reset()
|
|||
return r;
|
||||
}
|
||||
|
||||
uint8_t dsb_read_bit(void)
|
||||
uint8_t Ds18b20ReadBit(void)
|
||||
{
|
||||
uint8_t r;
|
||||
|
||||
|
@ -63,20 +63,20 @@ uint8_t dsb_read_bit(void)
|
|||
return r;
|
||||
}
|
||||
|
||||
uint8_t dsb_read(void)
|
||||
uint8_t Ds18b20Read(void)
|
||||
{
|
||||
uint8_t bitMask;
|
||||
uint8_t bit_mask;
|
||||
uint8_t r = 0;
|
||||
|
||||
for (bitMask = 1; bitMask; bitMask <<= 1) {
|
||||
if (dsb_read_bit()) {
|
||||
r |= bitMask;
|
||||
for (bit_mask = 1; bit_mask; bit_mask <<= 1) {
|
||||
if (Ds18b20ReadBit()) {
|
||||
r |= bit_mask;
|
||||
}
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
void dsb_write_bit(uint8_t v)
|
||||
void Ds18b20WriteBit(uint8_t v)
|
||||
{
|
||||
if (v & 1) {
|
||||
digitalWrite(pin[GPIO_DSB], LOW);
|
||||
|
@ -93,16 +93,16 @@ void dsb_write_bit(uint8_t v)
|
|||
}
|
||||
}
|
||||
|
||||
void dsb_write(uint8_t ByteToWrite)
|
||||
void Ds18b20Write(uint8_t byte_to_write)
|
||||
{
|
||||
uint8_t bitMask;
|
||||
uint8_t bit_mask;
|
||||
|
||||
for (bitMask = 1; bitMask; bitMask <<= 1) {
|
||||
dsb_write_bit((bitMask & ByteToWrite) ? 1 : 0);
|
||||
for (bit_mask = 1; bit_mask; bit_mask <<= 1) {
|
||||
Ds18b20WriteBit((bit_mask & byte_to_write) ? 1 : 0);
|
||||
}
|
||||
}
|
||||
|
||||
uint8 dsb_crc(uint8 inp, uint8 crc)
|
||||
uint8 Ds18b20Crc(uint8 inp, uint8 crc)
|
||||
{
|
||||
inp ^= crc;
|
||||
crc = 0;
|
||||
|
@ -117,66 +117,66 @@ uint8 dsb_crc(uint8 inp, uint8 crc)
|
|||
return crc;
|
||||
}
|
||||
|
||||
void dsb_readTempPrep()
|
||||
void Ds18b20ReadTempPrep()
|
||||
{
|
||||
dsb_reset();
|
||||
dsb_write(0xCC); // Skip ROM
|
||||
dsb_write(0x44); // Start conversion
|
||||
Ds18b20Reset();
|
||||
Ds18b20Write(0xCC); // Skip ROM
|
||||
Ds18b20Write(0x44); // Start conversion
|
||||
}
|
||||
|
||||
boolean dsb_readTemp(float &t)
|
||||
boolean Ds18b20ReadTemperature(float &t)
|
||||
{
|
||||
int16_t DSTemp;
|
||||
byte msb, lsb, crc, sign = 1;
|
||||
|
||||
if (!dsb_mt) {
|
||||
if (!ds18b20_last_temperature) {
|
||||
t = NAN;
|
||||
} else {
|
||||
dsb_lastresult++;
|
||||
if (dsb_lastresult > 8) { // Reset after 8 misses
|
||||
dsb_mt = NAN;
|
||||
ds18b20_last_result++;
|
||||
if (ds18b20_last_result > 8) { // Reset after 8 misses
|
||||
ds18b20_last_temperature = NAN;
|
||||
}
|
||||
t = dsb_mt;
|
||||
t = ds18b20_last_temperature;
|
||||
}
|
||||
|
||||
if (!dsb_read_bit()) { //check measurement end
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_BUSY));
|
||||
if (!Ds18b20ReadBit()) { //check measurement end
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_BUSY));
|
||||
return !isnan(t);
|
||||
}
|
||||
/*
|
||||
dsb_reset();
|
||||
dsb_write(0xCC); // Skip ROM
|
||||
dsb_write(0x44); // Start conversion
|
||||
Ds18b20Reset();
|
||||
Ds18b20Write(0xCC); // Skip ROM
|
||||
Ds18b20Write(0x44); // Start conversion
|
||||
delay(800);
|
||||
*/
|
||||
dsb_reset();
|
||||
dsb_write(0xCC); // Skip ROM
|
||||
dsb_write(0xBE); // Read scratchpad
|
||||
lsb = dsb_read();
|
||||
msb = dsb_read();
|
||||
crc = dsb_crc(lsb, crc);
|
||||
crc = dsb_crc(msb, crc);
|
||||
crc = dsb_crc(dsb_read(), crc);
|
||||
crc = dsb_crc(dsb_read(), crc);
|
||||
crc = dsb_crc(dsb_read(), crc);
|
||||
crc = dsb_crc(dsb_read(), crc);
|
||||
crc = dsb_crc(dsb_read(), crc);
|
||||
crc = dsb_crc(dsb_read(), crc);
|
||||
crc = dsb_crc(dsb_read(), crc);
|
||||
dsb_reset();
|
||||
Ds18b20Reset();
|
||||
Ds18b20Write(0xCC); // Skip ROM
|
||||
Ds18b20Write(0xBE); // Read scratchpad
|
||||
lsb = Ds18b20Read();
|
||||
msb = Ds18b20Read();
|
||||
crc = Ds18b20Crc(lsb, crc);
|
||||
crc = Ds18b20Crc(msb, crc);
|
||||
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||
Ds18b20Reset();
|
||||
if (crc) { //check crc
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_CRC_ERROR));
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_CRC_ERROR));
|
||||
} else {
|
||||
DSTemp = (msb << 8) + lsb;
|
||||
if (DSTemp > 2047) {
|
||||
DSTemp = (~DSTemp) +1;
|
||||
sign = -1;
|
||||
}
|
||||
t = convertTemp((float)sign * DSTemp * 0.0625);
|
||||
dsb_lastresult = 0;
|
||||
t = ConvertTemp((float)sign * DSTemp * 0.0625);
|
||||
ds18b20_last_result = 0;
|
||||
}
|
||||
if (!isnan(t)) {
|
||||
dsb_mt = t;
|
||||
ds18b20_last_temperature = t;
|
||||
}
|
||||
return !isnan(t);
|
||||
}
|
||||
|
@ -185,37 +185,37 @@ boolean dsb_readTemp(float &t)
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void dsb_mqttPresent(uint8_t* djson)
|
||||
void MqttShowDs18b20(uint8_t* djson)
|
||||
{
|
||||
char stemp1[10];
|
||||
float t;
|
||||
|
||||
if (dsb_readTemp(t)) { // Check if read failed
|
||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
||||
if (Ds18b20ReadTemperature(t)) { // Check if read failed
|
||||
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18B20\":{\"" D_TEMPERATURE "\":%s}"), mqtt_data, stemp1);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
domoticz_sensor(DZ_TEMP, stemp1);
|
||||
DomoticzSensor(DZ_TEMP, stemp1);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
String dsb_webPresent()
|
||||
String WebShowDs18b20()
|
||||
{
|
||||
// Needs TelePeriod to refresh data (Do not do it here as it takes too much time)
|
||||
String page = "";
|
||||
float st;
|
||||
|
||||
if (dsb_readTemp(st)) { // Check if read failed
|
||||
if (Ds18b20ReadTemperature(st)) { // Check if read failed
|
||||
char stemp[10];
|
||||
char sensor[80];
|
||||
|
||||
dtostrfi(st, sysCfg.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "DS18B20", stemp, tempUnit());
|
||||
dtostrfi(st, Settings.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "DS18B20", stemp, TempUnit());
|
||||
page += sensor;
|
||||
}
|
||||
dsb_readTempPrep();
|
||||
Ds18b20ReadTempPrep();
|
||||
return page;
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
|
|
|
@ -36,64 +36,62 @@
|
|||
|
||||
OneWire *ds = NULL;
|
||||
|
||||
uint8_t ds18x20_addr[DS18X20_MAX_SENSORS][8];
|
||||
uint8_t ds18x20_idx[DS18X20_MAX_SENSORS];
|
||||
uint8_t ds18x20_snsrs = 0;
|
||||
char dsbstype[9];
|
||||
uint8_t ds18x20_address[DS18X20_MAX_SENSORS][8];
|
||||
uint8_t ds18x20_index[DS18X20_MAX_SENSORS];
|
||||
uint8_t ds18x20_sensors = 0;
|
||||
char ds18x20_types[9];
|
||||
|
||||
void ds18x20_init()
|
||||
void Ds18x20Init()
|
||||
{
|
||||
ds = new OneWire(pin[GPIO_DSB]);
|
||||
}
|
||||
|
||||
void ds18x20_search()
|
||||
void Ds18x20Search()
|
||||
{
|
||||
uint8_t num_sensors=0;
|
||||
uint8_t sensor = 0;
|
||||
uint8_t i;
|
||||
|
||||
ds->reset_search();
|
||||
for (num_sensors = 0; num_sensors < DS18X20_MAX_SENSORS; num_sensors) {
|
||||
if (!ds->search(ds18x20_addr[num_sensors])) {
|
||||
if (!ds->search(ds18x20_address[num_sensors])) {
|
||||
ds->reset_search();
|
||||
break;
|
||||
}
|
||||
// If CRC Ok and Type DS18S20, DS18B20 or MAX31850
|
||||
if ((OneWire::crc8(ds18x20_addr[num_sensors], 7) == ds18x20_addr[num_sensors][7]) &&
|
||||
((ds18x20_addr[num_sensors][0]==DS18S20_CHIPID) || (ds18x20_addr[num_sensors][0]==DS18B20_CHIPID) || (ds18x20_addr[num_sensors][0]==MAX31850_CHIPID))) {
|
||||
if ((OneWire::crc8(ds18x20_address[num_sensors], 7) == ds18x20_address[num_sensors][7]) &&
|
||||
((ds18x20_address[num_sensors][0]==DS18S20_CHIPID) || (ds18x20_address[num_sensors][0]==DS18B20_CHIPID) || (ds18x20_address[num_sensors][0]==MAX31850_CHIPID))) {
|
||||
num_sensors++;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < num_sensors; i++) {
|
||||
ds18x20_idx[i] = i;
|
||||
for (byte i = 0; i < num_sensors; i++) {
|
||||
ds18x20_index[i] = i;
|
||||
}
|
||||
for (int i = 0; i < num_sensors; i++) {
|
||||
for (int j = i + 1; j < num_sensors; j++) {
|
||||
if (uint32_t(ds18x20_addr[ds18x20_idx[i]]) > uint32_t(ds18x20_addr[ds18x20_idx[j]])) {
|
||||
std::swap(ds18x20_idx[i], ds18x20_idx[j]);
|
||||
for (byte i = 0; i < num_sensors; i++) {
|
||||
for (byte j = i + 1; j < num_sensors; j++) {
|
||||
if (uint32_t(ds18x20_address[ds18x20_index[i]]) > uint32_t(ds18x20_address[ds18x20_index[j]])) {
|
||||
std::swap(ds18x20_index[i], ds18x20_index[j]);
|
||||
}
|
||||
}
|
||||
}
|
||||
ds18x20_snsrs = num_sensors;
|
||||
ds18x20_sensors = num_sensors;
|
||||
}
|
||||
|
||||
uint8_t ds18x20_sensors()
|
||||
uint8_t Ds18x20Sensors()
|
||||
{
|
||||
return ds18x20_snsrs;
|
||||
return ds18x20_sensors;
|
||||
}
|
||||
|
||||
String ds18x20_address(uint8_t sensor)
|
||||
String Ds18x20Addresses(uint8_t sensor)
|
||||
{
|
||||
char addrStr[20];
|
||||
uint8_t i;
|
||||
char address[20];
|
||||
|
||||
for (i = 0; i < 8; i++) {
|
||||
sprintf(addrStr+2*i, "%02X", ds18x20_addr[ds18x20_idx[sensor]][i]);
|
||||
for (byte i = 0; i < 8; i++) {
|
||||
sprintf(address+2*i, "%02X", ds18x20_address[ds18x20_index[sensor]][i]);
|
||||
}
|
||||
return String(addrStr);
|
||||
return String(address);
|
||||
}
|
||||
|
||||
void ds18x20_convert()
|
||||
void Ds18x20Convert()
|
||||
{
|
||||
ds->reset();
|
||||
ds->write(W1_SKIP_ROM); // Address all Sensors on Bus
|
||||
|
@ -101,40 +99,25 @@ void ds18x20_convert()
|
|||
// delay(750); // 750ms should be enough for 12bit conv
|
||||
}
|
||||
|
||||
boolean ds18x20_read(uint8_t sensor, float &t)
|
||||
boolean Ds18x20Read(uint8_t sensor, float &t)
|
||||
{
|
||||
byte data[12];
|
||||
int8_t sign = 1;
|
||||
uint8_t i = 0;
|
||||
float temp9 = 0.0;
|
||||
uint8_t present = 0;
|
||||
|
||||
t = NAN;
|
||||
|
||||
ds->reset();
|
||||
ds->select(ds18x20_addr[ds18x20_idx[sensor]]);
|
||||
ds->select(ds18x20_address[ds18x20_index[sensor]]);
|
||||
ds->write(W1_READ_SCRATCHPAD); // Read Scratchpad
|
||||
|
||||
for (i = 0; i < 9; i++) {
|
||||
for (byte i = 0; i < 9; i++) {
|
||||
data[i] = ds->read();
|
||||
}
|
||||
if (OneWire::crc8(data, 8) == data[8]) {
|
||||
switch(ds18x20_addr[ds18x20_idx[sensor]][0]) {
|
||||
switch(ds18x20_address[ds18x20_index[sensor]][0]) {
|
||||
case DS18S20_CHIPID: // DS18S20
|
||||
/*
|
||||
// App_note AN162.pdf page 9
|
||||
int temp_lsb, temp_msb;
|
||||
temp_msb = data[1]; // Sign byte + lsbit
|
||||
temp_lsb = data[0]; // Temp data plus lsb
|
||||
if (temp_msb <= 0x80) temp_lsb = (temp_lsb/2); // Shift to get whole degree
|
||||
temp_msb = temp_msb & 0x80; // Mask all but the sign bit
|
||||
if (temp_msb >= 0x80) { // Negative temperature
|
||||
temp_lsb = (~temp_lsb)+1; // Twos complement
|
||||
temp_lsb = (temp_lsb/2); // Shift to get whole degree
|
||||
temp_lsb = ((-1)*temp_lsb); // Add sign bit
|
||||
}
|
||||
t = (int)temp_lsb; // Temperature in whole degree
|
||||
*/
|
||||
if (data[1] > 0x80) {
|
||||
data[0] = (~data[0]) +1;
|
||||
sign = -1; // App-Note fix possible sign error
|
||||
|
@ -144,7 +127,7 @@ boolean ds18x20_read(uint8_t sensor, float &t)
|
|||
} else {
|
||||
temp9 = (data[0] >> 1) * sign;
|
||||
}
|
||||
t = convertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
|
||||
t = ConvertTemp((temp9 - 0.25) + ((16.0 - data[6]) / 16.0));
|
||||
break;
|
||||
case DS18B20_CHIPID: // DS18B20
|
||||
case MAX31850_CHIPID: // MAX31850
|
||||
|
@ -153,7 +136,7 @@ boolean ds18x20_read(uint8_t sensor, float &t)
|
|||
temp12 = (~temp12) +1;
|
||||
sign = -1;
|
||||
}
|
||||
t = convertTemp(sign * temp12 * 0.0625);
|
||||
t = ConvertTemp(sign * temp12 * 0.0625);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -164,33 +147,33 @@ boolean ds18x20_read(uint8_t sensor, float &t)
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void ds18x20_type(uint8_t sensor)
|
||||
void Ds18x20Type(uint8_t sensor)
|
||||
{
|
||||
strcpy_P(dsbstype, PSTR("DS18x20"));
|
||||
switch(ds18x20_addr[ds18x20_idx[sensor]][0]) {
|
||||
strcpy_P(ds18x20_types, PSTR("DS18x20"));
|
||||
switch(ds18x20_address[ds18x20_index[sensor]][0]) {
|
||||
case DS18S20_CHIPID:
|
||||
strcpy_P(dsbstype, PSTR("DS18S20"));
|
||||
strcpy_P(ds18x20_types, PSTR("DS18S20"));
|
||||
break;
|
||||
case DS18B20_CHIPID:
|
||||
strcpy_P(dsbstype, PSTR("DS18B20"));
|
||||
strcpy_P(ds18x20_types, PSTR("DS18B20"));
|
||||
break;
|
||||
case MAX31850_CHIPID:
|
||||
strcpy_P(dsbstype, PSTR("MAX31850"));
|
||||
strcpy_P(ds18x20_types, PSTR("MAX31850"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void ds18x20_mqttPresent(uint8_t* djson)
|
||||
void MqttShowDs18x20(uint8_t* djson)
|
||||
{
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
float t;
|
||||
|
||||
byte dsxflg = 0;
|
||||
for (byte i = 0; i < ds18x20_sensors(); i++) {
|
||||
if (ds18x20_read(i, t)) { // Check if read failed
|
||||
ds18x20_type(i);
|
||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp2);
|
||||
for (byte i = 0; i < Ds18x20Sensors(); i++) {
|
||||
if (Ds18x20Read(i, t)) { // Check if read failed
|
||||
Ds18x20Type(i);
|
||||
dtostrfd(t, Settings.flag.temperature_resolution, stemp2);
|
||||
if (!dsxflg) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18x20\":{"), mqtt_data);
|
||||
*djson = 1;
|
||||
|
@ -198,11 +181,11 @@ void ds18x20_mqttPresent(uint8_t* djson)
|
|||
}
|
||||
dsxflg++;
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"DS%d\":{\"" D_TYPE "\":\"%s\", \"" D_ADDRESS "\":\"%s\", \"" D_TEMPERATURE "\":%s}"),
|
||||
mqtt_data, stemp1, i +1, dsbstype, ds18x20_address(i).c_str(), stemp2);
|
||||
mqtt_data, stemp1, i +1, ds18x20_types, Ds18x20Addresses(i).c_str(), stemp2);
|
||||
strcpy(stemp1, ", ");
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (1 == dsxflg) {
|
||||
domoticz_sensor(DZ_TEMP, stemp2);
|
||||
DomoticzSensor(DZ_TEMP, stemp2);
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
@ -213,7 +196,7 @@ void ds18x20_mqttPresent(uint8_t* djson)
|
|||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
String ds18x20_webPresent()
|
||||
String WebShowDs18x20()
|
||||
{
|
||||
String page = "";
|
||||
char stemp[10];
|
||||
|
@ -221,17 +204,17 @@ String ds18x20_webPresent()
|
|||
char sensor[80];
|
||||
float t;
|
||||
|
||||
for (byte i = 0; i < ds18x20_sensors(); i++) {
|
||||
if (ds18x20_read(i, t)) { // Check if read failed
|
||||
ds18x20_type(i);
|
||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
||||
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s-%d"), dsbstype, i +1);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, stemp2, stemp, tempUnit());
|
||||
for (byte i = 0; i < Ds18x20Sensors(); i++) {
|
||||
if (Ds18x20Read(i, t)) { // Check if read failed
|
||||
Ds18x20Type(i);
|
||||
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s-%d"), ds18x20_types, i +1);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, stemp2, stemp, TempUnit());
|
||||
page += sensor;
|
||||
}
|
||||
}
|
||||
ds18x20_search(); // Check for changes in sensors number
|
||||
ds18x20_convert(); // Start Conversion, takes up to one second
|
||||
Ds18x20Search(); // Check for changes in sensors number
|
||||
Ds18x20Convert(); // Start Conversion, takes up to one second
|
||||
return page;
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
|
|
|
@ -33,12 +33,12 @@
|
|||
|
||||
#define HLW_POWER_PROBE_TIME 10 // Number of seconds to probe for power before deciding none used
|
||||
|
||||
byte hlw_pminflg = 0;
|
||||
byte hlw_pmaxflg = 0;
|
||||
byte hlw_uminflg = 0;
|
||||
byte hlw_umaxflg = 0;
|
||||
byte hlw_iminflg = 0;
|
||||
byte hlw_imaxflg = 0;
|
||||
byte hlw_pmin_flag = 0;
|
||||
byte hlw_pmax_flag = 0;
|
||||
byte hlw_umin_flag = 0;
|
||||
byte hlw_umax_flag = 0;
|
||||
byte hlw_imin_flag = 0;
|
||||
byte hlw_imax_flag = 0;
|
||||
|
||||
byte power_steady_cntr;
|
||||
byte hlw_mkwh_state = 0;
|
||||
|
@ -49,59 +49,59 @@ byte hlw_mkwh_state = 0;
|
|||
uint16_t hlw_mplw_counter = 0;
|
||||
#endif // FEATURE_POWER_LIMIT
|
||||
|
||||
byte hlw_SELflag;
|
||||
byte hlw_select_ui_flag;
|
||||
byte hlw_load_off;
|
||||
byte hlw_cf1_timer;
|
||||
byte hlw_fifth_second;
|
||||
byte hlw_startup;
|
||||
unsigned long hlw_cf_plen;
|
||||
unsigned long hlw_cf_last;
|
||||
unsigned long hlw_cf1_plen;
|
||||
unsigned long hlw_cf1_last;
|
||||
unsigned long hlw_cf1_ptot;
|
||||
unsigned long hlw_cf1_pcnt;
|
||||
unsigned long hlw_cf1u_plen;
|
||||
unsigned long hlw_cf1i_plen;
|
||||
unsigned long hlw_Ecntr;
|
||||
unsigned long hlw_EDcntr;
|
||||
unsigned long hlw_cf_pulse_length;
|
||||
unsigned long hlw_cf_pulse_last_time;
|
||||
unsigned long hlw_cf1_pulse_length;
|
||||
unsigned long hlw_cf1_pulse_last_time;
|
||||
unsigned long hlw_cf1_summed_pulse_length;
|
||||
unsigned long hlw_cf1_pulse_counter;
|
||||
unsigned long hlw_cf1_voltage_pulse_length;
|
||||
unsigned long hlw_cf1_current_pulse_length;
|
||||
unsigned long hlw_energy_counter;
|
||||
unsigned long hlw_energy_period_counter;
|
||||
unsigned long hlw_kWhtoday;
|
||||
uint32_t hlw_lasttime;
|
||||
|
||||
unsigned long hlw_cf1u_pcntmax;
|
||||
unsigned long hlw_cf1i_pcntmax;
|
||||
unsigned long hlw_cf1_voltage_max_pulse_counter;
|
||||
unsigned long hlw_cf1_current_max_pulse_counter;
|
||||
|
||||
Ticker tickerHLW;
|
||||
|
||||
#ifndef USE_WS2812_DMA // Collides with Neopixelbus but solves exception
|
||||
void hlw_cf_interrupt() ICACHE_RAM_ATTR;
|
||||
void hlw_cf1_interrupt() ICACHE_RAM_ATTR;
|
||||
void HlwCfInterrupt() ICACHE_RAM_ATTR;
|
||||
void HlwCf1Interrupt() ICACHE_RAM_ATTR;
|
||||
#endif // USE_WS2812_DMA
|
||||
|
||||
void hlw_cf_interrupt() // Service Power
|
||||
void HlwCfInterrupt() // Service Power
|
||||
{
|
||||
unsigned long us = micros();
|
||||
|
||||
if (hlw_load_off) { // Restart plen measurement
|
||||
hlw_cf_last = us;
|
||||
hlw_cf_pulse_last_time = us;
|
||||
hlw_load_off = 0;
|
||||
} else {
|
||||
hlw_cf_plen = us - hlw_cf_last;
|
||||
hlw_cf_last = us;
|
||||
hlw_EDcntr++;
|
||||
hlw_Ecntr++;
|
||||
hlw_cf_pulse_length = us - hlw_cf_pulse_last_time;
|
||||
hlw_cf_pulse_last_time = us;
|
||||
hlw_energy_period_counter++;
|
||||
hlw_energy_counter++;
|
||||
}
|
||||
}
|
||||
|
||||
void hlw_cf1_interrupt() // Service Voltage and Current
|
||||
void HlwCf1Interrupt() // Service Voltage and Current
|
||||
{
|
||||
unsigned long us = micros();
|
||||
|
||||
hlw_cf1_plen = us - hlw_cf1_last;
|
||||
hlw_cf1_last = us;
|
||||
hlw_cf1_pulse_length = us - hlw_cf1_pulse_last_time;
|
||||
hlw_cf1_pulse_last_time = us;
|
||||
if ((hlw_cf1_timer > 2) && (hlw_cf1_timer < 8)) { // Allow for 300 mSec set-up time and measure for up to 1 second
|
||||
hlw_cf1_ptot += hlw_cf1_plen;
|
||||
hlw_cf1_pcnt++;
|
||||
if (10 == hlw_cf1_pcnt) {
|
||||
hlw_cf1_summed_pulse_length += hlw_cf1_pulse_length;
|
||||
hlw_cf1_pulse_counter++;
|
||||
if (10 == hlw_cf1_pulse_counter) {
|
||||
hlw_cf1_timer = 8; // We need up to ten samples within 1 second (low current could take up to 0.3 second)
|
||||
}
|
||||
}
|
||||
|
@ -116,71 +116,71 @@ void hlw_200mS()
|
|||
if (5 == hlw_fifth_second) {
|
||||
hlw_fifth_second = 0;
|
||||
|
||||
if (hlw_EDcntr) {
|
||||
hlw_len = 10000 / hlw_EDcntr;
|
||||
hlw_EDcntr = 0;
|
||||
if (hlw_energy_period_counter) {
|
||||
hlw_len = 10000 / hlw_energy_period_counter;
|
||||
hlw_energy_period_counter = 0;
|
||||
if (hlw_len) {
|
||||
hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / 36;
|
||||
hlw_temp = ((HLW_PREF * Settings.hlw_power_calibration) / hlw_len) / 36;
|
||||
hlw_kWhtoday += hlw_temp;
|
||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
||||
RtcSettings.hlw_kWhtoday = hlw_kWhtoday;
|
||||
}
|
||||
}
|
||||
if (rtcTime.Valid) {
|
||||
if (rtc_loctime() == rtc_midnight()) {
|
||||
sysCfg.hlw_kWhyesterday = hlw_kWhtoday;
|
||||
sysCfg.hlw_kWhtotal += (hlw_kWhtoday / 1000);
|
||||
rtcMem.hlw_kWhtotal = sysCfg.hlw_kWhtotal;
|
||||
if (RtcTime.valid) {
|
||||
if (LocalTime() == Midnight()) {
|
||||
Settings.hlw_kWhyesterday = hlw_kWhtoday;
|
||||
Settings.hlw_kWhtotal += (hlw_kWhtoday / 1000);
|
||||
RtcSettings.hlw_kWhtotal = Settings.hlw_kWhtotal;
|
||||
hlw_kWhtoday = 0;
|
||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
||||
RtcSettings.hlw_kWhtoday = hlw_kWhtoday;
|
||||
hlw_mkwh_state = 3;
|
||||
}
|
||||
if ((rtcTime.Hour == sysCfg.hlw_mkwhs) && (3 == hlw_mkwh_state)) {
|
||||
if ((RtcTime.hour == Settings.hlw_mkwhs) && (3 == hlw_mkwh_state)) {
|
||||
hlw_mkwh_state = 0;
|
||||
}
|
||||
if (hlw_startup && (rtcTime.DayOfYear == sysCfg.hlw_kWhdoy)) {
|
||||
hlw_kWhtoday = sysCfg.hlw_kWhtoday;
|
||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
||||
if (hlw_startup && (RtcTime.day_of_year == Settings.hlw_kWhdoy)) {
|
||||
hlw_kWhtoday = Settings.hlw_kWhtoday;
|
||||
RtcSettings.hlw_kWhtoday = hlw_kWhtoday;
|
||||
hlw_startup = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (micros() - hlw_cf_last > (HLW_POWER_PROBE_TIME * 1000000)) {
|
||||
hlw_cf_plen = 0; // No load for some time
|
||||
if (micros() - hlw_cf_pulse_last_time > (HLW_POWER_PROBE_TIME * 1000000)) {
|
||||
hlw_cf_pulse_length = 0; // No load for some time
|
||||
hlw_load_off = 1;
|
||||
}
|
||||
|
||||
hlw_cf1_timer++;
|
||||
if (hlw_cf1_timer >= 8) {
|
||||
hlw_cf1_timer = 0;
|
||||
hlw_SELflag = (hlw_SELflag) ? 0 : 1;
|
||||
digitalWrite(pin[GPIO_HLW_SEL], hlw_SELflag);
|
||||
hlw_select_ui_flag = (hlw_select_ui_flag) ? 0 : 1;
|
||||
digitalWrite(pin[GPIO_HLW_SEL], hlw_select_ui_flag);
|
||||
|
||||
if (hlw_cf1_pcnt) {
|
||||
hlw_cf1_plen = hlw_cf1_ptot / hlw_cf1_pcnt;
|
||||
if (hlw_cf1_pulse_counter) {
|
||||
hlw_cf1_pulse_length = hlw_cf1_summed_pulse_length / hlw_cf1_pulse_counter;
|
||||
} else {
|
||||
hlw_cf1_plen = 0;
|
||||
hlw_cf1_pulse_length = 0;
|
||||
}
|
||||
if (hlw_SELflag) {
|
||||
hlw_cf1u_plen = hlw_cf1_plen;
|
||||
hlw_cf1u_pcntmax = hlw_cf1_pcnt;
|
||||
if (hlw_select_ui_flag) {
|
||||
hlw_cf1_voltage_pulse_length = hlw_cf1_pulse_length;
|
||||
hlw_cf1_voltage_max_pulse_counter = hlw_cf1_pulse_counter;
|
||||
} else {
|
||||
hlw_cf1i_plen = hlw_cf1_plen;
|
||||
hlw_cf1i_pcntmax = hlw_cf1_pcnt;
|
||||
hlw_cf1_current_pulse_length = hlw_cf1_pulse_length;
|
||||
hlw_cf1_current_max_pulse_counter = hlw_cf1_pulse_counter;
|
||||
}
|
||||
hlw_cf1_ptot = 0;
|
||||
hlw_cf1_pcnt = 0;
|
||||
hlw_cf1_summed_pulse_length = 0;
|
||||
hlw_cf1_pulse_counter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void hlw_savestate()
|
||||
void HlwSaveState()
|
||||
{
|
||||
sysCfg.hlw_kWhdoy = (rtcTime.Valid) ? rtcTime.DayOfYear : 0;
|
||||
sysCfg.hlw_kWhtoday = hlw_kWhtoday;
|
||||
sysCfg.hlw_kWhtotal = rtcMem.hlw_kWhtotal;
|
||||
Settings.hlw_kWhdoy = (RtcTime.valid) ? RtcTime.day_of_year : 0;
|
||||
Settings.hlw_kWhtoday = hlw_kWhtoday;
|
||||
Settings.hlw_kWhtotal = RtcSettings.hlw_kWhtotal;
|
||||
}
|
||||
|
||||
void hlw_readEnergy(byte option, float &et, float &ed, float &e, float &w, float &u, float &i, float &c)
|
||||
void HlwReadEnergy(byte option, float &total_energy, float &daily_energy, float &energy, float &watts, float &voltage, float ¤t, float &power_factor)
|
||||
{
|
||||
/* option 0 = do not calculate period energy usage
|
||||
* option 1 = calculate period energy usage
|
||||
|
@ -192,91 +192,90 @@ void hlw_readEnergy(byte option, float &et, float &ed, float &e, float &w, float
|
|||
unsigned long hlw_u;
|
||||
unsigned long hlw_i;
|
||||
uint16_t hlw_period;
|
||||
uint16_t hlw_interval;
|
||||
|
||||
//snprintf_P(log_data, sizeof(log_data), PSTR("HLW: CF %d, CF1U %d (%d), CF1I %d (%d)"), hlw_cf_plen, hlw_cf1u_plen, hlw_cf1u_pcntmax, hlw_cf1i_plen, hlw_cf1i_pcntmax);
|
||||
//addLog(LOG_LEVEL_DEBUG);
|
||||
//snprintf_P(log_data, sizeof(log_data), PSTR("HLW: CF %d, CF1U %d (%d), CF1I %d (%d)"), hlw_cf_pulse_length, hlw_cf1_voltage_pulse_length, hlw_cf1_voltage_max_pulse_counter, hlw_cf1_current_pulse_length, hlw_cf1_current_max_pulse_counter);
|
||||
//AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
et = (float)(rtcMem.hlw_kWhtotal + (cur_kWhtoday / 1000)) / 100000;
|
||||
ed = 0;
|
||||
total_energy = (float)(RtcSettings.hlw_kWhtotal + (cur_kWhtoday / 1000)) / 100000;
|
||||
daily_energy = 0;
|
||||
if (cur_kWhtoday) {
|
||||
ed = (float)cur_kWhtoday / 100000000;
|
||||
daily_energy = (float)cur_kWhtoday / 100000000;
|
||||
}
|
||||
e = 0;
|
||||
energy = 0;
|
||||
if (option) {
|
||||
if (!hlw_lasttime) {
|
||||
hlw_period = sysCfg.tele_period;
|
||||
hlw_period = Settings.tele_period;
|
||||
} else {
|
||||
hlw_period = rtc_loctime() - hlw_lasttime;
|
||||
hlw_period = LocalTime() - hlw_lasttime;
|
||||
}
|
||||
hlw_lasttime = rtc_loctime();
|
||||
hlw_lasttime = LocalTime();
|
||||
if (hlw_period) {
|
||||
hlw_interval = 3600 / hlw_period;
|
||||
if (hlw_Ecntr) {
|
||||
hlw_len = hlw_period * 1000000 / hlw_Ecntr;
|
||||
uint16_t hlw_interval = 3600 / hlw_period;
|
||||
if (hlw_energy_counter) {
|
||||
hlw_len = hlw_period * 1000000 / hlw_energy_counter;
|
||||
if (hlw_interval && hlw_len) {
|
||||
hlw_Ecntr = 0;
|
||||
hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / hlw_interval;
|
||||
e = (float)hlw_temp / 10;
|
||||
hlw_energy_counter = 0;
|
||||
hlw_temp = ((HLW_PREF * Settings.hlw_power_calibration) / hlw_len) / hlw_interval;
|
||||
energy = (float)hlw_temp / 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
w = 0;
|
||||
if (hlw_cf_plen && (power &1) && !hlw_load_off) {
|
||||
hlw_w = (HLW_PREF * sysCfg.hlw_pcal) / hlw_cf_plen;
|
||||
w = (float)hlw_w / 10;
|
||||
watts = 0;
|
||||
if (hlw_cf_pulse_length && (power &1) && !hlw_load_off) {
|
||||
hlw_w = (HLW_PREF * Settings.hlw_power_calibration) / hlw_cf_pulse_length;
|
||||
watts = (float)hlw_w / 10;
|
||||
}
|
||||
u = 0;
|
||||
if (hlw_cf1u_plen && (power &1)) { // If powered on always provide voltage
|
||||
hlw_u = (HLW_UREF * sysCfg.hlw_ucal) / hlw_cf1u_plen;
|
||||
u = (float)hlw_u / 10;
|
||||
voltage = 0;
|
||||
if (hlw_cf1_voltage_pulse_length && (power &1)) { // If powered on always provide voltage
|
||||
hlw_u = (HLW_UREF * Settings.hlw_voltage_calibration) / hlw_cf1_voltage_pulse_length;
|
||||
voltage = (float)hlw_u / 10;
|
||||
}
|
||||
i = 0;
|
||||
if (hlw_cf1i_plen && w) { // No current if no power being consumed
|
||||
hlw_i = (HLW_IREF * sysCfg.hlw_ical) / hlw_cf1i_plen;
|
||||
i = (float)hlw_i / 1000;
|
||||
current = 0;
|
||||
if (hlw_cf1_current_pulse_length && watts) { // No current if no power being consumed
|
||||
hlw_i = (HLW_IREF * Settings.hlw_current_calibration) / hlw_cf1_current_pulse_length;
|
||||
current = (float)hlw_i / 1000;
|
||||
}
|
||||
c = 0;
|
||||
if (hlw_i && hlw_u && hlw_w && w) {
|
||||
power_factor = 0;
|
||||
if (hlw_i && hlw_u && hlw_w && watts) {
|
||||
hlw_temp = (hlw_w * 100) / ((hlw_u * hlw_i) / 1000);
|
||||
if (hlw_temp > 100) {
|
||||
hlw_temp = 100;
|
||||
}
|
||||
c = (float)hlw_temp / 100;
|
||||
power_factor = (float)hlw_temp / 100;
|
||||
}
|
||||
}
|
||||
|
||||
void hlw_init()
|
||||
void HlwInit()
|
||||
{
|
||||
if (!sysCfg.hlw_pcal || (4975 == sysCfg.hlw_pcal)) {
|
||||
sysCfg.hlw_pcal = HLW_PREF_PULSE;
|
||||
sysCfg.hlw_ucal = HLW_UREF_PULSE;
|
||||
sysCfg.hlw_ical = HLW_IREF_PULSE;
|
||||
if (!Settings.hlw_power_calibration || (4975 == Settings.hlw_power_calibration)) {
|
||||
Settings.hlw_power_calibration = HLW_PREF_PULSE;
|
||||
Settings.hlw_voltage_calibration = HLW_UREF_PULSE;
|
||||
Settings.hlw_current_calibration = HLW_IREF_PULSE;
|
||||
}
|
||||
|
||||
hlw_cf_plen = 0;
|
||||
hlw_cf_last = 0;
|
||||
hlw_cf1_plen = 0;
|
||||
hlw_cf1_last = 0;
|
||||
hlw_cf1u_plen = 0;
|
||||
hlw_cf1i_plen = 0;
|
||||
hlw_cf1u_pcntmax = 0;
|
||||
hlw_cf1i_pcntmax = 0;
|
||||
hlw_cf_pulse_length = 0;
|
||||
hlw_cf_pulse_last_time = 0;
|
||||
hlw_cf1_pulse_length = 0;
|
||||
hlw_cf1_pulse_last_time = 0;
|
||||
hlw_cf1_voltage_pulse_length = 0;
|
||||
hlw_cf1_current_pulse_length = 0;
|
||||
hlw_cf1_voltage_max_pulse_counter = 0;
|
||||
hlw_cf1_current_max_pulse_counter = 0;
|
||||
|
||||
hlw_load_off = 1;
|
||||
hlw_Ecntr = 0;
|
||||
hlw_EDcntr = 0;
|
||||
hlw_kWhtoday = (RTC_Valid()) ? rtcMem.hlw_kWhtoday : 0;
|
||||
hlw_energy_counter = 0;
|
||||
hlw_energy_period_counter = 0;
|
||||
hlw_kWhtoday = (RtcSettingsValid()) ? RtcSettings.hlw_kWhtoday : 0;
|
||||
|
||||
hlw_SELflag = 0; // Voltage;
|
||||
hlw_select_ui_flag = 0; // Voltage;
|
||||
|
||||
pinMode(pin[GPIO_HLW_SEL], OUTPUT);
|
||||
digitalWrite(pin[GPIO_HLW_SEL], hlw_SELflag);
|
||||
digitalWrite(pin[GPIO_HLW_SEL], hlw_select_ui_flag);
|
||||
pinMode(pin[GPIO_HLW_CF1], INPUT_PULLUP);
|
||||
attachInterrupt(pin[GPIO_HLW_CF1], hlw_cf1_interrupt, FALLING);
|
||||
attachInterrupt(pin[GPIO_HLW_CF1], HlwCf1Interrupt, FALLING);
|
||||
pinMode(pin[GPIO_HLW_CF], INPUT_PULLUP);
|
||||
attachInterrupt(pin[GPIO_HLW_CF], hlw_cf_interrupt, FALLING);
|
||||
attachInterrupt(pin[GPIO_HLW_CF], HlwCfInterrupt, FALLING);
|
||||
|
||||
hlw_startup = 1;
|
||||
hlw_lasttime = 0;
|
||||
|
@ -287,41 +286,41 @@ void hlw_init()
|
|||
|
||||
/********************************************************************************************/
|
||||
|
||||
boolean hlw_margin(byte type, uint16_t margin, uint16_t value, byte &flag, byte &saveflag)
|
||||
boolean HlwMargin(byte type, uint16_t margin, uint16_t value, byte &flag, byte &save_flag)
|
||||
{
|
||||
byte change;
|
||||
|
||||
if (!margin) {
|
||||
return false;
|
||||
}
|
||||
change = saveflag;
|
||||
change = save_flag;
|
||||
if (type) {
|
||||
flag = (value > margin);
|
||||
} else {
|
||||
flag = (value < margin);
|
||||
}
|
||||
saveflag = flag;
|
||||
return (change != saveflag);
|
||||
save_flag = flag;
|
||||
return (change != save_flag);
|
||||
}
|
||||
|
||||
void hlw_setPowerSteadyCounter(byte value)
|
||||
void HlwSetPowerSteadyCounter(byte value)
|
||||
{
|
||||
power_steady_cntr = 2;
|
||||
}
|
||||
|
||||
void hlw_margin_chk()
|
||||
void HlwMarginCheck()
|
||||
{
|
||||
float pet;
|
||||
float ped;
|
||||
float pe;
|
||||
float pw;
|
||||
float pu;
|
||||
float pi;
|
||||
float pc;
|
||||
uint16_t uped;
|
||||
uint16_t pwv;
|
||||
uint16_t puv;
|
||||
uint16_t piv;
|
||||
float total_energy;
|
||||
float daily_energy;
|
||||
float energy;
|
||||
float watts;
|
||||
float voltage;
|
||||
float current;
|
||||
float power_factor;
|
||||
uint16_t udaily_energy;
|
||||
uint16_t uwatts;
|
||||
uint16_t uvoltage;
|
||||
uint16_t ucurrent;
|
||||
boolean flag;
|
||||
boolean jsonflg;
|
||||
|
||||
|
@ -330,69 +329,69 @@ void hlw_margin_chk()
|
|||
return;
|
||||
}
|
||||
|
||||
hlw_readEnergy(0, pet, ped, pe, pw, pu, pi, pc);
|
||||
if (power && (sysCfg.hlw_pmin || sysCfg.hlw_pmax || sysCfg.hlw_umin || sysCfg.hlw_umax || sysCfg.hlw_imin || sysCfg.hlw_imax)) {
|
||||
pwv = (uint16_t)(pw);
|
||||
puv = (uint16_t)(pu);
|
||||
piv = (uint16_t)(pi * 1000);
|
||||
HlwReadEnergy(0, total_energy, daily_energy, energy, watts, voltage, current, power_factor);
|
||||
if (power && (Settings.hlw_pmin || Settings.hlw_pmax || Settings.hlw_umin || Settings.hlw_umax || Settings.hlw_imin || Settings.hlw_imax)) {
|
||||
uwatts = (uint16_t)(watts);
|
||||
uvoltage = (uint16_t)(voltage);
|
||||
ucurrent = (uint16_t)(current * 1000);
|
||||
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("HLW: W %d, U %d, I %d"), pw, pu, piv);
|
||||
// addLog(LOG_LEVEL_DEBUG);
|
||||
// snprintf_P(log_data, sizeof(log_data), PSTR("HLW: W %d, U %d, I %d"), watts, voltage, ucurrent);
|
||||
// AddLog(LOG_LEVEL_DEBUG);
|
||||
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{"));
|
||||
jsonflg = 0;
|
||||
if (hlw_margin(0, sysCfg.hlw_pmin, pwv, flag, hlw_pminflg)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
|
||||
if (HlwMargin(0, Settings.hlw_pmin, uwatts, flag, hlw_pmin_flag)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (hlw_margin(1, sysCfg.hlw_pmax, pwv, flag, hlw_pmaxflg)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
|
||||
if (HlwMargin(1, Settings.hlw_pmax, uwatts, flag, hlw_pmax_flag)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (hlw_margin(0, sysCfg.hlw_umin, puv, flag, hlw_uminflg)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGELOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
|
||||
if (HlwMargin(0, Settings.hlw_umin, uvoltage, flag, hlw_umin_flag)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGELOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (hlw_margin(1, sysCfg.hlw_umax, puv, flag, hlw_umaxflg)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGEHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
|
||||
if (HlwMargin(1, Settings.hlw_umax, uvoltage, flag, hlw_umax_flag)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGEHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (hlw_margin(0, sysCfg.hlw_imin, piv, flag, hlw_iminflg)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
|
||||
if (HlwMargin(0, Settings.hlw_imin, ucurrent, flag, hlw_imin_flag)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (hlw_margin(1, sysCfg.hlw_imax, piv, flag, hlw_imaxflg)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", getStateText(flag));
|
||||
if (HlwMargin(1, Settings.hlw_imax, ucurrent, flag, hlw_imax_flag)) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||
jsonflg = 1;
|
||||
}
|
||||
if (jsonflg) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
|
||||
mqtt_publish_topic_P(2, PSTR(D_RSLT_MARGINS));
|
||||
hlw_mqttPresent(0);
|
||||
MqttPublishPrefixTopic_P(2, PSTR(D_RSLT_MARGINS));
|
||||
MqttShowHlw8012(0);
|
||||
}
|
||||
}
|
||||
|
||||
#if FEATURE_POWER_LIMIT
|
||||
// Max Power
|
||||
if (sysCfg.hlw_mpl) {
|
||||
if (pw > sysCfg.hlw_mpl) {
|
||||
if (Settings.hlw_mpl) {
|
||||
if (watts > Settings.hlw_mpl) {
|
||||
if (!hlw_mplh_counter) {
|
||||
hlw_mplh_counter = sysCfg.hlw_mplh;
|
||||
hlw_mplh_counter = Settings.hlw_mplh;
|
||||
} else {
|
||||
hlw_mplh_counter--;
|
||||
if (!hlw_mplh_counter) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHED "\":\"%d%s\"}"), pwv, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
mqtt_publish_topic_P(1, S_RSLT_WARNING);
|
||||
hlw_mqttPresent(0);
|
||||
do_cmnd_power(1, 0);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHED "\":\"%d%s\"}"), uwatts, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
MqttPublishPrefixTopic_P(1, S_RSLT_WARNING);
|
||||
MqttShowHlw8012(0);
|
||||
ExecuteCommandPower(1, 0);
|
||||
if (!hlw_mplr_counter) {
|
||||
hlw_mplr_counter = sysCfg.param[P_MAX_POWER_RETRY] +1;
|
||||
hlw_mplr_counter = Settings.param[P_MAX_POWER_RETRY] +1;
|
||||
}
|
||||
hlw_mplw_counter = sysCfg.hlw_mplw;
|
||||
hlw_mplw_counter = Settings.hlw_mplw;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (power && (pwv <= sysCfg.hlw_mpl)) {
|
||||
else if (power && (uwatts <= Settings.hlw_mpl)) {
|
||||
hlw_mplh_counter = 0;
|
||||
hlw_mplr_counter = 0;
|
||||
hlw_mplw_counter = 0;
|
||||
|
@ -404,13 +403,13 @@ void hlw_margin_chk()
|
|||
if (hlw_mplr_counter) {
|
||||
hlw_mplr_counter--;
|
||||
if (hlw_mplr_counter) {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_POWERMONITOR "\":\"%s\"}"), getStateText(1));
|
||||
mqtt_publish_topic_P(5, PSTR(D_POWERMONITOR));
|
||||
do_cmnd_power(1, 1);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_POWERMONITOR "\":\"%s\"}"), GetStateText(1));
|
||||
MqttPublishPrefixTopic_P(5, PSTR(D_POWERMONITOR));
|
||||
ExecuteCommandPower(1, 1);
|
||||
} else {
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHEDRETRY "\":\"%s\"}"), getStateText(0));
|
||||
mqtt_publish_topic_P(1, S_RSLT_WARNING);
|
||||
hlw_mqttPresent(0);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0));
|
||||
MqttPublishPrefixTopic_P(1, S_RSLT_WARNING);
|
||||
MqttShowHlw8012(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -418,21 +417,21 @@ void hlw_margin_chk()
|
|||
}
|
||||
|
||||
// Max Energy
|
||||
if (sysCfg.hlw_mkwh) {
|
||||
uped = (uint16_t)(ped * 1000);
|
||||
if (!hlw_mkwh_state && (rtcTime.Hour == sysCfg.hlw_mkwhs)) {
|
||||
if (Settings.hlw_mkwh) {
|
||||
udaily_energy = (uint16_t)(daily_energy * 1000);
|
||||
if (!hlw_mkwh_state && (RtcTime.hour == Settings.hlw_mkwhs)) {
|
||||
hlw_mkwh_state = 1;
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_ENERGYMONITOR "\":\"%s\"}"), getStateText(1));
|
||||
mqtt_publish_topic_P(5, PSTR(D_ENERGYMONITOR));
|
||||
do_cmnd_power(1, 1);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1));
|
||||
MqttPublishPrefixTopic_P(5, PSTR(D_ENERGYMONITOR));
|
||||
ExecuteCommandPower(1, 1);
|
||||
}
|
||||
else if ((1 == hlw_mkwh_state) && (uped >= sysCfg.hlw_mkwh)) {
|
||||
else if ((1 == hlw_mkwh_state) && (udaily_energy >= Settings.hlw_mkwh)) {
|
||||
hlw_mkwh_state = 2;
|
||||
dtostrfd(ped, 3, mqtt_data);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (sysCfg.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
|
||||
mqtt_publish_topic_P(1, S_RSLT_WARNING);
|
||||
hlw_mqttPresent(0);
|
||||
do_cmnd_power(1, 0);
|
||||
dtostrfd(daily_energy, 3, mqtt_data);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (Settings.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
|
||||
MqttPublishPrefixTopic_P(1, S_RSLT_WARNING);
|
||||
MqttShowHlw8012(0);
|
||||
ExecuteCommandPower(1, 0);
|
||||
}
|
||||
}
|
||||
#endif // FEATURE_POWER_LIMIT
|
||||
|
@ -442,157 +441,158 @@ void hlw_margin_chk()
|
|||
* Commands
|
||||
\*********************************************************************************************/
|
||||
|
||||
boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
boolean HlwCommand(char *type, uint16_t index, char *dataBuf, uint16_t data_len, int16_t payload)
|
||||
{
|
||||
boolean serviced = true;
|
||||
uint8_t caltext = 0;
|
||||
|
||||
if (!strcasecmp_P(type, PSTR(D_CMND_POWERLOW))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_pmin = payload;
|
||||
Settings.hlw_pmin = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_POWERLOW "\":\"%d%s\"}"), sysCfg.hlw_pmin, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_POWERLOW "\":\"%d%s\"}"), Settings.hlw_pmin, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_POWERHIGH))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_pmax = payload;
|
||||
Settings.hlw_pmax = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_POWERHIGH "\":\"%d%s\"}"), sysCfg.hlw_pmax, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_POWERHIGH "\":\"%d%s\"}"), Settings.hlw_pmax, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_VOLTAGELOW))) {
|
||||
if ((payload >= 0) && (payload < 501)) {
|
||||
sysCfg.hlw_umin = payload;
|
||||
Settings.hlw_umin = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_VOLTAGELOW "\":\"%d%s\"}"), sysCfg.hlw_umin, (sysCfg.flag.value_units) ? " " D_UNIT_VOLT : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_VOLTAGELOW "\":\"%d%s\"}"), Settings.hlw_umin, (Settings.flag.value_units) ? " " D_UNIT_VOLT : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_VOLTAGEHIGH))) {
|
||||
if ((payload >= 0) && (payload < 501)) {
|
||||
sysCfg.hlw_umax = payload;
|
||||
Settings.hlw_umax = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_VOLTAGEHIGH "\":\"%d%s\"}"), sysCfg.hlw_umax, (sysCfg.flag.value_units) ? " " D_UNIT_VOLT : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_VOLTAGEHIGH "\":\"%d%s\"}"), Settings.hlw_umax, (Settings.flag.value_units) ? " " D_UNIT_VOLT : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_CURRENTLOW))) {
|
||||
if ((payload >= 0) && (payload < 16001)) {
|
||||
sysCfg.hlw_imin = payload;
|
||||
Settings.hlw_imin = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_CURRENTLOW "\":\"%d%s\"}"), sysCfg.hlw_imin, (sysCfg.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_CURRENTLOW "\":\"%d%s\"}"), Settings.hlw_imin, (Settings.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_CURRENTHIGH))) {
|
||||
if ((payload >= 0) && (payload < 16001)) {
|
||||
sysCfg.hlw_imax = payload;
|
||||
Settings.hlw_imax = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_CURRENTHIGH "\":\"%d%s\"}"), sysCfg.hlw_imax, (sysCfg.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_CURRENTHIGH "\":\"%d%s\"}"), Settings.hlw_imax, (Settings.flag.value_units) ? " " D_UNIT_MILLIAMPERE : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_ENERGYRESET))) {
|
||||
if ((payload >= 1) && (payload <= 3)) {
|
||||
switch (payload) {
|
||||
case 1:
|
||||
hlw_kWhtoday = 0;
|
||||
rtcMem.hlw_kWhtoday = 0;
|
||||
sysCfg.hlw_kWhtoday = 0;
|
||||
RtcSettings.hlw_kWhtoday = 0;
|
||||
Settings.hlw_kWhtoday = 0;
|
||||
break;
|
||||
case 2:
|
||||
sysCfg.hlw_kWhyesterday = 0;
|
||||
Settings.hlw_kWhyesterday = 0;
|
||||
break;
|
||||
case 3:
|
||||
rtcMem.hlw_kWhtotal = 0;
|
||||
sysCfg.hlw_kWhtotal = rtcMem.hlw_kWhtotal;
|
||||
RtcSettings.hlw_kWhtotal = 0;
|
||||
Settings.hlw_kWhtotal = RtcSettings.hlw_kWhtotal;
|
||||
break;
|
||||
}
|
||||
}
|
||||
char sey[10];
|
||||
char sen[10];
|
||||
char set[10];
|
||||
dtostrfd((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
|
||||
dtostrfd((float)rtcMem.hlw_kWhtoday / 100000000, sysCfg.flag.energy_resolution, sen);
|
||||
dtostrfd((float)(rtcMem.hlw_kWhtotal + (hlw_kWhtoday / 1000)) / 100000, sysCfg.flag.energy_resolution, set);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_ENERGYRESET "\":{\"" D_TOTAL "\":%s, \"" D_YESTERDAY "\":%s, \"" D_TODAY "\":%s}}"), set, sey, sen);
|
||||
char syesterday_energy[10];
|
||||
char stoday_energy[10];
|
||||
char stotal_energy[10];
|
||||
dtostrfd((float)Settings.hlw_kWhyesterday / 100000000, Settings.flag.energy_resolution, syesterday_energy);
|
||||
dtostrfd((float)RtcSettings.hlw_kWhtoday / 100000000, Settings.flag.energy_resolution, stoday_energy);
|
||||
dtostrfd((float)(RtcSettings.hlw_kWhtotal + (hlw_kWhtoday / 1000)) / 100000, Settings.flag.energy_resolution, stotal_energy);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_ENERGYRESET "\":{\"" D_TOTAL "\":%s, \"" D_YESTERDAY "\":%s, \"" D_TODAY "\":%s}}"),
|
||||
stotal_energy, syesterday_energy, stoday_energy);
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWPCAL))) {
|
||||
if ((payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_pcal = (payload > 4000) ? payload : HLW_PREF_PULSE; // 12530
|
||||
Settings.hlw_power_calibration = (payload > 4000) ? payload : HLW_PREF_PULSE; // 12530
|
||||
}
|
||||
caltext = 1;
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWPSET))) {
|
||||
if ((payload > 0) && (payload < 3601) && hlw_cf_plen) {
|
||||
sysCfg.hlw_pcal = (payload * 10 * hlw_cf_plen) / HLW_PREF;
|
||||
if ((payload > 0) && (payload < 3601) && hlw_cf_pulse_length) {
|
||||
Settings.hlw_power_calibration = (payload * 10 * hlw_cf_pulse_length) / HLW_PREF;
|
||||
}
|
||||
caltext = 1;
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWUCAL))) {
|
||||
if ((payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_ucal = (payload > 999) ? payload : HLW_UREF_PULSE; // 1950
|
||||
Settings.hlw_voltage_calibration = (payload > 999) ? payload : HLW_UREF_PULSE; // 1950
|
||||
}
|
||||
caltext = 2;
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWUSET))) {
|
||||
if ((payload > 0) && (payload < 501) && hlw_cf1u_plen) {
|
||||
sysCfg.hlw_ucal = (payload * 10 * hlw_cf1u_plen) / HLW_UREF;
|
||||
if ((payload > 0) && (payload < 501) && hlw_cf1_voltage_pulse_length) {
|
||||
Settings.hlw_voltage_calibration = (payload * 10 * hlw_cf1_voltage_pulse_length) / HLW_UREF;
|
||||
}
|
||||
caltext = 2;
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWICAL))) {
|
||||
if ((payload > 0) && (payload < 32001)) {
|
||||
sysCfg.hlw_ical = (payload > 1100) ? payload : HLW_IREF_PULSE; // 3500
|
||||
Settings.hlw_current_calibration = (payload > 1100) ? payload : HLW_IREF_PULSE; // 3500
|
||||
}
|
||||
caltext = 3;
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWISET))) {
|
||||
if ((payload > 0) && (payload < 16001) && hlw_cf1i_plen) {
|
||||
sysCfg.hlw_ical = (payload * hlw_cf1i_plen) / HLW_IREF;
|
||||
if ((payload > 0) && (payload < 16001) && hlw_cf1_current_pulse_length) {
|
||||
Settings.hlw_current_calibration = (payload * hlw_cf1_current_pulse_length) / HLW_IREF;
|
||||
}
|
||||
caltext = 3;
|
||||
}
|
||||
#if FEATURE_POWER_LIMIT
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWER))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mpl = payload;
|
||||
Settings.hlw_mpl = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWER "\":\"%d%s\"}"), sysCfg.hlw_mpl, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWER "\":\"%d%s\"}"), Settings.hlw_mpl, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWERHOLD))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mplh = (1 == payload) ? MAX_POWER_HOLD : payload;
|
||||
Settings.hlw_mplh = (1 == payload) ? MAX_POWER_HOLD : payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWERHOLD "\":\"%d%s\"}"), sysCfg.hlw_mplh, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWERHOLD "\":\"%d%s\"}"), Settings.hlw_mplh, (Settings.flag.value_units) ? " " D_UNIT_SECOND : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWERWINDOW))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mplw = (1 == payload) ? MAX_POWER_WINDOW : payload;
|
||||
Settings.hlw_mplw = (1 == payload) ? MAX_POWER_WINDOW : payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWERWINDOW "\":\"%d%s\"}"), sysCfg.hlw_mplw, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXPOWERWINDOW "\":\"%d%s\"}"), Settings.hlw_mplw, (Settings.flag.value_units) ? " " D_UNIT_SECOND : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWER))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mspl = payload;
|
||||
Settings.hlw_mspl = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWER "\":\"%d%s\"}"), sysCfg.hlw_mspl, (sysCfg.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWER "\":\"%d%s\"}"), Settings.hlw_mspl, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWERHOLD))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_msplh = (1 == payload) ? SAFE_POWER_HOLD : payload;
|
||||
Settings.hlw_msplh = (1 == payload) ? SAFE_POWER_HOLD : payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWERHOLD "\":\"%d%s\"}"), sysCfg.hlw_msplh, (sysCfg.flag.value_units) ? " " D_UNIT_SECOND : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWERHOLD "\":\"%d%s\"}"), Settings.hlw_msplh, (Settings.flag.value_units) ? " " D_UNIT_SECOND : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWERWINDOW))) {
|
||||
if ((payload >= 0) && (payload < 1440)) {
|
||||
sysCfg.hlw_msplw = (1 == payload) ? SAFE_POWER_WINDOW : payload;
|
||||
Settings.hlw_msplw = (1 == payload) ? SAFE_POWER_WINDOW : payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWERWINDOW "\":\"%d%s\"}"), sysCfg.hlw_msplw, (sysCfg.flag.value_units) ? " " D_UNIT_MINUTE : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_SAFEPOWERWINDOW "\":\"%d%s\"}"), Settings.hlw_msplw, (Settings.flag.value_units) ? " " D_UNIT_MINUTE : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXENERGY))) {
|
||||
if ((payload >= 0) && (payload < 3601)) {
|
||||
sysCfg.hlw_mkwh = payload;
|
||||
Settings.hlw_mkwh = payload;
|
||||
hlw_mkwh_state = 3;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXENERGY "\":\"%d%s\"}"), sysCfg.hlw_mkwh, (sysCfg.flag.value_units) ? " " D_UNIT_WATTHOUR : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXENERGY "\":\"%d%s\"}"), Settings.hlw_mkwh, (Settings.flag.value_units) ? " " D_UNIT_WATTHOUR : "");
|
||||
}
|
||||
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXENERGYSTART))) {
|
||||
if ((payload >= 0) && (payload < 24)) {
|
||||
sysCfg.hlw_mkwhs = payload;
|
||||
Settings.hlw_mkwhs = payload;
|
||||
}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXENERGYSTART "\":\"%d%s\"}"), sysCfg.hlw_mkwhs, (sysCfg.flag.value_units) ? " " D_UNIT_HOUR : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_MAXENERGYSTART "\":\"%d%s\"}"), Settings.hlw_mkwhs, (Settings.flag.value_units) ? " " D_UNIT_HOUR : "");
|
||||
}
|
||||
#endif // FEATURE_POWER_LIMIT
|
||||
else {
|
||||
|
@ -600,13 +600,13 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
|
|||
}
|
||||
switch (caltext) {
|
||||
case 1:
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWPCAL "\":\"%d%s\"}"), sysCfg.hlw_pcal, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWPCAL "\":\"%d%s\"}"), Settings.hlw_power_calibration, (Settings.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
|
||||
break;
|
||||
case 2:
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWUCAL "\":\"%d%s\"}"), sysCfg.hlw_ucal, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWUCAL "\":\"%d%s\"}"), Settings.hlw_voltage_calibration, (Settings.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
|
||||
break;
|
||||
case 3:
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWICAL "\":\"%d%s\"}"), sysCfg.hlw_ical, (sysCfg.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_HLWICAL "\":\"%d%s\"}"), Settings.hlw_current_calibration, (Settings.flag.value_units) ? " " D_UNIT_MICROSECOND : "");
|
||||
break;
|
||||
}
|
||||
return serviced;
|
||||
|
@ -616,65 +616,65 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void hlw_mqttStat(byte option)
|
||||
void HlwMqttStat(byte option)
|
||||
{
|
||||
/* option 0 = do not show period energy usage
|
||||
* option 1 = show period energy usage
|
||||
*/
|
||||
float pet;
|
||||
float ped;
|
||||
float pe;
|
||||
float pw;
|
||||
float pu;
|
||||
float pi;
|
||||
float pc;
|
||||
char spet[10];
|
||||
char sped[10];
|
||||
char spe[10];
|
||||
char spw[10];
|
||||
char spu[10];
|
||||
char spi[10];
|
||||
char spc[10];
|
||||
char sey[10];
|
||||
float total_energy;
|
||||
float daily_energy;
|
||||
float energy;
|
||||
float watts;
|
||||
float voltage;
|
||||
float current;
|
||||
float power_factor;
|
||||
char stotal_energy[10];
|
||||
char sdaily_energy[10];
|
||||
char senergy[10];
|
||||
char swatts[10];
|
||||
char svoltage[10];
|
||||
char scurrent[10];
|
||||
char spower_factor[10];
|
||||
char syesterday_energy[10];
|
||||
char speriod[20];
|
||||
|
||||
hlw_readEnergy(option, pet, ped, pe, pw, pu, pi, pc);
|
||||
dtostrfd(pet, sysCfg.flag.energy_resolution, spet);
|
||||
dtostrfd(ped, sysCfg.flag.energy_resolution, sped);
|
||||
dtostrfd(pe, sysCfg.flag.wattage_resolution, spe);
|
||||
dtostrfd(pw, sysCfg.flag.wattage_resolution, spw);
|
||||
dtostrfd(pu, sysCfg.flag.voltage_resolution, spu);
|
||||
dtostrfd(pi, 3, spi);
|
||||
dtostrfd(pc, 2, spc);
|
||||
dtostrfd((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
|
||||
snprintf_P(speriod, sizeof(speriod), PSTR(", \"" D_PERIOD "\":%s"), spe);
|
||||
HlwReadEnergy(option, total_energy, daily_energy, energy, watts, voltage, current, power_factor);
|
||||
dtostrfd(total_energy, Settings.flag.energy_resolution, stotal_energy);
|
||||
dtostrfd(daily_energy, Settings.flag.energy_resolution, sdaily_energy);
|
||||
dtostrfd(energy, Settings.flag.wattage_resolution, senergy);
|
||||
dtostrfd(watts, Settings.flag.wattage_resolution, swatts);
|
||||
dtostrfd(voltage, Settings.flag.voltage_resolution, svoltage);
|
||||
dtostrfd(current, 3, scurrent);
|
||||
dtostrfd(power_factor, 2, spower_factor);
|
||||
dtostrfd((float)Settings.hlw_kWhyesterday / 100000000, Settings.flag.energy_resolution, syesterday_energy);
|
||||
snprintf_P(speriod, sizeof(speriod), PSTR(", \"" D_PERIOD "\":%s"), senergy);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s\"" D_TOTAL "\":%s, \"" D_YESTERDAY "\":%s, \"" D_TODAY "\":%s%s, \"" D_POWERUSAGE "\":%s, \"" D_POWERFACTOR "\":%s, \"" D_VOLTAGE "\":%s, \"" D_CURRENT "\":%s}"),
|
||||
mqtt_data, spet, sey, sped, (option) ? speriod : "", spw, spc, spu, spi);
|
||||
mqtt_data, stotal_energy, syesterday_energy, sdaily_energy, (option) ? speriod : "", swatts, spower_factor, svoltage, scurrent);
|
||||
#ifdef USE_DOMOTICZ
|
||||
if (option) { // Only send if telemetry
|
||||
dtostrfd(pet * 1000, 1, spet);
|
||||
domoticz_sensor4((uint16_t)pw, spet); // PowerUsage, EnergyToday
|
||||
domoticz_sensor(DZ_VOLTAGE, spu); // Voltage
|
||||
domoticz_sensor(DZ_CURRENT, spi); // Current
|
||||
dtostrfd(total_energy * 1000, 1, stotal_energy);
|
||||
DomoticzSensorPowerEnergy((uint16_t)watts, stotal_energy); // PowerUsage, EnergyToday
|
||||
DomoticzSensor(DZ_VOLTAGE, svoltage); // Voltage
|
||||
DomoticzSensor(DZ_CURRENT, scurrent); // Current
|
||||
}
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
||||
void hlw_mqttPresent(byte option)
|
||||
void MqttShowHlw8012(byte option)
|
||||
{
|
||||
/* option 0 = do not show period energy usage
|
||||
* option 1 = show period energy usage
|
||||
*/
|
||||
// {"Time":"2017-03-04T13:37:24", "Total":0.013, "Yesterday":0.013, "Today":0.000, "Period":0, "Power":0, "Factor":0.00, "Voltage":0, "Current":0.000}
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_TIME "\":\"%s\", "), getDateTime().c_str());
|
||||
hlw_mqttStat(option);
|
||||
mqtt_publish_topic_P(2, PSTR(D_RSLT_ENERGY), sysCfg.flag.mqtt_sensor_retain);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_TIME "\":\"%s\", "), GetDateAndTime().c_str());
|
||||
HlwMqttStat(option);
|
||||
MqttPublishPrefixTopic_P(2, PSTR(D_RSLT_ENERGY), Settings.flag.mqtt_sensor_retain);
|
||||
}
|
||||
|
||||
void hlw_mqttStatus()
|
||||
void HlwMqttStatus()
|
||||
{
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_STATUS D_STATUS8_POWER "\":{"));
|
||||
hlw_mqttStat(0);
|
||||
HlwMqttStat(0);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
|
||||
}
|
||||
|
||||
|
@ -688,34 +688,33 @@ const char HTTP_ENERGY_SNS[] PROGMEM =
|
|||
"<tr><th>" D_ENERGY_YESTERDAY "</th><td>%s " D_UNIT_KILOWATTHOUR "</td></tr>"
|
||||
"<tr><th>" D_ENERGY_TOTAL "</th><td>%s " D_UNIT_KILOWATTHOUR "</td></tr>";
|
||||
|
||||
String hlw_webPresent()
|
||||
String WebShowHlw()
|
||||
{
|
||||
float pet;
|
||||
float ped;
|
||||
float pe;
|
||||
float pw;
|
||||
float pu;
|
||||
float pi;
|
||||
float pc;
|
||||
char spet[10];
|
||||
char sped[10];
|
||||
char spw[10];
|
||||
char spu[10];
|
||||
char spi[10];
|
||||
char spc[10];
|
||||
char sey[10];
|
||||
float total_energy;
|
||||
float daily_energy;
|
||||
float energy;
|
||||
float watts;
|
||||
float voltage;
|
||||
float current;
|
||||
float power_factor;
|
||||
char stotal_energy[10];
|
||||
char sdaily_energy[10];
|
||||
char swatts[10];
|
||||
char svoltage[10];
|
||||
char scurrent[10];
|
||||
char spower_factor[10];
|
||||
char syesterday_energy[10];
|
||||
char sensor[400];
|
||||
|
||||
hlw_readEnergy(0, pet, ped, pe, pw, pu, pi, pc);
|
||||
dtostrfi(pet, sysCfg.flag.energy_resolution, spet);
|
||||
dtostrfi(ped, sysCfg.flag.energy_resolution, sped);
|
||||
dtostrfi(pw, sysCfg.flag.wattage_resolution, spw);
|
||||
dtostrfi(pu, sysCfg.flag.voltage_resolution, spu);
|
||||
dtostrfi(pi, 3, spi);
|
||||
dtostrfi(pc, 2, spc);
|
||||
dtostrfi((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_ENERGY_SNS, spu, spi, spw, spc, sped, sey, spet);
|
||||
HlwReadEnergy(0, total_energy, daily_energy, energy, watts, voltage, current, power_factor);
|
||||
dtostrfi(total_energy, Settings.flag.energy_resolution, stotal_energy);
|
||||
dtostrfi(daily_energy, Settings.flag.energy_resolution, sdaily_energy);
|
||||
dtostrfi(watts, Settings.flag.wattage_resolution, swatts);
|
||||
dtostrfi(voltage, Settings.flag.voltage_resolution, svoltage);
|
||||
dtostrfi(current, 3, scurrent);
|
||||
dtostrfi(power_factor, 2, spower_factor);
|
||||
dtostrfi((float)Settings.hlw_kWhyesterday / 100000000, Settings.flag.energy_resolution, syesterday_energy);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_ENERGY_SNS, svoltage, scurrent, swatts, spower_factor, sdaily_energy, syesterday_energy, stotal_energy);
|
||||
return String(sensor);
|
||||
}
|
||||
#endif // USE_WEBSERVER
|
||||
|
||||
|
|
|
@ -52,13 +52,13 @@
|
|||
|
||||
#define HTU21_CRC8_POLYNOM 0x13100
|
||||
|
||||
uint8_t htuaddr;
|
||||
uint8_t htutype = 0;
|
||||
uint8_t delayT;
|
||||
uint8_t delayH = 50;
|
||||
char htustype[7];
|
||||
uint8_t htu_address;
|
||||
uint8_t htu_type = 0;
|
||||
uint8_t delay_temp;
|
||||
uint8_t delay_humidity = 50;
|
||||
char htu_types[7];
|
||||
|
||||
uint8_t check_crc8(uint16_t data)
|
||||
uint8_t HtuCheckCrc8(uint16_t data)
|
||||
{
|
||||
for (uint8_t bit = 0; bit < 16; bit++) {
|
||||
if (data & 0x8000) {
|
||||
|
@ -70,7 +70,7 @@ uint8_t check_crc8(uint16_t data)
|
|||
return data >>= 8;
|
||||
}
|
||||
|
||||
uint8_t htu21_readDeviceID(void)
|
||||
uint8_t HtuReadDeviceId(void)
|
||||
{
|
||||
uint16_t deviceID = 0;
|
||||
uint8_t checksum = 0;
|
||||
|
@ -84,7 +84,7 @@ uint8_t htu21_readDeviceID(void)
|
|||
deviceID = Wire.read() << 8;
|
||||
deviceID |= Wire.read();
|
||||
checksum = Wire.read();
|
||||
if (check_crc8(deviceID) == checksum) {
|
||||
if (HtuCheckCrc8(deviceID) == checksum) {
|
||||
deviceID = deviceID >> 8;
|
||||
} else {
|
||||
deviceID = 0;
|
||||
|
@ -92,15 +92,15 @@ uint8_t htu21_readDeviceID(void)
|
|||
return (uint8_t)deviceID;
|
||||
}
|
||||
|
||||
void htu21_setRes(uint8_t resolution)
|
||||
void HtuSetResolution(uint8_t resolution)
|
||||
{
|
||||
uint8_t current = i2c_read8(HTU21_ADDR, HTU21_READREG);
|
||||
uint8_t current = I2cRead8(HTU21_ADDR, HTU21_READREG);
|
||||
current &= 0x7E; // Replace current resolution bits with 0
|
||||
current |= resolution; // Add new resolution bits to register
|
||||
i2c_write8(HTU21_ADDR, HTU21_WRITEREG, current);
|
||||
I2cWrite8(HTU21_ADDR, HTU21_WRITEREG, current);
|
||||
}
|
||||
|
||||
void htu21_reset(void)
|
||||
void HtuReset(void)
|
||||
{
|
||||
Wire.beginTransmission(HTU21_ADDR);
|
||||
Wire.write(HTU21_RESET);
|
||||
|
@ -108,9 +108,9 @@ void htu21_reset(void)
|
|||
delay(15); // Reset takes 15ms
|
||||
}
|
||||
|
||||
void htu21_heater(uint8_t heater)
|
||||
void HtuHeater(uint8_t heater)
|
||||
{
|
||||
uint8_t current = i2c_read8(HTU21_ADDR, HTU21_READREG);
|
||||
uint8_t current = I2cRead8(HTU21_ADDR, HTU21_READREG);
|
||||
|
||||
switch(heater)
|
||||
{
|
||||
|
@ -121,18 +121,18 @@ void htu21_heater(uint8_t heater)
|
|||
default : current &= heater;
|
||||
break;
|
||||
}
|
||||
i2c_write8(HTU21_ADDR, HTU21_WRITEREG, current);
|
||||
I2cWrite8(HTU21_ADDR, HTU21_WRITEREG, current);
|
||||
}
|
||||
|
||||
boolean htu21_init()
|
||||
boolean HtuInit()
|
||||
{
|
||||
htu21_reset();
|
||||
htu21_heater(HTU21_HEATER_OFF);
|
||||
htu21_setRes(HTU21_RES_RH12_T14);
|
||||
HtuReset();
|
||||
HtuHeater(HTU21_HEATER_OFF);
|
||||
HtuSetResolution(HTU21_RES_RH12_T14);
|
||||
return true;
|
||||
}
|
||||
|
||||
float htu21_readHumidity(void)
|
||||
float HtuReadHumidity(void)
|
||||
{
|
||||
uint8_t checksum = 0;
|
||||
uint16_t sensorval = 0;
|
||||
|
@ -143,7 +143,7 @@ float htu21_readHumidity(void)
|
|||
if (Wire.endTransmission() != 0) {
|
||||
return 0.0; // In case of error
|
||||
}
|
||||
delay(delayH); // Sensor time at max resolution
|
||||
delay(delay_humidity); // Sensor time at max resolution
|
||||
|
||||
Wire.requestFrom(HTU21_ADDR, 3);
|
||||
if (3 <= Wire.available()) {
|
||||
|
@ -151,7 +151,7 @@ float htu21_readHumidity(void)
|
|||
sensorval |= Wire.read(); // LSB
|
||||
checksum = Wire.read();
|
||||
}
|
||||
if (check_crc8(sensorval) != checksum) {
|
||||
if (HtuCheckCrc8(sensorval) != checksum) {
|
||||
return 0.0; // Checksum mismatch
|
||||
}
|
||||
|
||||
|
@ -168,7 +168,7 @@ float htu21_readHumidity(void)
|
|||
return humidity;
|
||||
}
|
||||
|
||||
float htu21_readTemperature()
|
||||
float HtuReadTemperature()
|
||||
{
|
||||
uint8_t checksum=0;
|
||||
uint16_t sensorval=0;
|
||||
|
@ -179,7 +179,7 @@ float htu21_readTemperature()
|
|||
if (Wire.endTransmission() != 0) {
|
||||
return 0.0; // In case of error
|
||||
}
|
||||
delay(delayT); // Sensor time at max resolution
|
||||
delay(delay_temp); // Sensor time at max resolution
|
||||
|
||||
Wire.requestFrom(HTU21_ADDR, 3);
|
||||
if (3 == Wire.available()) {
|
||||
|
@ -187,15 +187,15 @@ float htu21_readTemperature()
|
|||
sensorval |= Wire.read(); // LSB
|
||||
checksum = Wire.read();
|
||||
}
|
||||
if (check_crc8(sensorval) != checksum) {
|
||||
if (HtuCheckCrc8(sensorval) != checksum) {
|
||||
return 0.0; // Checksum mismatch
|
||||
}
|
||||
|
||||
t = convertTemp(0.002681 * (float)sensorval - 46.85);
|
||||
t = ConvertTemp(0.002681 * (float)sensorval - 46.85);
|
||||
return t;
|
||||
}
|
||||
|
||||
float htu21_compensatedHumidity(float humidity, float temperature)
|
||||
float HtuCompensatedHumidity(float humidity, float temperature)
|
||||
{
|
||||
if(humidity == 0.00 && temperature == 0.00) {
|
||||
return 0.0;
|
||||
|
@ -205,48 +205,48 @@ float htu21_compensatedHumidity(float humidity, float temperature)
|
|||
}
|
||||
}
|
||||
|
||||
uint8_t htu_detect()
|
||||
uint8_t HtuDetect()
|
||||
{
|
||||
if (htutype) {
|
||||
if (htu_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean success = false;
|
||||
|
||||
htuaddr = HTU21_ADDR;
|
||||
htutype = htu21_readDeviceID();
|
||||
success = htu21_init();
|
||||
switch (htutype) {
|
||||
htu_address = HTU21_ADDR;
|
||||
htu_type = HtuReadDeviceId();
|
||||
success = HtuInit();
|
||||
switch (htu_type) {
|
||||
case HTU21_CHIPID:
|
||||
strcpy_P(htustype, PSTR("HTU21"));
|
||||
delayT=50;
|
||||
delayH=16;
|
||||
strcpy_P(htu_types, PSTR("HTU21"));
|
||||
delay_temp=50;
|
||||
delay_humidity=16;
|
||||
break;
|
||||
case SI7013_CHIPID:
|
||||
strcpy_P(htustype, PSTR("SI7013"));
|
||||
delayT=12;
|
||||
delayH=23;
|
||||
strcpy_P(htu_types, PSTR("SI7013"));
|
||||
delay_temp=12;
|
||||
delay_humidity=23;
|
||||
break;
|
||||
case SI7020_CHIPID:
|
||||
strcpy_P(htustype, PSTR("SI7020"));
|
||||
delayT=12;
|
||||
delayH=23;
|
||||
strcpy_P(htu_types, PSTR("SI7020"));
|
||||
delay_temp=12;
|
||||
delay_humidity=23;
|
||||
break;
|
||||
case SI7021_CHIPID:
|
||||
strcpy_P(htustype, PSTR("SI7021"));
|
||||
delayT=12;
|
||||
delayH=23;
|
||||
strcpy_P(htu_types, PSTR("SI7021"));
|
||||
delay_temp=12;
|
||||
delay_humidity=23;
|
||||
break;
|
||||
default:
|
||||
strcpy_P(htustype, PSTR("T/RH?"));
|
||||
delayT=50;
|
||||
delayH=23;
|
||||
strcpy_P(htu_types, PSTR("T/RH?"));
|
||||
delay_temp=50;
|
||||
delay_humidity=23;
|
||||
}
|
||||
if (success) {
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), htustype, htuaddr);
|
||||
addLog(LOG_LEVEL_DEBUG);
|
||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), htu_types, htu_address);
|
||||
AddLog(LOG_LEVEL_DEBUG);
|
||||
} else {
|
||||
htutype = 0;
|
||||
htu_type = 0;
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
@ -255,43 +255,43 @@ uint8_t htu_detect()
|
|||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void htu_mqttPresent(uint8_t* djson)
|
||||
void MqttShowHtu(uint8_t* djson)
|
||||
{
|
||||
if (!htutype) {
|
||||
if (!htu_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
char stemp1[10];
|
||||
char stemp2[10];
|
||||
|
||||
float t = htu21_readTemperature();
|
||||
float h = htu21_readHumidity();
|
||||
h = htu21_compensatedHumidity(h, t);
|
||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
||||
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, htustype, stemp1, stemp2);
|
||||
float t = HtuReadTemperature();
|
||||
float h = HtuReadHumidity();
|
||||
h = HtuCompensatedHumidity(h, t);
|
||||
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||
dtostrfd(h, Settings.flag.humidity_resolution, stemp2);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, htu_types, stemp1, stemp2);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
domoticz_sensor2(stemp1, stemp2);
|
||||
DomoticzTempHumSensor(stemp1, stemp2);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
String htu_webPresent()
|
||||
String WebShowHtu()
|
||||
{
|
||||
String page = "";
|
||||
if (htutype) {
|
||||
if (htu_type) {
|
||||
char stemp[10];
|
||||
char sensor[80];
|
||||
|
||||
float t_htu21 = htu21_readTemperature();
|
||||
float h_htu21 = htu21_readHumidity();
|
||||
h_htu21 = htu21_compensatedHumidity(h_htu21, t_htu21);
|
||||
dtostrfi(t_htu21, sysCfg.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, htustype, stemp, tempUnit());
|
||||
float t_htu21 = HtuReadTemperature();
|
||||
float h_htu21 = HtuReadHumidity();
|
||||
h_htu21 = HtuCompensatedHumidity(h_htu21, t_htu21);
|
||||
dtostrfi(t_htu21, Settings.flag.temperature_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, htu_types, stemp, TempUnit());
|
||||
page += sensor;
|
||||
dtostrfi(h_htu21, sysCfg.flag.humidity_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, htustype, stemp);
|
||||
dtostrfi(h_htu21, Settings.flag.humidity_resolution, stemp);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, htu_types, stemp);
|
||||
page += sensor;
|
||||
}
|
||||
return page;
|
||||
|
|
|
@ -34,9 +34,9 @@ enum {
|
|||
|
||||
uint8_t sht_sda_pin;
|
||||
uint8_t sht_scl_pin;
|
||||
uint8_t shttype = 0;
|
||||
uint8_t sht_type = 0;
|
||||
|
||||
boolean sht_reset()
|
||||
boolean ShtReset()
|
||||
{
|
||||
pinMode(sht_sda_pin, INPUT_PULLUP);
|
||||
pinMode(sht_scl_pin, OUTPUT);
|
||||
|
@ -45,12 +45,12 @@ boolean sht_reset()
|
|||
digitalWrite(sht_scl_pin, HIGH);
|
||||
digitalWrite(sht_scl_pin, LOW);
|
||||
}
|
||||
boolean success = sht_sendCommand(SHT1X_CMD_SOFT_RESET);
|
||||
boolean success = ShtSendCommand(SHT1X_CMD_SOFT_RESET);
|
||||
delay(11);
|
||||
return success;
|
||||
}
|
||||
|
||||
boolean sht_sendCommand(const byte cmd)
|
||||
boolean ShtSendCommand(const byte cmd)
|
||||
{
|
||||
pinMode(sht_sda_pin, OUTPUT);
|
||||
// Transmission Start sequence
|
||||
|
@ -76,13 +76,13 @@ boolean sht_sendCommand(const byte cmd)
|
|||
ackerror = true;
|
||||
}
|
||||
if (ackerror) {
|
||||
shttype = 0;
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_DID_NOT_ACK_COMMAND));
|
||||
sht_type = 0;
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_DID_NOT_ACK_COMMAND));
|
||||
}
|
||||
return (!ackerror);
|
||||
}
|
||||
|
||||
boolean sht_awaitResult()
|
||||
boolean ShtAwaitResult()
|
||||
{
|
||||
// Maximum 320ms for 14 bit measurement
|
||||
for (byte i = 0; i < 16; i++) {
|
||||
|
@ -91,12 +91,12 @@ boolean sht_awaitResult()
|
|||
}
|
||||
delay(20);
|
||||
}
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_BUSY));
|
||||
shttype = 0;
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_BUSY));
|
||||
sht_type = 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
int sht_readData()
|
||||
int ShtReadData()
|
||||
{
|
||||
int val = 0;
|
||||
|
||||
|
@ -117,7 +117,7 @@ int sht_readData()
|
|||
return val;
|
||||
}
|
||||
|
||||
boolean sht_readTempHum(float &t, float &h)
|
||||
boolean ShtReadTempHum(float &t, float &h)
|
||||
{
|
||||
float tempRaw;
|
||||
float humRaw;
|
||||
|
@ -126,27 +126,27 @@ boolean sht_readTempHum(float &t, float &h)
|
|||
t = NAN;
|
||||
h = NAN;
|
||||
|
||||
if (!sht_reset()) {
|
||||
if (!ShtReset()) {
|
||||
return false;
|
||||
}
|
||||
if (!sht_sendCommand(SHT1X_CMD_MEASURE_TEMP)) {
|
||||
if (!ShtSendCommand(SHT1X_CMD_MEASURE_TEMP)) {
|
||||
return false;
|
||||
}
|
||||
if (!sht_awaitResult()) {
|
||||
if (!ShtAwaitResult()) {
|
||||
return false;
|
||||
}
|
||||
tempRaw = sht_readData();
|
||||
tempRaw = ShtReadData();
|
||||
// Temperature conversion coefficients from SHT1X datasheet for version 4
|
||||
const float d1 = -39.7; // 3.5V
|
||||
const float d2 = 0.01; // 14-bit
|
||||
t = d1 + (tempRaw * d2);
|
||||
if (!sht_sendCommand(SHT1X_CMD_MEASURE_RH)) {
|
||||
if (!ShtSendCommand(SHT1X_CMD_MEASURE_RH)) {
|
||||
return false;
|
||||
}
|
||||
if (!sht_awaitResult()) {
|
||||
if (!ShtAwaitResult()) {
|
||||
return false;
|
||||
}
|
||||
humRaw = sht_readData();
|
||||
humRaw = ShtReadData();
|
||||
// Temperature conversion coefficients from SHT1X datasheet for version 4
|
||||
const float c1 = -2.0468;
|
||||
const float c2 = 0.0367;
|
||||
|
@ -155,13 +155,13 @@ boolean sht_readTempHum(float &t, float &h)
|
|||
const float t2 = 0.00008;
|
||||
rhLinear = c1 + c2 * humRaw + c3 * humRaw * humRaw;
|
||||
h = (t - 25) * (t1 + t2 * humRaw) + rhLinear;
|
||||
t = convertTemp(t);
|
||||
t = ConvertTemp(t);
|
||||
return (!isnan(t) && !isnan(h));
|
||||
}
|
||||
|
||||
boolean sht_detect()
|
||||
boolean ShtDetect()
|
||||
{
|
||||
if (shttype) {
|
||||
if (sht_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -170,59 +170,59 @@ boolean sht_detect()
|
|||
|
||||
sht_sda_pin = pin[GPIO_I2C_SDA];
|
||||
sht_scl_pin = pin[GPIO_I2C_SCL];
|
||||
if (sht_readTempHum(t, h)) {
|
||||
shttype = 1;
|
||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND));
|
||||
if (ShtReadTempHum(t, h)) {
|
||||
sht_type = 1;
|
||||
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND));
|
||||
} else {
|
||||
Wire.begin(sht_sda_pin, sht_scl_pin);
|
||||
shttype = 0;
|
||||
sht_type = 0;
|
||||
}
|
||||
return shttype;
|
||||
return sht_type;
|
||||
}
|
||||
|
||||
/*********************************************************************************************\
|
||||
* Presentation
|
||||
\*********************************************************************************************/
|
||||
|
||||
void sht_mqttPresent(uint8_t* djson)
|
||||
void MqttShowSht(uint8_t* djson)
|
||||
{
|
||||
if (!shttype) {
|
||||
if (!sht_type) {
|
||||
return;
|
||||
}
|
||||
|
||||
float t;
|
||||
float h;
|
||||
|
||||
if (sht_readTempHum(t, h)) {
|
||||
if (ShtReadTempHum(t, h)) {
|
||||
char stemp[10];
|
||||
char shum[10];
|
||||
|
||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp);
|
||||
dtostrfd(h, sysCfg.flag.humidity_resolution, shum);
|
||||
dtostrfd(t, Settings.flag.temperature_resolution, stemp);
|
||||
dtostrfd(h, Settings.flag.humidity_resolution, shum);
|
||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, "SHT1X", stemp, shum);
|
||||
*djson = 1;
|
||||
#ifdef USE_DOMOTICZ
|
||||
domoticz_sensor2(stemp, shum);
|
||||
DomoticzTempHumSensor(stemp, shum);
|
||||
#endif // USE_DOMOTICZ
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_WEBSERVER
|
||||
String sht_webPresent()
|
||||
String WebShowSht()
|
||||
{
|
||||
float t;
|
||||
float h;
|
||||
|
||||
String page = "";
|
||||
if (shttype) {
|
||||
if (sht_readTempHum(t, h)) {
|
||||
if (sht_type) {
|
||||
if (ShtReadTempHum(t, h)) {
|
||||
char stemp[10];
|
||||
char shum[10];
|
||||
char sensor[80];
|
||||
|
||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
||||
dtostrfi(h, sysCfg.flag.humidity_resolution, shum);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "SHT1X", stemp, tempUnit());
|
||||
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||
dtostrfi(h, Settings.flag.humidity_resolution, shum);
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "SHT1X", stemp, TempUnit());
|
||||
page += sensor;
|
||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, "SHT1X", shum);
|
||||
page += sensor;
|
||||
|
|
Loading…
Reference in New Issue