Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conditional HomieNode creation #706

Open
SvenDowideit opened this issue Mar 7, 2021 · 6 comments
Open

Conditional HomieNode creation #706

SvenDowideit opened this issue Mar 7, 2021 · 6 comments

Comments

@SvenDowideit
Copy link

I would like to have one firmware that has code for all the sensors that I use, and then to use the configuration settings to decide which to enable (d1 wemos, and non-technical users)

SensorNode *sensors[10];
uint sensorCount = 0;

HomieSetting<bool> hasButton("button", "has button"); // id, description

void setup()
{
  Homie_setFirmware(FW_NAME, FW_VERSION);
  Homie_setBrand(FW_BRAND);

  hasButton.setDefaultValue(false);

  Homie.setup();
  if (hasButton.get())
  {
    Serial.printf("adding a button");
    sensors[sensorCount++] = new ButtonNode("button", "test", D3);
  }
}

but atm, it looks like the settings aren't parsed until Homie.setup() is called, and the devices need to be created before Homie.setup() is called.

is there a right way to do this? or should I look at making a PR to separate out the configuration parsing and the setup?

@luebbe
Copy link
Collaborator

luebbe commented Mar 7, 2021

Take a look at my homie node collection. There are some examples (e.g. the bme280 node) where the (per node) settings are created at run time. I don't creat the nodes at run time, because I don't have your use case, but maybe it can help you to get started.

@birnbeidla
Copy link

Had the same requirement.
As a workaround, I made a new method in HomieClass that lets me call _config->load() from outside. Called after declaring settings but before calling setup, it seems to provide a solution for config dependent nodes and devices.

@SvenDowideit
Copy link
Author

SvenDowideit commented Apr 1, 2021

@luebbe would you be interested in a PR (or just do it - I don't know enough about testing forks of platformio modules yet) to add a HomieClass::LoadConfig() that can be called before the Homie.setup()?

Admittedly, I need to work out how to do it soon, as I think I want to take that further :)

EDIT later - oh, gosh, adding a repo URL to lib_deps_external - pretty awesome....

@luebbe
Copy link
Collaborator

luebbe commented Apr 1, 2021

Sure, go ahead. But I'm not that deep into the homie sources to provide a good review, depending on the complexitiy of the PR.

@SvenDowideit
Copy link
Author

SvenDowideit commented Apr 1, 2021

well darn. I have something that works for me, but is clearly naive.

but at the same time, Platformio (or a vscode plugin) has reformatted so much code as to be a useless diff.

guess this will take a few weeks (assuming we get to go on the no-computer easter holiday)

I've got some ideas tho :)

one of which is that I now want a json settings type...

@RunningPenguin
Copy link

Hi, is here any progress?

I have a similar use case. I would like to provide a firmware which is able to connect to 1-5 sensors over serial interface. Each sensor has to be paired on its own and has its own serial number.

To achieve this my plan was to use five HomieSetting<const char *> for which the end user could write his serial number(s) and leave some blank if he has less than 5 sensors attached. For example he provides the information's with the Android "Homie setup" App.
Then I would like to count the amount of given serial numbers and either create an individual node (at runtime) or create/advertise the corresponding amount of values (at runtime).

I have to put the serial numbers in a char array too, that is right now a problem I haven't resolved yet.

I had already a look into the BME280 Node from @luebbe and in the documentation of the HomieSetting but right now I have no plan if the use-case is possible or not without changes to the Homie esp8266 implementation. Perhaps somebody could give me a few tips?

Thanks in advance

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants