Giter VIP home page Giter VIP logo

Comments (11)

enavarro222 avatar enavarro222 commented on May 23, 2024

👍 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.

marvinroger avatar marvinroger commented on May 23, 2024

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.

enavarro222 avatar enavarro222 commented on May 23, 2024

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.

furyfire avatar furyfire commented on May 23, 2024

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.

furyfire avatar furyfire commented on May 23, 2024

And I just posted on the wrong issue. Disregard that last comment

from homie-esp8266.

marvinroger avatar marvinroger commented on May 23, 2024

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.

furyfire avatar furyfire commented on May 23, 2024

The time.h lib simply starts the clock from UNIX epoch. Every schedule you start will simply run relative to that.

from homie-esp8266.

marvinroger avatar marvinroger commented on May 23, 2024

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.

marvinroger avatar marvinroger commented on May 23, 2024

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.

marvinroger avatar marvinroger commented on May 23, 2024

Docs are in place, I can close this.

from homie-esp8266.

enavarro222 avatar enavarro222 commented on May 23, 2024

Nice ! good job ;)

from homie-esp8266.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.