Skip to content

Conditional HomieNode creation #706

@SvenDowideit

Description

@SvenDowideit

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions