homieiot / homie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT
http://homieiot.github.io/homie-esp8266
MIT License
1.36k stars 308 forks source link

Set default device setting without using MQTT? #451

Closed tripflex closed 6 years ago

tripflex commented 6 years ago

Is there a way to set default device property, specifically $stats/interval in setup code? can’t find anything online that details it and would like to change it to 5 minutes by default for all devices instead of just 1 minute

so I found const uint32_t STATS_SEND_INTERVAL = 1 * 60 * 1000; in Constants.hpp but still can’t seem to figure out the correct way to set this without modifying the lib code

timpur commented 6 years ago

Nope (that I know of) will add in my next release.

tripflex commented 6 years ago

Awesome thank you, just the ability to configure or override any default settings would be perfect 👍 thanks!!

tripflex commented 6 years ago

@timpur now that i'm looking at this ... is it even possible to set interval via MQTT? I can't seem to figure out any way to change the interval value used ... which maybe I don't understand the purpose of it, but my understanding is that interval would be something settable so you can change it as needed ... but now it looks like it's just a static value?

timpur commented 6 years ago

The interval is used to send info like signal and up time

It would be nice to be able to configure this. Thinking of doing this through the config, thus you can also update over mqtt via incremental json

luebbe commented 6 years ago

But isn't it also important for the MQTT server to receive this kind of "ping" message in a not "too long" interval? Kind of keepalive. Otherwise he will consider the device offline?!? I don't know enough about MQTT (whether and how it is possible to connect and tell the server at the same time how often you will ping it). I only remember having problems with one (non C) MQTT library where I couldn't set a keepalive interval and had to make sure to ping the server once every minute.

timpur commented 6 years ago

The keep alive period is handled by the mqtt lib and has nothing to do with homie. By protocol (my understanding) when the client connects it tells the broker the keep alive period and if that period is broken then the broker considers the connection broken....

Nothing to do with this stats interval with homie.

tripflex commented 6 years ago

@timpur yeah i'll probably start working on this and submit a PR if you haven't already ... did you have any specific ideas in mind of how to set it up? I can probably work on the code if you wanted it done in a specific way, but I will need this for my current project.

Reason being ... use case scenario would be outputting data on a dashboard ... so when the user is viewing dashboard for a device, we would want to update the interval to say, every 15 seconds to give a better UI experience, whereas, when just storing stats, we would only want it set to every 300 seconds (5 minutes) instead

timpur commented 6 years ago

Okay well that's not a big change let me do this tonight.

timpur commented 6 years ago

Closed by #455

You can now add the interval in seconds in the config file, which means you can also use incremental json to change this via mqtt if you like. Node not yet set this in the web UI configurator

tripflex commented 6 years ago

Awesome, thank you!! Yeah I doubt it would need to be set in the web UI, just as long as it's configurable in the main source files and via mqtt, is perfect for me, thanks!!

tripflex commented 6 years ago

Any possibility of adding a function similar to Homie_setFirmware for the interval, say, Homie_setStatsInterval to allows configuring initial interval in the setup function?

I did see you added the ability in the config file, just wasn't sure if Homie would read incremental config.json from spiff or not ... as I do still want to use the Web UI setup (interval not necessary to set in web UI)

Also posted this in #454

timpur commented 6 years ago

Kinda lost with your last comment (@tripflex), you can upload the config file via spiffs, which would also have your interval in it ? or update this value via incremental json from mqtt??

tripflex commented 6 years ago

@timpur yeah understandable, but I meant that I would like to be able to set the default value configured for the device even before it's setup and ready to go.

Mainly to set default to around 5 minutes, and then I can adjust via MQTT once it's connected to the broker via incremental json. I guess for now I can just immediately send an incremental json to the device once it connects to the broker and change it from 1 minute to 5 minutes ... which just be much cleaner to be able to set the default value in the setup function, just like we would with a normal HomieSetting

timpur commented 6 years ago

i think you miss understand, you can upload the config file from your computer with the 5min value with out the need of mqtt. See http://marvinroger.github.io/homie-esp8266/docs/develop/configuration/json-configuration-file/ .You also dont need to use configurator if you wait to just upload the config file via your computer. Uploading files to file system

also see https://github.com/marvinroger/homie-esp8266/tree/develop/data/homie