Convert Figma logo to code with AI

homieiot logohomie-esp8266

💡 ESP8266 framework for Homie, a lightweight MQTT convention for the IoT

1,363
307
1,363
87

Top Related Projects

A client library for the Arduino Ethernet Shield that provides support for MQTT.

MQTT library for Arduino

📟 JSON library for Arduino and embedded C++. Simple and efficient.

Quick Overview

Homie-ESP8266 is an open-source firmware for ESP8266 devices that implements the Homie convention for IoT. It provides a standardized way to control and monitor ESP8266-based devices over MQTT, making it easier to integrate them into home automation systems.

Pros

  • Easy integration with home automation systems due to Homie convention compliance
  • Over-the-Air (OTA) updates supported
  • Extensive configuration options via JSON
  • Built-in Wi-Fi manager for easy network setup

Cons

  • Limited to ESP8266 devices only
  • Requires MQTT broker for communication
  • Learning curve for users unfamiliar with MQTT or Homie convention
  • May have higher memory footprint compared to bare-metal implementations

Code Examples

  1. Basic device setup:
#include <Homie.h>

void setup() {
  Serial.begin(115200);
  Homie_setFirmware("my-firmware", "1.0.0");
  Homie.setup();
}

void loop() {
  Homie.loop();
}
  1. Creating a node with a temperature sensor:
#include <Homie.h>

HomieNode temperatureNode("temperature", "temperature");

void setupHandler() {
  temperatureNode.advertise("degrees").setName("Temperature").setUnit("°C").setDatatype("float");
}

void loopHandler() {
  float temperature = readTemperature(); // Implement this function
  temperatureNode.setProperty("degrees").send(String(temperature));
  Homie.getLogger() << "Temperature: " << temperature << " °C" << endl;
}

void setup() {
  Serial.begin(115200);
  Homie_setFirmware("temperature-sensor", "1.0.0");
  Homie.setSetupFunction(setupHandler);
  Homie.setLoopFunction(loopHandler);
  Homie.setup();
}

void loop() {
  Homie.loop();
}
  1. Handling a settable property:
#include <Homie.h>

HomieNode ledNode("led", "switch");

bool ledOnHandler(const HomieRange& range, const String& value) {
  if (value == "true") {
    digitalWrite(LED_BUILTIN, LOW); // Turn LED on
    ledNode.setProperty("on").send("true");
    return true;
  } else if (value == "false") {
    digitalWrite(LED_BUILTIN, HIGH); // Turn LED off
    ledNode.setProperty("on").send("false");
    return true;
  }
  return false;
}

void setup() {
  Serial.begin(115200);
  pinMode(LED_BUILTIN, OUTPUT);
  Homie_setFirmware("led-controller", "1.0.0");
  ledNode.advertise("on").setName("On").setDatatype("boolean").settable(ledOnHandler);
  Homie.setup();
}

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

Getting Started

  1. Install the Arduino IDE and ESP8266 board support
  2. Install the Homie library via the Arduino Library Manager
  3. Copy the following code into a new sketch:
#include <Homie.h>

void setup() {
  Serial.begin(115200);
  Homie_setFirmware("my-device", "1.0.0");
  Homie.setup();
}

void loop() {
  Homie.loop();
}
  1. Configure your device using the config.json file
  2. Upload the sketch to your ESP8266 device
  3. Connect to the device's Wi-Fi AP and configure network settings
  4. Your device should now connect to your MQTT broker and be discoverable by Homie-compatible systems

Competitor Comparisons

A client library for the Arduino Ethernet Shield that provides support for MQTT.

Pros of PubSubClient

  • Lightweight and simple MQTT client library
  • Supports a wide range of Arduino-compatible boards
  • Well-documented and easy to use for basic MQTT functionality

Cons of PubSubClient

  • Limited features compared to Homie-ESP8266
  • Lacks built-in support for device discovery and configuration
  • Requires manual implementation of MQTT topic structure and message handling

Code Comparison

PubSubClient:

#include <PubSubClient.h>

PubSubClient client(espClient);
client.setServer(mqtt_server, 1883);
client.setCallback(callback);
client.publish("topic", "message");

Homie-ESP8266:

#include <Homie.h>

HomieNode temperatureNode("temperature", "temperature");
Homie.setup();
temperatureNode.setProperty("degrees").send(String(temperature));
Homie.loop();

PubSubClient provides a simple interface for MQTT communication, while Homie-ESP8266 offers a more structured approach with built-in conventions for IoT devices. PubSubClient requires manual handling of MQTT topics and messages, whereas Homie-ESP8266 abstracts these details and provides a higher-level API for device management and communication.

MQTT library for Arduino

Pros of arduino-mqtt

  • Lightweight and focused solely on MQTT functionality
  • Supports a wider range of Arduino-compatible boards
  • Simpler implementation for basic MQTT communication

Cons of arduino-mqtt

  • Lacks built-in device management and configuration features
  • Doesn't provide a standardized structure for IoT devices
  • Requires more manual setup for advanced MQTT usage

Code Comparison

homie-esp8266:

Homie_setFirmware("device-name", "1.0.0");
Homie.setup();

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

arduino-mqtt:

MQTTClient client;
client.begin("broker.example.com", net);
client.connect("device-id");

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

The homie-esp8266 library provides a higher-level abstraction with built-in device management, while arduino-mqtt offers a more direct MQTT implementation. homie-esp8266 is specifically designed for ESP8266 devices and follows the Homie convention, providing a standardized approach to IoT device communication. On the other hand, arduino-mqtt is more versatile in terms of board compatibility but requires more manual configuration for advanced features.

Choose homie-esp8266 for a comprehensive IoT framework on ESP8266 devices, or arduino-mqtt for a lightweight MQTT solution across various Arduino-compatible boards.

📟 JSON library for Arduino and embedded C++. Simple and efficient.

Pros of ArduinoJson

  • More versatile, can be used for general JSON parsing and serialization
  • Extensive documentation and examples
  • Supports a wider range of Arduino-compatible boards

Cons of ArduinoJson

  • Requires manual handling of MQTT communication
  • Less focused on IoT-specific features
  • May require more code to implement IoT functionality

Code Comparison

ArduinoJson:

StaticJsonDocument<200> doc;
doc["sensor"] = "temperature";
doc["value"] = 25.5;
String output;
serializeJson(doc, output);

homie-esp8266:

HomieNode temperatureNode("temperature", "temperature");
temperatureNode.setProperty("value").send(String(25.5));

ArduinoJson is a general-purpose JSON library for Arduino and IoT devices, while homie-esp8266 is specifically designed for IoT projects using the Homie convention. ArduinoJson offers more flexibility but requires more setup for IoT applications, whereas homie-esp8266 provides a streamlined approach for IoT devices with built-in MQTT support and convention adherence.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Build Status Latest Release Gitter PlatformIO

Homie for ESP8266 / ESP32

homie-esp8266 banner

An Arduino for ESP8266 / ESP32 implementation of Homie, an MQTT convention for the IoT.

This branch of Homie for ESP8266 implements Homie 3.0.1 and adds support for ESP32.

works with MQTT Homie

Download

The Git repository contains the development version of Homie for ESP8266. Stable releases are available on the releases page.

Using with PlatformIO

PlatformIO is an open source ecosystem for IoT development with cross platform build system, library manager and full support for Espressif ESP8266 development. It works on the popular host OS: Mac OS X, Windows, Linux 32/64, Linux ARM (like Raspberry Pi, BeagleBone, CubieBoard).

  1. Install PlatformIO IDE
  2. Create new project using "PlatformIO Home > New Project"
  3. Open Project Configuration File platformio.ini

Stable version

  1. Add "Homie" to project using platformio.ini and lib_deps option:
[env:myboard]
platform = espressif8266
board = ...
framework = arduino
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
lib_deps = Homie

Add the PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY build flag to ensure reliable OTA updates.

Development version

  1. Update dev/platform to staging version:

  2. Before editing platformio.ini as shown below, you must install "git" if you don't already have it. For Windows, just go to http://git-scm.com/download/win and the download will start automatically. Note, this is only a requirement for the development versions.

  3. Add development version of "Homie" to project using platformio.ini and lib_deps option:

[env:myboard]
platform = ...
board = ...
framework = arduino
build_flags = -D PIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY

; the latest development branch (convention V3.0.x)
lib_deps = https://github.com/homieiot/homie-esp8266.git#develop


Happy coding with PlatformIO!

Features

#include <Homie.h>

const int PIN_RELAY = 5;

HomieNode lightNode("light", "Light", "switch");

bool lightOnHandler(const HomieRange& range, const String& value) {
  if (value != "true" && value != "false") return false;

  bool on = (value == "true");
  digitalWrite(PIN_RELAY, on ? HIGH : LOW);
  lightNode.setProperty("on").send(value);
  Homie.getLogger() << "Light is " << (on ? "on" : "off") << endl;

  return true;
}

void setup() {
  Serial.begin(115200);
  Serial << endl << endl;
  pinMode(PIN_RELAY, OUTPUT);
  digitalWrite(PIN_RELAY, LOW);

  Homie_setFirmware("awesome-relay", "1.0.0");

  lightNode.advertise("on", "On", "boolean").settable(lightOnHandler);

  Homie.setup();
}

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

Requirements, installation and usage

The project is documented on https://homieiot.github.io/homie-esp8266/ with a Getting started guide and every piece of information you will need.

Donate

I am a student and maintaining Homie for ESP8266 takes time. I am not in need and I will continue to maintain this project as much as I can even without donations. Consider this as a way to tip the project if you like it. :wink:

Donate button