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
|
## 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.
|
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
|
### ATTENTION All versions
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@ src_dir = sonoff
|
||||||
; *** Uncomment one of the lines below to build/upload only one environment
|
; *** Uncomment one of the lines below to build/upload only one environment
|
||||||
;env_default = sonoff
|
;env_default = sonoff
|
||||||
;env_default = sonoff-NL
|
;env_default = sonoff-NL
|
||||||
|
;env_default = sonoff-DE
|
||||||
;env_default = sonoff-minimal
|
;env_default = sonoff-minimal
|
||||||
;env_default = sonoff-ds18x20
|
;env_default = sonoff-ds18x20
|
||||||
|
|
||||||
|
@ -62,6 +63,29 @@ monitor_baud = 115200
|
||||||
;upload_port = domus1:80/api/upload-arduino.php
|
;upload_port = domus1:80/api/upload-arduino.php
|
||||||
;extra_scripts = pio/http-uploader.py
|
;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
|
; Sonoff minimal
|
||||||
[env:sonoff-minimal] ; Placeholder to be configured
|
[env:sonoff-minimal] ; Placeholder to be configured
|
||||||
platform = espressif8266
|
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
|
* 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)
|
* Fix inverted relay status after restart or power on as regression from 5.8.0d (#909)
|
||||||
* Add send protocol Panasonic to IRsend (#1014)
|
* Add send protocol Panasonic to IRsend (#1014)
|
||||||
|
@ -1018,7 +1027,7 @@
|
||||||
* Add reset 2 option erasing flash
|
* Add reset 2 option erasing flash
|
||||||
* Add status 5 option displaying network info
|
* Add status 5 option displaying network info
|
||||||
* Add syslog check for Wifi connection
|
* Add syslog check for Wifi connection
|
||||||
* Resize mqtt_publish log array
|
* Resize MqttPublish log array
|
||||||
* Change Wifi smartconfig active from 100 to 60 seconds
|
* Change Wifi smartconfig active from 100 to 60 seconds
|
||||||
* Update Wifi initialization
|
* Update Wifi initialization
|
||||||
*
|
*
|
||||||
|
|
|
@ -17,6 +17,9 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _I18N_H_
|
||||||
|
#define _I18N_H_
|
||||||
|
|
||||||
#ifndef MY_LANGUAGE
|
#ifndef MY_LANGUAGE
|
||||||
#include "language/en-GB.h"
|
#include "language/en-GB.h"
|
||||||
#else
|
#else
|
||||||
|
@ -38,20 +41,20 @@ const char S_OFFLINE[] PROGMEM = D_OFFLINE;
|
||||||
|
|
||||||
// sonoff.ino
|
// sonoff.ino
|
||||||
#define MAX_BUTTON_COMMANDS 5 // Max number of button commands supported
|
#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 " 1", // Press button three times
|
||||||
D_CMND_WIFICONFIG " 2", // Press button four times
|
D_CMND_WIFICONFIG " 2", // Press button four times
|
||||||
D_CMND_WIFICONFIG " 3", // Press button five times
|
D_CMND_WIFICONFIG " 3", // Press button five times
|
||||||
D_CMND_RESTART " 1", // Press button six times
|
D_CMND_RESTART " 1", // Press button six times
|
||||||
D_CMND_UPGRADE " 1" }; // Press button seven 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_0_RESTART,
|
||||||
D_WCFG_1_SMARTCONFIG,
|
D_WCFG_1_SMARTCONFIG,
|
||||||
D_WCFG_2_WIFIMANAGER,
|
D_WCFG_2_WIFIMANAGER,
|
||||||
D_WCFG_3_WPSCONFIG,
|
D_WCFG_3_WPSCONFIG,
|
||||||
D_WCFG_4_RETRY,
|
D_WCFG_4_RETRY,
|
||||||
D_WCFG_5_WAIT };
|
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_CMND,
|
||||||
D_STAT,
|
D_STAT,
|
||||||
D_TELE };
|
D_TELE };
|
||||||
|
@ -60,7 +63,7 @@ const char JSON_SNS_TEMPHUM[] PROGMEM =
|
||||||
"%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s}";
|
"%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_HUMIDITY "\":%s}";
|
||||||
|
|
||||||
// support.ino
|
// support.ino
|
||||||
static const char monthNames[] = D_MONTH3LIST;
|
static const char kMonthNames[] = D_MONTH3LIST;
|
||||||
|
|
||||||
// webserver.ino
|
// webserver.ino
|
||||||
const char S_MAIN_MENU[] PROGMEM = D_MAIN_MENU;
|
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_CONSOLE[] PROGMEM = D_CONSOLE;
|
||||||
const char S_INFORMATION[] PROGMEM = D_INFORMATION;
|
const char S_INFORMATION[] PROGMEM = D_INFORMATION;
|
||||||
const char S_RESTART[] PROGMEM = D_RESTART;
|
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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _LANGUAGE_EN_GB_H_
|
||||||
|
#define _LANGUAGE_EN_GB_H_
|
||||||
|
|
||||||
/*************************** ATTENTION *******************************\
|
/*************************** ATTENTION *******************************\
|
||||||
*
|
*
|
||||||
* Due to memory constraints only UTF-8 is supported.
|
* 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).
|
* 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 StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||||
* Use online command Prefix to translate cmnd, stat and tele.
|
* Use online command Prefix to translate cmnd, stat and tele.
|
||||||
|
@ -379,7 +383,6 @@
|
||||||
#define D_DOMOTICZ_VOLTAGE "Voltage"
|
#define D_DOMOTICZ_VOLTAGE "Voltage"
|
||||||
#define D_DOMOTICZ_CURRENT "Current"
|
#define D_DOMOTICZ_CURRENT "Current"
|
||||||
#define D_DOMOTICZ_UPDATE_TIMER "Update timer"
|
#define D_DOMOTICZ_UPDATE_TIMER "Update timer"
|
||||||
#define D_CONFIGURE_DOMOTICZ "Configure Domoticz"
|
|
||||||
|
|
||||||
// xdrv_ir-send.ino
|
// xdrv_ir-send.ino
|
||||||
#define D_INVALID_JSON "Invalid JSON"
|
#define D_INVALID_JSON "Invalid JSON"
|
||||||
|
@ -461,8 +464,8 @@
|
||||||
#define D_SENSOR_IRSEND "IRsend"
|
#define D_SENSOR_IRSEND "IRsend"
|
||||||
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
|
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
|
||||||
#define D_SENSOR_BUTTON "Button" // Suffix "1"
|
#define D_SENSOR_BUTTON "Button" // Suffix "1"
|
||||||
#define D_SENSOR_RELAY "Relay" // Suffix "1I"
|
#define D_SENSOR_RELAY "Relay" // Suffix "1i"
|
||||||
#define D_SENSOR_LED "Led" // Suffix "1I"
|
#define D_SENSOR_LED "Led" // Suffix "1i"
|
||||||
#define D_SENSOR_PWM "PWM" // Suffix "1"
|
#define D_SENSOR_PWM "PWM" // Suffix "1"
|
||||||
#define D_SENSOR_COUNTER "Counter" // Suffix "1"
|
#define D_SENSOR_COUNTER "Counter" // Suffix "1"
|
||||||
#define D_SENSOR_IRRECV "IRrecv"
|
#define D_SENSOR_IRRECV "IRrecv"
|
||||||
|
@ -576,6 +579,8 @@
|
||||||
#define D_NOT_SUPPORTED "Not supported"
|
#define D_NOT_SUPPORTED "Not supported"
|
||||||
#define D_CMND_GPIOS "GPIOs"
|
#define D_CMND_GPIOS "GPIOs"
|
||||||
#define D_CMND_PWM "PWM"
|
#define D_CMND_PWM "PWM"
|
||||||
|
#define D_CMND_PWMFREQUENCY "PWMFrequency"
|
||||||
|
#define D_CMND_PWMRANGE "PWMRange"
|
||||||
#define D_CMND_COUNTER "Counter"
|
#define D_CMND_COUNTER "Counter"
|
||||||
#define D_CMND_COUNTERTYPE "CounterType"
|
#define D_CMND_COUNTERTYPE "CounterType"
|
||||||
#define D_CMND_COUNTERDEBOUNCE "CounterDebounce"
|
#define D_CMND_COUNTERDEBOUNCE "CounterDebounce"
|
||||||
|
@ -679,3 +684,5 @@
|
||||||
#define D_CMND_SAFEPOWERWINDOW "SafePowerWindow"
|
#define D_CMND_SAFEPOWERWINDOW "SafePowerWindow"
|
||||||
#define D_CMND_MAXENERGY "MaxEnergy"
|
#define D_CMND_MAXENERGY "MaxEnergy"
|
||||||
#define D_CMND_MAXENERGYSTART "MaxEnergyStart"
|
#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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _LANGUAGE_NL_NL_H_
|
||||||
|
#define _LANGUAGE_NL_NL_H_
|
||||||
|
|
||||||
/*************************** ATTENTION *******************************\
|
/*************************** ATTENTION *******************************\
|
||||||
*
|
*
|
||||||
* Due to memory constraints only UTF-8 is supported.
|
* 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).
|
* 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 StateText to translate ON, OFF, HOLD and TOGGLE.
|
||||||
* Use online command Prefix to translate cmnd, stat and tele.
|
* Use online command Prefix to translate cmnd, stat and tele.
|
||||||
|
@ -379,7 +383,6 @@
|
||||||
#define D_DOMOTICZ_VOLTAGE "Spanning"
|
#define D_DOMOTICZ_VOLTAGE "Spanning"
|
||||||
#define D_DOMOTICZ_CURRENT "Stroom"
|
#define D_DOMOTICZ_CURRENT "Stroom"
|
||||||
#define D_DOMOTICZ_UPDATE_TIMER "Bijwerk timer"
|
#define D_DOMOTICZ_UPDATE_TIMER "Bijwerk timer"
|
||||||
#define D_CONFIGURE_DOMOTICZ "Configureer Domoticz"
|
|
||||||
|
|
||||||
// xdrv_ir-send.ino
|
// xdrv_ir-send.ino
|
||||||
#define D_INVALID_JSON "Ongeldig JSON"
|
#define D_INVALID_JSON "Ongeldig JSON"
|
||||||
|
@ -461,8 +464,8 @@
|
||||||
#define D_SENSOR_IRSEND "IRsend"
|
#define D_SENSOR_IRSEND "IRsend"
|
||||||
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
|
#define D_SENSOR_SWITCH "Switch" // Suffix "1"
|
||||||
#define D_SENSOR_BUTTON "Button" // Suffix "1"
|
#define D_SENSOR_BUTTON "Button" // Suffix "1"
|
||||||
#define D_SENSOR_RELAY "Relais" // Suffix "1I"
|
#define D_SENSOR_RELAY "Relais" // Suffix "1i"
|
||||||
#define D_SENSOR_LED "Led" // Suffix "1I"
|
#define D_SENSOR_LED "Led" // Suffix "1i"
|
||||||
#define D_SENSOR_PWM "PWM" // Suffix "1"
|
#define D_SENSOR_PWM "PWM" // Suffix "1"
|
||||||
#define D_SENSOR_COUNTER "Teller" // Suffix "1"
|
#define D_SENSOR_COUNTER "Teller" // Suffix "1"
|
||||||
#define D_SENSOR_IRRECV "IRrecv"
|
#define D_SENSOR_IRRECV "IRrecv"
|
||||||
|
@ -472,7 +475,7 @@
|
||||||
|
|
||||||
// Units
|
// Units
|
||||||
#define D_UNIT_AMPERE "A"
|
#define D_UNIT_AMPERE "A"
|
||||||
#define D_UNIT_HOUR "Hr"
|
#define D_UNIT_HOUR "h"
|
||||||
#define D_UNIT_KILOWATTHOUR "kWh"
|
#define D_UNIT_KILOWATTHOUR "kWh"
|
||||||
#define D_UNIT_LUX "lx"
|
#define D_UNIT_LUX "lx"
|
||||||
#define D_UNIT_MICROSECOND "us"
|
#define D_UNIT_MICROSECOND "us"
|
||||||
|
@ -576,6 +579,8 @@
|
||||||
#define D_NOT_SUPPORTED "Not supported"
|
#define D_NOT_SUPPORTED "Not supported"
|
||||||
#define D_CMND_GPIOS "GPIOs"
|
#define D_CMND_GPIOS "GPIOs"
|
||||||
#define D_CMND_PWM "PWM"
|
#define D_CMND_PWM "PWM"
|
||||||
|
#define D_CMND_PWMFREQUENCY "PWMFrequency"
|
||||||
|
#define D_CMND_PWMRANGE "PWMRange"
|
||||||
#define D_CMND_COUNTER "Counter"
|
#define D_CMND_COUNTER "Counter"
|
||||||
#define D_CMND_COUNTERTYPE "CounterType"
|
#define D_CMND_COUNTERTYPE "CounterType"
|
||||||
#define D_CMND_COUNTERDEBOUNCE "CounterDebounce"
|
#define D_CMND_COUNTERDEBOUNCE "CounterDebounce"
|
||||||
|
@ -679,3 +684,5 @@
|
||||||
#define D_CMND_SAFEPOWERWINDOW "SafePowerWindow"
|
#define D_CMND_SAFEPOWERWINDOW "SafePowerWindow"
|
||||||
#define D_CMND_MAXENERGY "MaxEnergy"
|
#define D_CMND_MAXENERGY "MaxEnergy"
|
||||||
#define D_CMND_MAXENERGYSTART "MaxEnergyStart"
|
#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/>.
|
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
|
#define PARAM8_SIZE 23 // Number of param bytes
|
||||||
|
|
||||||
typedef union { // Restricted by MISRA-C Rule 18.4 but so usefull...
|
typedef union { // Restricted by MISRA-C Rule 18.4 but so usefull...
|
||||||
uint32_t data; // Allow bit manipulation using SetOption
|
uint32_t data; // Allow bit manipulation using SetOption
|
||||||
struct {
|
struct {
|
||||||
uint32_t savestate : 1; // bit 0
|
uint32_t save_state : 1; // bit 0
|
||||||
uint32_t button_restrict : 1; // bit 1
|
uint32_t button_restrict : 1; // bit 1
|
||||||
uint32_t value_units : 1; // bit 2
|
uint32_t value_units : 1; // bit 2
|
||||||
uint32_t mqtt_enabled : 1; // bit 3
|
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 humidity_resolution : 2;
|
||||||
uint32_t temperature_resolution : 2;
|
uint32_t temperature_resolution : 2;
|
||||||
};
|
};
|
||||||
} sysBitfield;
|
} SysBitfield;
|
||||||
|
|
||||||
struct SYSCFG {
|
struct SYSCFG {
|
||||||
unsigned long cfg_holder; // 000
|
unsigned long cfg_holder; // 000
|
||||||
unsigned long saveFlag; // 004
|
unsigned long save_flag; // 004
|
||||||
unsigned long version; // 008
|
unsigned long version; // 008
|
||||||
unsigned long bootcount; // 00C
|
unsigned long bootcount; // 00C
|
||||||
sysBitfield flag; // 010 Add flag since 5.0.2
|
SysBitfield flag; // 010 Add flag since 5.0.2
|
||||||
int16_t savedata; // 014
|
int16_t save_data; // 014
|
||||||
int8_t timezone; // 016
|
int8_t timezone; // 016
|
||||||
char otaUrl[101]; // 017
|
char ota_url[101]; // 017
|
||||||
char mqtt_prefix[3][11]; // 07C
|
char mqtt_prefix[3][11]; // 07C
|
||||||
|
|
||||||
byte free_09D[1]; // 09D
|
byte free_09D[1]; // 09D
|
||||||
|
@ -89,11 +92,9 @@ struct SYSCFG {
|
||||||
char mqtt_grptopic[33]; // 2B1
|
char mqtt_grptopic[33]; // 2B1
|
||||||
uint8_t mqtt_fingerprinth[20]; // 2D2 Reserved for binary fingerprint
|
uint8_t mqtt_fingerprinth[20]; // 2D2 Reserved for binary fingerprint
|
||||||
|
|
||||||
byte free_2E6[2]; // 2E6
|
uint16_t pwm_frequency; // 2E6
|
||||||
|
|
||||||
power_t power; // 2E8
|
power_t power; // 2E8
|
||||||
uint16_t pwmvalue[MAX_PWMS]; // 2EC
|
uint16_t pwm_value[MAX_PWMS]; // 2EC
|
||||||
// byte free_2EC[10]; // 2EC
|
|
||||||
|
|
||||||
int16_t altitude; // 2F6 Add since 5.8.0i
|
int16_t altitude; // 2F6 Add since 5.8.0i
|
||||||
uint16_t tele_period; // 2F8
|
uint16_t tele_period; // 2F8
|
||||||
|
@ -105,15 +106,14 @@ struct SYSCFG {
|
||||||
byte free_33F[1]; // 33F
|
byte free_33F[1]; // 33F
|
||||||
|
|
||||||
uint16_t domoticz_update_timer; // 340
|
uint16_t domoticz_update_timer; // 340
|
||||||
|
uint16_t pwm_range; // 342
|
||||||
byte free_342[2]; // 342
|
|
||||||
|
|
||||||
unsigned long domoticz_relay_idx[MAX_DOMOTICZ_IDX]; // 344
|
unsigned long domoticz_relay_idx[MAX_DOMOTICZ_IDX]; // 344
|
||||||
unsigned long domoticz_key_idx[MAX_DOMOTICZ_IDX]; // 354
|
unsigned long domoticz_key_idx[MAX_DOMOTICZ_IDX]; // 354
|
||||||
|
|
||||||
unsigned long hlw_pcal; // 364
|
unsigned long hlw_power_calibration; // 364
|
||||||
unsigned long hlw_ucal; // 368
|
unsigned long hlw_voltage_calibration; // 368
|
||||||
unsigned long hlw_ical; // 36C
|
unsigned long hlw_current_calibration; // 36C
|
||||||
unsigned long hlw_kWhtoday; // 370
|
unsigned long hlw_kWhtoday; // 370
|
||||||
unsigned long hlw_kWhyesterday; // 374
|
unsigned long hlw_kWhyesterday; // 374
|
||||||
uint16_t hlw_kWhdoy; // 378
|
uint16_t hlw_kWhdoy; // 378
|
||||||
|
@ -189,8 +189,8 @@ struct SYSCFG {
|
||||||
|
|
||||||
byte free_531[1]; // 531
|
byte free_531[1]; // 531
|
||||||
|
|
||||||
uint16_t pulsetime[MAX_PULSETIMERS]; // 532
|
uint16_t pulse_timer[MAX_PULSETIMERS]; // 532
|
||||||
//uint16_t ex_pwmvalue[MAX_PWMS]; // 53A
|
//uint16_t ex_pwm_value[MAX_PWMS]; // 53A
|
||||||
|
|
||||||
byte free_542[2]; // 542
|
byte free_542[2]; // 542
|
||||||
|
|
||||||
|
@ -200,24 +200,52 @@ struct SYSCFG {
|
||||||
|
|
||||||
byte free_5BD[3]; // 5BD
|
byte free_5BD[3]; // 5BD
|
||||||
|
|
||||||
unsigned long pCounter[MAX_COUNTERS]; // 5C0
|
unsigned long pulse_counter[MAX_COUNTERS]; // 5C0
|
||||||
uint16_t pCounterType; // 5D0
|
uint16_t pulse_counter_type; // 5D0
|
||||||
uint16_t pCounterDebounce; // 5D2
|
uint16_t pulse_counter_debounce; // 5D2
|
||||||
uint8_t sfb_code[17][9]; // 5D4
|
uint8_t rf_code[17][9]; // 5D4
|
||||||
|
|
||||||
} sysCfg;
|
} Settings;
|
||||||
|
|
||||||
struct RTCMEM {
|
struct RTCMEM {
|
||||||
uint16_t valid; // 000
|
uint16_t valid; // 000
|
||||||
byte osw_flag; // 002
|
byte oswatch_blocked_loop; // 002
|
||||||
uint8_t unused; // 003
|
uint8_t unused; // 003
|
||||||
unsigned long hlw_kWhtoday; // 004
|
unsigned long hlw_kWhtoday; // 004
|
||||||
unsigned long hlw_kWhtotal; // 008
|
unsigned long hlw_kWhtotal; // 008
|
||||||
unsigned long pCounter[MAX_COUNTERS]; // 00C
|
unsigned long pulse_counter[MAX_COUNTERS]; // 00C
|
||||||
power_t power; // 01C
|
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
|
// See issue https://github.com/esp8266/Arduino/issues/2913
|
||||||
#ifdef USE_ADC_VCC
|
#ifdef USE_ADC_VCC
|
||||||
ADC_MODE(ADC_VCC); // Set ADC input for Power Supply Voltage usage
|
ADC_MODE(ADC_VCC); // Set ADC input for Power Supply Voltage usage
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // _SETTINGS_H_
|
|
@ -21,7 +21,7 @@
|
||||||
#define DOMOTICZ_UPDATE_TIMER 0 // [DomoticzUpdateTimer] Send relay status (0 = disable, 1 - 3600 seconds) (Optional)
|
#define DOMOTICZ_UPDATE_TIMER 0 // [DomoticzUpdateTimer] Send relay status (0 = disable, 1 - 3600 seconds) (Optional)
|
||||||
#endif
|
#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
|
* RTC memory
|
||||||
|
@ -29,12 +29,12 @@ const uint8_t sfb_codeDefault[9] PROGMEM = { 0x21, 0x16, 0x01, 0x0E, 0x03, 0x48,
|
||||||
|
|
||||||
#define RTC_MEM_VALID 0xA55A
|
#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;
|
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++) {
|
for (uint16_t i = 0; i < sizeof(RTCMEM); i++) {
|
||||||
hash += bytes[i]*(i+1);
|
hash += bytes[i]*(i+1);
|
||||||
|
@ -42,47 +42,47 @@ uint32_t getRtcHash()
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RTC_Save()
|
void RtcSettingsSave()
|
||||||
{
|
{
|
||||||
if (getRtcHash() != _rtcHash) {
|
if (GetRtcSettingsHash() != rtc_settings_hash) {
|
||||||
rtcMem.valid = RTC_MEM_VALID;
|
RtcSettings.valid = RTC_MEM_VALID;
|
||||||
ESP.rtcUserMemoryWrite(100, (uint32_t*)&rtcMem, sizeof(RTCMEM));
|
ESP.rtcUserMemoryWrite(100, (uint32_t*)&RtcSettings, sizeof(RTCMEM));
|
||||||
_rtcHash = getRtcHash();
|
rtc_settings_hash = GetRtcSettingsHash();
|
||||||
#ifdef DEBUG_THEO
|
#ifdef DEBUG_THEO
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Save"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Save"));
|
||||||
RTC_Dump();
|
RtcSettingsDump();
|
||||||
#endif // DEBUG_THEO
|
#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
|
#ifdef DEBUG_THEO
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Load"));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR("Dump: Load"));
|
||||||
RTC_Dump();
|
RtcSettingsDump();
|
||||||
#endif // DEBUG_THEO
|
#endif // DEBUG_THEO
|
||||||
if (rtcMem.valid != RTC_MEM_VALID) {
|
if (RtcSettings.valid != RTC_MEM_VALID) {
|
||||||
memset(&rtcMem, 0, sizeof(RTCMEM));
|
memset(&RtcSettings, 0, sizeof(RTCMEM));
|
||||||
rtcMem.valid = RTC_MEM_VALID;
|
RtcSettings.valid = RTC_MEM_VALID;
|
||||||
rtcMem.hlw_kWhtoday = sysCfg.hlw_kWhtoday;
|
RtcSettings.hlw_kWhtoday = Settings.hlw_kWhtoday;
|
||||||
rtcMem.hlw_kWhtotal = sysCfg.hlw_kWhtotal;
|
RtcSettings.hlw_kWhtotal = Settings.hlw_kWhtotal;
|
||||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
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;
|
RtcSettings.power = Settings.power;
|
||||||
RTC_Save();
|
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
|
#ifdef DEBUG_THEO
|
||||||
void RTC_Dump()
|
void RtcSettingsDump()
|
||||||
{
|
{
|
||||||
#define CFG_COLS 16
|
#define CFG_COLS 16
|
||||||
|
|
||||||
|
@ -91,7 +91,7 @@ void RTC_Dump()
|
||||||
uint16_t row;
|
uint16_t row;
|
||||||
uint16_t col;
|
uint16_t col;
|
||||||
|
|
||||||
uint8_t *buffer = (uint8_t *) &rtcMem;
|
uint8_t *buffer = (uint8_t *) &RtcSettings;
|
||||||
maxrow = ((sizeof(RTCMEM)+CFG_COLS)/CFG_COLS);
|
maxrow = ((sizeof(RTCMEM)+CFG_COLS)/CFG_COLS);
|
||||||
|
|
||||||
for (row = 0; row < maxrow; row++) {
|
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%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);
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
||||||
addLog(LOG_LEVEL_INFO);
|
AddLog(LOG_LEVEL_INFO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // DEBUG_THEO
|
#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
|
#define SPIFFS_END ((uint32_t)&_SPIFFS_end - 0x40200000) / SPI_FLASH_SEC_SIZE
|
||||||
|
|
||||||
// Version 3.x config
|
// Version 3.x config
|
||||||
#define CFG_LOCATION_3 SPIFFS_END - 4
|
#define SETTINGS_LOCATION_3 SPIFFS_END - 4
|
||||||
|
|
||||||
// Version 4.2 config = eeprom area
|
// 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
|
// Version 5.2 allow for more flash space
|
||||||
#define CFG_ROTATES 8 // Number of flash sectors used (handles uploads)
|
#define CFG_ROTATES 8 // Number of flash sectors used (handles uploads)
|
||||||
|
|
||||||
uint32_t _cfgHash = 0;
|
uint32_t settings_hash = 0;
|
||||||
uint32_t _cfgLocation = CFG_LOCATION;
|
uint32_t settings_location = SETTINGS_LOCATION;
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
/*
|
/*
|
||||||
* Based on cores/esp8266/Updater.cpp
|
* Based on cores/esp8266/Updater.cpp
|
||||||
*/
|
*/
|
||||||
void setFlashModeDout()
|
void SetFlashModeDout()
|
||||||
{
|
{
|
||||||
uint8_t *_buffer;
|
uint8_t *_buffer;
|
||||||
uint32_t address;
|
uint32_t address;
|
||||||
|
@ -166,10 +166,10 @@ void setFlashModeDout()
|
||||||
delete[] _buffer;
|
delete[] _buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getHash()
|
uint32_t GetSettingsHash()
|
||||||
{
|
{
|
||||||
uint32_t hash = 0;
|
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++) {
|
for (uint16_t i = 0; i < sizeof(SYSCFG); i++) {
|
||||||
hash += bytes[i]*(i+1);
|
hash += bytes[i]*(i+1);
|
||||||
|
@ -181,12 +181,12 @@ uint32_t getHash()
|
||||||
* Config Save - Save parameters to Flash ONLY if any parameter has changed
|
* 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
|
/* 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)
|
* stop_flash_rotate 1 = Allow only eeprom flash slot use (SetOption12 1)
|
||||||
*/
|
*/
|
||||||
#ifndef BE_MINIMAL
|
#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)
|
if (1 == rotate) { // Use eeprom flash slot only and disable flash rotate from now on (upgrade)
|
||||||
stop_flash_rotate = 1;
|
stop_flash_rotate = 1;
|
||||||
}
|
}
|
||||||
if (2 == rotate) { // Use eeprom flash slot and erase next flash slots if stop_flash_rotate is off (default)
|
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) {
|
if (stop_flash_rotate) {
|
||||||
_cfgLocation = CFG_LOCATION;
|
settings_location = SETTINGS_LOCATION;
|
||||||
} else {
|
} else {
|
||||||
_cfgLocation--;
|
settings_location--;
|
||||||
if (_cfgLocation <= (CFG_LOCATION - CFG_ROTATES)) {
|
if (settings_location <= (SETTINGS_LOCATION - CFG_ROTATES)) {
|
||||||
_cfgLocation = CFG_LOCATION;
|
settings_location = SETTINGS_LOCATION;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sysCfg.saveFlag++;
|
Settings.save_flag++;
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
spi_flash_erase_sector(_cfgLocation);
|
spi_flash_erase_sector(settings_location);
|
||||||
spi_flash_write(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
spi_flash_write(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
||||||
interrupts();
|
interrupts();
|
||||||
if (!stop_flash_rotate && rotate) {
|
if (!stop_flash_rotate && rotate) {
|
||||||
for (byte i = 1; i < CFG_ROTATES; i++) {
|
for (byte i = 1; i < CFG_ROTATES; i++) {
|
||||||
noInterrupts();
|
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();
|
interrupts();
|
||||||
delay(1);
|
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"),
|
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));
|
settings_location, Settings.save_flag, sizeof(SYSCFG));
|
||||||
addLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
_cfgHash = getHash();
|
settings_hash = GetSettingsHash();
|
||||||
}
|
}
|
||||||
#endif // BE_MINIMAL
|
#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
|
/* Load configuration from eeprom or one of 7 slots below if first load does not stop_flash_rotate
|
||||||
*/
|
*/
|
||||||
struct SYSCFGH {
|
struct SYSCFGH {
|
||||||
unsigned long cfg_holder;
|
unsigned long cfg_holder;
|
||||||
unsigned long saveFlag;
|
unsigned long save_flag;
|
||||||
} _sysCfgH;
|
} _SettingsH;
|
||||||
|
|
||||||
_cfgLocation = CFG_LOCATION +1;
|
settings_location = SETTINGS_LOCATION +1;
|
||||||
for (byte i = 0; i < CFG_ROTATES; i++) {
|
for (byte i = 0; i < CFG_ROTATES; i++) {
|
||||||
_cfgLocation--;
|
settings_location--;
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
spi_flash_read(_cfgLocation * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
spi_flash_read(settings_location * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
||||||
spi_flash_read((_cfgLocation -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
spi_flash_read((settings_location -1) * SPI_FLASH_SEC_SIZE, (uint32*)&_SettingsH, sizeof(SYSCFGH));
|
||||||
interrupts();
|
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);
|
// 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);
|
// 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;
|
break;
|
||||||
}
|
}
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %d"),
|
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_CONFIG D_LOADED_FROM_FLASH_AT " %X, " D_COUNT " %d"),
|
||||||
_cfgLocation, sysCfg.saveFlag);
|
settings_location, Settings.save_flag);
|
||||||
addLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
if (sysCfg.cfg_holder != CFG_HOLDER) {
|
if (Settings.cfg_holder != CFG_HOLDER) {
|
||||||
// Auto upgrade
|
// Auto upgrade
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
spi_flash_read((CFG_LOCATION_3) * 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((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_sysCfgH, sizeof(SYSCFGH));
|
spi_flash_read((SETTINGS_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&_SettingsH, sizeof(SYSCFGH));
|
||||||
if (sysCfg.saveFlag < _sysCfgH.saveFlag)
|
if (Settings.save_flag < _SettingsH.save_flag)
|
||||||
spi_flash_read((CFG_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&sysCfg, sizeof(SYSCFG));
|
spi_flash_read((SETTINGS_LOCATION_3 + 1) * SPI_FLASH_SEC_SIZE, (uint32*)&Settings, sizeof(SYSCFG));
|
||||||
interrupts();
|
interrupts();
|
||||||
if ((sysCfg.cfg_holder != CFG_HOLDER) || (sysCfg.version >= 0x04020000)) {
|
if ((Settings.cfg_holder != CFG_HOLDER) || (Settings.version >= 0x04020000)) {
|
||||||
CFG_Default();
|
SettingsDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_cfgHash = getHash();
|
settings_hash = GetSettingsHash();
|
||||||
|
|
||||||
RTC_Load();
|
RtcSettingsLoad();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFG_Erase()
|
void SettingsErase()
|
||||||
{
|
{
|
||||||
SpiFlashOpResult result;
|
SpiFlashOpResult result;
|
||||||
|
|
||||||
|
@ -289,7 +289,7 @@ void CFG_Erase()
|
||||||
boolean _serialoutput = (LOG_LEVEL_DEBUG_MORE <= seriallog_level);
|
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);
|
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++) {
|
for (uint32_t _sector = _sectorStart; _sector < _sectorEnd; _sector++) {
|
||||||
noInterrupts();
|
noInterrupts();
|
||||||
|
@ -305,11 +305,11 @@ void CFG_Erase()
|
||||||
}
|
}
|
||||||
delay(10);
|
delay(10);
|
||||||
}
|
}
|
||||||
osw_loop();
|
OsWatchLoop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFG_Dump(char* parms)
|
void SettingsDump(char* parms)
|
||||||
{
|
{
|
||||||
#define CFG_COLS 16
|
#define CFG_COLS 16
|
||||||
|
|
||||||
|
@ -319,14 +319,14 @@ void CFG_Dump(char* parms)
|
||||||
uint16_t col;
|
uint16_t col;
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
uint8_t *buffer = (uint8_t *) &sysCfg;
|
uint8_t *buffer = (uint8_t *) &Settings;
|
||||||
maxrow = ((sizeof(SYSCFG)+CFG_COLS)/CFG_COLS);
|
maxrow = ((sizeof(SYSCFG)+CFG_COLS)/CFG_COLS);
|
||||||
|
|
||||||
uint16_t srow = strtol(parms, &p, 16) / CFG_COLS;
|
uint16_t srow = strtol(parms, &p, 16) / CFG_COLS;
|
||||||
uint16_t mrow = strtol(p, &p, 10);
|
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);
|
// 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
|
if (0 == mrow) { // Default only 8 lines
|
||||||
mrow = 8;
|
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%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);
|
snprintf_P(log_data, sizeof(log_data), PSTR("%s|"), log_data);
|
||||||
addLog(LOG_LEVEL_INFO);
|
AddLog(LOG_LEVEL_INFO);
|
||||||
delay(1);
|
delay(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void CFG_Default()
|
void SettingsDefault()
|
||||||
{
|
{
|
||||||
addLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_USE_DEFAULTS));
|
AddLog_P(LOG_LEVEL_NONE, PSTR(D_LOG_CONFIG D_USE_DEFAULTS));
|
||||||
CFG_DefaultSet1();
|
SettingsDefaultSet1();
|
||||||
CFG_DefaultSet2();
|
SettingsDefaultSet2();
|
||||||
CFG_Save(2);
|
SettingsSave(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFG_DefaultSet1()
|
void SettingsDefaultSet1()
|
||||||
{
|
{
|
||||||
memset(&sysCfg, 0x00, sizeof(SYSCFG));
|
memset(&Settings, 0x00, sizeof(SYSCFG));
|
||||||
|
|
||||||
sysCfg.cfg_holder = CFG_HOLDER;
|
Settings.cfg_holder = CFG_HOLDER;
|
||||||
// sysCfg.saveFlag = 0;
|
// Settings.save_flag = 0;
|
||||||
sysCfg.version = VERSION;
|
Settings.version = VERSION;
|
||||||
// sysCfg.bootcount = 0;
|
// 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;
|
Settings.flag.save_state = SAVE_STATE;
|
||||||
//sysCfg.flag.button_restrict = 0;
|
//Settings.flag.button_restrict = 0;
|
||||||
//sysCfg.flag.value_units = 0;
|
//Settings.flag.value_units = 0;
|
||||||
sysCfg.flag.mqtt_enabled = MQTT_USE;
|
Settings.flag.mqtt_enabled = MQTT_USE;
|
||||||
//sysCfg.flag.mqtt_response = 0;
|
//Settings.flag.mqtt_response = 0;
|
||||||
sysCfg.flag.mqtt_power_retain = MQTT_POWER_RETAIN;
|
Settings.flag.mqtt_power_retain = MQTT_POWER_RETAIN;
|
||||||
sysCfg.flag.mqtt_button_retain = MQTT_BUTTON_RETAIN;
|
Settings.flag.mqtt_button_retain = MQTT_BUTTON_RETAIN;
|
||||||
sysCfg.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
Settings.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
||||||
|
|
||||||
sysCfg.flag.emulation = EMULATION;
|
Settings.flag.emulation = EMULATION;
|
||||||
|
|
||||||
sysCfg.savedata = SAVE_DATA;
|
Settings.save_data = SAVE_DATA;
|
||||||
sysCfg.timezone = APP_TIMEZONE;
|
Settings.timezone = APP_TIMEZONE;
|
||||||
strlcpy(sysCfg.otaUrl, OTA_URL, sizeof(sysCfg.otaUrl));
|
strlcpy(Settings.ota_url, OTA_URL, sizeof(Settings.ota_url));
|
||||||
|
|
||||||
sysCfg.seriallog_level = SERIAL_LOG_LEVEL;
|
Settings.seriallog_level = SERIAL_LOG_LEVEL;
|
||||||
// sysCfg.sta_active = 0;
|
// Settings.sta_active = 0;
|
||||||
strlcpy(sysCfg.sta_ssid[0], STA_SSID1, sizeof(sysCfg.sta_ssid[0]));
|
strlcpy(Settings.sta_ssid[0], STA_SSID1, sizeof(Settings.sta_ssid[0]));
|
||||||
strlcpy(sysCfg.sta_pwd[0], STA_PASS1, sizeof(sysCfg.sta_pwd[0]));
|
strlcpy(Settings.sta_pwd[0], STA_PASS1, sizeof(Settings.sta_pwd[0]));
|
||||||
strlcpy(sysCfg.sta_ssid[1], STA_SSID2, sizeof(sysCfg.sta_ssid[1]));
|
strlcpy(Settings.sta_ssid[1], STA_SSID2, sizeof(Settings.sta_ssid[1]));
|
||||||
strlcpy(sysCfg.sta_pwd[1], STA_PASS2, sizeof(sysCfg.sta_pwd[1]));
|
strlcpy(Settings.sta_pwd[1], STA_PASS2, sizeof(Settings.sta_pwd[1]));
|
||||||
strlcpy(sysCfg.hostname, WIFI_HOSTNAME, sizeof(sysCfg.hostname));
|
strlcpy(Settings.hostname, WIFI_HOSTNAME, sizeof(Settings.hostname));
|
||||||
sysCfg.sta_config = WIFI_CONFIG_TOOL;
|
Settings.sta_config = WIFI_CONFIG_TOOL;
|
||||||
strlcpy(sysCfg.syslog_host, SYS_LOG_HOST, sizeof(sysCfg.syslog_host));
|
strlcpy(Settings.syslog_host, SYS_LOG_HOST, sizeof(Settings.syslog_host));
|
||||||
sysCfg.syslog_port = SYS_LOG_PORT;
|
Settings.syslog_port = SYS_LOG_PORT;
|
||||||
sysCfg.syslog_level = SYS_LOG_LEVEL;
|
Settings.syslog_level = SYS_LOG_LEVEL;
|
||||||
sysCfg.webserver = WEB_SERVER;
|
Settings.webserver = WEB_SERVER;
|
||||||
sysCfg.weblog_level = WEB_LOG_LEVEL;
|
Settings.weblog_level = WEB_LOG_LEVEL;
|
||||||
|
|
||||||
strlcpy(sysCfg.mqtt_fingerprint, MQTT_FINGERPRINT, sizeof(sysCfg.mqtt_fingerprint));
|
strlcpy(Settings.mqtt_fingerprint, MQTT_FINGERPRINT, sizeof(Settings.mqtt_fingerprint));
|
||||||
strlcpy(sysCfg.mqtt_host, MQTT_HOST, sizeof(sysCfg.mqtt_host));
|
strlcpy(Settings.mqtt_host, MQTT_HOST, sizeof(Settings.mqtt_host));
|
||||||
sysCfg.mqtt_port = MQTT_PORT;
|
Settings.mqtt_port = MQTT_PORT;
|
||||||
strlcpy(sysCfg.mqtt_client, MQTT_CLIENT_ID, sizeof(sysCfg.mqtt_client));
|
strlcpy(Settings.mqtt_client, MQTT_CLIENT_ID, sizeof(Settings.mqtt_client));
|
||||||
strlcpy(sysCfg.mqtt_user, MQTT_USER, sizeof(sysCfg.mqtt_user));
|
strlcpy(Settings.mqtt_user, MQTT_USER, sizeof(Settings.mqtt_user));
|
||||||
strlcpy(sysCfg.mqtt_pwd, MQTT_PASS, sizeof(sysCfg.mqtt_pwd));
|
strlcpy(Settings.mqtt_pwd, MQTT_PASS, sizeof(Settings.mqtt_pwd));
|
||||||
strlcpy(sysCfg.mqtt_topic, MQTT_TOPIC, sizeof(sysCfg.mqtt_topic));
|
strlcpy(Settings.mqtt_topic, MQTT_TOPIC, sizeof(Settings.mqtt_topic));
|
||||||
strlcpy(sysCfg.button_topic, "0", sizeof(sysCfg.button_topic));
|
strlcpy(Settings.button_topic, "0", sizeof(Settings.button_topic));
|
||||||
strlcpy(sysCfg.mqtt_grptopic, MQTT_GRPTOPIC, sizeof(sysCfg.mqtt_grptopic));
|
strlcpy(Settings.mqtt_grptopic, MQTT_GRPTOPIC, sizeof(Settings.mqtt_grptopic));
|
||||||
sysCfg.tele_period = TELE_PERIOD;
|
Settings.tele_period = TELE_PERIOD;
|
||||||
|
|
||||||
sysCfg.power = APP_POWER;
|
Settings.power = APP_POWER;
|
||||||
sysCfg.poweronstate = APP_POWERON_STATE;
|
Settings.poweronstate = APP_POWERON_STATE;
|
||||||
sysCfg.ledstate = APP_LEDSTATE;
|
Settings.ledstate = APP_LEDSTATE;
|
||||||
sysCfg.blinktime = APP_BLINKTIME;
|
Settings.blinktime = APP_BLINKTIME;
|
||||||
sysCfg.blinkcount = APP_BLINKCOUNT;
|
Settings.blinkcount = APP_BLINKCOUNT;
|
||||||
sysCfg.sleep = APP_SLEEP;
|
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++) {
|
for (byte i = 0; i < MAX_SWITCHES; i++) {
|
||||||
sysCfg.switchmode[i] = SWITCH_MODE;
|
Settings.switchmode[i] = SWITCH_MODE;
|
||||||
// sysCfg.domoticz_relay_idx[i] = 0;
|
// Settings.domoticz_relay_idx[i] = 0;
|
||||||
// sysCfg.domoticz_key_idx[i] = 0;
|
// Settings.domoticz_key_idx[i] = 0;
|
||||||
// sysCfg.domoticz_switch_idx[i] = 0;
|
// Settings.domoticz_switch_idx[i] = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sysCfg.hlw_pcal = HLW_PREF_PULSE;
|
Settings.hlw_power_calibration = HLW_PREF_PULSE;
|
||||||
sysCfg.hlw_ucal = HLW_UREF_PULSE;
|
Settings.hlw_voltage_calibration = HLW_UREF_PULSE;
|
||||||
sysCfg.hlw_ical = HLW_IREF_PULSE;
|
Settings.hlw_current_calibration = HLW_IREF_PULSE;
|
||||||
// sysCfg.hlw_kWhtoday = 0;
|
// Settings.hlw_kWhtoday = 0;
|
||||||
// sysCfg.hlw_kWhyesterday = 0;
|
// Settings.hlw_kWhyesterday = 0;
|
||||||
// sysCfg.hlw_kWhdoy = 0;
|
// Settings.hlw_kWhdoy = 0;
|
||||||
// sysCfg.hlw_pmin = 0;
|
// Settings.hlw_pmin = 0;
|
||||||
// sysCfg.hlw_pmax = 0;
|
// Settings.hlw_pmax = 0;
|
||||||
// sysCfg.hlw_umin = 0;
|
// Settings.hlw_umin = 0;
|
||||||
// sysCfg.hlw_umax = 0;
|
// Settings.hlw_umax = 0;
|
||||||
// sysCfg.hlw_imin = 0;
|
// Settings.hlw_imin = 0;
|
||||||
// sysCfg.hlw_imax = 0;
|
// Settings.hlw_imax = 0;
|
||||||
// sysCfg.hlw_mpl = 0; // MaxPowerLimit
|
// Settings.hlw_mpl = 0; // MaxPowerLimit
|
||||||
sysCfg.hlw_mplh = MAX_POWER_HOLD;
|
Settings.hlw_mplh = MAX_POWER_HOLD;
|
||||||
sysCfg.hlw_mplw = MAX_POWER_WINDOW;
|
Settings.hlw_mplw = MAX_POWER_WINDOW;
|
||||||
// sysCfg.hlw_mspl = 0; // MaxSafePowerLimit
|
// Settings.hlw_mspl = 0; // MaxSafePowerLimit
|
||||||
sysCfg.hlw_msplh = SAFE_POWER_HOLD;
|
Settings.hlw_msplh = SAFE_POWER_HOLD;
|
||||||
sysCfg.hlw_msplw = SAFE_POWER_WINDOW;
|
Settings.hlw_msplw = SAFE_POWER_WINDOW;
|
||||||
// sysCfg.hlw_mkwh = 0; // MaxEnergy
|
// Settings.hlw_mkwh = 0; // MaxEnergy
|
||||||
// sysCfg.hlw_mkwhs = 0; // MaxEnergyStart
|
// 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(Settings.friendlyname[0], FRIENDLY_NAME, sizeof(Settings.friendlyname[0]));
|
||||||
strlcpy(sysCfg.friendlyname[1], FRIENDLY_NAME"2", sizeof(sysCfg.friendlyname[1]));
|
strlcpy(Settings.friendlyname[1], FRIENDLY_NAME"2", sizeof(Settings.friendlyname[1]));
|
||||||
strlcpy(sysCfg.friendlyname[2], FRIENDLY_NAME"3", sizeof(sysCfg.friendlyname[2]));
|
strlcpy(Settings.friendlyname[2], FRIENDLY_NAME"3", sizeof(Settings.friendlyname[2]));
|
||||||
strlcpy(sysCfg.friendlyname[3], FRIENDLY_NAME"4", sizeof(sysCfg.friendlyname[3]));
|
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();
|
SettingsDefaultSet_4_0_4();
|
||||||
sysCfg.pulsetime[0] = APP_PULSETIME;
|
Settings.pulse_timer[0] = APP_PULSETIME;
|
||||||
|
|
||||||
// 4.0.7
|
// 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
|
// 4.0.9
|
||||||
CFG_DefaultSet_4_0_9();
|
SettingsDefaultSet_4_0_9();
|
||||||
|
|
||||||
// 4.1.1 + 5.1.6
|
// 4.1.1 + 5.1.6
|
||||||
CFG_DefaultSet_4_1_1();
|
SettingsDefaultSet_4_1_1();
|
||||||
|
|
||||||
// 5.0.2
|
// 5.0.2
|
||||||
CFG_DefaultSet_5_0_2();
|
SettingsDefaultSet_5_0_2();
|
||||||
|
|
||||||
// 5.0.4
|
// 5.0.4
|
||||||
// sysCfg.hlw_kWhtotal = 0;
|
// Settings.hlw_kWhtotal = 0;
|
||||||
rtcMem.hlw_kWhtotal = 0;
|
RtcSettings.hlw_kWhtotal = 0;
|
||||||
|
|
||||||
// 5.0.5
|
// 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
|
// 5.0.6
|
||||||
sysCfg.mqtt_retry = MQTT_RETRY_SECS;
|
Settings.mqtt_retry = MQTT_RETRY_SECS;
|
||||||
|
|
||||||
// 5.1.7
|
// 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
|
// 5.2.0
|
||||||
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
Settings.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||||
|
|
||||||
// 5.4.1
|
// 5.4.1
|
||||||
memcpy_P(sysCfg.sfb_code[0], sfb_codeDefault, 9);
|
memcpy_P(Settings.rf_code[0], kDefaultRfCode, 9);
|
||||||
|
|
||||||
// 5.8.0
|
// 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;
|
Settings.ws_pixels = WS2812_LEDS;
|
||||||
sysCfg.ws_red = 255;
|
Settings.ws_red = 255;
|
||||||
sysCfg.ws_green = 0;
|
Settings.ws_green = 0;
|
||||||
sysCfg.ws_blue = 0;
|
Settings.ws_blue = 0;
|
||||||
sysCfg.ws_ledtable = 0;
|
Settings.ws_ledtable = 0;
|
||||||
sysCfg.ws_dimmer = 8;
|
Settings.ws_dimmer = 8;
|
||||||
sysCfg.ws_fade = 0;
|
Settings.ws_fade = 0;
|
||||||
sysCfg.ws_speed = 1;
|
Settings.ws_speed = 1;
|
||||||
sysCfg.ws_scheme = 0;
|
Settings.ws_scheme = 0;
|
||||||
sysCfg.ws_width = 1;
|
Settings.ws_width = 1;
|
||||||
sysCfg.ws_wakeup = 0;
|
Settings.ws_wakeup = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFG_DefaultSet_3_9_3()
|
void SettingsDefaultSet_3_9_3()
|
||||||
{
|
{
|
||||||
for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
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++) {
|
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++){
|
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++) {
|
for (byte i = 0; i < MAX_PWMS; i++) {
|
||||||
sysCfg.led_color[i] = 255;
|
Settings.led_color[i] = 255;
|
||||||
}
|
}
|
||||||
sysCfg.led_table = 0;
|
Settings.led_table = 0;
|
||||||
sysCfg.led_dimmer = 10;
|
Settings.led_dimmer = 10;
|
||||||
sysCfg.led_fade = 0;
|
Settings.led_fade = 0;
|
||||||
sysCfg.led_speed = 1;
|
Settings.led_speed = 1;
|
||||||
sysCfg.led_scheme = 0;
|
Settings.led_scheme = 0;
|
||||||
sysCfg.led_width = 1;
|
Settings.led_width = 1;
|
||||||
sysCfg.led_wakeup = 0;
|
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(Settings.ntp_server[0], NTP_SERVER1, sizeof(Settings.ntp_server[0]));
|
||||||
strlcpy(sysCfg.ntp_server[1], NTP_SERVER2, sizeof(sysCfg.ntp_server[1]));
|
strlcpy(Settings.ntp_server[1], NTP_SERVER2, sizeof(Settings.ntp_server[1]));
|
||||||
strlcpy(sysCfg.ntp_server[2], NTP_SERVER3, sizeof(sysCfg.ntp_server[2]));
|
strlcpy(Settings.ntp_server[2], NTP_SERVER3, sizeof(Settings.ntp_server[2]));
|
||||||
for (byte j = 0; j < 3; j++) {
|
for (byte j = 0; j < 3; j++) {
|
||||||
for (byte i = 0; i < strlen(sysCfg.ntp_server[j]); i++) {
|
for (byte i = 0; i < strlen(Settings.ntp_server[j]); i++) {
|
||||||
if (sysCfg.ntp_server[j][i] == ',') {
|
if (Settings.ntp_server[j][i] == ',') {
|
||||||
sysCfg.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++) {
|
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(Settings.mqtt_prefix[0], SUB_PREFIX, sizeof(Settings.mqtt_prefix[0]));
|
||||||
strlcpy(sysCfg.mqtt_prefix[1], PUB_PREFIX, sizeof(sysCfg.mqtt_prefix[1]));
|
strlcpy(Settings.mqtt_prefix[1], PUB_PREFIX, sizeof(Settings.mqtt_prefix[1]));
|
||||||
strlcpy(sysCfg.mqtt_prefix[2], PUB_PREFIX2, sizeof(sysCfg.mqtt_prefix[2]));
|
strlcpy(Settings.mqtt_prefix[2], PUB_PREFIX2, sizeof(Settings.mqtt_prefix[2]));
|
||||||
parseIP(&sysCfg.ip_address[0], WIFI_IP_ADDRESS);
|
ParseIp(&Settings.ip_address[0], WIFI_IP_ADDRESS);
|
||||||
parseIP(&sysCfg.ip_address[1], WIFI_GATEWAY);
|
ParseIp(&Settings.ip_address[1], WIFI_GATEWAY);
|
||||||
parseIP(&sysCfg.ip_address[2], WIFI_SUBNETMASK);
|
ParseIp(&Settings.ip_address[2], WIFI_SUBNETMASK);
|
||||||
parseIP(&sysCfg.ip_address[3], WIFI_DNS);
|
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(Settings.state_text[0], MQTT_STATUS_OFF, sizeof(Settings.state_text[0]));
|
||||||
strlcpy(sysCfg.state_text[1], MQTT_STATUS_ON, sizeof(sysCfg.state_text[1]));
|
strlcpy(Settings.state_text[1], MQTT_STATUS_ON, sizeof(Settings.state_text[1]));
|
||||||
strlcpy(sysCfg.state_text[2], MQTT_CMND_TOGGLE, sizeof(sysCfg.state_text[2]));
|
strlcpy(Settings.state_text[2], MQTT_CMND_TOGGLE, sizeof(Settings.state_text[2]));
|
||||||
strlcpy(sysCfg.state_text[3], MQTT_CMND_HOLD, sizeof(sysCfg.state_text[3])); // v5.1.6
|
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;
|
Settings.flag.temperature_conversion = TEMP_CONVERSION;
|
||||||
sysCfg.flag.temperature_resolution = TEMP_RESOLUTION;
|
Settings.flag.temperature_resolution = TEMP_RESOLUTION;
|
||||||
sysCfg.flag.humidity_resolution = HUMIDITY_RESOLUTION;
|
Settings.flag.humidity_resolution = HUMIDITY_RESOLUTION;
|
||||||
sysCfg.flag.pressure_resolution = PRESSURE_RESOLUTION;
|
Settings.flag.pressure_resolution = PRESSURE_RESOLUTION;
|
||||||
sysCfg.flag.energy_resolution = ENERGY_RESOLUTION;
|
Settings.flag.energy_resolution = ENERGY_RESOLUTION;
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void CFG_Delta()
|
void SettingsDelta()
|
||||||
{
|
{
|
||||||
if (sysCfg.version != VERSION) { // Fix version dependent changes
|
if (Settings.version != VERSION) { // Fix version dependent changes
|
||||||
if (sysCfg.version < 0x03010200) { // 3.1.2 - Add parameter
|
if (Settings.version < 0x03010200) { // 3.1.2 - Add parameter
|
||||||
sysCfg.poweronstate = APP_POWERON_STATE;
|
Settings.poweronstate = APP_POWERON_STATE;
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x03010600) { // 3.1.6 - Add parameter
|
if (Settings.version < 0x03010600) { // 3.1.6 - Add parameter
|
||||||
sysCfg.blinktime = APP_BLINKTIME;
|
Settings.blinktime = APP_BLINKTIME;
|
||||||
sysCfg.blinkcount = APP_BLINKCOUNT;
|
Settings.blinkcount = APP_BLINKCOUNT;
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x03020400) { // 3.2.4 - Add parameter
|
if (Settings.version < 0x03020400) { // 3.2.4 - Add parameter
|
||||||
CFG_DefaultSet_3_2_4();
|
SettingsDefaultSet_3_2_4();
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x03020500) { // 3.2.5 - Add parameter
|
if (Settings.version < 0x03020500) { // 3.2.5 - Add parameter
|
||||||
getClient(sysCfg.friendlyname[0], sysCfg.mqtt_client, sizeof(sysCfg.friendlyname[0]));
|
GetMqttClient(Settings.friendlyname[0], Settings.mqtt_client, sizeof(Settings.friendlyname[0]));
|
||||||
strlcpy(sysCfg.friendlyname[1], FRIENDLY_NAME"2", sizeof(sysCfg.friendlyname[1]));
|
strlcpy(Settings.friendlyname[1], FRIENDLY_NAME"2", sizeof(Settings.friendlyname[1]));
|
||||||
strlcpy(sysCfg.friendlyname[2], FRIENDLY_NAME"3", sizeof(sysCfg.friendlyname[2]));
|
strlcpy(Settings.friendlyname[2], FRIENDLY_NAME"3", sizeof(Settings.friendlyname[2]));
|
||||||
strlcpy(sysCfg.friendlyname[3], FRIENDLY_NAME"4", sizeof(sysCfg.friendlyname[3]));
|
strlcpy(Settings.friendlyname[3], FRIENDLY_NAME"4", sizeof(Settings.friendlyname[3]));
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x03020800) { // 3.2.8 - Add parameter
|
if (Settings.version < 0x03020800) { // 3.2.8 - Add parameter
|
||||||
strlcpy(sysCfg.switch_topic, sysCfg.button_topic, sizeof(sysCfg.switch_topic));
|
strlcpy(Settings.switch_topic, Settings.button_topic, sizeof(Settings.switch_topic));
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x03020C00) { // 3.2.12 - Add parameter
|
if (Settings.version < 0x03020C00) { // 3.2.12 - Add parameter
|
||||||
sysCfg.sleep = APP_SLEEP;
|
Settings.sleep = APP_SLEEP;
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x03090300) { // 3.9.2d - Add parameter
|
if (Settings.version < 0x03090300) { // 3.9.2d - Add parameter
|
||||||
CFG_DefaultSet_3_9_3();
|
SettingsDefaultSet_3_9_3();
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x03091400) {
|
if (Settings.version < 0x03091400) {
|
||||||
strlcpy(sysCfg.web_password, WEB_PASSWORD, sizeof(sysCfg.web_password));
|
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++) {
|
for (byte i = 0; i < MAX_SWITCHES; i++) {
|
||||||
sysCfg.switchmode[i] = SWITCH_MODE;
|
Settings.switchmode[i] = SWITCH_MODE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x04000400) {
|
if (Settings.version < 0x04000400) {
|
||||||
CFG_DefaultSet_4_0_4();
|
SettingsDefaultSet_4_0_4();
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x04000500) {
|
if (Settings.version < 0x04000500) {
|
||||||
memmove(sysCfg.my_gp.io, sysCfg.my_gp.io +1, MAX_GPIO_PIN -1); // move myio 1 byte to front
|
memmove(Settings.my_gp.io, Settings.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
|
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++) {
|
for (byte i = 0; i < MAX_PWMS; i++) {
|
||||||
sysCfg.pwmvalue[i] = 0;
|
Settings.pwm_value[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x04000804) {
|
if (Settings.version < 0x04000804) {
|
||||||
CFG_DefaultSet_4_0_9();
|
SettingsDefaultSet_4_0_9();
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x04010100) {
|
if (Settings.version < 0x04010100) {
|
||||||
CFG_DefaultSet_4_1_1();
|
SettingsDefaultSet_4_1_1();
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05000105) {
|
if (Settings.version < 0x05000105) {
|
||||||
sysCfg.flag = { 0 };
|
Settings.flag = { 0 };
|
||||||
sysCfg.flag.savestate = SAVE_STATE;
|
Settings.flag.save_state = SAVE_STATE;
|
||||||
// sysCfg.flag.button_restrict = 0;
|
// Settings.flag.button_restrict = 0;
|
||||||
// sysCfg.flag.value_units = 0;
|
// Settings.flag.value_units = 0;
|
||||||
sysCfg.flag.mqtt_enabled = MQTT_USE;
|
Settings.flag.mqtt_enabled = MQTT_USE;
|
||||||
// sysCfg.flag.mqtt_response = 0;
|
// Settings.flag.mqtt_response = 0;
|
||||||
// sysCfg.flag.mqtt_power_retain = 0;
|
// Settings.flag.mqtt_power_retain = 0;
|
||||||
// sysCfg.flag.mqtt_button_retain = 0;
|
// Settings.flag.mqtt_button_retain = 0;
|
||||||
sysCfg.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
Settings.flag.mqtt_switch_retain = MQTT_SWITCH_RETAIN;
|
||||||
sysCfg.flag.emulation = EMULATION;
|
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) {
|
if (Settings.version < 0x05000400) {
|
||||||
sysCfg.hlw_kWhtotal = 0;
|
Settings.hlw_kWhtotal = 0;
|
||||||
rtcMem.hlw_kWhtotal = 0;
|
RtcSettings.hlw_kWhtotal = 0;
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05000500) {
|
if (Settings.version < 0x05000500) {
|
||||||
strlcpy(sysCfg.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(sysCfg.mqtt_fulltopic));
|
strlcpy(Settings.mqtt_fulltopic, MQTT_FULLTOPIC, sizeof(Settings.mqtt_fulltopic));
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05000600) {
|
if (Settings.version < 0x05000600) {
|
||||||
sysCfg.mqtt_retry = MQTT_RETRY_SECS;
|
Settings.mqtt_retry = MQTT_RETRY_SECS;
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05010100) {
|
if (Settings.version < 0x05010100) {
|
||||||
sysCfg.pCounterType = 0;
|
Settings.pulse_counter_type = 0;
|
||||||
sysCfg.pCounterDebounce = 0;
|
Settings.pulse_counter_debounce = 0;
|
||||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||||
sysCfg.pCounter[i] = 0;
|
Settings.pulse_counter[i] = 0;
|
||||||
rtcMem.pCounter[i] = 0;
|
RtcSettings.pulse_counter[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05010600) {
|
if (Settings.version < 0x05010600) {
|
||||||
CFG_DefaultSet_4_1_1();
|
SettingsDefaultSet_4_1_1();
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05010700) {
|
if (Settings.version < 0x05010700) {
|
||||||
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
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05020000) {
|
if (Settings.version < 0x05020000) {
|
||||||
sysCfg.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
Settings.param[P_MAX_POWER_RETRY] = MAX_POWER_RETRY;
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x05050000) {
|
if (Settings.version < 0x05050000) {
|
||||||
for (byte i = 0; i < 17; i++) {
|
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;
|
uint8_t cfg_wsflg = 0;
|
||||||
for (byte i = 0; i < MAX_GPIO_PIN; i++) {
|
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;
|
cfg_wsflg = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!sysCfg.led_pixels && cfg_wsflg) {
|
if (!Settings.led_pixels && cfg_wsflg) {
|
||||||
sysCfg.led_pixels = sysCfg.ws_pixels;
|
Settings.led_pixels = Settings.ws_pixels;
|
||||||
sysCfg.led_color[0] = sysCfg.ws_red;
|
Settings.led_color[0] = Settings.ws_red;
|
||||||
sysCfg.led_color[1] = sysCfg.ws_green;
|
Settings.led_color[1] = Settings.ws_green;
|
||||||
sysCfg.led_color[2] = sysCfg.ws_blue;
|
Settings.led_color[2] = Settings.ws_blue;
|
||||||
sysCfg.led_dimmer = sysCfg.ws_dimmer;
|
Settings.led_dimmer = Settings.ws_dimmer;
|
||||||
sysCfg.led_table = sysCfg.ws_ledtable;
|
Settings.led_table = Settings.ws_ledtable;
|
||||||
sysCfg.led_fade = sysCfg.ws_fade;
|
Settings.led_fade = Settings.ws_fade;
|
||||||
sysCfg.led_speed = sysCfg.ws_speed;
|
Settings.led_speed = Settings.ws_speed;
|
||||||
sysCfg.led_scheme = sysCfg.ws_scheme;
|
Settings.led_scheme = Settings.ws_scheme;
|
||||||
sysCfg.led_width = sysCfg.ws_width;
|
Settings.led_width = Settings.ws_width;
|
||||||
sysCfg.led_wakeup = sysCfg.ws_wakeup;
|
Settings.led_wakeup = Settings.ws_wakeup;
|
||||||
} else {
|
} else {
|
||||||
sysCfg.led_pixels = WS2812_LEDS;
|
Settings.led_pixels = WS2812_LEDS;
|
||||||
sysCfg.led_width = 1;
|
Settings.led_width = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x0508000A) {
|
if (Settings.version < 0x0508000A) {
|
||||||
sysCfg.power = sysCfg.ex_power;
|
Settings.power = Settings.ex_power;
|
||||||
sysCfg.altitude = 0;
|
Settings.altitude = 0;
|
||||||
}
|
}
|
||||||
if (sysCfg.version < 0x0508000B) {
|
if (Settings.version < 0x0508000B) {
|
||||||
for (byte i = 0; i < MAX_GPIO_PIN; i++) { // Move GPIO_LEDs
|
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
|
if ((Settings.my_gp.io[i] >= 25) && (Settings.my_gp.io[i] <= 32)) { // Was GPIO_LED1
|
||||||
sysCfg.my_gp.io[i] += 23; // Move 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
|
for (byte i = 0; i < MAX_PWMS; i++) { // Move pwm_value and reset additional pulse_timerrs
|
||||||
sysCfg.pwmvalue[i] = sysCfg.pulsetime[4 +i];
|
Settings.pwm_value[i] = Settings.pulse_timer[4 +i];
|
||||||
sysCfg.pulsetime[4 +i] = 0;
|
Settings.pulse_timer[4 +i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (Settings.version < 0x0508000D) {
|
||||||
|
Settings.pwm_frequency = PWM_FREQ;
|
||||||
|
Settings.pwm_range = PWM_RANGE;
|
||||||
|
}
|
||||||
|
|
||||||
sysCfg.version = VERSION;
|
Settings.version = VERSION;
|
||||||
CFG_Save(1);
|
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
|
Copyright (C) 2017 Theo Arends
|
||||||
|
|
||||||
|
@ -17,6 +17,9 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _SONOFF_H_
|
||||||
|
#define _SONOFF_H_
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Power Type
|
* Power Type
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
@ -81,7 +84,7 @@ typedef unsigned long power_t; // Power (Relay) type
|
||||||
#else
|
#else
|
||||||
#define MAX_LOG_LINES 20 // Max number of lines in weblog
|
#define MAX_LOG_LINES 20 // Max number of lines in weblog
|
||||||
#endif
|
#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 MIN_BACKLOG_DELAY 2 // Minimal backlog delay in 0.1 seconds
|
||||||
|
|
||||||
#define APP_BAUDRATE 115200 // Default serial baudrate
|
#define APP_BAUDRATE 115200 // Default serial baudrate
|
||||||
|
@ -91,15 +94,16 @@ typedef unsigned long power_t; // Power (Relay) type
|
||||||
* Enumeration
|
* Enumeration
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
enum week_t {Last, First, Second, Third, Fourth};
|
enum WeekInMonthOptions {Last, First, Second, Third, Fourth};
|
||||||
enum dow_t {Sun=1, Mon, Tue, Wed, Thu, Fri, Sat};
|
enum DayOfTheWeekOptions {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 MonthNamesOptions {Jan=1, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec};
|
||||||
enum hemis_t {North, South};
|
enum HemisphereOptions {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 LoggingLevels {LOG_LEVEL_NONE, LOG_LEVEL_ERROR, LOG_LEVEL_INFO, LOG_LEVEL_DEBUG, LOG_LEVEL_DEBUG_MORE, LOG_LEVEL_ALL};
|
||||||
enum wifi_t {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION}; // WifiConfig
|
enum WifiConfigOptions {WIFI_RESTART, WIFI_SMARTCONFIG, WIFI_MANAGER, WIFI_WPSCONFIG, WIFI_RETRY, WIFI_WAIT, MAX_WIFI_OPTION};
|
||||||
enum swtch_t {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION}; // SwitchMode
|
enum SwitchModeOptions {TOGGLE, FOLLOW, FOLLOW_INV, PUSHBUTTON, PUSHBUTTON_INV, PUSHBUTTONHOLD, PUSHBUTTONHOLD_INV, MAX_SWITCH_OPTION};
|
||||||
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 LedStateOptions {LED_OFF, LED_POWER, LED_MQTTSUB, LED_POWER_MQTTSUB, LED_MQTTPUB, LED_POWER_MQTTPUB, LED_MQTT, LED_POWER_MQTT, MAX_LED_OPTION};
|
||||||
enum emul_t {EMUL_NONE, EMUL_WEMO, EMUL_HUE, EMUL_MAX}; // Emulation
|
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};
|
#endif // _SONOFF_H_
|
||||||
enum opt_t {P_HOLD_TIME, P_MAX_POWER_RETRY, P_MAX_PARAM8}; // Index in sysCfg.param
|
|
1932
sonoff/sonoff.ino
1932
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/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#ifndef _SONOFF_TEMPLATE_H_
|
||||||
|
#define _SONOFF_TEMPLATE_H_
|
||||||
|
|
||||||
// User selectable GPIO functionality
|
// User selectable GPIO functionality
|
||||||
enum upins_t {
|
enum UserSelectablePins {
|
||||||
GPIO_NONE, // Not used
|
GPIO_NONE, // Not used
|
||||||
GPIO_DHT11, // DHT11
|
GPIO_DHT11, // DHT11
|
||||||
GPIO_DHT21, // DHT21, AM2301
|
GPIO_DHT21, // DHT21, AM2301
|
||||||
|
@ -78,7 +81,7 @@ enum upins_t {
|
||||||
GPIO_SENSOR_END };
|
GPIO_SENSOR_END };
|
||||||
|
|
||||||
// Text in webpage Module Parameters and commands GPIOS and GPIO
|
// 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_NONE,
|
||||||
D_SENSOR_DHT11,
|
D_SENSOR_DHT11,
|
||||||
D_SENSOR_AM2301,
|
D_SENSOR_AM2301,
|
||||||
|
@ -138,7 +141,7 @@ const char sensors[GPIO_SENSOR_END][9] PROGMEM = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Programmer selectable GPIO functionality offset by user selectable GPIOs
|
// Programmer selectable GPIO functionality offset by user selectable GPIOs
|
||||||
enum fpins_t {
|
enum ProgramSelectablePins {
|
||||||
GPIO_RXD = GPIO_SENSOR_END, // Serial interface
|
GPIO_RXD = GPIO_SENSOR_END, // Serial interface
|
||||||
GPIO_TXD, // Serial interface
|
GPIO_TXD, // Serial interface
|
||||||
GPIO_HLW_SEL, // HLW8012 Sel output (Sonoff Pow)
|
GPIO_HLW_SEL, // HLW8012 Sel output (Sonoff Pow)
|
||||||
|
@ -153,7 +156,7 @@ enum fpins_t {
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
// Supported hardware modules
|
// Supported hardware modules
|
||||||
enum module_t {
|
enum SupportedModules {
|
||||||
SONOFF_BASIC,
|
SONOFF_BASIC,
|
||||||
SONOFF_RF,
|
SONOFF_RF,
|
||||||
SONOFF_SV,
|
SONOFF_SV,
|
||||||
|
@ -206,7 +209,7 @@ typedef struct MYTMPLT {
|
||||||
myio gp;
|
myio gp;
|
||||||
} mytmplt;
|
} mytmplt;
|
||||||
|
|
||||||
const uint8_t nicelist[MAXMODULE] PROGMEM = {
|
const uint8_t kNiceList[MAXMODULE] PROGMEM = {
|
||||||
SONOFF_BASIC,
|
SONOFF_BASIC,
|
||||||
SONOFF_RF,
|
SONOFF_RF,
|
||||||
SONOFF_TH,
|
SONOFF_TH,
|
||||||
|
@ -245,7 +248,7 @@ const uint8_t nicelist[MAXMODULE] PROGMEM = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Default module settings
|
// Default module settings
|
||||||
const mytmplt modules[MAXMODULE] PROGMEM = {
|
const mytmplt kModules[MAXMODULE] PROGMEM = {
|
||||||
{ "Sonoff Basic", // Sonoff Basic (ESP8266)
|
{ "Sonoff Basic", // Sonoff Basic (ESP8266)
|
||||||
GPIO_KEY1, // GPIO00 Button
|
GPIO_KEY1, // GPIO00 Button
|
||||||
GPIO_USER, // GPIO01 Serial RXD and Optional sensor
|
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/>.
|
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
|
* ATTENTION: Changes to most PARAMETER defines will only override flash settings if you change
|
||||||
* define CFG_HOLDER.
|
* define CFG_HOLDER.
|
||||||
|
@ -28,6 +31,7 @@
|
||||||
// -- Localization --------------------------------
|
// -- Localization --------------------------------
|
||||||
//#define MY_LANGUAGE en-GB // Enabled by Default
|
//#define MY_LANGUAGE en-GB // Enabled by Default
|
||||||
//#define MY_LANGUAGE nl-NL
|
//#define MY_LANGUAGE nl-NL
|
||||||
|
//#define MY_LANGUAGE de-DE
|
||||||
|
|
||||||
// -- Project -------------------------------------
|
// -- Project -------------------------------------
|
||||||
#define PROJECT "sonoff" // PROJECT is used as the default topic delimiter and OTA file name
|
#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 // 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_CTYPE 1 // WS2812 Color type (0 - RGB, 1 - GRB)
|
||||||
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial RXD) (+1k mem)
|
// #define USE_WS2812_DMA // DMA supports only GPIO03 (= Serial RXD) (+1k mem). When USE_WS2812_DMA is enabled expect Exceptions on Pow
|
||||||
// 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!
|
* 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"
|
#error "This software is supported with Arduino IDE starting from 1.6.10 and ESP8266 Release 2.3.0"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif // _USER_CONFIG_H_
|
|
@ -17,6 +17,9 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
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
|
* ATTENTION: - Changes to most PARAMETER defines will only override flash settings if you change
|
||||||
* define CFG_HOLDER.
|
* define CFG_HOLDER.
|
||||||
|
@ -38,3 +41,4 @@
|
||||||
//#endif
|
//#endif
|
||||||
//#define STA_SSID1 "yourssid1"
|
//#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>";
|
"<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
|
#endif // USE_WEBSERVER
|
||||||
|
|
||||||
enum domoticz_sensors_t {
|
enum DomoticzSensors {
|
||||||
DZ_TEMP,
|
DZ_TEMP,
|
||||||
DZ_TEMP_HUM,
|
DZ_TEMP_HUM,
|
||||||
DZ_TEMP_HUM_BARO,
|
DZ_TEMP_HUM_BARO,
|
||||||
|
@ -46,7 +46,7 @@ enum domoticz_sensors_t {
|
||||||
DZ_CURRENT,
|
DZ_CURRENT,
|
||||||
DZ_MAX_SENSORS };
|
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,
|
||||||
D_DOMOTICZ_TEMP_HUM,
|
D_DOMOTICZ_TEMP_HUM,
|
||||||
D_DOMOTICZ_TEMP_HUM_BARO,
|
D_DOMOTICZ_TEMP_HUM_BARO,
|
||||||
|
@ -63,67 +63,62 @@ boolean domoticz_subscribe = false;
|
||||||
int domoticz_update_timer = 0;
|
int domoticz_update_timer = 0;
|
||||||
byte domoticz_update_flag = 1;
|
byte domoticz_update_flag = 1;
|
||||||
|
|
||||||
void mqtt_publishDomoticzPowerState(byte device)
|
void MqttPublishDomoticzPowerState(byte device)
|
||||||
{
|
{
|
||||||
char sdimmer[8];
|
char sdimmer[8];
|
||||||
|
|
||||||
if ((device < 1) || (device > Maxdevice)) {
|
if ((device < 1) || (device > devices_present)) {
|
||||||
device = 1;
|
device = 1;
|
||||||
}
|
}
|
||||||
if (sysCfg.flag.mqtt_enabled && sysCfg.domoticz_relay_idx[device -1]) {
|
if (Settings.flag.mqtt_enabled && Settings.domoticz_relay_idx[device -1]) {
|
||||||
snprintf_P(sdimmer, sizeof(sdimmer), PSTR("%d"), sysCfg.led_dimmer);
|
snprintf_P(sdimmer, sizeof(sdimmer), PSTR("%d"), Settings.led_dimmer);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"idx\":%d,\"nvalue\":%d,\"svalue\":\"%s\"}"),
|
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 : "");
|
Settings.domoticz_relay_idx[device -1], (power & (1 << (device -1))) ? 1 : 0, (light_type) ? sdimmer : "");
|
||||||
mqtt_publish(domoticz_in_topic);
|
MqttPublish(domoticz_in_topic);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void domoticz_updatePowerState(byte device)
|
void DomoticzUpdatePowerState(byte device)
|
||||||
{
|
{
|
||||||
if (domoticz_update_flag) {
|
if (domoticz_update_flag) {
|
||||||
mqtt_publishDomoticzPowerState(device);
|
MqttPublishDomoticzPowerState(device);
|
||||||
}
|
}
|
||||||
domoticz_update_flag = 1;
|
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--;
|
domoticz_update_timer--;
|
||||||
if (domoticz_update_timer <= 0) {
|
if (domoticz_update_timer <= 0) {
|
||||||
domoticz_update_timer = sysCfg.domoticz_update_timer;
|
domoticz_update_timer = Settings.domoticz_update_timer;
|
||||||
for (byte i = 1; i <= Maxdevice; i++) {
|
for (byte i = 1; i <= devices_present; i++) {
|
||||||
mqtt_publishDomoticzPowerState(i);
|
MqttPublishDomoticzPowerState(i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void domoticz_setUpdateTimer(uint16_t value)
|
void DomoticzSetUpdateTimer(uint16_t value)
|
||||||
{
|
{
|
||||||
domoticz_update_timer = 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++) {
|
for (byte i = 0; i < maxdev; i++) {
|
||||||
if (sysCfg.domoticz_relay_idx[i]) {
|
if (Settings.domoticz_relay_idx[i]) {
|
||||||
domoticz_subscribe = true;
|
domoticz_subscribe = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (domoticz_subscribe) {
|
if (domoticz_subscribe) {
|
||||||
char stopic[TOPSZ];
|
char stopic[TOPSZ];
|
||||||
snprintf_P(stopic, sizeof(stopic), PSTR("%s/#"), domoticz_out_topic); // domoticz topic
|
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
|
* 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 stemp1[10];
|
||||||
char scommand[10];
|
char scommand[10];
|
||||||
|
@ -166,16 +161,16 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
||||||
nvalue = domoticz["nvalue"];
|
nvalue = domoticz["nvalue"];
|
||||||
|
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_DOMOTICZ "idx %d, nvalue %d"), idx, 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)) {
|
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++) {
|
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);
|
snprintf_P(stemp1, sizeof(stemp1), PSTR("%d"), i +1);
|
||||||
if (2 == nvalue) {
|
if (2 == nvalue) {
|
||||||
nvalue = domoticz["svalue1"];
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
snprintf_P(topicBuf, stopicBuf, PSTR("/" D_CMND_DIMMER));
|
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) {
|
if (((power >> i) &1) == nvalue) {
|
||||||
return 1;
|
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);
|
snprintf_P(dataBuf, sdataBuf, PSTR("%d"), nvalue);
|
||||||
found = 1;
|
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);
|
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;
|
domoticz_update_flag = 0;
|
||||||
}
|
}
|
||||||
|
@ -209,7 +204,7 @@ boolean domoticz_mqttData(char *topicBuf, uint16_t stopicBuf, char *dataBuf, uin
|
||||||
* Commands
|
* 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;
|
boolean serviced = true;
|
||||||
uint8_t dmtcz_len = strlen(D_CMND_DOMOTICZ); // Prep for string length change
|
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 (!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 (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_IDX)) && (index > 0) && (index <= MAX_DOMOTICZ_IDX)) {
|
||||||
if (payload >= 0) {
|
if (payload >= 0) {
|
||||||
sysCfg.domoticz_relay_idx[index -1] = payload;
|
Settings.domoticz_relay_idx[index -1] = payload;
|
||||||
restartflag = 2;
|
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)) {
|
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_KEYIDX)) && (index > 0) && (index <= MAX_DOMOTICZ_IDX)) {
|
||||||
if (payload >= 0) {
|
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)) {
|
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_SWITCHIDX)) && (index > 0) && (index <= MAX_DOMOTICZ_IDX)) {
|
||||||
if (payload >= 0) {
|
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)) {
|
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_SENSORIDX)) && (index > 0) && (index <= DZ_MAX_SENSORS)) {
|
||||||
if (payload >= 0) {
|
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))) {
|
else if (!strcasecmp_P(type +dmtcz_len, PSTR(D_CMND_UPDATETIMER))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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;
|
else serviced = false;
|
||||||
}
|
}
|
||||||
|
@ -252,12 +247,12 @@ boolean domoticz_command(const char *type, uint16_t index, char *dataBuf, uint16
|
||||||
return serviced;
|
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\"}"),
|
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");
|
(key) ? Settings.domoticz_switch_idx[device -1] : Settings.domoticz_key_idx[device -1], (state) ? (2 == state) ? "Toggle" : "On" : "Off");
|
||||||
mqtt_publish(domoticz_in_topic);
|
MqttPublish(domoticz_in_topic);
|
||||||
return 1;
|
return 1;
|
||||||
} else {
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -268,51 +263,51 @@ boolean domoticz_button(byte key, byte device, byte state, byte svalflg)
|
||||||
* Sensors
|
* Sensors
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
uint8_t dom_hum_stat(char *hum)
|
uint8_t DomoticzHumidityState(char *hum)
|
||||||
{
|
{
|
||||||
uint8_t h = atoi(hum);
|
uint8_t h = atoi(hum);
|
||||||
return (!h) ? 0 : (h < 40) ? 2 : (h > 70) ? 3 : 1;
|
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];
|
char dmess[64];
|
||||||
|
|
||||||
memcpy(dmess, mqtt_data, sizeof(dmess));
|
memcpy(dmess, mqtt_data, sizeof(dmess));
|
||||||
snprintf_P(mqtt_data, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"),
|
snprintf_P(mqtt_data, sizeof(dmess), PSTR("{\"idx\":%d,\"nvalue\":0,\"svalue\":\"%s\"}"),
|
||||||
sysCfg.domoticz_sensor_idx[idx], data);
|
Settings.domoticz_sensor_idx[idx], data);
|
||||||
mqtt_publish(domoticz_in_topic);
|
MqttPublish(domoticz_in_topic);
|
||||||
memcpy(mqtt_data, dmess, sizeof(dmess));
|
memcpy(mqtt_data, dmess, sizeof(dmess));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void domoticz_sensor(byte idx, uint32_t value)
|
void DomoticzSensor(byte idx, uint32_t value)
|
||||||
{
|
{
|
||||||
char data[16];
|
char data[16];
|
||||||
snprintf_P(data, sizeof(data), PSTR("%d"), value);
|
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];
|
char data[16];
|
||||||
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d"), temp, hum, dom_hum_stat(hum));
|
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d"), temp, hum, DomoticzHumidityState(hum));
|
||||||
domoticz_sensor(DZ_TEMP_HUM, data);
|
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];
|
char data[32];
|
||||||
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d;%s;5"), temp, hum, dom_hum_stat(hum), baro);
|
snprintf_P(data, sizeof(data), PSTR("%s;%s;%d;%s;5"), temp, hum, DomoticzHumidityState(hum), baro);
|
||||||
domoticz_sensor(DZ_TEMP_HUM_BARO, data);
|
DomoticzSensor(DZ_TEMP_HUM_BARO, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void domoticz_sensor4(uint16_t power, char *energy)
|
void DomoticzSensorPowerEnergy(uint16_t power, char *energy)
|
||||||
{
|
{
|
||||||
char data[16];
|
char data[16];
|
||||||
snprintf_P(data, sizeof(data), PSTR("%d;%s"), power, energy);
|
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
|
#ifdef USE_WEBSERVER
|
||||||
const char S_CONFIGURE_DOMOTICZ[] PROGMEM = D_CONFIGURE_DOMOTICZ;
|
const char S_CONFIGURE_DOMOTICZ[] PROGMEM = D_CONFIGURE_DOMOTICZ;
|
||||||
|
|
||||||
void handleDomoticz()
|
void HandleDomoticzConfiguration()
|
||||||
{
|
{
|
||||||
if (HTTP_USER == _httpflag) {
|
if (HTTP_USER == webserver_state) {
|
||||||
handleRoot();
|
HandleRoot();
|
||||||
return;
|
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];
|
char stemp[20];
|
||||||
|
|
||||||
|
@ -336,59 +331,59 @@ void handleDomoticz()
|
||||||
page.replace(F("{v}"), FPSTR(S_CONFIGURE_DOMOTICZ));
|
page.replace(F("{v}"), FPSTR(S_CONFIGURE_DOMOTICZ));
|
||||||
page += FPSTR(HTTP_FORM_DOMOTICZ);
|
page += FPSTR(HTTP_FORM_DOMOTICZ);
|
||||||
for (int i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
for (int i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
||||||
if (i < Maxdevice) {
|
if (i < devices_present) {
|
||||||
page += FPSTR(HTTP_FORM_DOMOTICZ_RELAY);
|
page += FPSTR(HTTP_FORM_DOMOTICZ_RELAY);
|
||||||
page.replace("{2", String((int)sysCfg.domoticz_relay_idx[i]));
|
page.replace("{2", String((int)Settings.domoticz_relay_idx[i]));
|
||||||
page.replace("{3", String((int)sysCfg.domoticz_key_idx[i]));
|
page.replace("{3", String((int)Settings.domoticz_key_idx[i]));
|
||||||
}
|
}
|
||||||
if (pin[GPIO_SWT1 +i] < 99) {
|
if (pin[GPIO_SWT1 +i] < 99) {
|
||||||
page += FPSTR(HTTP_FORM_DOMOTICZ_SWITCH);
|
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));
|
page.replace("{1", String(i +1));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < DZ_MAX_SENSORS; i++) {
|
for (int i = 0; i < DZ_MAX_SENSORS; i++) {
|
||||||
page += FPSTR(HTTP_FORM_DOMOTICZ_SENSOR);
|
page += FPSTR(HTTP_FORM_DOMOTICZ_SENSOR);
|
||||||
page.replace("{1", String(i +1));
|
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("{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 += 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 += F("</table>");
|
||||||
page += FPSTR(HTTP_FORM_END);
|
page += FPSTR(HTTP_FORM_END);
|
||||||
page += FPSTR(HTTP_BTN_CONF);
|
page += FPSTR(HTTP_BTN_CONF);
|
||||||
showPage(page);
|
ShowPage(page);
|
||||||
}
|
}
|
||||||
|
|
||||||
void domoticz_saveSettings()
|
void DomoticzSaveSettings()
|
||||||
{
|
{
|
||||||
char stemp[20];
|
char stemp[20];
|
||||||
|
|
||||||
for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
for (byte i = 0; i < MAX_DOMOTICZ_IDX; i++) {
|
||||||
snprintf_P(stemp, sizeof(stemp), PSTR("r%d"), i +1);
|
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);
|
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);
|
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++) {
|
for (byte i = 0; i < DZ_MAX_SENSORS; i++) {
|
||||||
snprintf_P(stemp, sizeof(stemp), PSTR("l%d"), i +1);
|
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"),
|
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],
|
Settings.domoticz_relay_idx[0], Settings.domoticz_relay_idx[1], Settings.domoticz_relay_idx[2], Settings.domoticz_relay_idx[3],
|
||||||
sysCfg.domoticz_update_timer);
|
Settings.domoticz_update_timer);
|
||||||
addLog(LOG_LEVEL_INFO);
|
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"),
|
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],
|
Settings.domoticz_key_idx[0], Settings.domoticz_key_idx[1], Settings.domoticz_key_idx[2], Settings.domoticz_key_idx[3],
|
||||||
sysCfg.domoticz_switch_idx[0], sysCfg.domoticz_switch_idx[1], sysCfg.domoticz_switch_idx[2], sysCfg.domoticz_switch_idx[3],
|
Settings.domoticz_switch_idx[0], Settings.domoticz_switch_idx[1], Settings.domoticz_switch_idx[2], Settings.domoticz_switch_idx[3],
|
||||||
sysCfg.domoticz_sensor_idx[0], sysCfg.domoticz_sensor_idx[1], sysCfg.domoticz_sensor_idx[2], sysCfg.domoticz_sensor_idx[3],
|
Settings.domoticz_sensor_idx[0], Settings.domoticz_sensor_idx[1], Settings.domoticz_sensor_idx[2], Settings.domoticz_sensor_idx[3],
|
||||||
sysCfg.domoticz_sensor_idx[4], sysCfg.domoticz_sensor_idx[5], sysCfg.domoticz_sensor_idx[6], sysCfg.domoticz_sensor_idx[7]);
|
Settings.domoticz_sensor_idx[4], Settings.domoticz_sensor_idx[5], Settings.domoticz_sensor_idx[6], Settings.domoticz_sensor_idx[7]);
|
||||||
addLog(LOG_LEVEL_INFO);
|
AddLog(LOG_LEVEL_INFO);
|
||||||
}
|
}
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
|
|
|
@ -39,8 +39,8 @@
|
||||||
|
|
||||||
IRMitsubishiAC *mitsubir = NULL;
|
IRMitsubishiAC *mitsubir = NULL;
|
||||||
|
|
||||||
const char FANSPEED[] = "A12345S";
|
const char kFanSpeedOptions[] = "A12345S";
|
||||||
const char HVACMODE[] = "HDCA";
|
const char kHvacModeOptions[] = "HDCA";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
|
@ -49,7 +49,7 @@ const char HVACMODE[] = "HDCA";
|
||||||
|
|
||||||
IRsend *irsend = NULL;
|
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 = new IRsend(pin[GPIO_IRSEND]); // an IR led is at GPIO_IRSEND
|
||||||
irsend->begin();
|
irsend->begin();
|
||||||
|
@ -69,15 +69,15 @@ void ir_send_init(void)
|
||||||
IRrecv *irrecv = NULL;
|
IRrecv *irrecv = NULL;
|
||||||
unsigned long ir_lasttime = 0;
|
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 = new IRrecv(pin[GPIO_IRRECV]); // an IR led is at GPIO_IRRECV
|
||||||
irrecv->enableIRIn(); // Start the receiver
|
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 sirtype[100];
|
||||||
char *protocol;
|
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"),
|
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);
|
results.rawlen, results.bits, results.value, results.decode_type);
|
||||||
addLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
if ((now - ir_lasttime > IR_TIME_AVOID_DUPLICATE) && (UNKNOWN != results.decode_type) && (results.bits > 0)) {
|
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\"}}"),
|
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);
|
protocol, results.bits, results.value);
|
||||||
mqtt_publish_topic_P(6, PSTR(D_IRRECEIVED));
|
MqttPublishPrefixTopic_P(6, PSTR(D_IRRECEIVED));
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
unsigned long value = results.value | (diridx << 28); // [Protocol:4, Data:28]
|
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
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,7 +128,7 @@ void ir_recv_check()
|
||||||
* IR Heating, Ventilation and Air Conditioning using IRMitsubishiAC library
|
* 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];
|
unsigned int rawdata[2 + 2 * 8 * HVAC_TOSHIBA_DATALEN + 2];
|
||||||
byte data[HVAC_TOSHIBA_DATALEN] = {0xF2, 0x0D, 0x03, 0xFC, 0x01, 0x00, 0x00, 0x00, 0x00};
|
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;
|
uint8_t mode;
|
||||||
|
|
||||||
if (HVAC_Mode == NULL) {
|
if (HVAC_Mode == NULL) {
|
||||||
p = (char *)HVACMODE; // default HVAC_HOT
|
p = (char *)kHvacModeOptions; // default HVAC_HOT
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
|
p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0]));
|
||||||
}
|
}
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return true;
|
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) {
|
if (!HVAC_Power) {
|
||||||
data[6] = (byte)0x07; // Turn OFF HVAC
|
data[6] = (byte)0x07; // Turn OFF HVAC
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HVAC_FanMode == NULL) {
|
if (HVAC_FanMode == NULL) {
|
||||||
p = (char *)FANSPEED; // default FAN_SPEED_AUTO
|
p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
|
p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0]));
|
||||||
}
|
}
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mode = p - FANSPEED + 1;
|
mode = p - kFanSpeedOptions + 1;
|
||||||
if ((1 == mode) || (7 == mode)) {
|
if ((1 == mode) || (7 == mode)) {
|
||||||
mode = 0;
|
mode = 0;
|
||||||
}
|
}
|
||||||
|
@ -218,7 +218,7 @@ boolean ir_hvac_toshiba(const char *HVAC_Mode, const char *HVAC_FanMode, boolean
|
||||||
return false;
|
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 *p;
|
||||||
char *token;
|
char *token;
|
||||||
|
@ -227,29 +227,29 @@ boolean ir_hvac_mitsubishi(const char *HVAC_Mode, const char *HVAC_FanMode, bool
|
||||||
mitsubir->stateReset();
|
mitsubir->stateReset();
|
||||||
|
|
||||||
if (HVAC_Mode == NULL) {
|
if (HVAC_Mode == NULL) {
|
||||||
p = (char *)HVACMODE; // default HVAC_HOT
|
p = (char *)kHvacModeOptions; // default HVAC_HOT
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p = strchr(HVACMODE, toupper(HVAC_Mode[0]));
|
p = strchr(kHvacModeOptions, toupper(HVAC_Mode[0]));
|
||||||
}
|
}
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return true;
|
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->setMode(mode);
|
||||||
|
|
||||||
mitsubir->setPower(HVAC_Power);
|
mitsubir->setPower(HVAC_Power);
|
||||||
|
|
||||||
if (HVAC_FanMode == NULL) {
|
if (HVAC_FanMode == NULL) {
|
||||||
p = (char *)FANSPEED; // default FAN_SPEED_AUTO
|
p = (char *)kFanSpeedOptions; // default FAN_SPEED_AUTO
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
p = strchr(FANSPEED, toupper(HVAC_FanMode[0]));
|
p = strchr(kFanSpeedOptions, toupper(HVAC_FanMode[0]));
|
||||||
}
|
}
|
||||||
if (!p) {
|
if (!p) {
|
||||||
return true;
|
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->setFan(mode);
|
||||||
|
|
||||||
mitsubir->setTemp(HVAC_Temp);
|
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"),
|
// 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());
|
// mitsubir->getPower(), mitsubir->getMode(), mitsubir->getFan(), mitsubir->getTemp(), mitsubir->getVane());
|
||||||
// addLog(LOG_LEVEL_DEBUG);
|
// AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
return false;
|
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> }
|
{ "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 serviced = true;
|
||||||
boolean error = false;
|
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"),
|
// 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);
|
// 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"))) {
|
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"))) {
|
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 {
|
else {
|
||||||
error = true;
|
error = true;
|
||||||
|
|
|
@ -23,108 +23,106 @@
|
||||||
|
|
||||||
#define SFB_TIME_AVOID_DUPLICATE 2000 // Milliseconds
|
#define SFB_TIME_AVOID_DUPLICATE 2000 // Milliseconds
|
||||||
|
|
||||||
uint8_t sfb_rcvflg = 0;
|
uint8_t sonoff_bridge_receive_flag = 0;
|
||||||
uint8_t sfb_learnKey = 1;
|
uint8_t sonoff_bridge_learn_key = 1;
|
||||||
uint8_t sfb_learnFlg = 0;
|
uint8_t sonoff_bridge_learn_active = 0;
|
||||||
uint32_t sfb_lastrid = 0;
|
uint32_t sonoff_bridge_last_received_id = 0;
|
||||||
unsigned long sfb_lasttime = 0;
|
unsigned long sonoff_bridge_last_time = 0;
|
||||||
|
|
||||||
void sb_received()
|
void SonoffBridgeReceived()
|
||||||
{
|
{
|
||||||
uint8_t i = 0;
|
uint16_t sync_time = 0;
|
||||||
uint32_t sid = 0;
|
uint16_t low_time = 0;
|
||||||
uint32_t rid = 0;
|
uint16_t high_time = 0;
|
||||||
uint16_t rsy = 0;
|
uint32_t received_id = 0;
|
||||||
uint16_t rlo = 0;
|
|
||||||
uint16_t rhi = 0;
|
|
||||||
char svalue[90];
|
char svalue[90];
|
||||||
char rfkey[8];
|
char rfkey[8];
|
||||||
|
|
||||||
svalue[0] = '\0';
|
svalue[0] = '\0';
|
||||||
for (i = 0; i < SerialInByteCounter; i++) {
|
for (byte i = 0; i < serial_in_byte_counter; i++) {
|
||||||
snprintf_P(svalue, sizeof(svalue), PSTR("%s%02X "), svalue, serialInBuf[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);
|
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
|
if (0xA2 == serial_in_buffer[0]) { // Learn timeout
|
||||||
sfb_learnFlg = 0;
|
sonoff_bridge_learn_active = 0;
|
||||||
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 (0xA3 == serialInBuf[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
|
else if (0xA3 == serial_in_buffer[0]) { // Learned A3 20 F8 01 18 03 3E 2E 1A 22 55
|
||||||
sfb_learnFlg = 0;
|
sonoff_bridge_learn_active = 0;
|
||||||
rlo = serialInBuf[3] << 8 | serialInBuf[4]; // Low time in uSec
|
low_time = serial_in_buffer[3] << 8 | serial_in_buffer[4]; // Low time in uSec
|
||||||
rhi = serialInBuf[5] << 8 | serialInBuf[6]; // High time in uSec
|
high_time = serial_in_buffer[5] << 8 | serial_in_buffer[6]; // High time in uSec
|
||||||
if (rlo && rhi) {
|
if (low_time && high_time) {
|
||||||
for (i = 0; i < 9; i++) {
|
for (byte i = 0; i < 9; i++) {
|
||||||
sysCfg.sfb_code[sfb_learnKey][i] = serialInBuf[i +1];
|
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 {
|
} 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
|
else if (0xA4 == serial_in_buffer[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
|
sync_time = serial_in_buffer[1] << 8 | serial_in_buffer[2]; // Sync time in uSec
|
||||||
rlo = serialInBuf[3] << 8 | serialInBuf[4]; // Low time in uSec
|
low_time = serial_in_buffer[3] << 8 | serial_in_buffer[4]; // Low time in uSec
|
||||||
rhi = serialInBuf[5] << 8 | serialInBuf[6]; // High time in uSec
|
high_time = serial_in_buffer[5] << 8 | serial_in_buffer[6]; // High time in uSec
|
||||||
rid = serialInBuf[7] << 16 | serialInBuf[8] << 8 | serialInBuf[9];
|
received_id = serial_in_buffer[7] << 16 | serial_in_buffer[8] << 8 | serial_in_buffer[9];
|
||||||
|
|
||||||
unsigned long now = millis();
|
unsigned long now = millis();
|
||||||
if (!((rid == sfb_lastrid) && (now - sfb_lasttime < SFB_TIME_AVOID_DUPLICATE))) {
|
if (!((received_id == sonoff_bridge_last_received_id) && (now - sonoff_bridge_last_time < SFB_TIME_AVOID_DUPLICATE))) {
|
||||||
sfb_lastrid = rid;
|
sonoff_bridge_last_received_id = received_id;
|
||||||
sfb_lasttime = now;
|
sonoff_bridge_last_time = now;
|
||||||
strncpy_P(rfkey, PSTR("\"" D_NONE "\""), sizeof(rfkey));
|
strncpy_P(rfkey, PSTR("\"" D_NONE "\""), sizeof(rfkey));
|
||||||
for (i = 1; i <= 16; i++) {
|
for (byte i = 1; i <= 16; i++) {
|
||||||
if (sysCfg.sfb_code[i][0]) {
|
if (Settings.rf_code[i][0]) {
|
||||||
sid = sysCfg.sfb_code[i][6] << 16 | sysCfg.sfb_code[i][7] << 8 | sysCfg.sfb_code[i][8];
|
uint32_t send_id = Settings.rf_code[i][6] << 16 | Settings.rf_code[i][7] << 8 | Settings.rf_code[i][8];
|
||||||
if (sid == rid) {
|
if (send_id == received_id) {
|
||||||
snprintf_P(rfkey, sizeof(rfkey), PSTR("%d"), i);
|
snprintf_P(rfkey, sizeof(rfkey), PSTR("%d"), i);
|
||||||
break;
|
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}}"),
|
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);
|
sync_time, low_time, high_time, received_id, rfkey);
|
||||||
mqtt_publish_topic_P(6, PSTR(D_RFRECEIVED));
|
MqttPublishPrefixTopic_P(6, PSTR(D_RFRECEIVED));
|
||||||
#ifdef USE_DOMOTICZ
|
#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
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean sb_serial()
|
boolean SonoffBridgeSerialInput()
|
||||||
{
|
{
|
||||||
if (sfb_rcvflg) {
|
if (sonoff_bridge_receive_flag) {
|
||||||
if (!((SerialInByteCounter == 0) && (SerialInByte == 0))) { // Skip leading 0
|
if (!((serial_in_byte_counter == 0) && (serial_in_byte == 0))) { // Skip leading 0
|
||||||
serialInBuf[SerialInByteCounter++] = SerialInByte;
|
serial_in_buffer[serial_in_byte_counter++] = serial_in_byte;
|
||||||
if (0x55 == SerialInByte) { // 0x55 - End of text
|
if (0x55 == serial_in_byte) { // 0x55 - End of text
|
||||||
sb_received();
|
SonoffBridgeReceived();
|
||||||
sfb_rcvflg = 0;
|
sonoff_bridge_receive_flag = 0;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
SerialInByte = 0;
|
serial_in_byte = 0;
|
||||||
}
|
}
|
||||||
if (0xAA == SerialInByte) { // 0xAA - Start of text
|
if (0xAA == serial_in_byte) { // 0xAA - Start of text
|
||||||
SerialInByteCounter = 0;
|
serial_in_byte_counter = 0;
|
||||||
SerialInByte = 0;
|
serial_in_byte = 0;
|
||||||
sfb_rcvflg = 1;
|
sonoff_bridge_receive_flag = 1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sb_sendAck()
|
void SonoffBridgeSendAck()
|
||||||
{
|
{
|
||||||
Serial.write(0xAA); // Start of Text
|
Serial.write(0xAA); // Start of Text
|
||||||
Serial.write(0xA0); // Acknowledge
|
Serial.write(0xA0); // Acknowledge
|
||||||
Serial.write(0x55); // End of Text
|
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;
|
uint8_t code;
|
||||||
|
|
||||||
|
@ -132,26 +130,26 @@ void sb_send(uint8_t idx, uint8_t key)
|
||||||
Serial.write(0xAA); // Start of Text
|
Serial.write(0xAA); // Start of Text
|
||||||
Serial.write(0xA5); // Send following code
|
Serial.write(0xA5); // Send following code
|
||||||
for (uint8_t i = 0; i < 8; i++) {
|
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) {
|
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
|
code = (0x10 << (key >> 2)) | (1 << (key & 3)); // 11,12,14,18,21,22,24,28,41,42,44,48,81,82,84,88
|
||||||
} else {
|
} else {
|
||||||
code = sysCfg.sfb_code[idx][8];
|
code = Settings.rf_code[idx][8];
|
||||||
}
|
}
|
||||||
Serial.write(code);
|
Serial.write(code);
|
||||||
Serial.write(0x55); // End of Text
|
Serial.write(0x55); // End of Text
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
// uint32_t rid = sysCfg.sfb_code[idx][6] << 16 | sysCfg.sfb_code[idx][7] << 8 | code;
|
// uint32_t rid = Settings.rf_code[idx][6] << 16 | Settings.rf_code[idx][7] << 8 | code;
|
||||||
// domoticz_sensor(DZ_COUNT, rid); // Send rid as Domoticz Counter value
|
// DomoticzSensor(DZ_COUNT, rid); // Send rid as Domoticz Counter value
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
|
|
||||||
void sb_learn(uint8_t key)
|
void SonoffBridgeLearn(uint8_t key)
|
||||||
{
|
{
|
||||||
sfb_learnKey = key;
|
sonoff_bridge_learn_key = key;
|
||||||
sfb_learnFlg = 1;
|
sonoff_bridge_learn_active = 1;
|
||||||
Serial.write(0xAA); // Start of Text
|
Serial.write(0xAA); // Start of Text
|
||||||
Serial.write(0xA1); // Start learning
|
Serial.write(0xA1); // Start learning
|
||||||
Serial.write(0x55); // End of Text
|
Serial.write(0x55); // End of Text
|
||||||
|
@ -161,7 +159,7 @@ void sb_learn(uint8_t key)
|
||||||
* Commands
|
* 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;
|
boolean serviced = true;
|
||||||
char *p;
|
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 msb = hexcode >> 8;
|
||||||
uint8_t lsb = hexcode & 0xFF;
|
uint8_t lsb = hexcode & 0xFF;
|
||||||
if ((hexcode > 0) && (hexcode < 0x7FFF) && (msb != 0x55) && (lsb != 0x55)) {
|
if ((hexcode > 0) && (hexcode < 0x7FFF) && (msb != 0x55) && (lsb != 0x55)) {
|
||||||
sysCfg.sfb_code[0][6] = msb;
|
Settings.rf_code[0][6] = msb;
|
||||||
sysCfg.sfb_code[0][7] = lsb;
|
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)) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_RFKEY)) && (index > 0) && (index <= 16)) {
|
||||||
if (!sfb_learnFlg) {
|
if (!sonoff_bridge_learn_active) {
|
||||||
if (2 == payload) {
|
if (2 == payload) {
|
||||||
sb_learn(index);
|
SonoffBridgeLearn(index);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_START_LEARNING "\"}"), index);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_START_LEARNING "\"}"), index);
|
||||||
}
|
}
|
||||||
else if (3 == payload) {
|
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);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_SET_TO_DEFAULT "\"}"), index);
|
||||||
} else {
|
} else {
|
||||||
if ((1 == payload) || (0 == sysCfg.sfb_code[index][0])) {
|
if ((1 == payload) || (0 == Settings.rf_code[index][0])) {
|
||||||
sb_send(0, index);
|
SonoffBridgeSend(0, index);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_DEFAULT_SENT "\"}"), index);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_DEFAULT_SENT "\"}"), index);
|
||||||
} else {
|
} else {
|
||||||
sb_send(index, 0);
|
SonoffBridgeSend(index, 0);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED_SENT "\"}"), index);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_RFKEY "%d\":\"" D_LEARNED_SENT "\"}"), index);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} 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 {
|
else {
|
||||||
|
|
|
@ -20,7 +20,7 @@
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* PWM, WS2812, Sonoff B1, AiLight, Sonoff Led and BN-SZ01
|
* 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)
|
* 1 PWM1 W no (Sonoff BN-SZ)
|
||||||
* 2 PWM2 CW yes (Sonoff Led)
|
* 2 PWM2 CW yes (Sonoff Led)
|
||||||
* 3 PWM3 RGB no (H801 and MagicHome)
|
* 3 PWM3 RGB no (H801 and MagicHome)
|
||||||
|
@ -87,7 +87,7 @@ extern "C" {
|
||||||
uint8_t sl_pdi;
|
uint8_t sl_pdi;
|
||||||
uint8_t sl_pdcki;
|
uint8_t sl_pdcki;
|
||||||
|
|
||||||
void sl_di_pulse(uint8_t times)
|
void LightDiPulse(uint8_t times)
|
||||||
{
|
{
|
||||||
for (uint8_t i = 0; i < times; i++) {
|
for (uint8_t i = 0; i < times; i++) {
|
||||||
digitalWrite(sl_pdi, HIGH);
|
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++) {
|
for (uint8_t i = 0; i < times; i++) {
|
||||||
digitalWrite(sl_pdcki, HIGH);
|
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
|
for (uint8_t i = 0; i < 4; i++) { // Send 8bit Data
|
||||||
digitalWrite(sl_pdcki, LOW);
|
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.
|
os_delay_us(12); // TStop > 12us.
|
||||||
// Send 12 DI pulse, after 6 pulse's falling edge store duty data, and 12
|
// Send 12 DI pulse, after 6 pulse's falling edge store duty data, and 12
|
||||||
// pulse's rising edge convert to command mode.
|
// pulse's rising edge convert to command mode.
|
||||||
sl_di_pulse(12);
|
LightDiPulse(12);
|
||||||
os_delay_us(12); // Delay >12us, begin send CMD data
|
os_delay_us(12); // Delay >12us, begin send CMD data
|
||||||
for (uint8_t n = 0; n < chips; n++) { // 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.
|
os_delay_us(12); // TStart > 12us. Delay 12 us.
|
||||||
// Send 16 DI pulse, at 14 pulse's falling edge store CMD data, and
|
// Send 16 DI pulse, at 14 pulse's falling edge store CMD data, and
|
||||||
// at 16 pulse's falling edge convert to duty mode.
|
// at 16 pulse's falling edge convert to duty mode.
|
||||||
sl_di_pulse(16);
|
LightDiPulse(16);
|
||||||
os_delay_us(12); // TStop > 12us.
|
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 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
|
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
|
{ duty_w, duty_c, 0, duty_g, duty_r, duty_b }}; // Definition for RGBWC channels
|
||||||
|
|
||||||
os_delay_us(12); // TStop > 12us.
|
os_delay_us(12); // TStop > 12us.
|
||||||
for (uint8_t channel = 0; channel < channels[didx]; channel++) {
|
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.
|
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.
|
os_delay_us(12); // TStop > 12us.
|
||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void sl_init(void)
|
void LightInit(void)
|
||||||
{
|
{
|
||||||
if (sfl_flg < 6) { // PWM
|
if (light_type < 6) { // PWM
|
||||||
for (byte i = 0; i < sfl_flg; i++) {
|
for (byte i = 0; i < light_type; i++) {
|
||||||
sysCfg.pwmvalue[i] = 0; // Disable direct PWM control
|
Settings.pwm_value[i] = 0; // Disable direct PWM control
|
||||||
}
|
}
|
||||||
if (1 == sfl_flg) {
|
if (1 == light_type) {
|
||||||
sysCfg.led_color[0] = 255; // One PWM channel only supports Dimmer but needs max color
|
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]) {
|
if (!my_module.gp.io[4]) {
|
||||||
pinMode(4, OUTPUT); // Stop floating outputs
|
pinMode(4, OUTPUT); // Stop floating outputs
|
||||||
digitalWrite(4, LOW);
|
digitalWrite(4, LOW);
|
||||||
|
@ -180,13 +180,13 @@ void sl_init(void)
|
||||||
digitalWrite(14, LOW);
|
digitalWrite(14, LOW);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sysCfg.led_scheme = 0;
|
Settings.led_scheme = 0;
|
||||||
}
|
}
|
||||||
#ifdef USE_WS2812 // ************************************************************************
|
#ifdef USE_WS2812 // ************************************************************************
|
||||||
else if (11 == sfl_flg) {
|
else if (11 == light_type) {
|
||||||
ws2812_init();
|
Ws2812Init();
|
||||||
if (1 == sysCfg.led_scheme) {
|
if (1 == Settings.led_scheme) {
|
||||||
sysCfg.led_scheme = 0;
|
Settings.led_scheme = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // USE_WS2812 ************************************************************************
|
#endif // USE_WS2812 ************************************************************************
|
||||||
|
@ -199,8 +199,8 @@ void sl_init(void)
|
||||||
digitalWrite(sl_pdi, LOW);
|
digitalWrite(sl_pdi, LOW);
|
||||||
digitalWrite(sl_pdcki, LOW);
|
digitalWrite(sl_pdcki, LOW);
|
||||||
|
|
||||||
sl_my92x1_init();
|
LightMy92x1Init();
|
||||||
sysCfg.led_scheme = 0;
|
Settings.led_scheme = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
sl_power = 0;
|
sl_power = 0;
|
||||||
|
@ -208,7 +208,7 @@ void sl_init(void)
|
||||||
sl_wakeupActive = 0;
|
sl_wakeupActive = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sl_setColorTemp(uint16_t ct)
|
void LightSetColorTemp(uint16_t ct)
|
||||||
{
|
{
|
||||||
/* Color Temperature (https://developers.meethue.com/documentation/core-concepts)
|
/* 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 icold = (100 * (347 - my_ct)) / 136;
|
||||||
uint16_t iwarm = (100 * my_ct) / 136;
|
uint16_t iwarm = (100 * my_ct) / 136;
|
||||||
if (5 == (sfl_flg &7)) {
|
if (5 == (light_type &7)) {
|
||||||
sysCfg.led_color[0] = 0;
|
Settings.led_color[0] = 0;
|
||||||
sysCfg.led_color[1] = 0;
|
Settings.led_color[1] = 0;
|
||||||
sysCfg.led_color[2] = 0;
|
Settings.led_color[2] = 0;
|
||||||
sysCfg.led_color[3] = (uint8_t)icold;
|
Settings.led_color[3] = (uint8_t)icold;
|
||||||
sysCfg.led_color[4] = (uint8_t)iwarm;
|
Settings.led_color[4] = (uint8_t)iwarm;
|
||||||
} else {
|
} else {
|
||||||
sysCfg.led_color[0] = (uint8_t)icold;
|
Settings.led_color[0] = (uint8_t)icold;
|
||||||
sysCfg.led_color[1] = (uint8_t)iwarm;
|
Settings.led_color[1] = (uint8_t)iwarm;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t sl_getColorTemp()
|
uint16_t LightGetColorTemp()
|
||||||
{
|
{
|
||||||
uint8_t ct_idx = 0;
|
uint8_t ct_idx = 0;
|
||||||
if (5 == (sfl_flg &7)) {
|
if (5 == (light_type &7)) {
|
||||||
ct_idx = 3;
|
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) {
|
if (my_ct > 0) {
|
||||||
return ((my_ct * 136) / 100) + 154;
|
return ((my_ct * 136) / 100) + 154;
|
||||||
} else {
|
} else {
|
||||||
my_ct = sysCfg.led_color[ct_idx];
|
my_ct = Settings.led_color[ct_idx];
|
||||||
return 499 - ((my_ct * 136) / 100);
|
return 499 - ((my_ct * 136) / 100);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sl_setDim(uint8_t myDimmer)
|
void LightSetDimmer(uint8_t myDimmer)
|
||||||
{
|
{
|
||||||
float temp;
|
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
|
myDimmer = 99; // BN-SZ01 starts flickering at dimmer = 100
|
||||||
}
|
}
|
||||||
float newDim = 100 / (float)myDimmer;
|
float dimmer = 100 / (float)myDimmer;
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
temp = (float)sysCfg.led_color[i] / newDim;
|
temp = (float)Settings.led_color[i] / dimmer;
|
||||||
sl_dcolor[i] = (uint8_t)temp;
|
sl_dcolor[i] = (uint8_t)temp;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sl_setColor()
|
void LightSetColor()
|
||||||
{
|
{
|
||||||
uint8_t highest = 0;
|
uint8_t highest = 0;
|
||||||
float temp;
|
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]) {
|
if (highest < sl_dcolor[i]) {
|
||||||
highest = sl_dcolor[i];
|
highest = sl_dcolor[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
float mDim = (float)highest / 2.55;
|
float mDim = (float)highest / 2.55;
|
||||||
sysCfg.led_dimmer = (uint8_t)mDim;
|
Settings.led_dimmer = (uint8_t)mDim;
|
||||||
float newDim = 100 / mDim;
|
float dimmer = 100 / mDim;
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
temp = (float)sl_dcolor[i] * newDim;
|
temp = (float)sl_dcolor[i] * dimmer;
|
||||||
sysCfg.led_color[i] = (uint8_t)temp;
|
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';
|
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]);
|
snprintf_P(scolor, 11, PSTR("%s%02X"), scolor, sl_dcolor[i]);
|
||||||
}
|
}
|
||||||
return scolor;
|
return scolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void sl_prepPower()
|
void LightPreparePower()
|
||||||
{
|
{
|
||||||
char scolor[11];
|
char scolor[11];
|
||||||
char scommand[16];
|
char scommand[16];
|
||||||
|
|
||||||
if (sysCfg.led_dimmer && !(sl_power)) {
|
if (Settings.led_dimmer && !(sl_power)) {
|
||||||
do_cmnd_power(Maxdevice, 7); // No publishPowerState
|
ExecuteCommandPower(devices_present, 7); // No publishPowerState
|
||||||
}
|
}
|
||||||
else if (!sysCfg.led_dimmer && sl_power) {
|
else if (!Settings.led_dimmer && sl_power) {
|
||||||
do_cmnd_power(Maxdevice, 6); // No publishPowerState
|
ExecuteCommandPower(devices_present, 6); // No publishPowerState
|
||||||
}
|
}
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
// mqtt_publishDomoticzPowerState(1);
|
// MqttPublishDomoticzPowerState(1);
|
||||||
domoticz_updatePowerState(Maxdevice);
|
DomoticzUpdatePowerState(devices_present);
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
|
|
||||||
getPowerDevice(scommand, Maxdevice, sizeof(scommand));
|
GetPowerDevice(scommand, devices_present, sizeof(scommand));
|
||||||
if ((sfl_flg &7) > 1) {
|
if ((light_type &7) > 1) {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\", \"" D_CMND_DIMMER "\":%d, \"" D_CMND_COLOR "\":\"%s\"}"),
|
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 {
|
} else {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"%s\":\"%s\", \"" D_CMND_DIMMER "\":%d}"),
|
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) {
|
if (sl_wakeupActive) {
|
||||||
sl_wakeupActive--;
|
sl_wakeupActive--;
|
||||||
}
|
}
|
||||||
if (sl_power) {
|
if (sl_power) {
|
||||||
sl_any = 1;
|
sl_any = 1;
|
||||||
}
|
}
|
||||||
sl_animate();
|
LightAnimate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sl_animate()
|
void LightAnimate()
|
||||||
{
|
{
|
||||||
// {"Wakeup":"Done"}
|
// {"Wakeup":"Done"}
|
||||||
uint8_t fadeValue;
|
uint8_t fadeValue;
|
||||||
|
@ -337,29 +337,29 @@ void sl_animate()
|
||||||
|
|
||||||
stripTimerCntr++;
|
stripTimerCntr++;
|
||||||
if (!sl_power) { // Power Off
|
if (!sl_power) { // Power Off
|
||||||
sleep = sysCfg.sleep;
|
sleep = Settings.sleep;
|
||||||
stripTimerCntr = 0;
|
stripTimerCntr = 0;
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
sl_tcolor[i] = 0;
|
sl_tcolor[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
sleep = 0;
|
sleep = 0;
|
||||||
switch (sysCfg.led_scheme) {
|
switch (Settings.led_scheme) {
|
||||||
case 0: // Power On
|
case 0: // Power On
|
||||||
sl_setDim(sysCfg.led_dimmer); // Power On
|
LightSetDimmer(Settings.led_dimmer); // Power On
|
||||||
if (0 == sysCfg.led_fade) {
|
if (0 == Settings.led_fade) {
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
sl_tcolor[i] = sl_dcolor[i];
|
sl_tcolor[i] = sl_dcolor[i];
|
||||||
}
|
}
|
||||||
} else {
|
} 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]) {
|
||||||
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]) {
|
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
|
case 1: // Power On using wake up duration
|
||||||
if (2 == sl_wakeupActive) {
|
if (2 == sl_wakeupActive) {
|
||||||
sl_wakeupActive = 1;
|
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_tcolor[i] = 0;
|
||||||
}
|
}
|
||||||
sl_wakeupCntr = 0;
|
sl_wakeupCntr = 0;
|
||||||
sl_wakeupDimmer = 0;
|
sl_wakeupDimmer = 0;
|
||||||
}
|
}
|
||||||
sl_wakeupCntr++;
|
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_wakeupCntr = 0;
|
||||||
sl_wakeupDimmer++;
|
sl_wakeupDimmer++;
|
||||||
if (sl_wakeupDimmer <= sysCfg.led_dimmer) {
|
if (sl_wakeupDimmer <= Settings.led_dimmer) {
|
||||||
sl_setDim(sl_wakeupDimmer);
|
LightSetDimmer(sl_wakeupDimmer);
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
sl_tcolor[i] = sl_dcolor[i];
|
sl_tcolor[i] = sl_dcolor[i];
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_DONE "\"}"));
|
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;
|
sl_wakeupActive = 0;
|
||||||
sysCfg.led_scheme = 0;
|
Settings.led_scheme = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#ifdef USE_WS2812 // ************************************************************************
|
#ifdef USE_WS2812 // ************************************************************************
|
||||||
default:
|
default:
|
||||||
if (11 == sfl_flg) {
|
if (11 == light_type) {
|
||||||
ws2812_showScheme(sysCfg.led_scheme -2);
|
Ws2812ShowScheme(Settings.led_scheme -2);
|
||||||
}
|
}
|
||||||
#endif // USE_WS2812 ************************************************************************
|
#endif // USE_WS2812 ************************************************************************
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((sysCfg.led_scheme < 2) || !sl_power) {
|
if ((Settings.led_scheme < 2) || !sl_power) {
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
if (sl_lcolor[i] != sl_tcolor[i]) {
|
if (sl_lcolor[i] != sl_tcolor[i]) {
|
||||||
sl_any = 1;
|
sl_any = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (sl_any) {
|
if (sl_any) {
|
||||||
sl_any = 0;
|
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];
|
sl_lcolor[i] = sl_tcolor[i];
|
||||||
cur_col[i] = (sysCfg.led_table) ? ledTable[sl_lcolor[i]] : sl_lcolor[i];
|
cur_col[i] = (Settings.led_table) ? ledTable[sl_lcolor[i]] : sl_lcolor[i];
|
||||||
if (sfl_flg < 6) {
|
if (light_type < 6) {
|
||||||
if (pin[GPIO_PWM1 +i] < 99) {
|
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);
|
// 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);
|
// AddLog(LOG_LEVEL_DEBUG);
|
||||||
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? PWM_RANGE - curcol : curcol);
|
analogWrite(pin[GPIO_PWM1 +i], bitRead(pwm_inverted, i) ? Settings.pwm_range - curcol : curcol);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef USE_WS2812 // ************************************************************************
|
#ifdef USE_WS2812 // ************************************************************************
|
||||||
if (11 == sfl_flg) {
|
if (11 == light_type) {
|
||||||
ws2812_setColor(0, cur_col[0], cur_col[1], cur_col[2]);
|
Ws2812SetColor(0, cur_col[0], cur_col[1], cur_col[2]);
|
||||||
}
|
}
|
||||||
#endif // USE_ES2812 ************************************************************************
|
#endif // USE_ES2812 ************************************************************************
|
||||||
if (sfl_flg > 11) {
|
if (light_type > 11) {
|
||||||
sl_my92x1_duty(cur_col[0], cur_col[1], cur_col[2], cur_col[3], cur_col[4]);
|
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_Sat = 0.0;
|
||||||
float sl_Bri = 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)
|
// convert colors to float between (0.0 - 1.0)
|
||||||
float r = sl_dcolor[0] / 255.0f;
|
float r = sl_dcolor[0] / 255.0f;
|
||||||
|
@ -471,7 +471,7 @@ void sl_rgb2hsb()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void sl_hsb2rgb()
|
void LightHsbToRgb()
|
||||||
{
|
{
|
||||||
float r;
|
float r;
|
||||||
float g;
|
float g;
|
||||||
|
@ -537,37 +537,37 @@ void sl_hsb2rgb()
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void sl_replaceHSB(String *response)
|
void LightReplaceHsb(String *response)
|
||||||
{
|
{
|
||||||
if ((sfl_flg &7) > 2) {
|
if ((light_type &7) > 2) {
|
||||||
sl_rgb2hsb();
|
LightRgbToHsb();
|
||||||
response->replace("{h}", String((uint16_t)(65535.0f * sl_Hue)));
|
response->replace("{h}", String((uint16_t)(65535.0f * sl_Hue)));
|
||||||
response->replace("{s}", String((uint8_t)(254.0f * sl_Sat)));
|
response->replace("{s}", String((uint8_t)(254.0f * sl_Sat)));
|
||||||
response->replace("{b}", String((uint8_t)(254.0f * sl_Bri)));
|
response->replace("{b}", String((uint8_t)(254.0f * sl_Bri)));
|
||||||
} else {
|
} else {
|
||||||
response->replace("{h}", "0");
|
response->replace("{h}", "0");
|
||||||
response->replace("{s}", "0");
|
response->replace("{s}", "0");
|
||||||
// response->replace("{b}", String((uint8_t)(2.54f * (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)sysCfg.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) {
|
if ((light_type &7) > 2) {
|
||||||
sl_rgb2hsb();
|
LightRgbToHsb();
|
||||||
*hue = sl_Hue;
|
*hue = sl_Hue;
|
||||||
*sat = sl_Sat;
|
*sat = sl_Sat;
|
||||||
*bri = sl_Bri;
|
*bri = sl_Bri;
|
||||||
} else {
|
} else {
|
||||||
*hue = 0;
|
*hue = 0;
|
||||||
*sat = 0;
|
*sat = 0;
|
||||||
// *bri = (2.54f * (float)sysCfg.led_dimmer);
|
// *bri = (2.54f * (float)Settings.led_dimmer);
|
||||||
*bri = (0.01f * (float)sysCfg.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];
|
char stemp1[10];
|
||||||
|
@ -577,33 +577,33 @@ void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
|
||||||
dtostrfi(sat, 3, stemp2);
|
dtostrfi(sat, 3, stemp2);
|
||||||
dtostrfi(bri, 3, stemp3);
|
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);
|
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 (light_type > 2) {
|
||||||
if ((5 == (sfl_flg &7)) && (ct > 0)) {
|
if ((5 == (light_type &7)) && (ct > 0)) {
|
||||||
sl_setColorTemp(ct);
|
LightSetColorTemp(ct);
|
||||||
} else {
|
} else {
|
||||||
sl_Hue = hue;
|
sl_Hue = hue;
|
||||||
sl_Sat = sat;
|
sl_Sat = sat;
|
||||||
sl_Bri = bri;
|
sl_Bri = bri;
|
||||||
sl_hsb2rgb();
|
LightHsbToRgb();
|
||||||
sl_setColor();
|
LightSetColor();
|
||||||
}
|
}
|
||||||
sl_prepPower();
|
LightPreparePower();
|
||||||
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR));
|
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_COLOR));
|
||||||
} else {
|
} else {
|
||||||
uint8_t tmp = (uint8_t)(bri * 100);
|
uint8_t tmp = (uint8_t)(bri * 100);
|
||||||
sysCfg.led_dimmer = tmp;
|
Settings.led_dimmer = tmp;
|
||||||
if (2 == (sfl_flg &7)) {
|
if (2 == (light_type &7)) {
|
||||||
if (ct > 0) {
|
if (ct > 0) {
|
||||||
sl_setColorTemp(ct);
|
LightSetColorTemp(ct);
|
||||||
}
|
}
|
||||||
sl_prepPower();
|
LightPreparePower();
|
||||||
mqtt_publish_topic_P(5, PSTR(D_CMND_COLOR));
|
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_COLOR));
|
||||||
} else {
|
} else {
|
||||||
sl_prepPower();
|
LightPreparePower();
|
||||||
mqtt_publish_topic_P(5, PSTR(D_CMND_DIMMER));
|
MqttPublishPrefixTopic_P(5, PSTR(D_CMND_DIMMER));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -612,94 +612,94 @@ void sl_setHSB(float hue, float sat, float bri, uint16_t ct)
|
||||||
* Commands
|
* 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 serviced = true;
|
||||||
boolean coldim = false;
|
boolean coldim = false;
|
||||||
char scolor[11];
|
char scolor[11];
|
||||||
char *p;
|
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] == '#') {
|
if (dataBuf[0] == '#') {
|
||||||
dataBuf++;
|
dataBuf++;
|
||||||
data_len--;
|
data_len--;
|
||||||
}
|
}
|
||||||
if ((2 * (sfl_flg &7)) == data_len) {
|
if ((2 * (light_type &7)) == data_len) {
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
strlcpy(scolor, dataBuf + (i *2), 3);
|
strlcpy(scolor, dataBuf + (i *2), 3);
|
||||||
sl_dcolor[i] = (uint8_t)strtol(scolor, &p, 16);
|
sl_dcolor[i] = (uint8_t)strtol(scolor, &p, 16);
|
||||||
}
|
}
|
||||||
sl_setColor();
|
LightSetColor();
|
||||||
coldim = true;
|
coldim = true;
|
||||||
} else {
|
} 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 // ***********************************************************************
|
#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] == '#') {
|
if (dataBuf[0] == '#') {
|
||||||
dataBuf++;
|
dataBuf++;
|
||||||
data_len--;
|
data_len--;
|
||||||
}
|
}
|
||||||
uint8_t sl_ledcolor[3];
|
uint8_t sl_ledcolor[3];
|
||||||
if ((2 * (sfl_flg &7)) == data_len) {
|
if ((2 * (light_type &7)) == data_len) {
|
||||||
for (byte i = 0; i < (sfl_flg &7); i++) {
|
for (byte i = 0; i < (light_type &7); i++) {
|
||||||
strlcpy(scolor, dataBuf + (i *2), 3);
|
strlcpy(scolor, dataBuf + (i *2), 3);
|
||||||
sl_ledcolor[i] = (uint8_t)strtol(scolor, &p, 16);
|
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)) {
|
if ((payload > 0) && (payload <= WS2812_MAX_LEDS)) {
|
||||||
sysCfg.led_pixels = payload;
|
Settings.led_pixels = payload;
|
||||||
ws2812_clear();
|
Ws2812Clear();
|
||||||
sl_any = 1;
|
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)) {
|
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)) {
|
if ((payload >= 0) && (payload <= 9)) {
|
||||||
sysCfg.led_scheme = payload;
|
Settings.led_scheme = payload;
|
||||||
if (1 == sysCfg.led_scheme) {
|
if (1 == Settings.led_scheme) {
|
||||||
sl_wakeupActive = 3;
|
sl_wakeupActive = 3;
|
||||||
}
|
}
|
||||||
do_cmnd_power(Maxdevice, 1);
|
ExecuteCommandPower(devices_present, 1);
|
||||||
stripTimerCntr = 0;
|
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 ************************************************************************
|
#endif // USE_WS2812 ************************************************************************
|
||||||
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUP))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUP))) {
|
||||||
if ((payload >= 0) && (payload <= 100)) {
|
if ((payload >= 0) && (payload <= 100)) {
|
||||||
sysCfg.led_dimmer = payload;
|
Settings.led_dimmer = payload;
|
||||||
}
|
}
|
||||||
sl_wakeupActive = 3;
|
sl_wakeupActive = 3;
|
||||||
sysCfg.led_scheme = 1;
|
Settings.led_scheme = 1;
|
||||||
do_cmnd_power(Maxdevice, 1);
|
ExecuteCommandPower(devices_present, 1);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_CMND_WAKEUP "\":\"" D_STARTED "\"}"));
|
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
|
if ((payload >= 153) && (payload <= 500)) { // https://developers.meethue.com/documentation/core-concepts
|
||||||
sl_setColorTemp(payload);
|
LightSetColorTemp(payload);
|
||||||
coldim = true;
|
coldim = true;
|
||||||
} else {
|
} 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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_DIMMER))) {
|
||||||
if ((payload >= 0) && (payload <= 100)) {
|
if ((payload >= 0) && (payload <= 100)) {
|
||||||
sysCfg.led_dimmer = payload;
|
Settings.led_dimmer = payload;
|
||||||
coldim = true;
|
coldim = true;
|
||||||
} else {
|
} 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))) {
|
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) {
|
switch (payload) {
|
||||||
case 0: // Off
|
case 0: // Off
|
||||||
case 1: // On
|
case 1: // On
|
||||||
sysCfg.led_table = payload;
|
Settings.led_table = payload;
|
||||||
break;
|
break;
|
||||||
case 2: // Toggle
|
case 2: // Toggle
|
||||||
sysCfg.led_table ^= 1;
|
Settings.led_table ^= 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
sl_any = 1;
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_FADE))) {
|
||||||
switch (payload) {
|
switch (payload) {
|
||||||
case 0: // Off
|
case 0: // Off
|
||||||
case 1: // On
|
case 1: // On
|
||||||
sysCfg.led_fade = payload;
|
Settings.led_fade = payload;
|
||||||
break;
|
break;
|
||||||
case 2: // Toggle
|
case 2: // Toggle
|
||||||
sysCfg.led_fade ^= 1;
|
Settings.led_fade ^= 1;
|
||||||
break;
|
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
|
else if (!strcasecmp_P(type, PSTR(D_CMND_SPEED))) { // 1 - fast, 8 - slow
|
||||||
if ((payload > 0) && (payload <= 8)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_WAKEUPDURATION))) {
|
||||||
if ((payload > 0) && (payload < 3001)) {
|
if ((payload > 0) && (payload < 3001)) {
|
||||||
sysCfg.led_wakeup = payload;
|
Settings.led_wakeup = payload;
|
||||||
sl_wakeupActive = 0;
|
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
|
else if (!strcasecmp_P(type, PSTR("UNDOCA"))) { // Theos legacy status
|
||||||
sl_getColor(scolor);
|
LightGetColor(scolor);
|
||||||
scolor[6] = '\0'; // RGB only
|
scolor[6] = '\0'; // RGB only
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, %d, %d, %d, %d, %d"),
|
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);
|
scolor, Settings.led_fade, Settings.led_table, Settings.led_scheme, Settings.led_speed, Settings.led_width);
|
||||||
mqtt_publish_topic_P(1, type);
|
MqttPublishPrefixTopic_P(1, type);
|
||||||
mqtt_data[0] = '\0';
|
mqtt_data[0] = '\0';
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
serviced = false; // Unknown command
|
serviced = false; // Unknown command
|
||||||
}
|
}
|
||||||
if (coldim) {
|
if (coldim) {
|
||||||
sl_prepPower();
|
LightPreparePower();
|
||||||
}
|
}
|
||||||
return serviced;
|
return serviced;
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,29 +55,29 @@
|
||||||
|
|
||||||
uint16_t sc_value[5] = { 0 };
|
uint16_t sc_value[5] = { 0 };
|
||||||
|
|
||||||
void sc_send(const char *data)
|
void SonoffScSend(const char *data)
|
||||||
{
|
{
|
||||||
Serial.write(data);
|
Serial.write(data);
|
||||||
Serial.write('\x1B');
|
Serial.write('\x1B');
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SERIAL D_TRANSMIT " %s"), data);
|
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");
|
// SonoffScSend("AT+DEVCONFIG=\"uploadFreq\":1800");
|
||||||
sc_send("AT+START");
|
SonoffScSend("AT+START");
|
||||||
// sc_send("AT+STATUS");
|
// SonoffScSend("AT+STATUS");
|
||||||
}
|
}
|
||||||
|
|
||||||
void sc_rcvstat(char *rcvstat)
|
void SonoffScSerialInput(char *rcvstat)
|
||||||
{
|
{
|
||||||
char *p;
|
char *p;
|
||||||
char *str;
|
char *str;
|
||||||
uint16_t value[5] = { 0 };
|
uint16_t value[5] = { 0 };
|
||||||
|
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_SERIAL D_RECEIVED " %s"), rcvstat);
|
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)) {
|
if (!strncasecmp_P(rcvstat, PSTR("AT+UPDATE="), 10)) {
|
||||||
int8_t i = -1;
|
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[2] = (11 - sc_value[2]) * 10; // Invert light level
|
||||||
sc_value[3] *= 10;
|
sc_value[3] *= 10;
|
||||||
sc_value[4] = (11 - sc_value[4]) * 10; // Invert dust level
|
sc_value[4] = (11 - sc_value[4]) * 10; // Invert dust level
|
||||||
sc_send("AT+SEND=ok");
|
SonoffScSend("AT+SEND=ok");
|
||||||
} else {
|
} else {
|
||||||
sc_send("AT+SEND=fail");
|
SonoffScSend("AT+SEND=fail");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!strcasecmp_P(rcvstat, PSTR("AT+STATUS?"))) {
|
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
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void sc_mqttPresent(uint8_t* djson)
|
void MqttShowSonoffSC(uint8_t* djson)
|
||||||
{
|
{
|
||||||
if (sc_value[0] > 0) {
|
if (sc_value[0] > 0) {
|
||||||
char stemp1[10];
|
char stemp1[10];
|
||||||
char stemp2[10];
|
char stemp2[10];
|
||||||
|
|
||||||
float t = convertTemp(sc_value[1]);
|
float t = ConvertTemp(sc_value[1]);
|
||||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||||
float h = sc_value[0];
|
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"),
|
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]);
|
mqtt_data, stemp1, stemp2, sc_value[2], sc_value[3], sc_value[4]);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
domoticz_sensor2(stemp1, stemp2);
|
DomoticzTempHumSensor(stemp1, stemp2);
|
||||||
domoticz_sensor(DZ_ILLUMINANCE, sc_value[2]);
|
DomoticzSensor(DZ_ILLUMINANCE, sc_value[2]);
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
String sc_webPresent()
|
String WebShowSonoffSc()
|
||||||
{
|
{
|
||||||
String page = "";
|
String page = "";
|
||||||
|
|
||||||
|
@ -135,12 +135,12 @@ String sc_webPresent()
|
||||||
char sensor[80];
|
char sensor[80];
|
||||||
char scstype[] = "";
|
char scstype[] = "";
|
||||||
|
|
||||||
float t = convertTemp(sc_value[1]);
|
float t = ConvertTemp(sc_value[1]);
|
||||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, scstype, stemp, tempUnit());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, scstype, stemp, TempUnit());
|
||||||
page += sensor;
|
page += sensor;
|
||||||
float h = sc_value[0];
|
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);
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, scstype, stemp);
|
||||||
page += sensor;
|
page += sensor;
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_LIGHT, scstype, sc_value[2]);
|
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
|
#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)
|
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
|
* WeMo UPNP support routines
|
||||||
|
@ -49,7 +49,7 @@ const char WEMO_MSEARCH[] PROGMEM =
|
||||||
"X-User-Agent: redsonic\r\n"
|
"X-User-Agent: redsonic\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
String wemo_serial()
|
String WemoSerialnumber()
|
||||||
{
|
{
|
||||||
char serial[16];
|
char serial[16];
|
||||||
|
|
||||||
|
@ -57,31 +57,31 @@ String wemo_serial()
|
||||||
return String(serial);
|
return String(serial);
|
||||||
}
|
}
|
||||||
|
|
||||||
String wemo_UUID()
|
String WemoUuid()
|
||||||
{
|
{
|
||||||
char uuid[27];
|
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);
|
return String(uuid);
|
||||||
}
|
}
|
||||||
|
|
||||||
void wemo_respondToMSearch()
|
void WemoRespondToMSearch()
|
||||||
{
|
{
|
||||||
char message[TOPSZ];
|
char message[TOPSZ];
|
||||||
|
|
||||||
if (portUDP.beginPacket(portUDP.remoteIP(), portUDP.remotePort())) {
|
if (PortUdp.beginPacket(PortUdp.remoteIP(), PortUdp.remotePort())) {
|
||||||
String response = FPSTR(WEMO_MSEARCH);
|
String response = FPSTR(WEMO_MSEARCH);
|
||||||
response.replace("{r1}", WiFi.localIP().toString());
|
response.replace("{r1}", WiFi.localIP().toString());
|
||||||
response.replace("{r2}", wemo_UUID());
|
response.replace("{r2}", WemoUuid());
|
||||||
portUDP.write(response.c_str());
|
PortUdp.write(response.c_str());
|
||||||
portUDP.endPacket();
|
PortUdp.endPacket();
|
||||||
snprintf_P(message, sizeof(message), PSTR(D_RESPONSE_SENT));
|
snprintf_P(message, sizeof(message), PSTR(D_RESPONSE_SENT));
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(message, sizeof(message), PSTR(D_FAILED_TO_SEND_RESPONSE));
|
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"),
|
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());
|
message, PortUdp.remoteIP().toString().c_str(), PortUdp.remotePort());
|
||||||
addLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
|
@ -113,7 +113,7 @@ const char HUE_ST3[] PROGMEM =
|
||||||
"USN: uuid:{r3}\r\n"
|
"USN: uuid:{r3}\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
|
|
||||||
String hue_bridgeid()
|
String HueBridgeId()
|
||||||
{
|
{
|
||||||
String temp = WiFi.macAddress();
|
String temp = WiFi.macAddress();
|
||||||
temp.replace(":", "");
|
temp.replace(":", "");
|
||||||
|
@ -121,7 +121,7 @@ String hue_bridgeid()
|
||||||
return bridgeid; // 5CCF7FFFFE139F3D
|
return bridgeid; // 5CCF7FFFFE139F3D
|
||||||
}
|
}
|
||||||
|
|
||||||
String hue_serial()
|
String HueSerialnumber()
|
||||||
{
|
{
|
||||||
String serial = WiFi.macAddress();
|
String serial = WiFi.macAddress();
|
||||||
serial.replace(":", "");
|
serial.replace(":", "");
|
||||||
|
@ -129,106 +129,106 @@ String hue_serial()
|
||||||
return serial; // 5ccf7f139f3d
|
return serial; // 5ccf7f139f3d
|
||||||
}
|
}
|
||||||
|
|
||||||
String hue_UUID()
|
String HueUuid()
|
||||||
{
|
{
|
||||||
String uuid = F("f6543a06-da50-11ba-8d8f-");
|
String uuid = F("f6543a06-da50-11ba-8d8f-");
|
||||||
uuid += hue_serial();
|
uuid += HueSerialnumber();
|
||||||
return uuid; // f6543a06-da50-11ba-8d8f-5ccf7f139f3d
|
return uuid; // f6543a06-da50-11ba-8d8f-5ccf7f139f3d
|
||||||
}
|
}
|
||||||
|
|
||||||
void hue_respondToMSearch()
|
void HueRespondToMSearch()
|
||||||
{
|
{
|
||||||
char message[TOPSZ];
|
char message[TOPSZ];
|
||||||
|
|
||||||
if (portUDP.beginPacket(portUDP.remoteIP(), portUDP.remotePort())) {
|
if (PortUdp.beginPacket(PortUdp.remoteIP(), PortUdp.remotePort())) {
|
||||||
String response1 = FPSTR(HUE_RESPONSE);
|
String response1 = FPSTR(HUE_RESPONSE);
|
||||||
response1.replace("{r1}", WiFi.localIP().toString());
|
response1.replace("{r1}", WiFi.localIP().toString());
|
||||||
response1.replace("{r2}", hue_bridgeid());
|
response1.replace("{r2}", HueBridgeId());
|
||||||
|
|
||||||
String response = response1;
|
String response = response1;
|
||||||
response += FPSTR(HUE_ST1);
|
response += FPSTR(HUE_ST1);
|
||||||
response.replace("{r3}", hue_UUID());
|
response.replace("{r3}", HueUuid());
|
||||||
portUDP.write(response.c_str());
|
PortUdp.write(response.c_str());
|
||||||
portUDP.endPacket();
|
PortUdp.endPacket();
|
||||||
|
|
||||||
response = response1;
|
response = response1;
|
||||||
response += FPSTR(HUE_ST2);
|
response += FPSTR(HUE_ST2);
|
||||||
response.replace("{r3}", hue_UUID());
|
response.replace("{r3}", HueUuid());
|
||||||
portUDP.write(response.c_str());
|
PortUdp.write(response.c_str());
|
||||||
portUDP.endPacket();
|
PortUdp.endPacket();
|
||||||
|
|
||||||
response = response1;
|
response = response1;
|
||||||
response += FPSTR(HUE_ST3);
|
response += FPSTR(HUE_ST3);
|
||||||
response.replace("{r3}", hue_UUID());
|
response.replace("{r3}", HueUuid());
|
||||||
portUDP.write(response.c_str());
|
PortUdp.write(response.c_str());
|
||||||
portUDP.endPacket();
|
PortUdp.endPacket();
|
||||||
|
|
||||||
snprintf_P(message, sizeof(message), PSTR(D_3_RESPONSE_PACKETS_SENT));
|
snprintf_P(message, sizeof(message), PSTR(D_3_RESPONSE_PACKETS_SENT));
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(message, sizeof(message), PSTR(D_FAILED_TO_SEND_RESPONSE));
|
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"),
|
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());
|
message, PortUdp.remoteIP().toString().c_str(), PortUdp.remotePort());
|
||||||
addLog(LOG_LEVEL_DEBUG);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Belkin WeMo and Philips Hue bridge UDP multicast support
|
* Belkin WeMo and Philips Hue bridge UDP multicast support
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
boolean UDP_Disconnect()
|
boolean UdpDisconnect()
|
||||||
{
|
{
|
||||||
if (udpConnected) {
|
if (udp_connected) {
|
||||||
WiFiUDP::stopAll();
|
WiFiUDP::stopAll();
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP D_MULTICAST_DISABLED));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_UPNP D_MULTICAST_DISABLED));
|
||||||
udpConnected = false;
|
udp_connected = false;
|
||||||
}
|
}
|
||||||
return udpConnected;
|
return udp_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean UDP_Connect()
|
boolean UdpConnect()
|
||||||
{
|
{
|
||||||
if (!udpConnected) {
|
if (!udp_connected) {
|
||||||
if (portUDP.beginMulticast(WiFi.localIP(), ipMulticast, portMulticast)) {
|
if (PortUdp.beginMulticast(WiFi.localIP(), ipMulticast, port_multicast)) {
|
||||||
addLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_REJOINED));
|
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_REJOINED));
|
||||||
udpConnected = true;
|
udp_connected = true;
|
||||||
} else {
|
} else {
|
||||||
addLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_JOIN_FAILED));
|
AddLog_P(LOG_LEVEL_INFO, PSTR(D_LOG_UPNP D_MULTICAST_JOIN_FAILED));
|
||||||
udpConnected = false;
|
udp_connected = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return udpConnected;
|
return udp_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
void pollUDP()
|
void PollUdp()
|
||||||
{
|
{
|
||||||
if (udpConnected) {
|
if (udp_connected) {
|
||||||
if (portUDP.parsePacket()) {
|
if (PortUdp.parsePacket()) {
|
||||||
int len = portUDP.read(packetBuffer, UDP_BUFFER_SIZE -1);
|
int len = PortUdp.read(packet_buffer, UDP_BUFFER_SIZE -1);
|
||||||
if (len > 0) {
|
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, PSTR("UDP: Packet received"));
|
||||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, packetBuffer);
|
// AddLog_P(LOG_LEVEL_DEBUG_MORE, packet_buffer);
|
||||||
|
|
||||||
if (request.indexOf("M-SEARCH") >= 0) {
|
if (request.indexOf("M-SEARCH") >= 0) {
|
||||||
request.toLowerCase();
|
request.toLowerCase();
|
||||||
request.replace(" ", "");
|
request.replace(" ", "");
|
||||||
|
|
||||||
// addLog_P(LOG_LEVEL_DEBUG_MORE, PSTR("UDP: M-SEARCH Packet received"));
|
// 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, request.c_str());
|
||||||
|
|
||||||
if ((EMUL_WEMO == sysCfg.flag.emulation) && (request.indexOf(F("urn:belkin:device:**")) > 0)) {
|
if ((EMUL_WEMO == Settings.flag.emulation) && (request.indexOf(F("urn:belkin:device:**")) > 0)) {
|
||||||
wemo_respondToMSearch();
|
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:urn:schemas-upnp-org:device:basic:1")) > 0) ||
|
||||||
(request.indexOf(F("st:upnp:rootdevice")) > 0) ||
|
(request.indexOf(F("st:upnp:rootdevice")) > 0) ||
|
||||||
(request.indexOf(F("st:ssdpsearch:all")) > 0) ||
|
(request.indexOf(F("st:ssdpsearch:all")) > 0) ||
|
||||||
(request.indexOf(F("st:ssdp: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));
|
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_BASIC_EVENT));
|
||||||
String request = webServer->arg(0);
|
String request = WebServer->arg(0);
|
||||||
if (request.indexOf(F("State>1</Binary")) > 0) {
|
if (request.indexOf(F("State>1</Binary")) > 0) {
|
||||||
// do_cmnd_power(1, 1);
|
// ExecuteCommandPower(1, 1);
|
||||||
do_cmnd_power(Maxdevice, 1);
|
ExecuteCommandPower(devices_present, 1);
|
||||||
}
|
}
|
||||||
if (request.indexOf(F("State>0</Binary")) > 0) {
|
if (request.indexOf(F("State>0</Binary")) > 0) {
|
||||||
// do_cmnd_power(1, 0);
|
// ExecuteCommandPower(1, 0);
|
||||||
do_cmnd_power(Maxdevice, 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));
|
AddLog_P(LOG_LEVEL_DEBUG, S_LOG_HTTP, PSTR(D_WEMO_EVENT_SERVICE));
|
||||||
webServer->send(200, FPSTR(HDR_CTYPE_PLAIN), FPSTR(WEMO_EVENTSERVICE_XML));
|
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);
|
String setup_xml = FPSTR(WEMO_SETUP_XML);
|
||||||
setup_xml.replace("{x1}", sysCfg.friendlyname[0]);
|
setup_xml.replace("{x1}", Settings.friendlyname[0]);
|
||||||
setup_xml.replace("{x2}", wemo_UUID());
|
setup_xml.replace("{x2}", WemoUuid());
|
||||||
setup_xml.replace("{x3}", wemo_serial());
|
setup_xml.replace("{x3}", WemoSerialnumber());
|
||||||
webServer->send(200, FPSTR(HDR_CTYPE_XML), setup_xml);
|
WebServer->send(200, FPSTR(HDR_CTYPE_XML), setup_xml);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
|
@ -353,7 +353,7 @@ const char HUE_DESCRIPTION_XML[] PROGMEM =
|
||||||
"</device>"
|
"</device>"
|
||||||
"</root>\r\n"
|
"</root>\r\n"
|
||||||
"\r\n";
|
"\r\n";
|
||||||
const char HUE_LIGHT_STATUS_JSON[] PROGMEM =
|
const char HueLightStatus_JSON[] PROGMEM =
|
||||||
"\"on\":{state},"
|
"\"on\":{state},"
|
||||||
"\"bri\":{b},"
|
"\"bri\":{b},"
|
||||||
"\"hue\":{h},"
|
"\"hue\":{h},"
|
||||||
|
@ -377,7 +377,7 @@ const char HUE_GROUP0_STATUS_JSON[] PROGMEM =
|
||||||
"\"type\":\"LightGroup\","
|
"\"type\":\"LightGroup\","
|
||||||
"\"action\":{";
|
"\"action\":{";
|
||||||
// "\"scene\":\"none\",";
|
// "\"scene\":\"none\",";
|
||||||
const char HUE_CONFIG_RESPONSE_JSON[] PROGMEM =
|
const char HueConfigResponse_JSON[] PROGMEM =
|
||||||
"{\"name\":\"Philips hue\","
|
"{\"name\":\"Philips hue\","
|
||||||
"\"mac\":\"{mac}\","
|
"\"mac\":\"{mac}\","
|
||||||
"\"dhcp\":true,"
|
"\"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);
|
String deviceid = WiFi.macAddress() + F(":00:11-") + String(id);
|
||||||
deviceid.toLowerCase();
|
deviceid.toLowerCase();
|
||||||
return deviceid; // 5c:cf:7f:13:9f:3d:00:11-1
|
return deviceid; // 5c:cf:7f:13:9f:3d:00:11-1
|
||||||
}
|
}
|
||||||
|
|
||||||
String hue_userId()
|
String GetHueUserId()
|
||||||
{
|
{
|
||||||
char userid[7];
|
char userid[7];
|
||||||
|
|
||||||
|
@ -420,50 +420,50 @@ String hue_userId()
|
||||||
return String(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);
|
String description_xml = FPSTR(HUE_DESCRIPTION_XML);
|
||||||
description_xml.replace("{x1}", WiFi.localIP().toString());
|
description_xml.replace("{x1}", WiFi.localIP().toString());
|
||||||
description_xml.replace("{x2}", hue_UUID());
|
description_xml.replace("{x2}", HueUuid());
|
||||||
description_xml.replace("{x3}", hue_serial());
|
description_xml.replace("{x3}", HueSerialnumber());
|
||||||
webServer->send(200, FPSTR(HDR_CTYPE_XML), description_xml);
|
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());
|
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("{mac}", WiFi.macAddress());
|
||||||
response->replace("{ip}", WiFi.localIP().toString());
|
response->replace("{ip}", WiFi.localIP().toString());
|
||||||
response->replace("{mask}", WiFi.subnetMask().toString());
|
response->replace("{mask}", WiFi.subnetMask().toString());
|
||||||
response->replace("{gw}", WiFi.gatewayIP().toString());
|
response->replace("{gw}", WiFi.gatewayIP().toString());
|
||||||
response->replace("{bid}", hue_bridgeid());
|
response->replace("{bid}", HueBridgeId());
|
||||||
response->replace("{dt}", getUTCDateTime());
|
response->replace("{dt}", GetUtcDateAndTime());
|
||||||
response->replace("{id}", hue_userId());
|
response->replace("{id}", GetHueUserId());
|
||||||
}
|
}
|
||||||
|
|
||||||
void hue_config(String *path)
|
void HueConfig(String *path)
|
||||||
{
|
{
|
||||||
String response = "";
|
String response = "";
|
||||||
hue_config_response(&response);
|
HueConfigResponse(&response);
|
||||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), 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");
|
response->replace("{state}", (power & (1 << (device-1))) ? "true" : "false");
|
||||||
|
|
||||||
if (sfl_flg) {
|
if (light_type) {
|
||||||
sl_replaceHSB(response);
|
LightReplaceHsb(response);
|
||||||
} else {
|
} else {
|
||||||
response->replace("{h}", "0");
|
response->replace("{h}", "0");
|
||||||
response->replace("{s}", "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;
|
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>
|
path->remove(0,1); // cut leading / to get <id>
|
||||||
response = F("{\"lights\":{\"");
|
response = F("{\"lights\":{\"");
|
||||||
for (uint8_t i = 1; i <= maxhue; i++) {
|
for (uint8_t i = 1; i <= maxhue; i++) {
|
||||||
response += i;
|
response += i;
|
||||||
response += F("\":{\"state\":{");
|
response += F("\":{\"state\":{");
|
||||||
hue_light_status(i, &response);
|
HueLightStatus(i, &response);
|
||||||
response += "},";
|
response += "},";
|
||||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
response.replace("{j1}", Settings.friendlyname[i-1]);
|
||||||
response.replace("{j2}", hue_deviceId(i));
|
response.replace("{j2}", GetHueDeviceId(i));
|
||||||
if (i < maxhue) {
|
if (i < maxhue) {
|
||||||
response += ",\"";
|
response += ",\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
|
response += F("},\"groups\":{},\"schedules\":{},\"config\":");
|
||||||
hue_config_response(&response);
|
HueConfigResponse(&response);
|
||||||
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];
|
char response[38];
|
||||||
|
|
||||||
snprintf_P(response, sizeof(response), PSTR("[{\"success\":{\"username\":\"%s\"}}]"), hue_userId().c_str());
|
snprintf_P(response, sizeof(response), PSTR("[{\"success\":{\"username\":\"%s\"}}]"), GetHueUserId().c_str());
|
||||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
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}
|
* 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 on = false;
|
||||||
bool change = false;
|
bool change = false;
|
||||||
char id[4];
|
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
|
path->remove(0,path->indexOf("/lights")); // Remove until /lights
|
||||||
if (path->endsWith("/lights")) { // Got /lights
|
if (path->endsWith("/lights")) { // Got /lights
|
||||||
|
@ -529,17 +529,17 @@ void hue_lights(String *path)
|
||||||
for (uint8_t i = 1; i <= maxhue; i++) {
|
for (uint8_t i = 1; i <= maxhue; i++) {
|
||||||
response += i;
|
response += i;
|
||||||
response += F("\":{\"state\":{");
|
response += F("\":{\"state\":{");
|
||||||
hue_light_status(i, &response);
|
HueLightStatus(i, &response);
|
||||||
response += "},";
|
response += "},";
|
||||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||||
response.replace("{j1}", sysCfg.friendlyname[i-1]);
|
response.replace("{j1}", Settings.friendlyname[i-1]);
|
||||||
response.replace("{j2}", hue_deviceId(i));
|
response.replace("{j2}", GetHueDeviceId(i));
|
||||||
if (i < maxhue) {
|
if (i < maxhue) {
|
||||||
response += ",\"";
|
response += ",\"";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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
|
else if (path->endsWith("/state")) { // Got ID/state
|
||||||
path->remove(0,8); // Remove /lights/
|
path->remove(0,8); // Remove /lights/
|
||||||
|
@ -548,11 +548,11 @@ void hue_lights(String *path)
|
||||||
if ((device < 1) || (device > maxhue)) {
|
if ((device < 1) || (device > maxhue)) {
|
||||||
device = 1;
|
device = 1;
|
||||||
}
|
}
|
||||||
if (1 == webServer->args()) {
|
if (1 == WebServer->args()) {
|
||||||
response = "[";
|
response = "[";
|
||||||
|
|
||||||
StaticJsonBuffer<400> jsonBuffer;
|
StaticJsonBuffer<400> jsonBuffer;
|
||||||
JsonObject &hue_json = jsonBuffer.parseObject(webServer->arg(0));
|
JsonObject &hue_json = jsonBuffer.parseObject(WebServer->arg(0));
|
||||||
if (hue_json.containsKey("on")) {
|
if (hue_json.containsKey("on")) {
|
||||||
|
|
||||||
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
response += FPSTR(HUE_LIGHT_RESPONSE_JSON);
|
||||||
|
@ -562,10 +562,10 @@ void hue_lights(String *path)
|
||||||
on = hue_json["on"];
|
on = hue_json["on"];
|
||||||
switch(on)
|
switch(on)
|
||||||
{
|
{
|
||||||
case false : do_cmnd_power(device, 0);
|
case false : ExecuteCommandPower(device, 0);
|
||||||
response.replace("{res}", "false");
|
response.replace("{res}", "false");
|
||||||
break;
|
break;
|
||||||
case true : do_cmnd_power(device, 1);
|
case true : ExecuteCommandPower(device, 1);
|
||||||
response.replace("{res}", "true");
|
response.replace("{res}", "true");
|
||||||
break;
|
break;
|
||||||
default : response.replace("{res}", (power & (1 << (device-1))) ? "true" : "false");
|
default : response.replace("{res}", (power & (1 << (device-1))) ? "true" : "false");
|
||||||
|
@ -574,8 +574,8 @@ void hue_lights(String *path)
|
||||||
resp = true;
|
resp = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sfl_flg) {
|
if (light_type) {
|
||||||
sl_getHSB(&hue,&sat,&bri);
|
LightGetHsb(&hue,&sat,&bri);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hue_json.containsKey("bri")) {
|
if (hue_json.containsKey("bri")) {
|
||||||
|
@ -628,8 +628,8 @@ void hue_lights(String *path)
|
||||||
change = true;
|
change = true;
|
||||||
}
|
}
|
||||||
if (change) {
|
if (change) {
|
||||||
if (sfl_flg) {
|
if (light_type) {
|
||||||
sl_setHSB(hue, sat, bri, ct);
|
LightSetHsb(hue, sat, bri, ct);
|
||||||
}
|
}
|
||||||
change = false;
|
change = false;
|
||||||
}
|
}
|
||||||
|
@ -642,7 +642,7 @@ void hue_lights(String *path)
|
||||||
response = FPSTR(HUE_ERROR_JSON);
|
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
|
else if(path->indexOf("/lights/") >= 0) { // Got /lights/ID
|
||||||
path->remove(0,8); // Remove /lights/
|
path->remove(0,8); // Remove /lights/
|
||||||
|
@ -651,25 +651,25 @@ void hue_lights(String *path)
|
||||||
device = 1;
|
device = 1;
|
||||||
}
|
}
|
||||||
response += F("{\"state\":{");
|
response += F("{\"state\":{");
|
||||||
hue_light_status(device, &response);
|
HueLightStatus(device, &response);
|
||||||
response += "},";
|
response += "},";
|
||||||
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
response += FPSTR(HUE_LIGHTS_STATUS_JSON);
|
||||||
response.replace("{j1}", sysCfg.friendlyname[device-1]);
|
response.replace("{j1}", Settings.friendlyname[device-1]);
|
||||||
response.replace("{j2}", hue_deviceId(device));
|
response.replace("{j2}", GetHueDeviceId(device));
|
||||||
webServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
WebServer->send(200, FPSTR(HDR_CTYPE_JSON), response);
|
||||||
}
|
}
|
||||||
else {
|
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"})
|
* http://sonoff/api/username/groups?1={"name":"Woonkamer","lights":[],"type":"Room","class":"Living room"})
|
||||||
*/
|
*/
|
||||||
String response = "{}";
|
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")) {
|
if (path->endsWith("/0")) {
|
||||||
response = FPSTR(HUE_GROUP0_STATUS_JSON);
|
response = FPSTR(HUE_GROUP0_STATUS_JSON);
|
||||||
|
@ -678,14 +678,14 @@ void hue_groups(String *path)
|
||||||
lights += ",\"" + String(i) + "\"";
|
lights += ",\"" + String(i) + "\"";
|
||||||
}
|
}
|
||||||
response.replace("{l1}", lights);
|
response.replace("{l1}", lights);
|
||||||
hue_light_status(1, &response);
|
HueLightStatus(1, &response);
|
||||||
response += F("}}");
|
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
|
/* 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
|
* 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
|
path->remove(0, 4); // remove /api
|
||||||
uint16_t apilen = path->length();
|
uint16_t apilen = path->length();
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_HTTP D_HUE_API " (%s)"), path->c_str());
|
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)
|
AddLog(LOG_LEVEL_DEBUG_MORE); // HTP: Hue API (//lights/1/state)
|
||||||
for (args = 0; args < webServer->args(); args++) {
|
for (args = 0; args < WebServer->args(); args++) {
|
||||||
String json = webServer->arg(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());
|
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
|
if (path->endsWith("/invalid/")) {} // Just ignore
|
||||||
else if (!apilen) hue_auth(path); // New HUE App setup
|
else if (!apilen) HueAuthentication(path); // New HUE App setup
|
||||||
else if (path->endsWith("/")) hue_auth(path); // New HUE App setup
|
else if (path->endsWith("/")) HueAuthentication(path); // New HUE App setup
|
||||||
else if (path->endsWith("/config")) hue_config(path);
|
else if (path->endsWith("/config")) HueConfig(path);
|
||||||
else if (path->indexOf("/lights") >= 0) hue_lights(path);
|
else if (path->indexOf("/lights") >= 0) HueLights(path);
|
||||||
else if (path->indexOf("/groups") >= 0) hue_groups(path);
|
else if (path->indexOf("/groups") >= 0) HueGroups(path);
|
||||||
else if (path->endsWith("/schedules")) hue_todo(path);
|
else if (path->endsWith("/schedules")) HueNotImplemented(path);
|
||||||
else if (path->endsWith("/sensors")) hue_todo(path);
|
else if (path->endsWith("/sensors")) HueNotImplemented(path);
|
||||||
else if (path->endsWith("/scenes")) hue_todo(path);
|
else if (path->endsWith("/scenes")) HueNotImplemented(path);
|
||||||
else if (path->endsWith("/rules")) hue_todo(path);
|
else if (path->endsWith("/rules")) HueNotImplemented(path);
|
||||||
else hue_global_cfg(path);
|
else HueGlobalConfig(path);
|
||||||
}
|
}
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
#endif // USE_EMULATION
|
#endif // USE_EMULATION
|
||||||
|
|
|
@ -38,45 +38,44 @@
|
||||||
#endif // USE_WS2812_CTYPE
|
#endif // USE_WS2812_CTYPE
|
||||||
#endif // USE_WS2812_DMA
|
#endif // USE_WS2812_DMA
|
||||||
|
|
||||||
struct wsColor {
|
struct WsColor {
|
||||||
uint8_t red, green, blue;
|
uint8_t red, green, blue;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct ColorScheme {
|
struct ColorScheme {
|
||||||
wsColor* colors;
|
WsColor* colors;
|
||||||
uint8_t count;
|
uint8_t count;
|
||||||
};
|
};
|
||||||
|
|
||||||
wsColor incandescent[2] = { 255, 140, 20, 0, 0, 0 };
|
WsColor kIncandescent[2] = { 255, 140, 20, 0, 0, 0 };
|
||||||
wsColor rgb[3] = { 255, 0, 0, 0, 255, 0, 0, 0, 255 };
|
WsColor kRgb[3] = { 255, 0, 0, 0, 255, 0, 0, 0, 255 };
|
||||||
wsColor christmas[2] = { 255, 0, 0, 0, 255, 0 };
|
WsColor kChristmas[2] = { 255, 0, 0, 0, 255, 0 };
|
||||||
wsColor hanukkah[2] = { 0, 0, 255, 255, 255, 255 };
|
WsColor kHanukkah[2] = { 0, 0, 255, 255, 255, 255 };
|
||||||
wsColor kwanzaa[3] = { 255, 0, 0, 0, 0, 0, 0, 255, 0 };
|
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 kRainbow[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 };
|
WsColor kFire[3] = { 255, 0, 0, 255, 102, 0, 255, 192, 0 };
|
||||||
ColorScheme schemes[7] = {
|
ColorScheme kSchemes[7] = {
|
||||||
incandescent, 2,
|
kIncandescent, 2,
|
||||||
rgb, 3,
|
kRgb, 3,
|
||||||
christmas, 2,
|
kChristmas, 2,
|
||||||
hanukkah, 2,
|
kHanukkah, 2,
|
||||||
kwanzaa, 3,
|
kwanzaa, 3,
|
||||||
rainbow, 7,
|
kRainbow, 7,
|
||||||
fire, 3 };
|
kFire, 3 };
|
||||||
|
|
||||||
uint8_t widthValues[5] = {
|
uint8_t kWidth[5] = {
|
||||||
1, // Small
|
1, // Small
|
||||||
2, // Medium
|
2, // Medium
|
||||||
4, // Large
|
4, // Large
|
||||||
8, // Largest
|
8, // Largest
|
||||||
255 }; // All
|
255 }; // All
|
||||||
uint8_t repeatValues[5] = {
|
uint8_t kRepeat[5] = {
|
||||||
8, // Small
|
8, // Small
|
||||||
6, // Medium
|
6, // Medium
|
||||||
4, // Large
|
4, // Large
|
||||||
2, // Largest
|
2, // Largest
|
||||||
1 }; // All
|
1 }; // All
|
||||||
|
uint8_t kSpeed[9] = {
|
||||||
uint8_t speedValues[9] = {
|
|
||||||
0, // None
|
0, // None
|
||||||
1 * (STATES / 10), // Fastest
|
1 * (STATES / 10), // Fastest
|
||||||
3 * (STATES / 10),
|
3 * (STATES / 10),
|
||||||
|
@ -87,16 +86,16 @@ uint8_t speedValues[9] = {
|
||||||
13 * (STATES / 10),
|
13 * (STATES / 10),
|
||||||
15 * (STATES / 10) }; // Slowest
|
15 * (STATES / 10) }; // Slowest
|
||||||
|
|
||||||
uint8_t ws2812_showNext = 1;
|
uint8_t ws_show_next = 1;
|
||||||
|
|
||||||
/********************************************************************************************/
|
/********************************************************************************************/
|
||||||
|
|
||||||
void ws2812_stripShow()
|
void Ws2812StripShow()
|
||||||
{
|
{
|
||||||
RgbColor c;
|
RgbColor c;
|
||||||
|
|
||||||
if (sysCfg.led_table) {
|
if (Settings.led_table) {
|
||||||
for (uint16_t i = 0; i < sysCfg.led_pixels; i++) {
|
for (uint16_t i = 0; i < Settings.led_pixels; i++) {
|
||||||
c = strip->GetPixelColor(i);
|
c = strip->GetPixelColor(i);
|
||||||
strip->SetPixelColor(i, RgbColor(ledTable[c.R], ledTable[c.G], ledTable[c.B]));
|
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;
|
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;
|
RgbColor c;
|
||||||
|
|
||||||
strip->ClearTo(0); // Reset strip
|
uint8_t hand_second_width = CLOCK_SECOND_WIDTH;
|
||||||
float newDim = 100 / (float)sysCfg.led_dimmer;
|
uint8_t hand_minute_width = CLOCK_MINUTE_WIDTH;
|
||||||
float f1 = 255 / newDim;
|
uint8_t hand_hour_width = CLOCK_HOUR_WIDTH;
|
||||||
uint8_t i1 = (uint8_t)f1;
|
RgbColor hand_second_color CLOCK_SECOND_COLOR;
|
||||||
float f2 = 127 / newDim;
|
RgbColor hand_minute_color CLOCK_MINUTE_COLOR;
|
||||||
uint8_t i2 = (uint8_t)f2;
|
RgbColor hand_hour_color CLOCK_HOUR_COLOR;
|
||||||
float f3 = 63 / newDim;
|
|
||||||
uint8_t i3 = (uint8_t)f3;
|
|
||||||
|
|
||||||
int j = sysCfg.led_pixels;
|
strip->ClearTo(0); // Reset strip
|
||||||
int clksize = 600 / j;
|
int clksize = 600 / (int)Settings.led_pixels;
|
||||||
int i = (rtcTime.Second * 10) / clksize;
|
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);
|
||||||
|
|
||||||
c = strip->GetPixelColor(mod(i, j)); c.B = i1; strip->SetPixelColor(mod(i, j), c);
|
Ws2812StripShow();
|
||||||
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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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.
|
* 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.
|
* This function is used internally by the gradient function.
|
||||||
*/
|
*/
|
||||||
ColorScheme scheme = schemes[schemenr];
|
ColorScheme scheme = kSchemes[schemenr];
|
||||||
uint16_t curRange = i / range;
|
uint16_t curRange = i / range;
|
||||||
uint16_t rangeIndex = i % range;
|
uint16_t rangeIndex = i % range;
|
||||||
uint16_t colorIndex = rangeIndex / gradRange;
|
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;
|
start = (scheme.count -1) - start;
|
||||||
end = (scheme.count -1) - end;
|
end = (scheme.count -1) - end;
|
||||||
}
|
}
|
||||||
float newDim = 100 / (float)sysCfg.led_dimmer;
|
float dimmer = 100 / (float)Settings.led_dimmer;
|
||||||
float fmyRed = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].red, scheme.colors[end].red) / newDim;
|
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) / newDim;
|
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) / newDim;
|
float fmyBlu = (float)map(rangeIndex % gradRange, 0, gradRange, scheme.colors[start].blue, scheme.colors[end].blue) / dimmer;
|
||||||
mColor->red = (uint8_t)fmyRed;
|
mColor->red = (uint8_t)fmyRed;
|
||||||
mColor->green = (uint8_t)fmyGrn;
|
mColor->green = (uint8_t)fmyGrn;
|
||||||
mColor->blue = (uint8_t)fmyBlu;
|
mColor->blue = (uint8_t)fmyBlu;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws2812_gradient(uint8_t schemenr)
|
void Ws2812Gradient(uint8_t schemenr)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This routine courtesy Tony DiCola (Adafruit)
|
* This routine courtesy Tony DiCola (Adafruit)
|
||||||
|
@ -178,28 +197,28 @@ void ws2812_gradient(uint8_t schemenr)
|
||||||
*/
|
*/
|
||||||
RgbColor c;
|
RgbColor c;
|
||||||
|
|
||||||
ColorScheme scheme = schemes[schemenr];
|
ColorScheme scheme = kSchemes[schemenr];
|
||||||
if (scheme.count < 2) {
|
if (scheme.count < 2) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t repeat = repeatValues[sysCfg.led_width]; // number of scheme.count per ledcount
|
uint8_t repeat = kRepeat[Settings.led_width]; // number of scheme.count per ledcount
|
||||||
uint16_t range = (uint16_t)ceil((float)sysCfg.led_pixels / (float)repeat);
|
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 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;
|
WsColor oldColor, currentColor;
|
||||||
ws2812_gradientColor(schemenr, &oldColor, range, gradRange, offset);
|
Ws2812GradientColor(schemenr, &oldColor, range, gradRange, offset);
|
||||||
currentColor = oldColor;
|
currentColor = oldColor;
|
||||||
for (uint16_t i = 0; i < sysCfg.led_pixels; i++) {
|
for (uint16_t i = 0; i < Settings.led_pixels; i++) {
|
||||||
if (repeatValues[sysCfg.led_width] > 1) {
|
if (kRepeat[Settings.led_width] > 1) {
|
||||||
ws2812_gradientColor(schemenr, ¤tColor, range, gradRange, i +offset);
|
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.
|
// 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.R = map(stripTimerCntr % kSpeed[Settings.led_speed], 0, kSpeed[Settings.led_speed], oldColor.red, currentColor.red);
|
||||||
c.G = map(stripTimerCntr % speedValues[sysCfg.led_speed], 0, speedValues[sysCfg.led_speed], oldColor.green, currentColor.green);
|
c.G = map(stripTimerCntr % kSpeed[Settings.led_speed], 0, kSpeed[Settings.led_speed], oldColor.green, currentColor.green);
|
||||||
c.B = map(stripTimerCntr % speedValues[sysCfg.led_speed], 0, speedValues[sysCfg.led_speed], oldColor.blue, currentColor.blue);
|
c.B = map(stripTimerCntr % kSpeed[Settings.led_speed], 0, kSpeed[Settings.led_speed], oldColor.blue, currentColor.blue);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// No animation, just use the current color.
|
// No animation, just use the current color.
|
||||||
|
@ -210,10 +229,10 @@ void ws2812_gradient(uint8_t schemenr)
|
||||||
strip->SetPixelColor(i, c);
|
strip->SetPixelColor(i, c);
|
||||||
oldColor = currentColor;
|
oldColor = currentColor;
|
||||||
}
|
}
|
||||||
ws2812_stripShow();
|
Ws2812StripShow();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws2812_bars(uint8_t schemenr)
|
void Ws2812Bars(uint8_t schemenr)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* This routine courtesy Tony DiCola (Adafruit)
|
* This routine courtesy Tony DiCola (Adafruit)
|
||||||
|
@ -223,44 +242,44 @@ void ws2812_bars(uint8_t schemenr)
|
||||||
RgbColor c;
|
RgbColor c;
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
|
|
||||||
ColorScheme scheme = schemes[schemenr];
|
ColorScheme scheme = kSchemes[schemenr];
|
||||||
|
|
||||||
uint16_t maxSize = sysCfg.led_pixels / scheme.count;
|
uint16_t maxSize = Settings.led_pixels / scheme.count;
|
||||||
if (widthValues[sysCfg.led_width] > maxSize) {
|
if (kWidth[Settings.led_width] > maxSize) {
|
||||||
maxSize = 0;
|
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));
|
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++) {
|
for (i = 0; i < scheme.count; i++) {
|
||||||
float fmyRed = (float)mcolor[i].red / newDim;
|
float fmyRed = (float)mcolor[i].red / dimmer;
|
||||||
float fmyGrn = (float)mcolor[i].green / newDim;
|
float fmyGrn = (float)mcolor[i].green / dimmer;
|
||||||
float fmyBlu = (float)mcolor[i].blue / newDim;
|
float fmyBlu = (float)mcolor[i].blue / dimmer;
|
||||||
mcolor[i].red = (uint8_t)fmyRed;
|
mcolor[i].red = (uint8_t)fmyRed;
|
||||||
mcolor[i].green = (uint8_t)fmyGrn;
|
mcolor[i].green = (uint8_t)fmyGrn;
|
||||||
mcolor[i].blue = (uint8_t)fmyBlu;
|
mcolor[i].blue = (uint8_t)fmyBlu;
|
||||||
}
|
}
|
||||||
uint8_t colorIndex = offset % scheme.count;
|
uint8_t colorIndex = offset % scheme.count;
|
||||||
for (i = 0; i < sysCfg.led_pixels; i++) {
|
for (i = 0; i < Settings.led_pixels; i++) {
|
||||||
if (maxSize) {
|
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.R = mcolor[colorIndex].red;
|
||||||
c.G = mcolor[colorIndex].green;
|
c.G = mcolor[colorIndex].green;
|
||||||
c.B = mcolor[colorIndex].blue;
|
c.B = mcolor[colorIndex].blue;
|
||||||
strip->SetPixelColor(i, c);
|
strip->SetPixelColor(i, c);
|
||||||
}
|
}
|
||||||
ws2812_stripShow();
|
Ws2812StripShow();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Public
|
* Public
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void ws2812_init()
|
void Ws2812Init()
|
||||||
{
|
{
|
||||||
#ifdef USE_WS2812_DMA
|
#ifdef USE_WS2812_DMA
|
||||||
#if (USE_WS2812_CTYPE == 1)
|
#if (USE_WS2812_CTYPE == 1)
|
||||||
|
@ -276,17 +295,17 @@ void ws2812_init()
|
||||||
#endif // USE_WS2812_CTYPE
|
#endif // USE_WS2812_CTYPE
|
||||||
#endif // USE_WS2812_DMA
|
#endif // USE_WS2812_DMA
|
||||||
strip->Begin();
|
strip->Begin();
|
||||||
ws2812_clear();
|
Ws2812Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws2812_clear()
|
void Ws2812Clear()
|
||||||
{
|
{
|
||||||
strip->ClearTo(0);
|
strip->ClearTo(0);
|
||||||
strip->Show();
|
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;
|
RgbColor lcolor;
|
||||||
lcolor.R = red;
|
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
|
strip->SetPixelColor(led -1, lcolor); // Led 1 is strip Led 0 -> substract offset 1
|
||||||
} else {
|
} else {
|
||||||
// strip->ClearTo(lcolor); // Set WS2812_MAX_LEDS pixels
|
// 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->SetPixelColor(i, lcolor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
strip->Show();
|
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];
|
uint8_t sl_ledcolor[3];
|
||||||
|
|
||||||
|
@ -319,22 +338,22 @@ char* ws2812_getColor(uint16_t led, char* scolor)
|
||||||
return scolor;
|
return scolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ws2812_showScheme(uint8_t scheme)
|
void Ws2812ShowScheme(uint8_t scheme)
|
||||||
{
|
{
|
||||||
switch (scheme) {
|
switch (scheme) {
|
||||||
case 0: // Clock
|
case 0: // Clock
|
||||||
if (((STATES/10)*2 == state) || (ws2812_showNext)) {
|
if (((STATES/10)*2 == state) || (ws_show_next)) {
|
||||||
ws2812_clock();
|
Ws2812Clock();
|
||||||
ws2812_showNext = 0;
|
ws_show_next = 0;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (1 == sysCfg.led_fade) {
|
if (1 == Settings.led_fade) {
|
||||||
ws2812_gradient(scheme -1);
|
Ws2812Gradient(scheme -1);
|
||||||
} else {
|
} else {
|
||||||
ws2812_bars(scheme -1);
|
Ws2812Bars(scheme -1);
|
||||||
}
|
}
|
||||||
ws2812_showNext = 1;
|
ws_show_next = 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,48 +28,48 @@
|
||||||
|
|
||||||
#define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10 // Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
#define BH1750_CONTINUOUS_HIGH_RES_MODE 0x10 // Start measurement at 1lx resolution. Measurement time is approx 120ms.
|
||||||
|
|
||||||
uint8_t bh1750addr;
|
uint8_t bh1750_address;
|
||||||
uint8_t bh1750type = 0;
|
uint8_t bh1750_type = 0;
|
||||||
char bh1750stype[7];
|
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 msb = Wire.read();
|
||||||
byte lsb = Wire.read();
|
byte lsb = Wire.read();
|
||||||
uint16_t value = ((msb << 8) | lsb) / 1.2;
|
uint16_t value = ((msb << 8) | lsb) / 1.2;
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean bh1750_detect()
|
boolean Bh1750Detect()
|
||||||
{
|
{
|
||||||
if (bh1750type) {
|
if (bh1750_type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t status;
|
uint8_t status;
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
bh1750addr = BH1750_ADDR1;
|
bh1750_address = BH1750_ADDR1;
|
||||||
Wire.beginTransmission(bh1750addr);
|
Wire.beginTransmission(bh1750_address);
|
||||||
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||||
status = Wire.endTransmission();
|
status = Wire.endTransmission();
|
||||||
if (status) {
|
if (status) {
|
||||||
bh1750addr = BH1750_ADDR2;
|
bh1750_address = BH1750_ADDR2;
|
||||||
Wire.beginTransmission(bh1750addr);
|
Wire.beginTransmission(bh1750_address);
|
||||||
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
Wire.write(BH1750_CONTINUOUS_HIGH_RES_MODE);
|
||||||
status = Wire.endTransmission();
|
status = Wire.endTransmission();
|
||||||
}
|
}
|
||||||
if (!status) {
|
if (!status) {
|
||||||
success = true;
|
success = true;
|
||||||
bh1750type = 1;
|
bh1750_type = 1;
|
||||||
strcpy_P(bh1750stype, PSTR("BH1750"));
|
strcpy_P(bh1750_types, PSTR("BH1750"));
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bh1750stype, bh1750addr);
|
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);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
} else {
|
} else {
|
||||||
bh1750type = 0;
|
bh1750_type = 0;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -78,17 +78,17 @@ boolean bh1750_detect()
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void bh1750_mqttPresent(uint8_t* djson)
|
void MqttShowBh1750(uint8_t* djson)
|
||||||
{
|
{
|
||||||
if (!bh1750type) {
|
if (!bh1750_type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint16_t l = bh1750_readLux();
|
uint16_t l = Bh1750ReadLux();
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_ILLUMINANCE "\":%d}"), mqtt_data, bh1750stype, l);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_ILLUMINANCE "\":%d}"), mqtt_data, bh1750_types, l);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
domoticz_sensor(DZ_ILLUMINANCE, l);
|
DomoticzSensor(DZ_ILLUMINANCE, l);
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,12 +96,12 @@ void bh1750_mqttPresent(uint8_t* djson)
|
||||||
const char HTTP_SNS_ILLUMINANCE[] PROGMEM =
|
const char HTTP_SNS_ILLUMINANCE[] PROGMEM =
|
||||||
"<tr><th>BH1750 " D_ILLUMINANCE "</th><td>%d " D_UNIT_LUX "</td></tr>";
|
"<tr><th>BH1750 " D_ILLUMINANCE "</th><td>%d " D_UNIT_LUX "</td></tr>";
|
||||||
|
|
||||||
String bh1750_webPresent()
|
String WebShowBh1750()
|
||||||
{
|
{
|
||||||
String page = "";
|
String page = "";
|
||||||
if (bh1750type) {
|
if (bh1750_type) {
|
||||||
char sensor[80];
|
char sensor[80];
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_ILLUMINANCE, bh1750_readLux());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_ILLUMINANCE, Bh1750ReadLux());
|
||||||
page += sensor;
|
page += sensor;
|
||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
|
|
|
@ -34,9 +34,9 @@
|
||||||
#define BMP_REGISTER_CHIPID 0xD0
|
#define BMP_REGISTER_CHIPID 0xD0
|
||||||
|
|
||||||
double bmp_sealevel = 0.0;
|
double bmp_sealevel = 0.0;
|
||||||
uint8_t bmpaddr;
|
uint8_t bmp_address;
|
||||||
uint8_t bmptype = 0;
|
uint8_t bmp_type = 0;
|
||||||
char bmpstype[7];
|
char bmp_types[7];
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* BMP085 and BME180
|
* BMP085 and BME180
|
||||||
|
@ -73,18 +73,18 @@ uint16_t cal_ac5;
|
||||||
uint16_t cal_ac6;
|
uint16_t cal_ac6;
|
||||||
int32_t bmp180_b5 = 0;
|
int32_t bmp180_b5 = 0;
|
||||||
|
|
||||||
boolean bmp180_calibration()
|
boolean Bmp180Calibration()
|
||||||
{
|
{
|
||||||
cal_ac1 = i2c_read16(bmpaddr, BMP180_AC1);
|
cal_ac1 = I2cRead16(bmp_address, BMP180_AC1);
|
||||||
cal_ac2 = i2c_read16(bmpaddr, BMP180_AC2);
|
cal_ac2 = I2cRead16(bmp_address, BMP180_AC2);
|
||||||
cal_ac3 = i2c_read16(bmpaddr, BMP180_AC3);
|
cal_ac3 = I2cRead16(bmp_address, BMP180_AC3);
|
||||||
cal_ac4 = i2c_read16(bmpaddr, BMP180_AC4);
|
cal_ac4 = I2cRead16(bmp_address, BMP180_AC4);
|
||||||
cal_ac5 = i2c_read16(bmpaddr, BMP180_AC5);
|
cal_ac5 = I2cRead16(bmp_address, BMP180_AC5);
|
||||||
cal_ac6 = i2c_read16(bmpaddr, BMP180_AC6);
|
cal_ac6 = I2cRead16(bmp_address, BMP180_AC6);
|
||||||
cal_b1 = i2c_read16(bmpaddr, BMP180_VB1);
|
cal_b1 = I2cRead16(bmp_address, BMP180_VB1);
|
||||||
cal_b2 = i2c_read16(bmpaddr, BMP180_VB2);
|
cal_b2 = I2cRead16(bmp_address, BMP180_VB2);
|
||||||
cal_mc = i2c_read16(bmpaddr, BMP180_MC);
|
cal_mc = I2cRead16(bmp_address, BMP180_MC);
|
||||||
cal_md = i2c_read16(bmpaddr, BMP180_MD);
|
cal_md = I2cRead16(bmp_address, BMP180_MD);
|
||||||
|
|
||||||
// Check for Errors in calibration data. Value never is 0x0000 or 0xFFFF
|
// 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) {
|
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;
|
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
|
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 x1 = (ut - (int32_t)cal_ac6) * ((int32_t)cal_ac5) >> 15;
|
||||||
int32_t x2 = ((int32_t)cal_mc << 11) / (x1 + (int32_t)cal_md);
|
int32_t x2 = ((int32_t)cal_mc << 11) / (x1 + (int32_t)cal_md);
|
||||||
bmp180_b5 = x1 + x2;
|
bmp180_b5 = x1 + x2;
|
||||||
|
@ -118,16 +118,16 @@ double bmp180_readTemperature()
|
||||||
return ((bmp180_b5 + 8) >> 4) / 10.0;
|
return ((bmp180_b5 + 8) >> 4) / 10.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bmp180_readPressure()
|
double Bmp180ReadPressure()
|
||||||
{
|
{
|
||||||
int32_t p;
|
int32_t p;
|
||||||
uint8_t msb;
|
uint8_t msb;
|
||||||
uint8_t lsb;
|
uint8_t lsb;
|
||||||
uint8_t xlsb;
|
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
|
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);
|
up >>= (8 - BMP180_OSS);
|
||||||
|
|
||||||
int32_t b6 = bmp180_b5 - 4000;
|
int32_t b6 = bmp180_b5 - 4000;
|
||||||
|
@ -157,12 +157,6 @@ double bmp180_readPressure()
|
||||||
return p / 100.0; // convert to mbar
|
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
|
* 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_H5 0xE5
|
||||||
#define BME280_REGISTER_DIG_H6 0xE7
|
#define BME280_REGISTER_DIG_H6 0xE7
|
||||||
|
|
||||||
struct bme280_calib_data
|
struct BME280CALIBDATA
|
||||||
{
|
{
|
||||||
uint16_t dig_T1;
|
uint16_t dig_T1;
|
||||||
int16_t dig_T2;
|
int16_t dig_T2;
|
||||||
|
@ -214,133 +208,112 @@ struct bme280_calib_data
|
||||||
int16_t dig_H4;
|
int16_t dig_H4;
|
||||||
int16_t dig_H5;
|
int16_t dig_H5;
|
||||||
int8_t dig_H6;
|
int8_t dig_H6;
|
||||||
} _bme280_calib;
|
} Bme280CalibrationData;
|
||||||
|
|
||||||
int32_t t_fine;
|
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);
|
Bme280CalibrationData.dig_T1 = I2cRead16LE(bmp_address, BME280_REGISTER_DIG_T1);
|
||||||
_bme280_calib.dig_T2 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_T2);
|
Bme280CalibrationData.dig_T2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_T2);
|
||||||
_bme280_calib.dig_T3 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_T3);
|
Bme280CalibrationData.dig_T3 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_T3);
|
||||||
_bme280_calib.dig_P1 = i2c_read16_LE(bmpaddr, BME280_REGISTER_DIG_P1);
|
Bme280CalibrationData.dig_P1 = I2cRead16LE(bmp_address, BME280_REGISTER_DIG_P1);
|
||||||
_bme280_calib.dig_P2 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P2);
|
Bme280CalibrationData.dig_P2 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P2);
|
||||||
_bme280_calib.dig_P3 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P3);
|
Bme280CalibrationData.dig_P3 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P3);
|
||||||
_bme280_calib.dig_P4 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P4);
|
Bme280CalibrationData.dig_P4 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P4);
|
||||||
_bme280_calib.dig_P5 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P5);
|
Bme280CalibrationData.dig_P5 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P5);
|
||||||
_bme280_calib.dig_P6 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P6);
|
Bme280CalibrationData.dig_P6 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P6);
|
||||||
_bme280_calib.dig_P7 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P7);
|
Bme280CalibrationData.dig_P7 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P7);
|
||||||
_bme280_calib.dig_P8 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P8);
|
Bme280CalibrationData.dig_P8 = I2cReadS16_LE(bmp_address, BME280_REGISTER_DIG_P8);
|
||||||
_bme280_calib.dig_P9 = i2c_readS16_LE(bmpaddr, BME280_REGISTER_DIG_P9);
|
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);
|
||||||
|
|
||||||
// i2c_write8(bmpaddr, BME280_REGISTER_CONTROL, 0x3F); // Temp 1x oversampling, Press 16x oversampling, normal mode (Adafruit)
|
// Set before CONTROL_meas (DS 5.4.3)
|
||||||
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean bme280_calibrate()
|
double Bme280ReadTemperature(void)
|
||||||
{
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
// 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)
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
double bmp280_readTemperature(void)
|
|
||||||
{
|
{
|
||||||
int32_t var1;
|
int32_t var1;
|
||||||
int32_t var2;
|
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;
|
adc_T >>= 4;
|
||||||
|
|
||||||
var1 = ((((adc_T >> 3) - ((int32_t)_bme280_calib.dig_T1 << 1))) * ((int32_t)_bme280_calib.dig_T2)) >> 11;
|
var1 = ((((adc_T >> 3) - ((int32_t)Bme280CalibrationData.dig_T1 << 1))) * ((int32_t)Bme280CalibrationData.dig_T2)) >> 11;
|
||||||
var2 = (((((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1)) * ((adc_T >> 4) - ((int32_t)_bme280_calib.dig_T1))) >> 12) *
|
var2 = (((((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1)) * ((adc_T >> 4) - ((int32_t)Bme280CalibrationData.dig_T1))) >> 12) *
|
||||||
((int32_t)_bme280_calib.dig_T3)) >>
|
((int32_t)Bme280CalibrationData.dig_T3)) >>
|
||||||
14;
|
14;
|
||||||
t_fine = var1 + var2;
|
t_fine = var1 + var2;
|
||||||
double T = (t_fine * 5 + 128) >> 8;
|
double T = (t_fine * 5 + 128) >> 8;
|
||||||
return T / 100.0;
|
return T / 100.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bmp280_readPressure(void)
|
double Bme280ReadPressure(void)
|
||||||
{
|
{
|
||||||
int64_t var1;
|
int64_t var1;
|
||||||
int64_t var2;
|
int64_t var2;
|
||||||
int64_t p;
|
int64_t p;
|
||||||
|
|
||||||
// Must be done first to get the t_fine variable set up
|
// 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;
|
adc_P >>= 4;
|
||||||
|
|
||||||
var1 = ((int64_t)t_fine) - 128000;
|
var1 = ((int64_t)t_fine) - 128000;
|
||||||
var2 = var1 * var1 * (int64_t)_bme280_calib.dig_P6;
|
var2 = var1 * var1 * (int64_t)Bme280CalibrationData.dig_P6;
|
||||||
var2 = var2 + ((var1 * (int64_t)_bme280_calib.dig_P5) << 17);
|
var2 = var2 + ((var1 * (int64_t)Bme280CalibrationData.dig_P5) << 17);
|
||||||
var2 = var2 + (((int64_t)_bme280_calib.dig_P4) << 35);
|
var2 = var2 + (((int64_t)Bme280CalibrationData.dig_P4) << 35);
|
||||||
var1 = ((var1 * var1 * (int64_t)_bme280_calib.dig_P3) >> 8) + ((var1 * (int64_t)_bme280_calib.dig_P2) << 12);
|
var1 = ((var1 * var1 * (int64_t)Bme280CalibrationData.dig_P3) >> 8) + ((var1 * (int64_t)Bme280CalibrationData.dig_P2) << 12);
|
||||||
var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)_bme280_calib.dig_P1) >> 33;
|
var1 = (((((int64_t)1) << 47) + var1)) * ((int64_t)Bme280CalibrationData.dig_P1) >> 33;
|
||||||
if (0 == var1) {
|
if (0 == var1) {
|
||||||
return 0; // avoid exception caused by division by zero
|
return 0; // avoid exception caused by division by zero
|
||||||
}
|
}
|
||||||
p = 1048576 - adc_P;
|
p = 1048576 - adc_P;
|
||||||
p = (((p << 31) - var2) * 3125) / var1;
|
p = (((p << 31) - var2) * 3125) / var1;
|
||||||
var1 = (((int64_t)_bme280_calib.dig_P9) * (p >> 13) * (p >> 13)) >> 25;
|
var1 = (((int64_t)Bme280CalibrationData.dig_P9) * (p >> 13) * (p >> 13)) >> 25;
|
||||||
var2 = (((int64_t)_bme280_calib.dig_P8) * p) >> 19;
|
var2 = (((int64_t)Bme280CalibrationData.dig_P8) * p) >> 19;
|
||||||
p = ((p + var1 + var2) >> 8) + (((int64_t)_bme280_calib.dig_P7) << 4);
|
p = ((p + var1 + var2) >> 8) + (((int64_t)Bme280CalibrationData.dig_P7) << 4);
|
||||||
return (double)p / 25600.0;
|
return (double)p / 25600.0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bme280_readHumidity(void)
|
double Bme280ReadHumidity(void)
|
||||||
{
|
{
|
||||||
int32_t v_x1_u32r;
|
int32_t v_x1_u32r;
|
||||||
|
|
||||||
// Must be done first to get the t_fine variable set up
|
// 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 = (t_fine - ((int32_t)76800));
|
||||||
|
|
||||||
v_x1_u32r = (((((adc_H << 14) - (((int32_t)_bme280_calib.dig_H4) << 20) -
|
v_x1_u32r = (((((adc_H << 14) - (((int32_t)Bme280CalibrationData.dig_H4) << 20) -
|
||||||
(((int32_t)_bme280_calib.dig_H5) * v_x1_u32r)) +
|
(((int32_t)Bme280CalibrationData.dig_H5) * v_x1_u32r)) +
|
||||||
((int32_t)16384)) >>
|
((int32_t)16384)) >>
|
||||||
15) *
|
15) *
|
||||||
(((((((v_x1_u32r * ((int32_t)_bme280_calib.dig_H6)) >> 10) *
|
(((((((v_x1_u32r * ((int32_t)Bme280CalibrationData.dig_H6)) >> 10) *
|
||||||
(((v_x1_u32r * ((int32_t)_bme280_calib.dig_H3)) >> 11) + ((int32_t)32768))) >>
|
(((v_x1_u32r * ((int32_t)Bme280CalibrationData.dig_H3)) >> 11) + ((int32_t)32768))) >>
|
||||||
10) +
|
10) +
|
||||||
((int32_t)2097152)) *
|
((int32_t)2097152)) *
|
||||||
((int32_t)_bme280_calib.dig_H2) +
|
((int32_t)Bme280CalibrationData.dig_H2) +
|
||||||
8192) >>
|
8192) >>
|
||||||
14));
|
14));
|
||||||
v_x1_u32r = (v_x1_u32r - (((((v_x1_u32r >> 15) * (v_x1_u32r >> 15)) >> 7) *
|
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));
|
4));
|
||||||
v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r;
|
v_x1_u32r = (v_x1_u32r < 0) ? 0 : v_x1_u32r;
|
||||||
v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r;
|
v_x1_u32r = (v_x1_u32r > 419430400) ? 419430400 : v_x1_u32r;
|
||||||
|
@ -352,116 +325,92 @@ double bme280_readHumidity(void)
|
||||||
* BMP
|
* BMP
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
double fastPrecisePow(double a, double b)
|
double BmpReadTemperature(void)
|
||||||
{
|
|
||||||
// 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 t = NAN;
|
double t = NAN;
|
||||||
|
|
||||||
switch (bmptype)
|
switch (bmp_type)
|
||||||
{
|
{
|
||||||
case BMP180_CHIPID:
|
case BMP180_CHIPID:
|
||||||
t = bmp180_readTemperature();
|
t = Bmp180ReadTemperature();
|
||||||
break;
|
break;
|
||||||
case BMP280_CHIPID:
|
case BMP280_CHIPID:
|
||||||
case BME280_CHIPID:
|
case BME280_CHIPID:
|
||||||
t = bmp280_readTemperature();
|
t = Bme280ReadTemperature();
|
||||||
}
|
}
|
||||||
if (!isnan(t))
|
if (!isnan(t))
|
||||||
{
|
{
|
||||||
t = convertTemp(t);
|
t = ConvertTemp(t);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bmp_readPressure(void)
|
double BmpReadPressure(void)
|
||||||
{
|
{
|
||||||
double pressure = 0.0;
|
double pressure = 0.0;
|
||||||
|
|
||||||
switch (bmptype) {
|
switch (bmp_type) {
|
||||||
case BMP180_CHIPID:
|
case BMP180_CHIPID:
|
||||||
pressure = bmp180_readPressure();
|
pressure = Bmp180ReadPressure();
|
||||||
break;
|
break;
|
||||||
case BMP280_CHIPID:
|
case BMP280_CHIPID:
|
||||||
case BME280_CHIPID:
|
case BME280_CHIPID:
|
||||||
pressure = bmp280_readPressure();
|
pressure = Bme280ReadPressure();
|
||||||
}
|
}
|
||||||
if (pressure != 0.0) {
|
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 / pow(1.0 - ((float)Settings.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 / FastPrecisePow(1.0 - ((float)Settings.altitude / 44330.0), 5.255)) - 21.6;
|
||||||
}
|
}
|
||||||
return pressure;
|
return pressure;
|
||||||
}
|
}
|
||||||
|
|
||||||
double bmp_readHumidity(void)
|
double BmpReadHumidity(void)
|
||||||
{
|
{
|
||||||
switch (bmptype) {
|
switch (bmp_type) {
|
||||||
case BMP180_CHIPID:
|
case BMP180_CHIPID:
|
||||||
case BMP280_CHIPID:
|
case BMP280_CHIPID:
|
||||||
break;
|
break;
|
||||||
case BME280_CHIPID:
|
case BME280_CHIPID:
|
||||||
return bme280_readHumidity();
|
return Bme280ReadHumidity();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean bmp_detect()
|
boolean BmpDetect()
|
||||||
{
|
{
|
||||||
if (bmptype) {
|
if (bmp_type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
bmpaddr = BMP_ADDR;
|
bmp_address = BMP_ADDR;
|
||||||
bmptype = i2c_read8(bmpaddr, BMP_REGISTER_CHIPID);
|
bmp_type = I2cRead8(bmp_address, BMP_REGISTER_CHIPID);
|
||||||
if (!bmptype) {
|
if (!bmp_type) {
|
||||||
bmpaddr--;
|
bmp_address--;
|
||||||
bmptype = i2c_read8(bmpaddr, BMP_REGISTER_CHIPID);
|
bmp_type = I2cRead8(bmp_address, BMP_REGISTER_CHIPID);
|
||||||
}
|
}
|
||||||
strcpy_P(bmpstype, PSTR("BMP"));
|
strcpy_P(bmp_types, PSTR("BMP"));
|
||||||
switch (bmptype) {
|
switch (bmp_type) {
|
||||||
case BMP180_CHIPID:
|
case BMP180_CHIPID:
|
||||||
success = bmp180_calibration();
|
success = Bmp180Calibration();
|
||||||
strcpy_P(bmpstype, PSTR("BMP180"));
|
strcpy_P(bmp_types, PSTR("BMP180"));
|
||||||
break;
|
break;
|
||||||
case BMP280_CHIPID:
|
case BMP280_CHIPID:
|
||||||
success = bmp280_calibrate();
|
success = Bmx280Calibrate();
|
||||||
strcpy_P(bmpstype, PSTR("BMP280"));
|
strcpy_P(bmp_types, PSTR("BMP280"));
|
||||||
break;
|
break;
|
||||||
case BME280_CHIPID:
|
case BME280_CHIPID:
|
||||||
success = bme280_calibrate();
|
success = Bmx280Calibrate();
|
||||||
strcpy_P(bmpstype, PSTR("BME280"));
|
strcpy_P(bmp_types, PSTR("BME280"));
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), bmpstype, bmpaddr);
|
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);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
bmptype = 0;
|
bmp_type = 0;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -470,66 +419,66 @@ boolean bmp_detect()
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void bmp_mqttPresent(uint8_t *djson)
|
void MqttShowBmp(uint8_t *djson)
|
||||||
{
|
{
|
||||||
if (!bmptype) {
|
if (!bmp_type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char stemp1[10];
|
char temperature[10];
|
||||||
char stemp2[10];
|
char pressure[10];
|
||||||
char stemp3[10];
|
char humidity[10];
|
||||||
char stemp4[10];
|
char sea_pressure[10];
|
||||||
char sealevel[40];
|
char sealevel[40];
|
||||||
|
|
||||||
double t = bmp_readTemperature();
|
double t = BmpReadTemperature();
|
||||||
double p = bmp_readPressure();
|
double p = BmpReadPressure();
|
||||||
double h = bmp_readHumidity();
|
double h = BmpReadHumidity();
|
||||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
dtostrfd(t, Settings.flag.temperature_resolution, temperature);
|
||||||
dtostrfd(p, sysCfg.flag.pressure_resolution, stemp2);
|
dtostrfd(p, Settings.flag.pressure_resolution, pressure);
|
||||||
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp3);
|
dtostrfd(h, Settings.flag.humidity_resolution, humidity);
|
||||||
|
|
||||||
dtostrfd(bmp_sealevel, sysCfg.flag.pressure_resolution, stemp4);
|
dtostrfd(bmp_sealevel, Settings.flag.pressure_resolution, sea_pressure);
|
||||||
snprintf_P(sealevel, sizeof(sealevel), PSTR(", \"" D_PRESSUREATSEALEVEL "\":%s"), stemp4);
|
snprintf_P(sealevel, sizeof(sealevel), PSTR(", \"" D_PRESSUREATSEALEVEL "\":%s"), sea_pressure);
|
||||||
if (!strcmp(bmpstype, "BME280")) {
|
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}"),
|
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 {
|
else {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"%s\":{\"" D_TEMPERATURE "\":%s, \"" D_PRESSURE "\":%s%s}"),
|
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;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
domoticz_sensor3(stemp1, stemp3, stemp2);
|
DomoticzTempHumPressureSensor(temperature, humidity, pressure);
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
String bmp_webPresent()
|
String WebShowBmp()
|
||||||
{
|
{
|
||||||
String page = "";
|
String page = "";
|
||||||
if (bmptype) {
|
if (bmp_type) {
|
||||||
char stemp[10];
|
char stemp[10];
|
||||||
char sensor[80];
|
char sensor[80];
|
||||||
|
|
||||||
double t_bmp = bmp_readTemperature();
|
double t = BmpReadTemperature();
|
||||||
double p_bmp = bmp_readPressure();
|
double p = BmpReadPressure();
|
||||||
double h_bmp = bmp_readHumidity();
|
double h = BmpReadHumidity();
|
||||||
dtostrfi(t_bmp, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, bmpstype, stemp, tempUnit());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, bmp_types, stemp, TempUnit());
|
||||||
page += sensor;
|
page += sensor;
|
||||||
if (!strcmp(bmpstype, "BME280")) {
|
if (BME280_CHIPID == bmp_type) {
|
||||||
dtostrfi(h_bmp, sysCfg.flag.humidity_resolution, stemp);
|
dtostrfi(h, Settings.flag.humidity_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, bmpstype, stemp);
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, bmp_types, stemp);
|
||||||
page += sensor;
|
page += sensor;
|
||||||
}
|
}
|
||||||
dtostrfi(p_bmp, sysCfg.flag.pressure_resolution, stemp);
|
dtostrfi(p, Settings.flag.pressure_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSURE, bmpstype, stemp);
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSURE, bmp_types, stemp);
|
||||||
page += sensor;
|
page += sensor;
|
||||||
if (sysCfg.altitude != 0) {
|
if (Settings.altitude != 0) {
|
||||||
dtostrfi(bmp_sealevel, sysCfg.flag.pressure_resolution, stemp);
|
dtostrfi(bmp_sealevel, Settings.flag.pressure_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSUREATSEALEVEL, bmpstype, stemp);
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_PRESSUREATSEALEVEL, bmp_types, stemp);
|
||||||
page += sensor;
|
page += sensor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,57 +21,57 @@
|
||||||
* Counter sensors (water meters, electricity meters etc.)
|
* 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];
|
unsigned long counter_debounce_time = millis() - last_counter_timer[index -1];
|
||||||
if (pTime > sysCfg.pCounterDebounce) {
|
if (counter_debounce_time > Settings.pulse_counter_debounce) {
|
||||||
pTimeLast[index -1] = millis();
|
last_counter_timer[index -1] = millis();
|
||||||
if (bitRead(sysCfg.pCounterType, index -1)) {
|
if (bitRead(Settings.pulse_counter_type, index -1)) {
|
||||||
rtcMem.pCounter[index -1] = pTime;
|
RtcSettings.pulse_counter[index -1] = counter_debounce_time;
|
||||||
} else {
|
} else {
|
||||||
rtcMem.pCounter[index -1]++;
|
RtcSettings.pulse_counter[index -1]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// snprintf_P(log_data, sizeof(log_data), PSTR("CNTR: Interrupt %d"), index);
|
// 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++) {
|
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
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) () ;
|
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++) {
|
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||||
|
@ -85,24 +85,24 @@ void counter_init()
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void counter_mqttPresent(uint8_t* djson)
|
void MqttShowCounter(uint8_t* djson)
|
||||||
{
|
{
|
||||||
char stemp[16];
|
char stemp[16];
|
||||||
|
|
||||||
byte dsxflg = 0;
|
byte dsxflg = 0;
|
||||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||||
if (bitRead(sysCfg.pCounterType, i)) {
|
if (bitRead(Settings.pulse_counter_type, i)) {
|
||||||
dtostrfd((double)rtcMem.pCounter[i] / 1000, 3, stemp);
|
dtostrfd((double)RtcSettings.pulse_counter[i] / 1000, 3, stemp);
|
||||||
} else {
|
} else {
|
||||||
dsxflg++;
|
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);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"" D_COUNTER "%d\":%s"), mqtt_data, i +1, stemp);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
if (1 == dsxflg) {
|
if (1 == dsxflg) {
|
||||||
domoticz_sensor(DZ_COUNT, rtcMem.pCounter[i]);
|
DomoticzSensor(DZ_COUNT, RtcSettings.pulse_counter[i]);
|
||||||
dsxflg++;
|
dsxflg++;
|
||||||
}
|
}
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
|
@ -114,7 +114,7 @@ void counter_mqttPresent(uint8_t* djson)
|
||||||
const char HTTP_SNS_COUNTER[] PROGMEM =
|
const char HTTP_SNS_COUNTER[] PROGMEM =
|
||||||
"<tr><th>" D_COUNTER "%d</th><td>%s%s</td></tr>";
|
"<tr><th>" D_COUNTER "%d</th><td>%s%s</td></tr>";
|
||||||
|
|
||||||
String counter_webPresent()
|
String WebShowCounter()
|
||||||
{
|
{
|
||||||
String page = "";
|
String page = "";
|
||||||
char stemp[16];
|
char stemp[16];
|
||||||
|
@ -122,12 +122,12 @@ String counter_webPresent()
|
||||||
|
|
||||||
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
for (byte i = 0; i < MAX_COUNTERS; i++) {
|
||||||
if (pin[GPIO_CNTR1 +i] < 99) {
|
if (pin[GPIO_CNTR1 +i] < 99) {
|
||||||
if (bitRead(sysCfg.pCounterType, i)) {
|
if (bitRead(Settings.pulse_counter_type, i)) {
|
||||||
dtostrfi((double)rtcMem.pCounter[i] / 1000, 3, stemp);
|
dtostrfi((double)RtcSettings.pulse_counter[i] / 1000, 3, stemp);
|
||||||
} else {
|
} 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;
|
page += sensor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@
|
||||||
#define DHT_MAX_SENSORS 3
|
#define DHT_MAX_SENSORS 3
|
||||||
#define MIN_INTERVAL 2000
|
#define MIN_INTERVAL 2000
|
||||||
|
|
||||||
uint32_t dht_maxcycles;
|
uint32_t dht_max_cycles;
|
||||||
uint8_t dht_data[5];
|
uint8_t dht_data[5];
|
||||||
byte dht_sensors = 0;
|
byte dht_sensors = 0;
|
||||||
|
|
||||||
|
@ -43,26 +43,26 @@ struct DHTSTRUCT {
|
||||||
float h = 0;
|
float h = 0;
|
||||||
} dht[DHT_MAX_SENSORS];
|
} dht[DHT_MAX_SENSORS];
|
||||||
|
|
||||||
void dht_readPrep()
|
void DhtReadPrep()
|
||||||
{
|
{
|
||||||
for (byte i = 0; i < dht_sensors; i++) {
|
for (byte i = 0; i < dht_sensors; i++) {
|
||||||
digitalWrite(dht[i].pin, HIGH);
|
digitalWrite(dht[i].pin, HIGH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t dht_expectPulse(byte sensor, bool level)
|
uint32_t DhtExpectPulse(byte sensor, bool level)
|
||||||
{
|
{
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
|
|
||||||
while (digitalRead(dht[sensor].pin) == level) {
|
while (digitalRead(dht[sensor].pin) == level) {
|
||||||
if (count++ >= dht_maxcycles) {
|
if (count++ >= dht_max_cycles) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dht_read(byte sensor)
|
void DhtRead(byte sensor)
|
||||||
{
|
{
|
||||||
uint32_t cycles[80];
|
uint32_t cycles[80];
|
||||||
uint32_t currenttime = millis();
|
uint32_t currenttime = millis();
|
||||||
|
@ -86,19 +86,19 @@ void dht_read(byte sensor)
|
||||||
delayMicroseconds(40);
|
delayMicroseconds(40);
|
||||||
pinMode(dht[sensor].pin, INPUT_PULLUP);
|
pinMode(dht[sensor].pin, INPUT_PULLUP);
|
||||||
delayMicroseconds(10);
|
delayMicroseconds(10);
|
||||||
if (0 == dht_expectPulse(sensor, LOW)) {
|
if (0 == DhtExpectPulse(sensor, LOW)) {
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_LOW " " D_PULSE));
|
||||||
dht[sensor].lastresult++;
|
dht[sensor].lastresult++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (0 == dht_expectPulse(sensor, HIGH)) {
|
if (0 == DhtExpectPulse(sensor, HIGH)) {
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_HIGH " " D_PULSE));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DHT D_TIMEOUT_WAITING_FOR " " D_START_SIGNAL_HIGH " " D_PULSE));
|
||||||
dht[sensor].lastresult++;
|
dht[sensor].lastresult++;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < 80; i += 2) {
|
for (int i = 0; i < 80; i += 2) {
|
||||||
cycles[i] = dht_expectPulse(sensor, LOW);
|
cycles[i] = DhtExpectPulse(sensor, LOW);
|
||||||
cycles[i+1] = dht_expectPulse(sensor, HIGH);
|
cycles[i+1] = DhtExpectPulse(sensor, HIGH);
|
||||||
}
|
}
|
||||||
interrupts();
|
interrupts();
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ void dht_read(byte sensor)
|
||||||
uint32_t lowCycles = cycles[2*i];
|
uint32_t lowCycles = cycles[2*i];
|
||||||
uint32_t highCycles = cycles[2*i+1];
|
uint32_t highCycles = cycles[2*i+1];
|
||||||
if ((0 == lowCycles) || (0 == highCycles)) {
|
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++;
|
dht[sensor].lastresult++;
|
||||||
return;
|
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"),
|
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);
|
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)) {
|
if (dht_data[4] == ((dht_data[0] + dht_data[1] + dht_data[2] + dht_data[3]) & 0xFF)) {
|
||||||
dht[sensor].lastresult = 0;
|
dht[sensor].lastresult = 0;
|
||||||
} else {
|
} 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++;
|
dht[sensor].lastresult++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dht_readTempHum(byte sensor, float &t, float &h)
|
boolean DhtReadTempHum(byte sensor, float &t, float &h)
|
||||||
{
|
{
|
||||||
if (!dht[sensor].h) {
|
if (!dht[sensor].h) {
|
||||||
t = NAN;
|
t = NAN;
|
||||||
|
@ -142,12 +142,12 @@ boolean dht_readTempHum(byte sensor, float &t, float &h)
|
||||||
h = dht[sensor].h;
|
h = dht[sensor].h;
|
||||||
}
|
}
|
||||||
|
|
||||||
dht_read(sensor);
|
DhtRead(sensor);
|
||||||
if (!dht[sensor].lastresult) {
|
if (!dht[sensor].lastresult) {
|
||||||
switch (dht[sensor].type) {
|
switch (dht[sensor].type) {
|
||||||
case GPIO_DHT11:
|
case GPIO_DHT11:
|
||||||
h = dht_data[0];
|
h = dht_data[0];
|
||||||
t = convertTemp(dht_data[2]);
|
t = ConvertTemp(dht_data[2]);
|
||||||
break;
|
break;
|
||||||
case GPIO_DHT22:
|
case GPIO_DHT22:
|
||||||
case GPIO_DHT21:
|
case GPIO_DHT21:
|
||||||
|
@ -162,7 +162,7 @@ boolean dht_readTempHum(byte sensor, float &t, float &h)
|
||||||
if (dht_data[2] & 0x80) {
|
if (dht_data[2] & 0x80) {
|
||||||
t *= -1;
|
t *= -1;
|
||||||
}
|
}
|
||||||
t = convertTemp(t);
|
t = ConvertTemp(t);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!isnan(t)) {
|
if (!isnan(t)) {
|
||||||
|
@ -175,7 +175,7 @@ boolean dht_readTempHum(byte sensor, float &t, float &h)
|
||||||
return (!isnan(t) && !isnan(h));
|
return (!isnan(t) && !isnan(h));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dht_setup(byte pin, byte type)
|
boolean DhtSetup(byte pin, byte type)
|
||||||
{
|
{
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
|
@ -188,9 +188,9 @@ boolean dht_setup(byte pin, byte type)
|
||||||
return success;
|
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++) {
|
for (byte i = 0; i < dht_sensors; i++) {
|
||||||
pinMode(dht[i].pin, INPUT_PULLUP);
|
pinMode(dht[i].pin, INPUT_PULLUP);
|
||||||
|
@ -216,7 +216,7 @@ void dht_init()
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void dht_mqttPresent(uint8_t* djson)
|
void MqttShowDht(uint8_t* djson)
|
||||||
{
|
{
|
||||||
char stemp1[10];
|
char stemp1[10];
|
||||||
char stemp2[10];
|
char stemp2[10];
|
||||||
|
@ -225,14 +225,14 @@ void dht_mqttPresent(uint8_t* djson)
|
||||||
|
|
||||||
byte dsxflg = 0;
|
byte dsxflg = 0;
|
||||||
for (byte i = 0; i < dht_sensors; i++) {
|
for (byte i = 0; i < dht_sensors; i++) {
|
||||||
if (dht_readTempHum(i, t, h)) { // Read temperature
|
if (DhtReadTempHum(i, t, h)) { // Read temperature
|
||||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||||
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
|
dtostrfd(h, Settings.flag.humidity_resolution, stemp2);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, dht[i].stype, stemp1, stemp2);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, dht[i].stype, stemp1, stemp2);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
if (!dsxflg) {
|
if (!dsxflg) {
|
||||||
domoticz_sensor2(stemp1, stemp2);
|
DomoticzTempHumSensor(stemp1, stemp2);
|
||||||
dsxflg++;
|
dsxflg++;
|
||||||
}
|
}
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
|
@ -241,7 +241,7 @@ void dht_mqttPresent(uint8_t* djson)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
String dht_webPresent()
|
String WebShowDht()
|
||||||
{
|
{
|
||||||
String page = "";
|
String page = "";
|
||||||
char stemp[10];
|
char stemp[10];
|
||||||
|
@ -250,11 +250,11 @@ String dht_webPresent()
|
||||||
float h;
|
float h;
|
||||||
|
|
||||||
for (byte i = 0; i < dht_sensors; i++) {
|
for (byte i = 0; i < dht_sensors; i++) {
|
||||||
if (dht_readTempHum(i, t, h)) {
|
if (DhtReadTempHum(i, t, h)) {
|
||||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, dht[i].stype, stemp, tempUnit());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, dht[i].stype, stemp, TempUnit());
|
||||||
page += sensor;
|
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);
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, dht[i].stype, stemp);
|
||||||
page += sensor;
|
page += sensor;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,10 +24,10 @@
|
||||||
* Source: Marinus vd Broek https://github.com/ESP8266nu/ESPEasy and AlexTransit (CRC)
|
* Source: Marinus vd Broek https://github.com/ESP8266nu/ESPEasy and AlexTransit (CRC)
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
float dsb_mt = 0;
|
float ds18b20_last_temperature = 0;
|
||||||
uint16_t dsb_lastresult = 0;
|
uint16_t ds18b20_last_result = 0;
|
||||||
|
|
||||||
uint8_t dsb_reset()
|
uint8_t Ds18b20Reset()
|
||||||
{
|
{
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
uint8_t retries = 125;
|
uint8_t retries = 125;
|
||||||
|
@ -49,7 +49,7 @@ uint8_t dsb_reset()
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t dsb_read_bit(void)
|
uint8_t Ds18b20ReadBit(void)
|
||||||
{
|
{
|
||||||
uint8_t r;
|
uint8_t r;
|
||||||
|
|
||||||
|
@ -63,20 +63,20 @@ uint8_t dsb_read_bit(void)
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t dsb_read(void)
|
uint8_t Ds18b20Read(void)
|
||||||
{
|
{
|
||||||
uint8_t bitMask;
|
uint8_t bit_mask;
|
||||||
uint8_t r = 0;
|
uint8_t r = 0;
|
||||||
|
|
||||||
for (bitMask = 1; bitMask; bitMask <<= 1) {
|
for (bit_mask = 1; bit_mask; bit_mask <<= 1) {
|
||||||
if (dsb_read_bit()) {
|
if (Ds18b20ReadBit()) {
|
||||||
r |= bitMask;
|
r |= bit_mask;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dsb_write_bit(uint8_t v)
|
void Ds18b20WriteBit(uint8_t v)
|
||||||
{
|
{
|
||||||
if (v & 1) {
|
if (v & 1) {
|
||||||
digitalWrite(pin[GPIO_DSB], LOW);
|
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) {
|
for (bit_mask = 1; bit_mask; bit_mask <<= 1) {
|
||||||
dsb_write_bit((bitMask & ByteToWrite) ? 1 : 0);
|
Ds18b20WriteBit((bit_mask & byte_to_write) ? 1 : 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8 dsb_crc(uint8 inp, uint8 crc)
|
uint8 Ds18b20Crc(uint8 inp, uint8 crc)
|
||||||
{
|
{
|
||||||
inp ^= crc;
|
inp ^= crc;
|
||||||
crc = 0;
|
crc = 0;
|
||||||
|
@ -117,66 +117,66 @@ uint8 dsb_crc(uint8 inp, uint8 crc)
|
||||||
return crc;
|
return crc;
|
||||||
}
|
}
|
||||||
|
|
||||||
void dsb_readTempPrep()
|
void Ds18b20ReadTempPrep()
|
||||||
{
|
{
|
||||||
dsb_reset();
|
Ds18b20Reset();
|
||||||
dsb_write(0xCC); // Skip ROM
|
Ds18b20Write(0xCC); // Skip ROM
|
||||||
dsb_write(0x44); // Start conversion
|
Ds18b20Write(0x44); // Start conversion
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dsb_readTemp(float &t)
|
boolean Ds18b20ReadTemperature(float &t)
|
||||||
{
|
{
|
||||||
int16_t DSTemp;
|
int16_t DSTemp;
|
||||||
byte msb, lsb, crc, sign = 1;
|
byte msb, lsb, crc, sign = 1;
|
||||||
|
|
||||||
if (!dsb_mt) {
|
if (!ds18b20_last_temperature) {
|
||||||
t = NAN;
|
t = NAN;
|
||||||
} else {
|
} else {
|
||||||
dsb_lastresult++;
|
ds18b20_last_result++;
|
||||||
if (dsb_lastresult > 8) { // Reset after 8 misses
|
if (ds18b20_last_result > 8) { // Reset after 8 misses
|
||||||
dsb_mt = NAN;
|
ds18b20_last_temperature = NAN;
|
||||||
}
|
}
|
||||||
t = dsb_mt;
|
t = ds18b20_last_temperature;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!dsb_read_bit()) { //check measurement end
|
if (!Ds18b20ReadBit()) { //check measurement end
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_BUSY));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_DSB D_SENSOR_BUSY));
|
||||||
return !isnan(t);
|
return !isnan(t);
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
dsb_reset();
|
Ds18b20Reset();
|
||||||
dsb_write(0xCC); // Skip ROM
|
Ds18b20Write(0xCC); // Skip ROM
|
||||||
dsb_write(0x44); // Start conversion
|
Ds18b20Write(0x44); // Start conversion
|
||||||
delay(800);
|
delay(800);
|
||||||
*/
|
*/
|
||||||
dsb_reset();
|
Ds18b20Reset();
|
||||||
dsb_write(0xCC); // Skip ROM
|
Ds18b20Write(0xCC); // Skip ROM
|
||||||
dsb_write(0xBE); // Read scratchpad
|
Ds18b20Write(0xBE); // Read scratchpad
|
||||||
lsb = dsb_read();
|
lsb = Ds18b20Read();
|
||||||
msb = dsb_read();
|
msb = Ds18b20Read();
|
||||||
crc = dsb_crc(lsb, crc);
|
crc = Ds18b20Crc(lsb, crc);
|
||||||
crc = dsb_crc(msb, crc);
|
crc = Ds18b20Crc(msb, crc);
|
||||||
crc = dsb_crc(dsb_read(), crc);
|
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||||
crc = dsb_crc(dsb_read(), crc);
|
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||||
crc = dsb_crc(dsb_read(), crc);
|
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||||
crc = dsb_crc(dsb_read(), crc);
|
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||||
crc = dsb_crc(dsb_read(), crc);
|
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||||
crc = dsb_crc(dsb_read(), crc);
|
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||||
crc = dsb_crc(dsb_read(), crc);
|
crc = Ds18b20Crc(Ds18b20Read(), crc);
|
||||||
dsb_reset();
|
Ds18b20Reset();
|
||||||
if (crc) { //check crc
|
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 {
|
} else {
|
||||||
DSTemp = (msb << 8) + lsb;
|
DSTemp = (msb << 8) + lsb;
|
||||||
if (DSTemp > 2047) {
|
if (DSTemp > 2047) {
|
||||||
DSTemp = (~DSTemp) +1;
|
DSTemp = (~DSTemp) +1;
|
||||||
sign = -1;
|
sign = -1;
|
||||||
}
|
}
|
||||||
t = convertTemp((float)sign * DSTemp * 0.0625);
|
t = ConvertTemp((float)sign * DSTemp * 0.0625);
|
||||||
dsb_lastresult = 0;
|
ds18b20_last_result = 0;
|
||||||
}
|
}
|
||||||
if (!isnan(t)) {
|
if (!isnan(t)) {
|
||||||
dsb_mt = t;
|
ds18b20_last_temperature = t;
|
||||||
}
|
}
|
||||||
return !isnan(t);
|
return !isnan(t);
|
||||||
}
|
}
|
||||||
|
@ -185,37 +185,37 @@ boolean dsb_readTemp(float &t)
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void dsb_mqttPresent(uint8_t* djson)
|
void MqttShowDs18b20(uint8_t* djson)
|
||||||
{
|
{
|
||||||
char stemp1[10];
|
char stemp1[10];
|
||||||
float t;
|
float t;
|
||||||
|
|
||||||
if (dsb_readTemp(t)) { // Check if read failed
|
if (Ds18b20ReadTemperature(t)) { // Check if read failed
|
||||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18B20\":{\"" D_TEMPERATURE "\":%s}"), mqtt_data, stemp1);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18B20\":{\"" D_TEMPERATURE "\":%s}"), mqtt_data, stemp1);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
domoticz_sensor(DZ_TEMP, stemp1);
|
DomoticzSensor(DZ_TEMP, stemp1);
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
String dsb_webPresent()
|
String WebShowDs18b20()
|
||||||
{
|
{
|
||||||
// Needs TelePeriod to refresh data (Do not do it here as it takes too much time)
|
// Needs TelePeriod to refresh data (Do not do it here as it takes too much time)
|
||||||
String page = "";
|
String page = "";
|
||||||
float st;
|
float st;
|
||||||
|
|
||||||
if (dsb_readTemp(st)) { // Check if read failed
|
if (Ds18b20ReadTemperature(st)) { // Check if read failed
|
||||||
char stemp[10];
|
char stemp[10];
|
||||||
char sensor[80];
|
char sensor[80];
|
||||||
|
|
||||||
dtostrfi(st, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfi(st, Settings.flag.temperature_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "DS18B20", stemp, tempUnit());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "DS18B20", stemp, TempUnit());
|
||||||
page += sensor;
|
page += sensor;
|
||||||
}
|
}
|
||||||
dsb_readTempPrep();
|
Ds18b20ReadTempPrep();
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
|
@ -36,64 +36,62 @@
|
||||||
|
|
||||||
OneWire *ds = NULL;
|
OneWire *ds = NULL;
|
||||||
|
|
||||||
uint8_t ds18x20_addr[DS18X20_MAX_SENSORS][8];
|
uint8_t ds18x20_address[DS18X20_MAX_SENSORS][8];
|
||||||
uint8_t ds18x20_idx[DS18X20_MAX_SENSORS];
|
uint8_t ds18x20_index[DS18X20_MAX_SENSORS];
|
||||||
uint8_t ds18x20_snsrs = 0;
|
uint8_t ds18x20_sensors = 0;
|
||||||
char dsbstype[9];
|
char ds18x20_types[9];
|
||||||
|
|
||||||
void ds18x20_init()
|
void Ds18x20Init()
|
||||||
{
|
{
|
||||||
ds = new OneWire(pin[GPIO_DSB]);
|
ds = new OneWire(pin[GPIO_DSB]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ds18x20_search()
|
void Ds18x20Search()
|
||||||
{
|
{
|
||||||
uint8_t num_sensors=0;
|
uint8_t num_sensors=0;
|
||||||
uint8_t sensor = 0;
|
uint8_t sensor = 0;
|
||||||
uint8_t i;
|
|
||||||
|
|
||||||
ds->reset_search();
|
ds->reset_search();
|
||||||
for (num_sensors = 0; num_sensors < DS18X20_MAX_SENSORS; num_sensors) {
|
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();
|
ds->reset_search();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// If CRC Ok and Type DS18S20, DS18B20 or MAX31850
|
// If CRC Ok and Type DS18S20, DS18B20 or MAX31850
|
||||||
if ((OneWire::crc8(ds18x20_addr[num_sensors], 7) == ds18x20_addr[num_sensors][7]) &&
|
if ((OneWire::crc8(ds18x20_address[num_sensors], 7) == ds18x20_address[num_sensors][7]) &&
|
||||||
((ds18x20_addr[num_sensors][0]==DS18S20_CHIPID) || (ds18x20_addr[num_sensors][0]==DS18B20_CHIPID) || (ds18x20_addr[num_sensors][0]==MAX31850_CHIPID))) {
|
((ds18x20_address[num_sensors][0]==DS18S20_CHIPID) || (ds18x20_address[num_sensors][0]==DS18B20_CHIPID) || (ds18x20_address[num_sensors][0]==MAX31850_CHIPID))) {
|
||||||
num_sensors++;
|
num_sensors++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (int i = 0; i < num_sensors; i++) {
|
for (byte i = 0; i < num_sensors; i++) {
|
||||||
ds18x20_idx[i] = i;
|
ds18x20_index[i] = i;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < num_sensors; i++) {
|
for (byte i = 0; i < num_sensors; i++) {
|
||||||
for (int j = i + 1; j < num_sensors; j++) {
|
for (byte j = i + 1; j < num_sensors; j++) {
|
||||||
if (uint32_t(ds18x20_addr[ds18x20_idx[i]]) > uint32_t(ds18x20_addr[ds18x20_idx[j]])) {
|
if (uint32_t(ds18x20_address[ds18x20_index[i]]) > uint32_t(ds18x20_address[ds18x20_index[j]])) {
|
||||||
std::swap(ds18x20_idx[i], ds18x20_idx[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];
|
char address[20];
|
||||||
uint8_t i;
|
|
||||||
|
|
||||||
for (i = 0; i < 8; i++) {
|
for (byte i = 0; i < 8; i++) {
|
||||||
sprintf(addrStr+2*i, "%02X", ds18x20_addr[ds18x20_idx[sensor]][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->reset();
|
||||||
ds->write(W1_SKIP_ROM); // Address all Sensors on Bus
|
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
|
// 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];
|
byte data[12];
|
||||||
int8_t sign = 1;
|
int8_t sign = 1;
|
||||||
uint8_t i = 0;
|
|
||||||
float temp9 = 0.0;
|
float temp9 = 0.0;
|
||||||
uint8_t present = 0;
|
uint8_t present = 0;
|
||||||
|
|
||||||
t = NAN;
|
t = NAN;
|
||||||
|
|
||||||
ds->reset();
|
ds->reset();
|
||||||
ds->select(ds18x20_addr[ds18x20_idx[sensor]]);
|
ds->select(ds18x20_address[ds18x20_index[sensor]]);
|
||||||
ds->write(W1_READ_SCRATCHPAD); // Read Scratchpad
|
ds->write(W1_READ_SCRATCHPAD); // Read Scratchpad
|
||||||
|
|
||||||
for (i = 0; i < 9; i++) {
|
for (byte i = 0; i < 9; i++) {
|
||||||
data[i] = ds->read();
|
data[i] = ds->read();
|
||||||
}
|
}
|
||||||
if (OneWire::crc8(data, 8) == data[8]) {
|
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
|
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) {
|
if (data[1] > 0x80) {
|
||||||
data[0] = (~data[0]) +1;
|
data[0] = (~data[0]) +1;
|
||||||
sign = -1; // App-Note fix possible sign error
|
sign = -1; // App-Note fix possible sign error
|
||||||
|
@ -144,7 +127,7 @@ boolean ds18x20_read(uint8_t sensor, float &t)
|
||||||
} else {
|
} else {
|
||||||
temp9 = (data[0] >> 1) * sign;
|
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;
|
break;
|
||||||
case DS18B20_CHIPID: // DS18B20
|
case DS18B20_CHIPID: // DS18B20
|
||||||
case MAX31850_CHIPID: // MAX31850
|
case MAX31850_CHIPID: // MAX31850
|
||||||
|
@ -153,7 +136,7 @@ boolean ds18x20_read(uint8_t sensor, float &t)
|
||||||
temp12 = (~temp12) +1;
|
temp12 = (~temp12) +1;
|
||||||
sign = -1;
|
sign = -1;
|
||||||
}
|
}
|
||||||
t = convertTemp(sign * temp12 * 0.0625);
|
t = ConvertTemp(sign * temp12 * 0.0625);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -164,33 +147,33 @@ boolean ds18x20_read(uint8_t sensor, float &t)
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void ds18x20_type(uint8_t sensor)
|
void Ds18x20Type(uint8_t sensor)
|
||||||
{
|
{
|
||||||
strcpy_P(dsbstype, PSTR("DS18x20"));
|
strcpy_P(ds18x20_types, PSTR("DS18x20"));
|
||||||
switch(ds18x20_addr[ds18x20_idx[sensor]][0]) {
|
switch(ds18x20_address[ds18x20_index[sensor]][0]) {
|
||||||
case DS18S20_CHIPID:
|
case DS18S20_CHIPID:
|
||||||
strcpy_P(dsbstype, PSTR("DS18S20"));
|
strcpy_P(ds18x20_types, PSTR("DS18S20"));
|
||||||
break;
|
break;
|
||||||
case DS18B20_CHIPID:
|
case DS18B20_CHIPID:
|
||||||
strcpy_P(dsbstype, PSTR("DS18B20"));
|
strcpy_P(ds18x20_types, PSTR("DS18B20"));
|
||||||
break;
|
break;
|
||||||
case MAX31850_CHIPID:
|
case MAX31850_CHIPID:
|
||||||
strcpy_P(dsbstype, PSTR("MAX31850"));
|
strcpy_P(ds18x20_types, PSTR("MAX31850"));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ds18x20_mqttPresent(uint8_t* djson)
|
void MqttShowDs18x20(uint8_t* djson)
|
||||||
{
|
{
|
||||||
char stemp1[10];
|
char stemp1[10];
|
||||||
char stemp2[10];
|
char stemp2[10];
|
||||||
float t;
|
float t;
|
||||||
|
|
||||||
byte dsxflg = 0;
|
byte dsxflg = 0;
|
||||||
for (byte i = 0; i < ds18x20_sensors(); i++) {
|
for (byte i = 0; i < Ds18x20Sensors(); i++) {
|
||||||
if (ds18x20_read(i, t)) { // Check if read failed
|
if (Ds18x20Read(i, t)) { // Check if read failed
|
||||||
ds18x20_type(i);
|
Ds18x20Type(i);
|
||||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp2);
|
dtostrfd(t, Settings.flag.temperature_resolution, stemp2);
|
||||||
if (!dsxflg) {
|
if (!dsxflg) {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18x20\":{"), mqtt_data);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s, \"DS18x20\":{"), mqtt_data);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
|
@ -198,11 +181,11 @@ void ds18x20_mqttPresent(uint8_t* djson)
|
||||||
}
|
}
|
||||||
dsxflg++;
|
dsxflg++;
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"DS%d\":{\"" D_TYPE "\":\"%s\", \"" D_ADDRESS "\":\"%s\", \"" D_TEMPERATURE "\":%s}"),
|
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, ", ");
|
strcpy(stemp1, ", ");
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
if (1 == dsxflg) {
|
if (1 == dsxflg) {
|
||||||
domoticz_sensor(DZ_TEMP, stemp2);
|
DomoticzSensor(DZ_TEMP, stemp2);
|
||||||
}
|
}
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
|
@ -213,7 +196,7 @@ void ds18x20_mqttPresent(uint8_t* djson)
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
String ds18x20_webPresent()
|
String WebShowDs18x20()
|
||||||
{
|
{
|
||||||
String page = "";
|
String page = "";
|
||||||
char stemp[10];
|
char stemp[10];
|
||||||
|
@ -221,17 +204,17 @@ String ds18x20_webPresent()
|
||||||
char sensor[80];
|
char sensor[80];
|
||||||
float t;
|
float t;
|
||||||
|
|
||||||
for (byte i = 0; i < ds18x20_sensors(); i++) {
|
for (byte i = 0; i < Ds18x20Sensors(); i++) {
|
||||||
if (ds18x20_read(i, t)) { // Check if read failed
|
if (Ds18x20Read(i, t)) { // Check if read failed
|
||||||
ds18x20_type(i);
|
Ds18x20Type(i);
|
||||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||||
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s-%d"), dsbstype, i +1);
|
snprintf_P(stemp2, sizeof(stemp2), PSTR("%s-%d"), ds18x20_types, i +1);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, stemp2, stemp, tempUnit());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, stemp2, stemp, TempUnit());
|
||||||
page += sensor;
|
page += sensor;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ds18x20_search(); // Check for changes in sensors number
|
Ds18x20Search(); // Check for changes in sensors number
|
||||||
ds18x20_convert(); // Start Conversion, takes up to one second
|
Ds18x20Convert(); // Start Conversion, takes up to one second
|
||||||
return page;
|
return page;
|
||||||
}
|
}
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
|
@ -33,12 +33,12 @@
|
||||||
|
|
||||||
#define HLW_POWER_PROBE_TIME 10 // Number of seconds to probe for power before deciding none used
|
#define HLW_POWER_PROBE_TIME 10 // Number of seconds to probe for power before deciding none used
|
||||||
|
|
||||||
byte hlw_pminflg = 0;
|
byte hlw_pmin_flag = 0;
|
||||||
byte hlw_pmaxflg = 0;
|
byte hlw_pmax_flag = 0;
|
||||||
byte hlw_uminflg = 0;
|
byte hlw_umin_flag = 0;
|
||||||
byte hlw_umaxflg = 0;
|
byte hlw_umax_flag = 0;
|
||||||
byte hlw_iminflg = 0;
|
byte hlw_imin_flag = 0;
|
||||||
byte hlw_imaxflg = 0;
|
byte hlw_imax_flag = 0;
|
||||||
|
|
||||||
byte power_steady_cntr;
|
byte power_steady_cntr;
|
||||||
byte hlw_mkwh_state = 0;
|
byte hlw_mkwh_state = 0;
|
||||||
|
@ -49,59 +49,59 @@ byte hlw_mkwh_state = 0;
|
||||||
uint16_t hlw_mplw_counter = 0;
|
uint16_t hlw_mplw_counter = 0;
|
||||||
#endif // FEATURE_POWER_LIMIT
|
#endif // FEATURE_POWER_LIMIT
|
||||||
|
|
||||||
byte hlw_SELflag;
|
byte hlw_select_ui_flag;
|
||||||
byte hlw_load_off;
|
byte hlw_load_off;
|
||||||
byte hlw_cf1_timer;
|
byte hlw_cf1_timer;
|
||||||
byte hlw_fifth_second;
|
byte hlw_fifth_second;
|
||||||
byte hlw_startup;
|
byte hlw_startup;
|
||||||
unsigned long hlw_cf_plen;
|
unsigned long hlw_cf_pulse_length;
|
||||||
unsigned long hlw_cf_last;
|
unsigned long hlw_cf_pulse_last_time;
|
||||||
unsigned long hlw_cf1_plen;
|
unsigned long hlw_cf1_pulse_length;
|
||||||
unsigned long hlw_cf1_last;
|
unsigned long hlw_cf1_pulse_last_time;
|
||||||
unsigned long hlw_cf1_ptot;
|
unsigned long hlw_cf1_summed_pulse_length;
|
||||||
unsigned long hlw_cf1_pcnt;
|
unsigned long hlw_cf1_pulse_counter;
|
||||||
unsigned long hlw_cf1u_plen;
|
unsigned long hlw_cf1_voltage_pulse_length;
|
||||||
unsigned long hlw_cf1i_plen;
|
unsigned long hlw_cf1_current_pulse_length;
|
||||||
unsigned long hlw_Ecntr;
|
unsigned long hlw_energy_counter;
|
||||||
unsigned long hlw_EDcntr;
|
unsigned long hlw_energy_period_counter;
|
||||||
unsigned long hlw_kWhtoday;
|
unsigned long hlw_kWhtoday;
|
||||||
uint32_t hlw_lasttime;
|
uint32_t hlw_lasttime;
|
||||||
|
|
||||||
unsigned long hlw_cf1u_pcntmax;
|
unsigned long hlw_cf1_voltage_max_pulse_counter;
|
||||||
unsigned long hlw_cf1i_pcntmax;
|
unsigned long hlw_cf1_current_max_pulse_counter;
|
||||||
|
|
||||||
Ticker tickerHLW;
|
Ticker tickerHLW;
|
||||||
|
|
||||||
#ifndef USE_WS2812_DMA // Collides with Neopixelbus but solves exception
|
#ifndef USE_WS2812_DMA // Collides with Neopixelbus but solves exception
|
||||||
void hlw_cf_interrupt() ICACHE_RAM_ATTR;
|
void HlwCfInterrupt() ICACHE_RAM_ATTR;
|
||||||
void hlw_cf1_interrupt() ICACHE_RAM_ATTR;
|
void HlwCf1Interrupt() ICACHE_RAM_ATTR;
|
||||||
#endif // USE_WS2812_DMA
|
#endif // USE_WS2812_DMA
|
||||||
|
|
||||||
void hlw_cf_interrupt() // Service Power
|
void HlwCfInterrupt() // Service Power
|
||||||
{
|
{
|
||||||
unsigned long us = micros();
|
unsigned long us = micros();
|
||||||
|
|
||||||
if (hlw_load_off) { // Restart plen measurement
|
if (hlw_load_off) { // Restart plen measurement
|
||||||
hlw_cf_last = us;
|
hlw_cf_pulse_last_time = us;
|
||||||
hlw_load_off = 0;
|
hlw_load_off = 0;
|
||||||
} else {
|
} else {
|
||||||
hlw_cf_plen = us - hlw_cf_last;
|
hlw_cf_pulse_length = us - hlw_cf_pulse_last_time;
|
||||||
hlw_cf_last = us;
|
hlw_cf_pulse_last_time = us;
|
||||||
hlw_EDcntr++;
|
hlw_energy_period_counter++;
|
||||||
hlw_Ecntr++;
|
hlw_energy_counter++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hlw_cf1_interrupt() // Service Voltage and Current
|
void HlwCf1Interrupt() // Service Voltage and Current
|
||||||
{
|
{
|
||||||
unsigned long us = micros();
|
unsigned long us = micros();
|
||||||
|
|
||||||
hlw_cf1_plen = us - hlw_cf1_last;
|
hlw_cf1_pulse_length = us - hlw_cf1_pulse_last_time;
|
||||||
hlw_cf1_last = us;
|
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
|
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_summed_pulse_length += hlw_cf1_pulse_length;
|
||||||
hlw_cf1_pcnt++;
|
hlw_cf1_pulse_counter++;
|
||||||
if (10 == hlw_cf1_pcnt) {
|
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)
|
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) {
|
if (5 == hlw_fifth_second) {
|
||||||
hlw_fifth_second = 0;
|
hlw_fifth_second = 0;
|
||||||
|
|
||||||
if (hlw_EDcntr) {
|
if (hlw_energy_period_counter) {
|
||||||
hlw_len = 10000 / hlw_EDcntr;
|
hlw_len = 10000 / hlw_energy_period_counter;
|
||||||
hlw_EDcntr = 0;
|
hlw_energy_period_counter = 0;
|
||||||
if (hlw_len) {
|
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;
|
hlw_kWhtoday += hlw_temp;
|
||||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
RtcSettings.hlw_kWhtoday = hlw_kWhtoday;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (rtcTime.Valid) {
|
if (RtcTime.valid) {
|
||||||
if (rtc_loctime() == rtc_midnight()) {
|
if (LocalTime() == Midnight()) {
|
||||||
sysCfg.hlw_kWhyesterday = hlw_kWhtoday;
|
Settings.hlw_kWhyesterday = hlw_kWhtoday;
|
||||||
sysCfg.hlw_kWhtotal += (hlw_kWhtoday / 1000);
|
Settings.hlw_kWhtotal += (hlw_kWhtoday / 1000);
|
||||||
rtcMem.hlw_kWhtotal = sysCfg.hlw_kWhtotal;
|
RtcSettings.hlw_kWhtotal = Settings.hlw_kWhtotal;
|
||||||
hlw_kWhtoday = 0;
|
hlw_kWhtoday = 0;
|
||||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
RtcSettings.hlw_kWhtoday = hlw_kWhtoday;
|
||||||
hlw_mkwh_state = 3;
|
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;
|
hlw_mkwh_state = 0;
|
||||||
}
|
}
|
||||||
if (hlw_startup && (rtcTime.DayOfYear == sysCfg.hlw_kWhdoy)) {
|
if (hlw_startup && (RtcTime.day_of_year == Settings.hlw_kWhdoy)) {
|
||||||
hlw_kWhtoday = sysCfg.hlw_kWhtoday;
|
hlw_kWhtoday = Settings.hlw_kWhtoday;
|
||||||
rtcMem.hlw_kWhtoday = hlw_kWhtoday;
|
RtcSettings.hlw_kWhtoday = hlw_kWhtoday;
|
||||||
hlw_startup = 0;
|
hlw_startup = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (micros() - hlw_cf_last > (HLW_POWER_PROBE_TIME * 1000000)) {
|
if (micros() - hlw_cf_pulse_last_time > (HLW_POWER_PROBE_TIME * 1000000)) {
|
||||||
hlw_cf_plen = 0; // No load for some time
|
hlw_cf_pulse_length = 0; // No load for some time
|
||||||
hlw_load_off = 1;
|
hlw_load_off = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
hlw_cf1_timer++;
|
hlw_cf1_timer++;
|
||||||
if (hlw_cf1_timer >= 8) {
|
if (hlw_cf1_timer >= 8) {
|
||||||
hlw_cf1_timer = 0;
|
hlw_cf1_timer = 0;
|
||||||
hlw_SELflag = (hlw_SELflag) ? 0 : 1;
|
hlw_select_ui_flag = (hlw_select_ui_flag) ? 0 : 1;
|
||||||
digitalWrite(pin[GPIO_HLW_SEL], hlw_SELflag);
|
digitalWrite(pin[GPIO_HLW_SEL], hlw_select_ui_flag);
|
||||||
|
|
||||||
if (hlw_cf1_pcnt) {
|
if (hlw_cf1_pulse_counter) {
|
||||||
hlw_cf1_plen = hlw_cf1_ptot / hlw_cf1_pcnt;
|
hlw_cf1_pulse_length = hlw_cf1_summed_pulse_length / hlw_cf1_pulse_counter;
|
||||||
} else {
|
} else {
|
||||||
hlw_cf1_plen = 0;
|
hlw_cf1_pulse_length = 0;
|
||||||
}
|
}
|
||||||
if (hlw_SELflag) {
|
if (hlw_select_ui_flag) {
|
||||||
hlw_cf1u_plen = hlw_cf1_plen;
|
hlw_cf1_voltage_pulse_length = hlw_cf1_pulse_length;
|
||||||
hlw_cf1u_pcntmax = hlw_cf1_pcnt;
|
hlw_cf1_voltage_max_pulse_counter = hlw_cf1_pulse_counter;
|
||||||
} else {
|
} else {
|
||||||
hlw_cf1i_plen = hlw_cf1_plen;
|
hlw_cf1_current_pulse_length = hlw_cf1_pulse_length;
|
||||||
hlw_cf1i_pcntmax = hlw_cf1_pcnt;
|
hlw_cf1_current_max_pulse_counter = hlw_cf1_pulse_counter;
|
||||||
}
|
}
|
||||||
hlw_cf1_ptot = 0;
|
hlw_cf1_summed_pulse_length = 0;
|
||||||
hlw_cf1_pcnt = 0;
|
hlw_cf1_pulse_counter = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void hlw_savestate()
|
void HlwSaveState()
|
||||||
{
|
{
|
||||||
sysCfg.hlw_kWhdoy = (rtcTime.Valid) ? rtcTime.DayOfYear : 0;
|
Settings.hlw_kWhdoy = (RtcTime.valid) ? RtcTime.day_of_year : 0;
|
||||||
sysCfg.hlw_kWhtoday = hlw_kWhtoday;
|
Settings.hlw_kWhtoday = hlw_kWhtoday;
|
||||||
sysCfg.hlw_kWhtotal = rtcMem.hlw_kWhtotal;
|
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 0 = do not calculate period energy usage
|
||||||
* option 1 = 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_u;
|
||||||
unsigned long hlw_i;
|
unsigned long hlw_i;
|
||||||
uint16_t hlw_period;
|
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);
|
//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);
|
//AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
et = (float)(rtcMem.hlw_kWhtotal + (cur_kWhtoday / 1000)) / 100000;
|
total_energy = (float)(RtcSettings.hlw_kWhtotal + (cur_kWhtoday / 1000)) / 100000;
|
||||||
ed = 0;
|
daily_energy = 0;
|
||||||
if (cur_kWhtoday) {
|
if (cur_kWhtoday) {
|
||||||
ed = (float)cur_kWhtoday / 100000000;
|
daily_energy = (float)cur_kWhtoday / 100000000;
|
||||||
}
|
}
|
||||||
e = 0;
|
energy = 0;
|
||||||
if (option) {
|
if (option) {
|
||||||
if (!hlw_lasttime) {
|
if (!hlw_lasttime) {
|
||||||
hlw_period = sysCfg.tele_period;
|
hlw_period = Settings.tele_period;
|
||||||
} else {
|
} else {
|
||||||
hlw_period = rtc_loctime() - hlw_lasttime;
|
hlw_period = LocalTime() - hlw_lasttime;
|
||||||
}
|
}
|
||||||
hlw_lasttime = rtc_loctime();
|
hlw_lasttime = LocalTime();
|
||||||
if (hlw_period) {
|
if (hlw_period) {
|
||||||
hlw_interval = 3600 / hlw_period;
|
uint16_t hlw_interval = 3600 / hlw_period;
|
||||||
if (hlw_Ecntr) {
|
if (hlw_energy_counter) {
|
||||||
hlw_len = hlw_period * 1000000 / hlw_Ecntr;
|
hlw_len = hlw_period * 1000000 / hlw_energy_counter;
|
||||||
if (hlw_interval && hlw_len) {
|
if (hlw_interval && hlw_len) {
|
||||||
hlw_Ecntr = 0;
|
hlw_energy_counter = 0;
|
||||||
hlw_temp = ((HLW_PREF * sysCfg.hlw_pcal) / hlw_len) / hlw_interval;
|
hlw_temp = ((HLW_PREF * Settings.hlw_power_calibration) / hlw_len) / hlw_interval;
|
||||||
e = (float)hlw_temp / 10;
|
energy = (float)hlw_temp / 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
w = 0;
|
watts = 0;
|
||||||
if (hlw_cf_plen && (power &1) && !hlw_load_off) {
|
if (hlw_cf_pulse_length && (power &1) && !hlw_load_off) {
|
||||||
hlw_w = (HLW_PREF * sysCfg.hlw_pcal) / hlw_cf_plen;
|
hlw_w = (HLW_PREF * Settings.hlw_power_calibration) / hlw_cf_pulse_length;
|
||||||
w = (float)hlw_w / 10;
|
watts = (float)hlw_w / 10;
|
||||||
}
|
}
|
||||||
u = 0;
|
voltage = 0;
|
||||||
if (hlw_cf1u_plen && (power &1)) { // If powered on always provide voltage
|
if (hlw_cf1_voltage_pulse_length && (power &1)) { // If powered on always provide voltage
|
||||||
hlw_u = (HLW_UREF * sysCfg.hlw_ucal) / hlw_cf1u_plen;
|
hlw_u = (HLW_UREF * Settings.hlw_voltage_calibration) / hlw_cf1_voltage_pulse_length;
|
||||||
u = (float)hlw_u / 10;
|
voltage = (float)hlw_u / 10;
|
||||||
}
|
}
|
||||||
i = 0;
|
current = 0;
|
||||||
if (hlw_cf1i_plen && w) { // No current if no power being consumed
|
if (hlw_cf1_current_pulse_length && watts) { // No current if no power being consumed
|
||||||
hlw_i = (HLW_IREF * sysCfg.hlw_ical) / hlw_cf1i_plen;
|
hlw_i = (HLW_IREF * Settings.hlw_current_calibration) / hlw_cf1_current_pulse_length;
|
||||||
i = (float)hlw_i / 1000;
|
current = (float)hlw_i / 1000;
|
||||||
}
|
}
|
||||||
c = 0;
|
power_factor = 0;
|
||||||
if (hlw_i && hlw_u && hlw_w && w) {
|
if (hlw_i && hlw_u && hlw_w && watts) {
|
||||||
hlw_temp = (hlw_w * 100) / ((hlw_u * hlw_i) / 1000);
|
hlw_temp = (hlw_w * 100) / ((hlw_u * hlw_i) / 1000);
|
||||||
if (hlw_temp > 100) {
|
if (hlw_temp > 100) {
|
||||||
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)) {
|
if (!Settings.hlw_power_calibration || (4975 == Settings.hlw_power_calibration)) {
|
||||||
sysCfg.hlw_pcal = HLW_PREF_PULSE;
|
Settings.hlw_power_calibration = HLW_PREF_PULSE;
|
||||||
sysCfg.hlw_ucal = HLW_UREF_PULSE;
|
Settings.hlw_voltage_calibration = HLW_UREF_PULSE;
|
||||||
sysCfg.hlw_ical = HLW_IREF_PULSE;
|
Settings.hlw_current_calibration = HLW_IREF_PULSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hlw_cf_plen = 0;
|
hlw_cf_pulse_length = 0;
|
||||||
hlw_cf_last = 0;
|
hlw_cf_pulse_last_time = 0;
|
||||||
hlw_cf1_plen = 0;
|
hlw_cf1_pulse_length = 0;
|
||||||
hlw_cf1_last = 0;
|
hlw_cf1_pulse_last_time = 0;
|
||||||
hlw_cf1u_plen = 0;
|
hlw_cf1_voltage_pulse_length = 0;
|
||||||
hlw_cf1i_plen = 0;
|
hlw_cf1_current_pulse_length = 0;
|
||||||
hlw_cf1u_pcntmax = 0;
|
hlw_cf1_voltage_max_pulse_counter = 0;
|
||||||
hlw_cf1i_pcntmax = 0;
|
hlw_cf1_current_max_pulse_counter = 0;
|
||||||
|
|
||||||
hlw_load_off = 1;
|
hlw_load_off = 1;
|
||||||
hlw_Ecntr = 0;
|
hlw_energy_counter = 0;
|
||||||
hlw_EDcntr = 0;
|
hlw_energy_period_counter = 0;
|
||||||
hlw_kWhtoday = (RTC_Valid()) ? rtcMem.hlw_kWhtoday : 0;
|
hlw_kWhtoday = (RtcSettingsValid()) ? RtcSettings.hlw_kWhtoday : 0;
|
||||||
|
|
||||||
hlw_SELflag = 0; // Voltage;
|
hlw_select_ui_flag = 0; // Voltage;
|
||||||
|
|
||||||
pinMode(pin[GPIO_HLW_SEL], OUTPUT);
|
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);
|
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);
|
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_startup = 1;
|
||||||
hlw_lasttime = 0;
|
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;
|
byte change;
|
||||||
|
|
||||||
if (!margin) {
|
if (!margin) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
change = saveflag;
|
change = save_flag;
|
||||||
if (type) {
|
if (type) {
|
||||||
flag = (value > margin);
|
flag = (value > margin);
|
||||||
} else {
|
} else {
|
||||||
flag = (value < margin);
|
flag = (value < margin);
|
||||||
}
|
}
|
||||||
saveflag = flag;
|
save_flag = flag;
|
||||||
return (change != saveflag);
|
return (change != save_flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hlw_setPowerSteadyCounter(byte value)
|
void HlwSetPowerSteadyCounter(byte value)
|
||||||
{
|
{
|
||||||
power_steady_cntr = 2;
|
power_steady_cntr = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
void hlw_margin_chk()
|
void HlwMarginCheck()
|
||||||
{
|
{
|
||||||
float pet;
|
float total_energy;
|
||||||
float ped;
|
float daily_energy;
|
||||||
float pe;
|
float energy;
|
||||||
float pw;
|
float watts;
|
||||||
float pu;
|
float voltage;
|
||||||
float pi;
|
float current;
|
||||||
float pc;
|
float power_factor;
|
||||||
uint16_t uped;
|
uint16_t udaily_energy;
|
||||||
uint16_t pwv;
|
uint16_t uwatts;
|
||||||
uint16_t puv;
|
uint16_t uvoltage;
|
||||||
uint16_t piv;
|
uint16_t ucurrent;
|
||||||
boolean flag;
|
boolean flag;
|
||||||
boolean jsonflg;
|
boolean jsonflg;
|
||||||
|
|
||||||
|
@ -330,69 +329,69 @@ void hlw_margin_chk()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
hlw_readEnergy(0, pet, ped, pe, pw, pu, pi, pc);
|
HlwReadEnergy(0, total_energy, daily_energy, energy, watts, voltage, current, power_factor);
|
||||||
if (power && (sysCfg.hlw_pmin || sysCfg.hlw_pmax || sysCfg.hlw_umin || sysCfg.hlw_umax || sysCfg.hlw_imin || sysCfg.hlw_imax)) {
|
if (power && (Settings.hlw_pmin || Settings.hlw_pmax || Settings.hlw_umin || Settings.hlw_umax || Settings.hlw_imin || Settings.hlw_imax)) {
|
||||||
pwv = (uint16_t)(pw);
|
uwatts = (uint16_t)(watts);
|
||||||
puv = (uint16_t)(pu);
|
uvoltage = (uint16_t)(voltage);
|
||||||
piv = (uint16_t)(pi * 1000);
|
ucurrent = (uint16_t)(current * 1000);
|
||||||
|
|
||||||
// snprintf_P(log_data, sizeof(log_data), PSTR("HLW: W %d, U %d, I %d"), pw, pu, piv);
|
// snprintf_P(log_data, sizeof(log_data), PSTR("HLW: W %d, U %d, I %d"), watts, voltage, ucurrent);
|
||||||
// addLog(LOG_LEVEL_DEBUG);
|
// AddLog(LOG_LEVEL_DEBUG);
|
||||||
|
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{"));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{"));
|
||||||
jsonflg = 0;
|
jsonflg = 0;
|
||||||
if (hlw_margin(0, sysCfg.hlw_pmin, pwv, flag, hlw_pminflg)) {
|
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));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||||
jsonflg = 1;
|
jsonflg = 1;
|
||||||
}
|
}
|
||||||
if (hlw_margin(1, sysCfg.hlw_pmax, pwv, flag, hlw_pmaxflg)) {
|
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));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_POWERHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||||
jsonflg = 1;
|
jsonflg = 1;
|
||||||
}
|
}
|
||||||
if (hlw_margin(0, sysCfg.hlw_umin, puv, flag, hlw_uminflg)) {
|
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));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGELOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||||
jsonflg = 1;
|
jsonflg = 1;
|
||||||
}
|
}
|
||||||
if (hlw_margin(1, sysCfg.hlw_umax, puv, flag, hlw_umaxflg)) {
|
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));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_VOLTAGEHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||||
jsonflg = 1;
|
jsonflg = 1;
|
||||||
}
|
}
|
||||||
if (hlw_margin(0, sysCfg.hlw_imin, piv, flag, hlw_iminflg)) {
|
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));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTLOW "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||||
jsonflg = 1;
|
jsonflg = 1;
|
||||||
}
|
}
|
||||||
if (hlw_margin(1, sysCfg.hlw_imax, piv, flag, hlw_imaxflg)) {
|
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));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s%s\"" D_CMND_CURRENTHIGH "\":\"%s\""), mqtt_data, (jsonflg)?", ":"", GetStateText(flag));
|
||||||
jsonflg = 1;
|
jsonflg = 1;
|
||||||
}
|
}
|
||||||
if (jsonflg) {
|
if (jsonflg) {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("%s}"), mqtt_data);
|
||||||
mqtt_publish_topic_P(2, PSTR(D_RSLT_MARGINS));
|
MqttPublishPrefixTopic_P(2, PSTR(D_RSLT_MARGINS));
|
||||||
hlw_mqttPresent(0);
|
MqttShowHlw8012(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if FEATURE_POWER_LIMIT
|
#if FEATURE_POWER_LIMIT
|
||||||
// Max Power
|
// Max Power
|
||||||
if (sysCfg.hlw_mpl) {
|
if (Settings.hlw_mpl) {
|
||||||
if (pw > sysCfg.hlw_mpl) {
|
if (watts > Settings.hlw_mpl) {
|
||||||
if (!hlw_mplh_counter) {
|
if (!hlw_mplh_counter) {
|
||||||
hlw_mplh_counter = sysCfg.hlw_mplh;
|
hlw_mplh_counter = Settings.hlw_mplh;
|
||||||
} else {
|
} else {
|
||||||
hlw_mplh_counter--;
|
hlw_mplh_counter--;
|
||||||
if (!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 : "");
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHED "\":\"%d%s\"}"), uwatts, (Settings.flag.value_units) ? " " D_UNIT_WATT : "");
|
||||||
mqtt_publish_topic_P(1, S_RSLT_WARNING);
|
MqttPublishPrefixTopic_P(1, S_RSLT_WARNING);
|
||||||
hlw_mqttPresent(0);
|
MqttShowHlw8012(0);
|
||||||
do_cmnd_power(1, 0);
|
ExecuteCommandPower(1, 0);
|
||||||
if (!hlw_mplr_counter) {
|
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_mplh_counter = 0;
|
||||||
hlw_mplr_counter = 0;
|
hlw_mplr_counter = 0;
|
||||||
hlw_mplw_counter = 0;
|
hlw_mplw_counter = 0;
|
||||||
|
@ -404,13 +403,13 @@ void hlw_margin_chk()
|
||||||
if (hlw_mplr_counter) {
|
if (hlw_mplr_counter) {
|
||||||
hlw_mplr_counter--;
|
hlw_mplr_counter--;
|
||||||
if (hlw_mplr_counter) {
|
if (hlw_mplr_counter) {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_POWERMONITOR "\":\"%s\"}"), getStateText(1));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_POWERMONITOR "\":\"%s\"}"), GetStateText(1));
|
||||||
mqtt_publish_topic_P(5, PSTR(D_POWERMONITOR));
|
MqttPublishPrefixTopic_P(5, PSTR(D_POWERMONITOR));
|
||||||
do_cmnd_power(1, 1);
|
ExecuteCommandPower(1, 1);
|
||||||
} else {
|
} else {
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHEDRETRY "\":\"%s\"}"), getStateText(0));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXPOWERREACHEDRETRY "\":\"%s\"}"), GetStateText(0));
|
||||||
mqtt_publish_topic_P(1, S_RSLT_WARNING);
|
MqttPublishPrefixTopic_P(1, S_RSLT_WARNING);
|
||||||
hlw_mqttPresent(0);
|
MqttShowHlw8012(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -418,21 +417,21 @@ void hlw_margin_chk()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Max Energy
|
// Max Energy
|
||||||
if (sysCfg.hlw_mkwh) {
|
if (Settings.hlw_mkwh) {
|
||||||
uped = (uint16_t)(ped * 1000);
|
udaily_energy = (uint16_t)(daily_energy * 1000);
|
||||||
if (!hlw_mkwh_state && (rtcTime.Hour == sysCfg.hlw_mkwhs)) {
|
if (!hlw_mkwh_state && (RtcTime.hour == Settings.hlw_mkwhs)) {
|
||||||
hlw_mkwh_state = 1;
|
hlw_mkwh_state = 1;
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_ENERGYMONITOR "\":\"%s\"}"), getStateText(1));
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_ENERGYMONITOR "\":\"%s\"}"), GetStateText(1));
|
||||||
mqtt_publish_topic_P(5, PSTR(D_ENERGYMONITOR));
|
MqttPublishPrefixTopic_P(5, PSTR(D_ENERGYMONITOR));
|
||||||
do_cmnd_power(1, 1);
|
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;
|
hlw_mkwh_state = 2;
|
||||||
dtostrfd(ped, 3, mqtt_data);
|
dtostrfd(daily_energy, 3, mqtt_data);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (sysCfg.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_MAXENERGYREACHED "\":\"%s%s\"}"), mqtt_data, (Settings.flag.value_units) ? " " D_UNIT_KILOWATTHOUR : "");
|
||||||
mqtt_publish_topic_P(1, S_RSLT_WARNING);
|
MqttPublishPrefixTopic_P(1, S_RSLT_WARNING);
|
||||||
hlw_mqttPresent(0);
|
MqttShowHlw8012(0);
|
||||||
do_cmnd_power(1, 0);
|
ExecuteCommandPower(1, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // FEATURE_POWER_LIMIT
|
#endif // FEATURE_POWER_LIMIT
|
||||||
|
@ -442,157 +441,158 @@ void hlw_margin_chk()
|
||||||
* Commands
|
* 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;
|
boolean serviced = true;
|
||||||
uint8_t caltext = 0;
|
uint8_t caltext = 0;
|
||||||
|
|
||||||
if (!strcasecmp_P(type, PSTR(D_CMND_POWERLOW))) {
|
if (!strcasecmp_P(type, PSTR(D_CMND_POWERLOW))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_POWERHIGH))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_VOLTAGELOW))) {
|
||||||
if ((payload >= 0) && (payload < 501)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_VOLTAGEHIGH))) {
|
||||||
if ((payload >= 0) && (payload < 501)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_CURRENTLOW))) {
|
||||||
if ((payload >= 0) && (payload < 16001)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_CURRENTHIGH))) {
|
||||||
if ((payload >= 0) && (payload < 16001)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_ENERGYRESET))) {
|
||||||
if ((payload >= 1) && (payload <= 3)) {
|
if ((payload >= 1) && (payload <= 3)) {
|
||||||
switch (payload) {
|
switch (payload) {
|
||||||
case 1:
|
case 1:
|
||||||
hlw_kWhtoday = 0;
|
hlw_kWhtoday = 0;
|
||||||
rtcMem.hlw_kWhtoday = 0;
|
RtcSettings.hlw_kWhtoday = 0;
|
||||||
sysCfg.hlw_kWhtoday = 0;
|
Settings.hlw_kWhtoday = 0;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
sysCfg.hlw_kWhyesterday = 0;
|
Settings.hlw_kWhyesterday = 0;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
rtcMem.hlw_kWhtotal = 0;
|
RtcSettings.hlw_kWhtotal = 0;
|
||||||
sysCfg.hlw_kWhtotal = rtcMem.hlw_kWhtotal;
|
Settings.hlw_kWhtotal = RtcSettings.hlw_kWhtotal;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
char sey[10];
|
char syesterday_energy[10];
|
||||||
char sen[10];
|
char stoday_energy[10];
|
||||||
char set[10];
|
char stotal_energy[10];
|
||||||
dtostrfd((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
|
dtostrfd((float)Settings.hlw_kWhyesterday / 100000000, Settings.flag.energy_resolution, syesterday_energy);
|
||||||
dtostrfd((float)rtcMem.hlw_kWhtoday / 100000000, sysCfg.flag.energy_resolution, sen);
|
dtostrfd((float)RtcSettings.hlw_kWhtoday / 100000000, Settings.flag.energy_resolution, stoday_energy);
|
||||||
dtostrfd((float)(rtcMem.hlw_kWhtotal + (hlw_kWhtoday / 1000)) / 100000, sysCfg.flag.energy_resolution, set);
|
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}}"), set, sey, sen);
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWPCAL))) {
|
||||||
if ((payload > 0) && (payload < 32001)) {
|
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;
|
caltext = 1;
|
||||||
}
|
}
|
||||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWPSET))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWPSET))) {
|
||||||
if ((payload > 0) && (payload < 3601) && hlw_cf_plen) {
|
if ((payload > 0) && (payload < 3601) && hlw_cf_pulse_length) {
|
||||||
sysCfg.hlw_pcal = (payload * 10 * hlw_cf_plen) / HLW_PREF;
|
Settings.hlw_power_calibration = (payload * 10 * hlw_cf_pulse_length) / HLW_PREF;
|
||||||
}
|
}
|
||||||
caltext = 1;
|
caltext = 1;
|
||||||
}
|
}
|
||||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWUCAL))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWUCAL))) {
|
||||||
if ((payload > 0) && (payload < 32001)) {
|
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;
|
caltext = 2;
|
||||||
}
|
}
|
||||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWUSET))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWUSET))) {
|
||||||
if ((payload > 0) && (payload < 501) && hlw_cf1u_plen) {
|
if ((payload > 0) && (payload < 501) && hlw_cf1_voltage_pulse_length) {
|
||||||
sysCfg.hlw_ucal = (payload * 10 * hlw_cf1u_plen) / HLW_UREF;
|
Settings.hlw_voltage_calibration = (payload * 10 * hlw_cf1_voltage_pulse_length) / HLW_UREF;
|
||||||
}
|
}
|
||||||
caltext = 2;
|
caltext = 2;
|
||||||
}
|
}
|
||||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWICAL))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWICAL))) {
|
||||||
if ((payload > 0) && (payload < 32001)) {
|
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;
|
caltext = 3;
|
||||||
}
|
}
|
||||||
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWISET))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_HLWISET))) {
|
||||||
if ((payload > 0) && (payload < 16001) && hlw_cf1i_plen) {
|
if ((payload > 0) && (payload < 16001) && hlw_cf1_current_pulse_length) {
|
||||||
sysCfg.hlw_ical = (payload * hlw_cf1i_plen) / HLW_IREF;
|
Settings.hlw_current_calibration = (payload * hlw_cf1_current_pulse_length) / HLW_IREF;
|
||||||
}
|
}
|
||||||
caltext = 3;
|
caltext = 3;
|
||||||
}
|
}
|
||||||
#if FEATURE_POWER_LIMIT
|
#if FEATURE_POWER_LIMIT
|
||||||
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWER))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWER))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWERHOLD))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXPOWERWINDOW))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWER))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWERHOLD))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_SAFEPOWERWINDOW))) {
|
||||||
if ((payload >= 0) && (payload < 1440)) {
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXENERGY))) {
|
||||||
if ((payload >= 0) && (payload < 3601)) {
|
if ((payload >= 0) && (payload < 3601)) {
|
||||||
sysCfg.hlw_mkwh = payload;
|
Settings.hlw_mkwh = payload;
|
||||||
hlw_mkwh_state = 3;
|
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))) {
|
else if (!strcasecmp_P(type, PSTR(D_CMND_MAXENERGYSTART))) {
|
||||||
if ((payload >= 0) && (payload < 24)) {
|
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
|
#endif // FEATURE_POWER_LIMIT
|
||||||
else {
|
else {
|
||||||
|
@ -600,13 +600,13 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
|
||||||
}
|
}
|
||||||
switch (caltext) {
|
switch (caltext) {
|
||||||
case 1:
|
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;
|
break;
|
||||||
case 2:
|
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;
|
break;
|
||||||
case 3:
|
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;
|
break;
|
||||||
}
|
}
|
||||||
return serviced;
|
return serviced;
|
||||||
|
@ -616,65 +616,65 @@ boolean hlw_command(char *type, uint16_t index, char *dataBuf, uint16_t data_len
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void hlw_mqttStat(byte option)
|
void HlwMqttStat(byte option)
|
||||||
{
|
{
|
||||||
/* option 0 = do not show period energy usage
|
/* option 0 = do not show period energy usage
|
||||||
* option 1 = show period energy usage
|
* option 1 = show period energy usage
|
||||||
*/
|
*/
|
||||||
float pet;
|
float total_energy;
|
||||||
float ped;
|
float daily_energy;
|
||||||
float pe;
|
float energy;
|
||||||
float pw;
|
float watts;
|
||||||
float pu;
|
float voltage;
|
||||||
float pi;
|
float current;
|
||||||
float pc;
|
float power_factor;
|
||||||
char spet[10];
|
char stotal_energy[10];
|
||||||
char sped[10];
|
char sdaily_energy[10];
|
||||||
char spe[10];
|
char senergy[10];
|
||||||
char spw[10];
|
char swatts[10];
|
||||||
char spu[10];
|
char svoltage[10];
|
||||||
char spi[10];
|
char scurrent[10];
|
||||||
char spc[10];
|
char spower_factor[10];
|
||||||
char sey[10];
|
char syesterday_energy[10];
|
||||||
char speriod[20];
|
char speriod[20];
|
||||||
|
|
||||||
hlw_readEnergy(option, pet, ped, pe, pw, pu, pi, pc);
|
HlwReadEnergy(option, total_energy, daily_energy, energy, watts, voltage, current, power_factor);
|
||||||
dtostrfd(pet, sysCfg.flag.energy_resolution, spet);
|
dtostrfd(total_energy, Settings.flag.energy_resolution, stotal_energy);
|
||||||
dtostrfd(ped, sysCfg.flag.energy_resolution, sped);
|
dtostrfd(daily_energy, Settings.flag.energy_resolution, sdaily_energy);
|
||||||
dtostrfd(pe, sysCfg.flag.wattage_resolution, spe);
|
dtostrfd(energy, Settings.flag.wattage_resolution, senergy);
|
||||||
dtostrfd(pw, sysCfg.flag.wattage_resolution, spw);
|
dtostrfd(watts, Settings.flag.wattage_resolution, swatts);
|
||||||
dtostrfd(pu, sysCfg.flag.voltage_resolution, spu);
|
dtostrfd(voltage, Settings.flag.voltage_resolution, svoltage);
|
||||||
dtostrfd(pi, 3, spi);
|
dtostrfd(current, 3, scurrent);
|
||||||
dtostrfd(pc, 2, spc);
|
dtostrfd(power_factor, 2, spower_factor);
|
||||||
dtostrfd((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
|
dtostrfd((float)Settings.hlw_kWhyesterday / 100000000, Settings.flag.energy_resolution, syesterday_energy);
|
||||||
snprintf_P(speriod, sizeof(speriod), PSTR(", \"" D_PERIOD "\":%s"), spe);
|
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}"),
|
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
|
#ifdef USE_DOMOTICZ
|
||||||
if (option) { // Only send if telemetry
|
if (option) { // Only send if telemetry
|
||||||
dtostrfd(pet * 1000, 1, spet);
|
dtostrfd(total_energy * 1000, 1, stotal_energy);
|
||||||
domoticz_sensor4((uint16_t)pw, spet); // PowerUsage, EnergyToday
|
DomoticzSensorPowerEnergy((uint16_t)watts, stotal_energy); // PowerUsage, EnergyToday
|
||||||
domoticz_sensor(DZ_VOLTAGE, spu); // Voltage
|
DomoticzSensor(DZ_VOLTAGE, svoltage); // Voltage
|
||||||
domoticz_sensor(DZ_CURRENT, spi); // Current
|
DomoticzSensor(DZ_CURRENT, scurrent); // Current
|
||||||
}
|
}
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
|
|
||||||
void hlw_mqttPresent(byte option)
|
void MqttShowHlw8012(byte option)
|
||||||
{
|
{
|
||||||
/* option 0 = do not show period energy usage
|
/* option 0 = do not show period energy usage
|
||||||
* option 1 = 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}
|
// {"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());
|
snprintf_P(mqtt_data, sizeof(mqtt_data), PSTR("{\"" D_TIME "\":\"%s\", "), GetDateAndTime().c_str());
|
||||||
hlw_mqttStat(option);
|
HlwMqttStat(option);
|
||||||
mqtt_publish_topic_P(2, PSTR(D_RSLT_ENERGY), sysCfg.flag.mqtt_sensor_retain);
|
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 "\":{"));
|
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);
|
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_YESTERDAY "</th><td>%s " D_UNIT_KILOWATTHOUR "</td></tr>"
|
||||||
"<tr><th>" D_ENERGY_TOTAL "</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 total_energy;
|
||||||
float ped;
|
float daily_energy;
|
||||||
float pe;
|
float energy;
|
||||||
float pw;
|
float watts;
|
||||||
float pu;
|
float voltage;
|
||||||
float pi;
|
float current;
|
||||||
float pc;
|
float power_factor;
|
||||||
char spet[10];
|
char stotal_energy[10];
|
||||||
char sped[10];
|
char sdaily_energy[10];
|
||||||
char spw[10];
|
char swatts[10];
|
||||||
char spu[10];
|
char svoltage[10];
|
||||||
char spi[10];
|
char scurrent[10];
|
||||||
char spc[10];
|
char spower_factor[10];
|
||||||
char sey[10];
|
char syesterday_energy[10];
|
||||||
char sensor[400];
|
char sensor[400];
|
||||||
|
|
||||||
hlw_readEnergy(0, pet, ped, pe, pw, pu, pi, pc);
|
HlwReadEnergy(0, total_energy, daily_energy, energy, watts, voltage, current, power_factor);
|
||||||
dtostrfi(pet, sysCfg.flag.energy_resolution, spet);
|
dtostrfi(total_energy, Settings.flag.energy_resolution, stotal_energy);
|
||||||
dtostrfi(ped, sysCfg.flag.energy_resolution, sped);
|
dtostrfi(daily_energy, Settings.flag.energy_resolution, sdaily_energy);
|
||||||
dtostrfi(pw, sysCfg.flag.wattage_resolution, spw);
|
dtostrfi(watts, Settings.flag.wattage_resolution, swatts);
|
||||||
dtostrfi(pu, sysCfg.flag.voltage_resolution, spu);
|
dtostrfi(voltage, Settings.flag.voltage_resolution, svoltage);
|
||||||
dtostrfi(pi, 3, spi);
|
dtostrfi(current, 3, scurrent);
|
||||||
dtostrfi(pc, 2, spc);
|
dtostrfi(power_factor, 2, spower_factor);
|
||||||
dtostrfi((float)sysCfg.hlw_kWhyesterday / 100000000, sysCfg.flag.energy_resolution, sey);
|
dtostrfi((float)Settings.hlw_kWhyesterday / 100000000, Settings.flag.energy_resolution, syesterday_energy);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_ENERGY_SNS, spu, spi, spw, spc, sped, sey, spet);
|
snprintf_P(sensor, sizeof(sensor), HTTP_ENERGY_SNS, svoltage, scurrent, swatts, spower_factor, sdaily_energy, syesterday_energy, stotal_energy);
|
||||||
return String(sensor);
|
return String(sensor);
|
||||||
}
|
}
|
||||||
#endif // USE_WEBSERVER
|
#endif // USE_WEBSERVER
|
||||||
|
|
||||||
|
|
|
@ -52,13 +52,13 @@
|
||||||
|
|
||||||
#define HTU21_CRC8_POLYNOM 0x13100
|
#define HTU21_CRC8_POLYNOM 0x13100
|
||||||
|
|
||||||
uint8_t htuaddr;
|
uint8_t htu_address;
|
||||||
uint8_t htutype = 0;
|
uint8_t htu_type = 0;
|
||||||
uint8_t delayT;
|
uint8_t delay_temp;
|
||||||
uint8_t delayH = 50;
|
uint8_t delay_humidity = 50;
|
||||||
char htustype[7];
|
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++) {
|
for (uint8_t bit = 0; bit < 16; bit++) {
|
||||||
if (data & 0x8000) {
|
if (data & 0x8000) {
|
||||||
|
@ -70,7 +70,7 @@ uint8_t check_crc8(uint16_t data)
|
||||||
return data >>= 8;
|
return data >>= 8;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t htu21_readDeviceID(void)
|
uint8_t HtuReadDeviceId(void)
|
||||||
{
|
{
|
||||||
uint16_t deviceID = 0;
|
uint16_t deviceID = 0;
|
||||||
uint8_t checksum = 0;
|
uint8_t checksum = 0;
|
||||||
|
@ -84,7 +84,7 @@ uint8_t htu21_readDeviceID(void)
|
||||||
deviceID = Wire.read() << 8;
|
deviceID = Wire.read() << 8;
|
||||||
deviceID |= Wire.read();
|
deviceID |= Wire.read();
|
||||||
checksum = Wire.read();
|
checksum = Wire.read();
|
||||||
if (check_crc8(deviceID) == checksum) {
|
if (HtuCheckCrc8(deviceID) == checksum) {
|
||||||
deviceID = deviceID >> 8;
|
deviceID = deviceID >> 8;
|
||||||
} else {
|
} else {
|
||||||
deviceID = 0;
|
deviceID = 0;
|
||||||
|
@ -92,15 +92,15 @@ uint8_t htu21_readDeviceID(void)
|
||||||
return (uint8_t)deviceID;
|
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 &= 0x7E; // Replace current resolution bits with 0
|
||||||
current |= resolution; // Add new resolution bits to register
|
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.beginTransmission(HTU21_ADDR);
|
||||||
Wire.write(HTU21_RESET);
|
Wire.write(HTU21_RESET);
|
||||||
|
@ -108,9 +108,9 @@ void htu21_reset(void)
|
||||||
delay(15); // Reset takes 15ms
|
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)
|
switch(heater)
|
||||||
{
|
{
|
||||||
|
@ -121,18 +121,18 @@ void htu21_heater(uint8_t heater)
|
||||||
default : current &= heater;
|
default : current &= heater;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
i2c_write8(HTU21_ADDR, HTU21_WRITEREG, current);
|
I2cWrite8(HTU21_ADDR, HTU21_WRITEREG, current);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean htu21_init()
|
boolean HtuInit()
|
||||||
{
|
{
|
||||||
htu21_reset();
|
HtuReset();
|
||||||
htu21_heater(HTU21_HEATER_OFF);
|
HtuHeater(HTU21_HEATER_OFF);
|
||||||
htu21_setRes(HTU21_RES_RH12_T14);
|
HtuSetResolution(HTU21_RES_RH12_T14);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
float htu21_readHumidity(void)
|
float HtuReadHumidity(void)
|
||||||
{
|
{
|
||||||
uint8_t checksum = 0;
|
uint8_t checksum = 0;
|
||||||
uint16_t sensorval = 0;
|
uint16_t sensorval = 0;
|
||||||
|
@ -143,7 +143,7 @@ float htu21_readHumidity(void)
|
||||||
if (Wire.endTransmission() != 0) {
|
if (Wire.endTransmission() != 0) {
|
||||||
return 0.0; // In case of error
|
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);
|
Wire.requestFrom(HTU21_ADDR, 3);
|
||||||
if (3 <= Wire.available()) {
|
if (3 <= Wire.available()) {
|
||||||
|
@ -151,7 +151,7 @@ float htu21_readHumidity(void)
|
||||||
sensorval |= Wire.read(); // LSB
|
sensorval |= Wire.read(); // LSB
|
||||||
checksum = Wire.read();
|
checksum = Wire.read();
|
||||||
}
|
}
|
||||||
if (check_crc8(sensorval) != checksum) {
|
if (HtuCheckCrc8(sensorval) != checksum) {
|
||||||
return 0.0; // Checksum mismatch
|
return 0.0; // Checksum mismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -168,7 +168,7 @@ float htu21_readHumidity(void)
|
||||||
return humidity;
|
return humidity;
|
||||||
}
|
}
|
||||||
|
|
||||||
float htu21_readTemperature()
|
float HtuReadTemperature()
|
||||||
{
|
{
|
||||||
uint8_t checksum=0;
|
uint8_t checksum=0;
|
||||||
uint16_t sensorval=0;
|
uint16_t sensorval=0;
|
||||||
|
@ -179,7 +179,7 @@ float htu21_readTemperature()
|
||||||
if (Wire.endTransmission() != 0) {
|
if (Wire.endTransmission() != 0) {
|
||||||
return 0.0; // In case of error
|
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);
|
Wire.requestFrom(HTU21_ADDR, 3);
|
||||||
if (3 == Wire.available()) {
|
if (3 == Wire.available()) {
|
||||||
|
@ -187,15 +187,15 @@ float htu21_readTemperature()
|
||||||
sensorval |= Wire.read(); // LSB
|
sensorval |= Wire.read(); // LSB
|
||||||
checksum = Wire.read();
|
checksum = Wire.read();
|
||||||
}
|
}
|
||||||
if (check_crc8(sensorval) != checksum) {
|
if (HtuCheckCrc8(sensorval) != checksum) {
|
||||||
return 0.0; // Checksum mismatch
|
return 0.0; // Checksum mismatch
|
||||||
}
|
}
|
||||||
|
|
||||||
t = convertTemp(0.002681 * (float)sensorval - 46.85);
|
t = ConvertTemp(0.002681 * (float)sensorval - 46.85);
|
||||||
return t;
|
return t;
|
||||||
}
|
}
|
||||||
|
|
||||||
float htu21_compensatedHumidity(float humidity, float temperature)
|
float HtuCompensatedHumidity(float humidity, float temperature)
|
||||||
{
|
{
|
||||||
if(humidity == 0.00 && temperature == 0.00) {
|
if(humidity == 0.00 && temperature == 0.00) {
|
||||||
return 0.0;
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean success = false;
|
boolean success = false;
|
||||||
|
|
||||||
htuaddr = HTU21_ADDR;
|
htu_address = HTU21_ADDR;
|
||||||
htutype = htu21_readDeviceID();
|
htu_type = HtuReadDeviceId();
|
||||||
success = htu21_init();
|
success = HtuInit();
|
||||||
switch (htutype) {
|
switch (htu_type) {
|
||||||
case HTU21_CHIPID:
|
case HTU21_CHIPID:
|
||||||
strcpy_P(htustype, PSTR("HTU21"));
|
strcpy_P(htu_types, PSTR("HTU21"));
|
||||||
delayT=50;
|
delay_temp=50;
|
||||||
delayH=16;
|
delay_humidity=16;
|
||||||
break;
|
break;
|
||||||
case SI7013_CHIPID:
|
case SI7013_CHIPID:
|
||||||
strcpy_P(htustype, PSTR("SI7013"));
|
strcpy_P(htu_types, PSTR("SI7013"));
|
||||||
delayT=12;
|
delay_temp=12;
|
||||||
delayH=23;
|
delay_humidity=23;
|
||||||
break;
|
break;
|
||||||
case SI7020_CHIPID:
|
case SI7020_CHIPID:
|
||||||
strcpy_P(htustype, PSTR("SI7020"));
|
strcpy_P(htu_types, PSTR("SI7020"));
|
||||||
delayT=12;
|
delay_temp=12;
|
||||||
delayH=23;
|
delay_humidity=23;
|
||||||
break;
|
break;
|
||||||
case SI7021_CHIPID:
|
case SI7021_CHIPID:
|
||||||
strcpy_P(htustype, PSTR("SI7021"));
|
strcpy_P(htu_types, PSTR("SI7021"));
|
||||||
delayT=12;
|
delay_temp=12;
|
||||||
delayH=23;
|
delay_humidity=23;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
strcpy_P(htustype, PSTR("T/RH?"));
|
strcpy_P(htu_types, PSTR("T/RH?"));
|
||||||
delayT=50;
|
delay_temp=50;
|
||||||
delayH=23;
|
delay_humidity=23;
|
||||||
}
|
}
|
||||||
if (success) {
|
if (success) {
|
||||||
snprintf_P(log_data, sizeof(log_data), PSTR(D_LOG_I2C "%s " D_FOUND_AT " 0x%x"), htustype, htuaddr);
|
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);
|
AddLog(LOG_LEVEL_DEBUG);
|
||||||
} else {
|
} else {
|
||||||
htutype = 0;
|
htu_type = 0;
|
||||||
}
|
}
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
@ -255,43 +255,43 @@ uint8_t htu_detect()
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void htu_mqttPresent(uint8_t* djson)
|
void MqttShowHtu(uint8_t* djson)
|
||||||
{
|
{
|
||||||
if (!htutype) {
|
if (!htu_type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
char stemp1[10];
|
char stemp1[10];
|
||||||
char stemp2[10];
|
char stemp2[10];
|
||||||
|
|
||||||
float t = htu21_readTemperature();
|
float t = HtuReadTemperature();
|
||||||
float h = htu21_readHumidity();
|
float h = HtuReadHumidity();
|
||||||
h = htu21_compensatedHumidity(h, t);
|
h = HtuCompensatedHumidity(h, t);
|
||||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp1);
|
dtostrfd(t, Settings.flag.temperature_resolution, stemp1);
|
||||||
dtostrfd(h, sysCfg.flag.humidity_resolution, stemp2);
|
dtostrfd(h, Settings.flag.humidity_resolution, stemp2);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, htustype, stemp1, stemp2);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, htu_types, stemp1, stemp2);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
domoticz_sensor2(stemp1, stemp2);
|
DomoticzTempHumSensor(stemp1, stemp2);
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
String htu_webPresent()
|
String WebShowHtu()
|
||||||
{
|
{
|
||||||
String page = "";
|
String page = "";
|
||||||
if (htutype) {
|
if (htu_type) {
|
||||||
char stemp[10];
|
char stemp[10];
|
||||||
char sensor[80];
|
char sensor[80];
|
||||||
|
|
||||||
float t_htu21 = htu21_readTemperature();
|
float t_htu21 = HtuReadTemperature();
|
||||||
float h_htu21 = htu21_readHumidity();
|
float h_htu21 = HtuReadHumidity();
|
||||||
h_htu21 = htu21_compensatedHumidity(h_htu21, t_htu21);
|
h_htu21 = HtuCompensatedHumidity(h_htu21, t_htu21);
|
||||||
dtostrfi(t_htu21, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfi(t_htu21, Settings.flag.temperature_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, htustype, stemp, tempUnit());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, htu_types, stemp, TempUnit());
|
||||||
page += sensor;
|
page += sensor;
|
||||||
dtostrfi(h_htu21, sysCfg.flag.humidity_resolution, stemp);
|
dtostrfi(h_htu21, Settings.flag.humidity_resolution, stemp);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, htustype, stemp);
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, htu_types, stemp);
|
||||||
page += sensor;
|
page += sensor;
|
||||||
}
|
}
|
||||||
return page;
|
return page;
|
||||||
|
|
|
@ -34,9 +34,9 @@ enum {
|
||||||
|
|
||||||
uint8_t sht_sda_pin;
|
uint8_t sht_sda_pin;
|
||||||
uint8_t sht_scl_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_sda_pin, INPUT_PULLUP);
|
||||||
pinMode(sht_scl_pin, OUTPUT);
|
pinMode(sht_scl_pin, OUTPUT);
|
||||||
|
@ -45,12 +45,12 @@ boolean sht_reset()
|
||||||
digitalWrite(sht_scl_pin, HIGH);
|
digitalWrite(sht_scl_pin, HIGH);
|
||||||
digitalWrite(sht_scl_pin, LOW);
|
digitalWrite(sht_scl_pin, LOW);
|
||||||
}
|
}
|
||||||
boolean success = sht_sendCommand(SHT1X_CMD_SOFT_RESET);
|
boolean success = ShtSendCommand(SHT1X_CMD_SOFT_RESET);
|
||||||
delay(11);
|
delay(11);
|
||||||
return success;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean sht_sendCommand(const byte cmd)
|
boolean ShtSendCommand(const byte cmd)
|
||||||
{
|
{
|
||||||
pinMode(sht_sda_pin, OUTPUT);
|
pinMode(sht_sda_pin, OUTPUT);
|
||||||
// Transmission Start sequence
|
// Transmission Start sequence
|
||||||
|
@ -76,13 +76,13 @@ boolean sht_sendCommand(const byte cmd)
|
||||||
ackerror = true;
|
ackerror = true;
|
||||||
}
|
}
|
||||||
if (ackerror) {
|
if (ackerror) {
|
||||||
shttype = 0;
|
sht_type = 0;
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_DID_NOT_ACK_COMMAND));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_DID_NOT_ACK_COMMAND));
|
||||||
}
|
}
|
||||||
return (!ackerror);
|
return (!ackerror);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean sht_awaitResult()
|
boolean ShtAwaitResult()
|
||||||
{
|
{
|
||||||
// Maximum 320ms for 14 bit measurement
|
// Maximum 320ms for 14 bit measurement
|
||||||
for (byte i = 0; i < 16; i++) {
|
for (byte i = 0; i < 16; i++) {
|
||||||
|
@ -91,12 +91,12 @@ boolean sht_awaitResult()
|
||||||
}
|
}
|
||||||
delay(20);
|
delay(20);
|
||||||
}
|
}
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_BUSY));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_SHT1 D_SENSOR_BUSY));
|
||||||
shttype = 0;
|
sht_type = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sht_readData()
|
int ShtReadData()
|
||||||
{
|
{
|
||||||
int val = 0;
|
int val = 0;
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ int sht_readData()
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean sht_readTempHum(float &t, float &h)
|
boolean ShtReadTempHum(float &t, float &h)
|
||||||
{
|
{
|
||||||
float tempRaw;
|
float tempRaw;
|
||||||
float humRaw;
|
float humRaw;
|
||||||
|
@ -126,27 +126,27 @@ boolean sht_readTempHum(float &t, float &h)
|
||||||
t = NAN;
|
t = NAN;
|
||||||
h = NAN;
|
h = NAN;
|
||||||
|
|
||||||
if (!sht_reset()) {
|
if (!ShtReset()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!sht_sendCommand(SHT1X_CMD_MEASURE_TEMP)) {
|
if (!ShtSendCommand(SHT1X_CMD_MEASURE_TEMP)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!sht_awaitResult()) {
|
if (!ShtAwaitResult()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
tempRaw = sht_readData();
|
tempRaw = ShtReadData();
|
||||||
// Temperature conversion coefficients from SHT1X datasheet for version 4
|
// Temperature conversion coefficients from SHT1X datasheet for version 4
|
||||||
const float d1 = -39.7; // 3.5V
|
const float d1 = -39.7; // 3.5V
|
||||||
const float d2 = 0.01; // 14-bit
|
const float d2 = 0.01; // 14-bit
|
||||||
t = d1 + (tempRaw * d2);
|
t = d1 + (tempRaw * d2);
|
||||||
if (!sht_sendCommand(SHT1X_CMD_MEASURE_RH)) {
|
if (!ShtSendCommand(SHT1X_CMD_MEASURE_RH)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!sht_awaitResult()) {
|
if (!ShtAwaitResult()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
humRaw = sht_readData();
|
humRaw = ShtReadData();
|
||||||
// Temperature conversion coefficients from SHT1X datasheet for version 4
|
// Temperature conversion coefficients from SHT1X datasheet for version 4
|
||||||
const float c1 = -2.0468;
|
const float c1 = -2.0468;
|
||||||
const float c2 = 0.0367;
|
const float c2 = 0.0367;
|
||||||
|
@ -155,13 +155,13 @@ boolean sht_readTempHum(float &t, float &h)
|
||||||
const float t2 = 0.00008;
|
const float t2 = 0.00008;
|
||||||
rhLinear = c1 + c2 * humRaw + c3 * humRaw * humRaw;
|
rhLinear = c1 + c2 * humRaw + c3 * humRaw * humRaw;
|
||||||
h = (t - 25) * (t1 + t2 * humRaw) + rhLinear;
|
h = (t - 25) * (t1 + t2 * humRaw) + rhLinear;
|
||||||
t = convertTemp(t);
|
t = ConvertTemp(t);
|
||||||
return (!isnan(t) && !isnan(h));
|
return (!isnan(t) && !isnan(h));
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean sht_detect()
|
boolean ShtDetect()
|
||||||
{
|
{
|
||||||
if (shttype) {
|
if (sht_type) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -170,59 +170,59 @@ boolean sht_detect()
|
||||||
|
|
||||||
sht_sda_pin = pin[GPIO_I2C_SDA];
|
sht_sda_pin = pin[GPIO_I2C_SDA];
|
||||||
sht_scl_pin = pin[GPIO_I2C_SCL];
|
sht_scl_pin = pin[GPIO_I2C_SCL];
|
||||||
if (sht_readTempHum(t, h)) {
|
if (ShtReadTempHum(t, h)) {
|
||||||
shttype = 1;
|
sht_type = 1;
|
||||||
addLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND));
|
AddLog_P(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_SHT1X_FOUND));
|
||||||
} else {
|
} else {
|
||||||
Wire.begin(sht_sda_pin, sht_scl_pin);
|
Wire.begin(sht_sda_pin, sht_scl_pin);
|
||||||
shttype = 0;
|
sht_type = 0;
|
||||||
}
|
}
|
||||||
return shttype;
|
return sht_type;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*********************************************************************************************\
|
/*********************************************************************************************\
|
||||||
* Presentation
|
* Presentation
|
||||||
\*********************************************************************************************/
|
\*********************************************************************************************/
|
||||||
|
|
||||||
void sht_mqttPresent(uint8_t* djson)
|
void MqttShowSht(uint8_t* djson)
|
||||||
{
|
{
|
||||||
if (!shttype) {
|
if (!sht_type) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
float t;
|
float t;
|
||||||
float h;
|
float h;
|
||||||
|
|
||||||
if (sht_readTempHum(t, h)) {
|
if (ShtReadTempHum(t, h)) {
|
||||||
char stemp[10];
|
char stemp[10];
|
||||||
char shum[10];
|
char shum[10];
|
||||||
|
|
||||||
dtostrfd(t, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfd(t, Settings.flag.temperature_resolution, stemp);
|
||||||
dtostrfd(h, sysCfg.flag.humidity_resolution, shum);
|
dtostrfd(h, Settings.flag.humidity_resolution, shum);
|
||||||
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, "SHT1X", stemp, shum);
|
snprintf_P(mqtt_data, sizeof(mqtt_data), JSON_SNS_TEMPHUM, mqtt_data, "SHT1X", stemp, shum);
|
||||||
*djson = 1;
|
*djson = 1;
|
||||||
#ifdef USE_DOMOTICZ
|
#ifdef USE_DOMOTICZ
|
||||||
domoticz_sensor2(stemp, shum);
|
DomoticzTempHumSensor(stemp, shum);
|
||||||
#endif // USE_DOMOTICZ
|
#endif // USE_DOMOTICZ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_WEBSERVER
|
#ifdef USE_WEBSERVER
|
||||||
String sht_webPresent()
|
String WebShowSht()
|
||||||
{
|
{
|
||||||
float t;
|
float t;
|
||||||
float h;
|
float h;
|
||||||
|
|
||||||
String page = "";
|
String page = "";
|
||||||
if (shttype) {
|
if (sht_type) {
|
||||||
if (sht_readTempHum(t, h)) {
|
if (ShtReadTempHum(t, h)) {
|
||||||
char stemp[10];
|
char stemp[10];
|
||||||
char shum[10];
|
char shum[10];
|
||||||
char sensor[80];
|
char sensor[80];
|
||||||
|
|
||||||
dtostrfi(t, sysCfg.flag.temperature_resolution, stemp);
|
dtostrfi(t, Settings.flag.temperature_resolution, stemp);
|
||||||
dtostrfi(h, sysCfg.flag.humidity_resolution, shum);
|
dtostrfi(h, Settings.flag.humidity_resolution, shum);
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "SHT1X", stemp, tempUnit());
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_TEMP, "SHT1X", stemp, TempUnit());
|
||||||
page += sensor;
|
page += sensor;
|
||||||
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, "SHT1X", shum);
|
snprintf_P(sensor, sizeof(sensor), HTTP_SNS_HUM, "SHT1X", shum);
|
||||||
page += sensor;
|
page += sensor;
|
||||||
|
|
Loading…
Reference in New Issue