Skip to content

Arduino code for ESP8266 based window sensor publishing to own MQTT server

Notifications You must be signed in to change notification settings

oo-dev17/MqttWindowSensor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Firmware Update Documentation

Overview

This firmware supports over-the-air (OTA) updates, allowing the device to download and apply new firmware versions without requiring physical access. The update process is managed via HTTP requests to a specified server hosting the firmware binary.

Update Process

  1. Firmware URL:
    The firmware binary is hosted on an HTTP server. The URL for the firmware is hardcoded in the firmware as:

    http://192.168.2.20:5005/UpdateImages/firmware.bin

    Ensure that the server is accessible and the firmware binary is available at this location.

  2. Authentication:
    The firmware supports basic authentication for the HTTP server. The credentials are defined in the firmware as:

  • Username: WEBDAV_NAME
  • Password: WEBDAV_PASS
  1. Update Trigger:
    The firmware periodically checks for updates by comparing the current version (THIS_VERSION) with the version available on the MQTT server. The URL for the current version is:

http://192.168.2.28:8093/v1/state/mqtt.0.WindowSensors.CurrentVersion

  1. Update Conditions:
  • If the version available on the server is greater than the current version, the update process is initiated.
  • The device downloads the firmware binary and streams it to the internal update library (Update).
  1. Update Completion:
  • If the update is successful, the device restarts to apply the new firmware.
  • If the update fails, an error message is logged, and the device continues running the current firmware.

MQTT Topics

The firmware uses MQTT to publish and log update-related information:

  • Current Version:
    After a successful update, the device publishes the current firmware version to the topic:

    WindowSensors//currentVersion

  • Logs:
    Update logs are published to the topic:

WindowSensors//log

  • IP Address:
    The device publishes its IP address to the topic:

WindowSensors//ipAddress

Configuration

  • MQTT Server:
    The MQTT server is configured as:

192.168.2.28

nsure the server is reachable and properly configured to handle the topics.

  • Device Class Identifier:
    The device class identifier is set as:

WindowSensors

  • MAC Address:
    The last three bytes of the device's MAC address are used to uniquely identify the device in MQTT topics.

Example Workflow

  1. The device checks the current firmware version from the MQTT server.
  2. If an update is available, it downloads the firmware binary from the specified URL.
  3. The update is applied, and the device restarts.
  4. After restarting, the device publishes its new version and IP address to the MQTT server.

Notes

  • Ensure the firmware binary is compatible with the device.
  • The HTTP server hosting the firmware must be reliable and accessible.
  • Proper error handling is implemented to ensure the device remains operational in case of update failures.

About

Arduino code for ESP8266 based window sensor publishing to own MQTT server

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages