Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By Marvin Roger
#36498 Hi there!

I like the ESP8266 very much, but I got tired of hard-coding Wi-Fi credentials into the code and writing boilerplate code to automatically reconnect to the network if anything goes wrong. But I also missed a convention that all my IoT devices could follow. So I picked MQTT as the underlying network technology, and I imagined a lightweight standard that works well for me, I named Homie. You can see the Homie convention here : https://github.com/marvinroger/homie

I then implemented the ESP8266 Arduino library : https://github.com/marvinroger/homie-esp8266
Everything is described in the README and there is a *Getting started* guide in the Wiki, but for example a sketch to control a light would be:

Code: Select all#include <Homie.h>

const int PIN_RELAY = D1;

HomieNode light("light", "light");

bool lightOnHandler(String message) {
  if (message == "true") {
    digitalWrite(PIN_RELAY, HIGH);
    Homie.setNodeProperty(light, "on", "true"); // Update the state of the light
    Serial.println("Light is on");
  } else if (message == "false") {
    digitalWrite(PIN_RELAY, LOW);
    Homie.setNodeProperty(light, "on", "false");
    Serial.println("Light is off");
  } else {
    return false;
  }

  return true;
}

void setup() {
  pinMode(PIN_RELAY, OUTPUT);
  digitalWrite(PIN_RELAY, LOW);
  Homie.setFirmware("awesome-relay" ,"1.0.0");
  light.subscribe("on", lightOnHandler);
  Homie.registerNode(light);
  Homie.setup();
}

void loop() {
  Homie.loop();
}

As you can see, this is pretty straightforward, and with that simple code, you get:
  • Network connection/reconnection, based on a JSON configuration file in the SPIFFS
  • OTA support

The only requirement to use the library is to run a MQTT broker. I think the project is in a pretty stable shape now, so it's time to share it. Do you have any questions or suggestions about this project? I'm all ears! ;)

Thanks!
Last edited by Marvin Roger on Sat Feb 06, 2016 1:17 pm, edited 2 times in total.
User avatar
By eduperez
#36525 This looks very interesting, and definitively relevant to my interests! This is similar to what I have been developing, I am pretty sure we will be exchanging ideas and code pretty soon. Considering that you are using MQTT, I guess the ESP part is almost universal, and could be configured to work with any automation system, doesn't it?
User avatar
By Marvin Roger
#36528 If by universal, you mean easily pluggable to another automation system, then the answer is yes. This is classic MQTT with some naming conventions, so for example to turn on the light of the example sketch in the first post, the automation system has to send:

Code: Select allTopic: devices/my-sample-light/light/on/set
Payload: true
User avatar
By bluman
#44115 Hi there,

Thank you for the great work on this frame work. I am having issues compiling.

I'm using Arduino IDE 1.6.8 with the following libraries.
Bounce2 version 2.1.0
JSON version 5.0.8
Pubsub version 2.6.0

All libraries were installed using the IDE library manager.
I am trying to compile the LightOnOff example sketch and receive the following error message.

Any help would be greatly appreciated.

Arduino: 1.6.8 (Linux), Board: "Generic ESP8266 Module, Serial, 80 MHz, 40MHz, DIO, 115200, 512K (64K SPIFFS), ck"

/home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp: In member function 'virtual void HomieInternals::BootOta::setup()':
/home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:65:180: error: no matching function for call to 'ESP8266HTTPUpdate::update(const char*&, uint16_t&, char [28], char [56], bool&, char [60], bool)'
t_httpUpdate_return ret = ESPhttpUpdate.update(host, port, Config.get().ota.path, dataToPass, Config.get().ota.server.ssl.enabled, Config.get().ota.server.ssl.fingerprint, false);
^
/home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:65:180: note: candidates are:
In file included from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.hpp:6:0,
from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:1:
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:52:29: note: t_httpUpdate_return ESP8266HTTPUpdate::update(const char*, const char*, const char*)
t_httpUpdate_return update(const char * url, const char * current_version = "", const char * httpsFingerprint = "");

^
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:52:29: note: candidate expects 3 arguments, 7 provided
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:53:29: note: t_httpUpdate_return ESP8266HTTPUpdate::update(const char*, uint16_t, const char*, const char*, bool, const char*)
t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "", bool https = false, const char * httpsFingerprint = "");

^
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:53:29: note: candidate expects 6 arguments, 7 provided
In file included from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.hpp:6:0,
from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:1:
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:54:29: note: t_httpUpdate_return ESP8266HTTPUpdate::update(String, uint16_t, String, String, bool, String)
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = "");

^
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:54:29: note: candidate expects 6 arguments, 7 provided
exit status 1
Error compiling for board Generic ESP8266 Module.
/home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp: In member function 'virtual void HomieInternals::BootOta::setup()':
/home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:65:180: error: no matching function for call to 'ESP8266HTTPUpdate::update(const char*&, uint16_t&, char [28], char [56], bool&, char [60], bool)'
t_httpUpdate_return ret = ESPhttpUpdate.update(host, port, Config.get().ota.path, dataToPass, Config.get().ota.server.ssl.enabled, Config.get().ota.server.ssl.fingerprint, false);
^
/home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:65:180: note: candidates are:
In file included from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.hpp:6:0,
from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:1:
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:52:29: note: t_httpUpdate_return ESP8266HTTPUpdate::update(const char*, const char*, const char*)
t_httpUpdate_return update(const char * url, const char * current_version = "", const char * httpsFingerprint = "");

^
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:52:29: note: candidate expects 3 arguments, 7 provided
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:53:29: note: t_httpUpdate_return ESP8266HTTPUpdate::update(const char*, uint16_t, const char*, const char*, bool, const char*)
t_httpUpdate_return update(const char * host, uint16_t port, const char * url = "/", const char * current_version = "", bool https = false, const char * httpsFingerprint = "");

^
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:53:29: note: candidate expects 6 arguments, 7 provided
In file included from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.hpp:6:0,
from /home/hp2540p/Arduino/libraries/homie-esp8266-master/src/Homie/Boot/BootOta.cpp:1:
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:54:29: note: t_httpUpdate_return ESP8266HTTPUpdate::update(String, uint16_t, String, String, bool, String)
t_httpUpdate_return update(String host, uint16_t port, String url = "/", String current_version = "", bool https = false, String httpsFingerprint = "");

^
/home/hp2540p/.arduino15/packages/esp8266/hardware/esp8266/2.0.0/libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h:54:29: note: candidate expects 6 arguments, 7 provided
exit status 1
Error compiling for board Generic ESP8266 Module.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.