Compare commits
11 Commits
795043a639
...
v0.3.2
Author | SHA1 | Date | |
---|---|---|---|
36ce6f976b | |||
a4c2d49fb0 | |||
bad20a7f58 | |||
c00d2afb27 | |||
|
0ae3824e88 | ||
|
847dda81be | ||
|
dc91211889 | ||
58bcd731fc | |||
6efa5bd0b8 | |||
2a3bbc3628 | |||
|
e322b5ddcd |
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,4 +1,5 @@
|
|||||||
.pioenvs
|
.pioenvs
|
||||||
.piolibdeps
|
.piolibdeps
|
||||||
|
.pio
|
||||||
data/homie/config.json
|
data/homie/config.json
|
||||||
nbproject
|
nbproject
|
||||||
|
BIN
.vscode/.BROWSE.C_CPP.DB
vendored
Normal file
BIN
.vscode/.BROWSE.C_CPP.DB
vendored
Normal file
Binary file not shown.
BIN
.vscode/.BROWSE.C_CPP.DB-shm
vendored
Normal file
BIN
.vscode/.BROWSE.C_CPP.DB-shm
vendored
Normal file
Binary file not shown.
BIN
.vscode/.BROWSE.C_CPP.DB-wal
vendored
Normal file
BIN
.vscode/.BROWSE.C_CPP.DB-wal
vendored
Normal file
Binary file not shown.
129
.vscode/c_cpp_properties.json
vendored
Normal file
129
.vscode/c_cpp_properties.json
vendored
Normal file
@ -0,0 +1,129 @@
|
|||||||
|
{
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "!!! WARNING !!! AUTO-GENERATED FILE, PLEASE DO NOT MODIFY IT AND USE https://docs.platformio.org/page/projectconf/section_env_build.html#build-flags"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "Win32",
|
||||||
|
"includePath": [
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/Homie/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266mDNS/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Ticker",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/DNSServer/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/ESP Async WebServer_ID306/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Hash/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/Bounce2_ID1106/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/AsyncMqttClient_ID346/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/ESPAsyncTCP_ID305/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/ArduinoJson_ID64/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/tools/sdk/include",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/tools/sdk/libc/xtensa-lx106-elf/include",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/cores/esp8266",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lwip2/include",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/variants/nodemcu",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/Syslog_ID1506/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ArduinoOTA",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/EEPROM",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266AVRISP/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPUpdateServer/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266LLMNR",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266NetBIOS",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SSDP",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SdFat/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WebServer/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFiMesh/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266httpUpdate/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Ethernet/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/GDBStub/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SD/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SDFS/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SPI",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SPISlave/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Servo/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SoftwareSerial/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/TFT_Touch_Shield_V2",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Wire",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/esp8266/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/tool-unity",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"browse": {
|
||||||
|
"limitSymbolsToIncludedHeaders": true,
|
||||||
|
"databaseFilename": "${workspaceRoot}/.vscode/.browse.c_cpp.db",
|
||||||
|
"path": [
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/Homie/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPClient/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266mDNS/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Ticker",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/DNSServer/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/ESP Async WebServer_ID306/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Hash/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/Bounce2_ID1106/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/AsyncMqttClient_ID346/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/ESPAsyncTCP_ID305/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFi/src",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/ArduinoJson_ID64/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/tools/sdk/include",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/tools/sdk/libc/xtensa-lx106-elf/include",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/cores/esp8266",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/tools/sdk/lwip2/include",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/variants/nodemcu",
|
||||||
|
"c:/Users/furyf/Dev/deskcontrol/.pio/libdeps/nodemcu/Syslog_ID1506/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ArduinoOTA",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/EEPROM",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266AVRISP/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266HTTPUpdateServer/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266LLMNR",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266NetBIOS",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SSDP",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266SdFat/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WebServer/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266WiFiMesh/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/ESP8266httpUpdate/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Ethernet/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/GDBStub/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SD/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SDFS/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SPI",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SPISlave/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Servo/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/SoftwareSerial/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/TFT_Touch_Shield_V2",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/Wire",
|
||||||
|
"C:/Users/furyf/.platformio/packages/framework-arduinoespressif8266/libraries/esp8266/src",
|
||||||
|
"C:/Users/furyf/.platformio/packages/tool-unity",
|
||||||
|
""
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"defines": [
|
||||||
|
"PLATFORMIO=40000",
|
||||||
|
"ESP8266",
|
||||||
|
"ARDUINO_ARCH_ESP8266",
|
||||||
|
"ARDUINO_ESP8266_NODEMCU",
|
||||||
|
"PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY",
|
||||||
|
"F_CPU=80000000L",
|
||||||
|
"__ets__",
|
||||||
|
"ICACHE_FLASH",
|
||||||
|
"ARDUINO=10805",
|
||||||
|
"ARDUINO_BOARD=\"PLATFORMIO_NODEMCU\"",
|
||||||
|
"FLASHMODE_QIO",
|
||||||
|
"LWIP_OPEN_SRC",
|
||||||
|
"NONOSDK221=1",
|
||||||
|
"TCP_MSS=536",
|
||||||
|
"LWIP_FEATURES=1",
|
||||||
|
"LWIP_IPV6=0",
|
||||||
|
"VTABLES_IN_FLASH",
|
||||||
|
""
|
||||||
|
],
|
||||||
|
"intelliSenseMode": "clang-x64",
|
||||||
|
"cStandard": "c99",
|
||||||
|
"cppStandard": "c++11",
|
||||||
|
"compilerPath": "\"C:/Users/furyf/.platformio/packages/toolchain-xtensa/bin/xtensa-lx106-elf-gcc.exe\" -mlongcalls -mtext-section-literals"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"version": 4
|
||||||
|
}
|
7
.vscode/extensions.json
vendored
Normal file
7
.vscode/extensions.json
vendored
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
// See http://go.microsoft.com/fwlink/?LinkId=827846
|
||||||
|
// for the documentation about the extensions.json format
|
||||||
|
"recommendations": [
|
||||||
|
"platformio.platformio-ide"
|
||||||
|
]
|
||||||
|
}
|
32
.vscode/launch.json
vendored
Normal file
32
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
// AUTOMATICALLY GENERATED FILE. PLEASE DO NOT MODIFY IT MANUALLY
|
||||||
|
|
||||||
|
// PIO Unified Debugger
|
||||||
|
//
|
||||||
|
// Documentation: https://docs.platformio.org/page/plus/debugging.html
|
||||||
|
// Configuration: https://docs.platformio.org/page/projectconf/section_env_debug.html
|
||||||
|
|
||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"type": "platformio-debug",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "PIO Debug",
|
||||||
|
"executable": "c:/Users/furyf/Dev/deskcontrol/.pio/build/nodemcu/firmware.elf",
|
||||||
|
"toolchainBinDir": "C:/Users/furyf/.platformio/packages/toolchain-xtensa/bin",
|
||||||
|
"preLaunchTask": {
|
||||||
|
"type": "PlatformIO",
|
||||||
|
"task": "Pre-Debug"
|
||||||
|
},
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"type": "platformio-debug",
|
||||||
|
"request": "launch",
|
||||||
|
"name": "PIO Debug (skip Pre-Debug)",
|
||||||
|
"executable": "c:/Users/furyf/Dev/deskcontrol/.pio/build/nodemcu/firmware.elf",
|
||||||
|
"toolchainBinDir": "C:/Users/furyf/.platformio/packages/toolchain-xtensa/bin",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
6
.vscode/settings.json
vendored
Normal file
6
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"terminal.integrated.env.windows": {
|
||||||
|
"PATH": "C:\\Program Files (x86)\\STMicroelectronics\\st_toolset\\asm;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility;C:\\Program Files\\doxygen\\bin;C:\\Program Files (x86)\\QuickTime\\QTSystem\\;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current;C:\\Users\\furyf\\go\\bin;C:\\Users\\furyf\\scoop\\apps\\composer\\current\\home\\vendor\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\gems\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\python27\\current\\scripts;C:\\Users\\furyf\\scoop\\apps\\latex\\current\\texmfs\\install\\miktex\\bin;C:\\Users\\furyf\\scoop\\apps\\gcc\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nmap\\current\\bin;C:\\Users\\furyf\\AppData\\Local\\Programs\\Python\\Launcher\\;C:\\Users\\furyf\\scoop\\shims;C:\\Users\\furyf\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\furyf\\scoop\\apps\\msys\\current\\bin;C:\\Users\\furyf\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\System\\PATH;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files (x86)\\STMicroelectronics\\st_toolset\\asm;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files (x86)\\STMicroelectronics\\STM32 ST-LINK Utility\\ST-LINK Utility;C:\\Program Files\\doxygen\\bin;C:\\Program Files (x86)\\QuickTime\\QTSystem\\;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nodejs\\current;C:\\Users\\furyf\\go\\bin;C:\\Users\\furyf\\scoop\\apps\\composer\\current\\home\\vendor\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\gems\\bin;C:\\Users\\furyf\\scoop\\apps\\ruby\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\python27\\current\\scripts;C:\\Users\\furyf\\scoop\\apps\\latex\\current\\texmfs\\install\\miktex\\bin;C:\\Users\\furyf\\scoop\\apps\\gcc\\current\\bin;C:\\Users\\furyf\\scoop\\apps\\nmap\\current\\bin;C:\\Users\\furyf\\AppData\\Local\\Programs\\Python\\Launcher\\;C:\\Users\\furyf\\scoop\\shims;C:\\Users\\furyf\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\furyf\\scoop\\apps\\msys\\current\\bin;C:\\Users\\furyf\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\System\\PATH;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps",
|
||||||
|
"PLATFORMIO_CALLER": "vscode"
|
||||||
|
}
|
||||||
|
}
|
@ -17,11 +17,17 @@
|
|||||||
# Automatic targets - enable auto-uploading
|
# Automatic targets - enable auto-uploading
|
||||||
# targets = upload
|
# targets = upload
|
||||||
|
|
||||||
[env:nodemcu]
|
[env]
|
||||||
platform = espressif8266
|
platform = espressif8266
|
||||||
framework = arduino
|
framework = arduino
|
||||||
board = nodemcu
|
|
||||||
upload_speed=921600
|
upload_speed=921600
|
||||||
|
|
||||||
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
|
||||||
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop, Syslog
|
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop-v3
|
||||||
|
|
||||||
|
[env:nodemcu]
|
||||||
|
board = nodemcu
|
||||||
|
|
||||||
|
[env:nodemcuv2]
|
||||||
|
board = nodemcuv2
|
143
src/main.cpp
143
src/main.cpp
@ -1,113 +1,82 @@
|
|||||||
#include <Homie.h>
|
#include <Homie.h>
|
||||||
#include <Syslog.h>
|
|
||||||
#include <WiFiUdp.h>
|
#include <WiFiUdp.h>
|
||||||
WiFiUDP udpClient;
|
|
||||||
Syslog syslog(udpClient, SYSLOG_PROTO_IETF);
|
|
||||||
|
|
||||||
const int PIN_RELAY = D1;
|
const int PIN_RELAY = D1;
|
||||||
int timer = 0;
|
#define OUTPUT_SET(x) digitalWrite(PIN_RELAY, x ? LOW : HIGH)
|
||||||
HomieNode powerNode("power", "switch");
|
unsigned int timer = 0;
|
||||||
|
unsigned int next_timer_update = 0;
|
||||||
|
HomieNode powerNode("power", "Power", "switch");
|
||||||
|
|
||||||
|
bool powerStateHandler(const HomieRange& range, const String& value) {
|
||||||
|
if (value != "on" && value != "off") return false;
|
||||||
bool powerOnHandler(const HomieRange& range, const String& value) {
|
powerNode.setProperty("state").send(value);
|
||||||
if (value != "true" && value != "false") return false;
|
powerNode.setProperty("timer").send("0");
|
||||||
bool on = (value == "true");
|
timer = 0;
|
||||||
digitalWrite(PIN_RELAY, on ? LOW : HIGH);
|
if(value == "on") {
|
||||||
powerNode.setProperty("on").send(value);
|
OUTPUT_SET(true);
|
||||||
Homie.getLogger() << "Power is " << (on ? "on" : "off") << endl;
|
Homie.getLogger() << "Power is on" << endl;
|
||||||
|
} else {
|
||||||
|
OUTPUT_SET(false);
|
||||||
|
Homie.getLogger() << "Power is off" << endl;
|
||||||
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupHandler() {
|
bool powerTimerHandler(const HomieRange& range, const String& value) {
|
||||||
pinMode(PIN_RELAY, OUTPUT);
|
int settimer = value.toInt();
|
||||||
digitalWrite(PIN_RELAY, HIGH);
|
if(settimer == 0 || settimer > 120)
|
||||||
|
return false;
|
||||||
|
|
||||||
powerNode.setProperty("on").send("false");
|
timer = millis() + (settimer * 1000 * 60);
|
||||||
|
next_timer_update = millis() + 60*1000;
|
||||||
|
powerNode.setProperty("timer").send(String(settimer));
|
||||||
|
powerNode.setProperty("state").send("on");
|
||||||
|
Homie.getLogger() << "Power is on for " << settimer << "minutes" << endl;
|
||||||
|
OUTPUT_SET(true);
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void onHomieEvent(const HomieEvent& event) {
|
|
||||||
switch(event.type) {
|
|
||||||
case HomieEventType::STANDALONE_MODE:
|
|
||||||
// Do whatever you want when standalone mode is started
|
|
||||||
break;
|
|
||||||
case HomieEventType::CONFIGURATION_MODE:
|
|
||||||
// Do whatever you want when configuration mode is started
|
|
||||||
break;
|
|
||||||
case HomieEventType::NORMAL_MODE:
|
|
||||||
// Do whatever you want when normal mode is started
|
|
||||||
break;
|
|
||||||
case HomieEventType::OTA_STARTED:
|
|
||||||
// Do whatever you want when OTA is started
|
|
||||||
break;
|
|
||||||
case HomieEventType::OTA_PROGRESS:
|
|
||||||
// Do whatever you want when OTA is in progress
|
|
||||||
|
|
||||||
// You can use event.sizeDone and event.sizeTotal
|
void setupHandler() {
|
||||||
break;
|
pinMode(PIN_RELAY, OUTPUT);
|
||||||
case HomieEventType::OTA_FAILED:
|
OUTPUT_SET(false);
|
||||||
// Do whatever you want when OTA is failed
|
powerNode.setProperty("state").send("off");
|
||||||
break;
|
powerNode.setProperty("timer").send("0");
|
||||||
case HomieEventType::OTA_SUCCESSFUL:
|
}
|
||||||
// Do whatever you want when OTA is successful
|
|
||||||
break;
|
|
||||||
case HomieEventType::ABOUT_TO_RESET:
|
|
||||||
// Do whatever you want when the device is about to reset
|
|
||||||
break;
|
|
||||||
case HomieEventType::WIFI_CONNECTED:
|
|
||||||
// Do whatever you want when Wi-Fi is connected in normal mode
|
|
||||||
syslog.deviceHostname(Homie.getConfiguration().name);
|
|
||||||
syslog.appName("deskcontrol");
|
|
||||||
syslog.defaultPriority(LOG_ERR);
|
|
||||||
syslog.log(LOG_INFO, "WiFi Connected, software version: 1.0");
|
|
||||||
// You can use event.ip, event.gateway, event.mask
|
|
||||||
break;
|
|
||||||
case HomieEventType::WIFI_DISCONNECTED:
|
|
||||||
// Do whatever you want when Wi-Fi is disconnected in normal mode
|
|
||||||
|
|
||||||
// You can use event.wifiReason
|
void loopHandler() {
|
||||||
break;
|
if(timer)
|
||||||
case HomieEventType::MQTT_READY:
|
{
|
||||||
// Do whatever you want when MQTT is connected in normal mode
|
if(timer < millis())
|
||||||
syslog.log(LOG_INFO, "MQTT connected");
|
{ //Timer has expired. (Ignore the wraparound...)
|
||||||
break;
|
timer = 0;
|
||||||
case HomieEventType::MQTT_DISCONNECTED:
|
OUTPUT_SET(false);
|
||||||
// Do whatever you want when MQTT is disconnected in normal mode
|
powerNode.setProperty("timer").send("0");
|
||||||
syslog.log(LOG_INFO, "MQTT disconnected");
|
powerNode.setProperty("state").send("off");
|
||||||
// You can use event.mqttReason
|
}
|
||||||
break;
|
|
||||||
case HomieEventType::MQTT_PACKET_ACKNOWLEDGED:
|
|
||||||
// Do whatever you want when an MQTT packet with QoS > 0 is acknowledged by the broker
|
|
||||||
|
|
||||||
// You can use event.packetId
|
if(next_timer_update && millis() > next_timer_update) {
|
||||||
break;
|
next_timer_update = millis() + 60*1000;
|
||||||
case HomieEventType::READY_TO_SLEEP:
|
unsigned int time_remaining = timer - millis();
|
||||||
// After you've called `prepareToSleep()`, the event is triggered when MQTT is disconnected
|
unsigned int min_left = time_remaining / (60*1000);
|
||||||
break;
|
powerNode.setProperty("timer").send(String(min_left));
|
||||||
case HomieEventType::SENDING_STATISTICS:
|
|
||||||
// Do whatever you want when statistics are sent in normal mode
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
syslog.server("192.168.1.100", 514);
|
|
||||||
|
|
||||||
|
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
|
|
||||||
Serial << endl << endl;
|
Homie_setFirmware("deskcontrol", "0.3.2");
|
||||||
Serial << "Firmware 0.0.1" << endl;
|
|
||||||
Serial << endl << endl;
|
|
||||||
|
|
||||||
Homie_setFirmware("deskcontrol", "1.0.0");
|
|
||||||
Homie_setBrand("FuryFire");
|
|
||||||
|
|
||||||
powerNode.advertise("on").settable(powerOnHandler);
|
|
||||||
|
|
||||||
|
Homie.disableResetTrigger();
|
||||||
|
powerNode.advertise("state").settable(powerStateHandler);
|
||||||
|
powerNode.advertise("timer").settable(powerTimerHandler);
|
||||||
Homie.setSetupFunction(setupHandler);
|
Homie.setSetupFunction(setupHandler);
|
||||||
Homie.onEvent(onHomieEvent); // before Homie.setup()
|
Homie.setLoopFunction(loopHandler);
|
||||||
Homie.setup();
|
Homie.setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user