Comments (11)
👍 looks nice. It should avoid -always the same- if/elseif in global handler.
Maybe handler could return a boolean that indicate if more specific ones should be call or not. For example on a msg:
- global handler is called,
- if returns false, then node level handler is called
- if returns false, property handler is called.
I'm not sure about the order (global to property level, or reverse...). At least if you want to have a logging on each msg, better to have global first.
Other good think I see is to create generic HomieNode by inheritance. For instance one can have a RelayNode, that you can use like that:
#include <Homie.h>
#include <HomieRelayNode.h>
HomieRelayNode light("light", "light", D1);
void setup() {
Homie.setFirmware("awesome-relay" ,"1.0.0");
light.setup(false); // set the initial state
Homie.registerNode(light); // do the subscribe and callback binding
Homie.setup();
}
void loop() {
Homie.loop();
}
from homie-esp8266.
Your propagation idea is a great one! Will definitely implement it. Yes, global to property is the best option.
The inheritance idea is complicated. The simplest case implies a relay, as you show. The goal is simple: set a relay HIGH or LOW. The fact is, some relays are HIGH-active, others are LOW-active, so there is already a complexity. Homie for ESP8266 goal is to throw the network complexity away, not hardware ones - at least not for now -. ;)
BTW, to implement SSL and user/pass auth, the JSON config structure has to be changed. What do you think of:
{
"name": "kitchen light",
"wifi": {
"ssid": "Network_1",
"password": "I'm a Wi-Fi password!"
},
"mqtt": {
"host": "192.168.1.10",
"port": 35589,
"auth": true,
"username": "user",
"password": "pass",
"ssl": true,
"fingerprint": "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C"
},
"ota": {
"enabled": true,
"host": "192.168.1.10",
"port": 35590,
"path": "/ota",
"ssl": true,
"fingerprint": "CF 05 98 89 CA FF 8E D8 5E 5C E0 C2 E4 F7 E6 C3 C7 50 DD 5C"
}
}
from homie-esp8266.
Yep, maybe inheritance is out of the scope on Homie (to keep it generic and lightweight), however it could be done in third part lib. For instance I got few devices with similar hardware (a buzzer, RGB lamps, ...). I already have some class that handle that hardware, for now the (always the same) binding with Hommie/MQTT is made by hand in the main file... It could be factorize in the hardware class (that inherit HomieNode).
New config json looks ok. It will also permit to have a ota server different of the mqtt one, that's nice.
from homie-esp8266.
I implemented a proof of concept where homie would get the clock from and ntp server.
This allows me to use the https://github.com/PaulStoffregen/Time and the https://github.com/PaulStoffregen/TimeAlarm modules which simplifies the main loop alot.
The timemodule let's you schedule events periodically or at fixed times.
from homie-esp8266.
And I just posted on the wrong issue. Disregard that last comment
from homie-esp8266.
Time was something I thinked about, thanks for that. Wrong issue as you said, but just be sure nothing fails if there is no internet connection, I want Homie-ESP8266 to be cloud-independant.
from homie-esp8266.
The time.h lib simply starts the clock from UNIX epoch. Every schedule you start will simply run relative to that.
from homie-esp8266.
Both the config API and the new API with node and property levels handlers have been implemented. Examples have been updated to reflect the changes.
The next big step is the documentation.
from homie-esp8266.
The API in the README is not up-to-date about the handlers, but it works the way it is described in the first post, and as @enavarro222 said:
- global handler is called,
- if returns false, then node level handler is called
- if returns false, property handler is called
This is probably not that clear, but it will be when the docs will be finished. :)
from homie-esp8266.
Docs are in place, I can close this.
from homie-esp8266.
Nice ! good job ;)
from homie-esp8266.
Related Issues (20)
- lint: fix warning "Using C-style cast" HOT 1
- Wemos D1 mini Pro crashes on boot up with debug flag enabled HOT 3
- Home Assistant integration
- Question: Delay between MQTT messages HOT 16
- [Request] Add support to save configure as json in web configurator
- Can't build with arduino-esp32 v2.0.2 (latest stable) HOT 4
- Public variables in PropertyInputHandler are undefined. HOT 2
- compilation failure on ESP32 HOT 3
- Get node property without intermediate variable HOT 1
- Compilation failure on ESP8266 HOT 2
- MQTT reconnect fails after Wifi-disconnect HOT 10
- Wrong MQTT topic used when advertising $unit HOT 1
- using ESP32 Serial1 interface triggers homie reset HOT 1
- Connection to HiveMQ Cloud not working
- 'HTTPClient::begin' declared with attribute error: obsolete API, use ::begin(WiFiClient, url) HOT 3
- version 4 HOT 1
- Issue with ArduinoIDE and manually installed libraries
- PlatformIO [email protected] linker error HOT 2
- HomieSetting.setDefaultValue("") might be freed crashing the mcu HOT 3
- Range index control is not valid
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from homie-esp8266.