Skip to content

Latest commit

 

History

History
136 lines (76 loc) · 4.63 KB

7.-API-reference.md

File metadata and controls

136 lines (76 loc) · 4.63 KB

API reference

Homie object

You don't have to instantiate an Homie instance, it is done internally.

void Homie.setup ()

Setup Homie. Must be called once in setup().

void Homie.loop ()

Handle Homie work. Must be called in loop().

void Homie.enableLogging (bool enable)

Enable or disable Homie Serial logging. If logging is enabled, Serial.begin(115200) will be called internally.

  • enable: Whether or not to enable logging. By default, logging is enabled

void Homie.enableBuiltInLedIndicator (bool enable)

Enable or disable the built-in LED to indicate the Homie state.

  • enable: Whether or not to enable built-in LED. By default, it is enabled

void Homie.setLedPin (unsigned char pin, unsigned char on)

Set pin of the LED to control.

  • pin: LED to control
  • on: state when the light is on (HIGH or LOW)

void Homie.setBrand (const char* name)

Set the brand of the device, used in the configuration AP, the device hostname and the MQTT client ID.

  • name: Name of the brand. Default value is Homie

void Homie.setFirmware (const char* name, const char* version)

Set the name and version of the firmware. This is useful for OTA, as Homie will check against the server if there is a newer version.

  • name: Name of the firmware. Default value is undefined
  • version: Version of the firmware. Default value is undefined

void Homie.registerNode (HomieNode node)

Register a node.

  • node: node to register

void Homie.setGlobalInputHandler (std::function<bool(String nodeId, String property, String value)> handler)

Set input handler for subscribed properties.

  • handler: Global input handler
  • node: Name of the node getting updated
  • property: Property of the node getting updated
  • value: Value of the new property

void Homie.onEvent (std::function<void(HomieEvent event)> callback)

Set the event handler. Useful if you want to hook to Homie events.

  • callback: Event handler

void Homie.setResetTrigger (unsigned char pin, unsigned char state, unsigned int time)

Set the reset trigger. By default, the device will reset when pin 0 is LOW for 5000ms.

  • pin: Pin of the reset trigger
  • state: Reset when the pin reaches this state for the given time
  • time: Time necessary to reset

void Homie.disableResetTrigger ()

Disable the reset trigger.

void Homie.setResetFunction (std::function<bool()> callback)

Set the reset function. This is a function that is going to be called at each loop iteration, which can trigger a device reset. If the function returns true, the device resets. Else, it does not.

  • callback: Reset function

void Homie.setSetupFunction (std::function<void()> callback)

You can provide the function that will be called when operating in normal mode.

  • callback: Setup function

void Homie.setLoopFunction (std::function<void()> callback)

You can provide the function that will be looped in normal mode.

  • callback: Loop function

void Homie.setNodeProperty (HomieNode node, String property, String value, bool retained = true)

Using this function, you can set the value of a node property, like a temperature for example.

  • node: HomieNode instance on which to set the property on
  • property: Property to send
  • value: Payload
  • retained: Optional. Should the MQTT broker retain this value, or is it a one-shot value?

void Homie.setResettable (bool resettable)

Is the device resettable? This is useful at runtime, because you might want the device not to be resettable when you have another library that is doing some unfinished work, like moving shutters for example.

  • resettable: Is the device resettable? Default value is true

bool Homie.isReadyToOperate ()

Is the device in normal mode, configured and connected? You should not need this function. But maybe you will.


HomieNode object

void HomieNode (const char* id, const char* type, std::function<bool(String property, String value)> handler = , bool subscribeToAll = false)

Constructor of a HomieNode object.

  • id: ID of the node
  • type: Type of the node
  • handler: Optional. Input handler of the node
  • subscribeToAll: Optional. Whether or not to call the handler for every properties, even the ones not registered

void .subscribe (const char* property, std::function<bool(String value)> handler) = )

Subscribes the node to the given property.

  • property: Property to subscribe to
  • handler: Optional. Input handler of the property of the node