Giter VIP home page Giter VIP logo

esp-mqtt-btn-switch's Introduction

ESP8266 Momentary Standalone Relay Switch with MQTT

This is used to toggle a relay with a push button, using the EX-Store WiFi-Relay Board. The Switch will work if no WiFi or MQTT is present. I'm using it in combination with a coupling relay to replace a surge switch (Eltako S12-100).

See also the excelent Espurna Firmware which supports the ex-store relay board.

It should work on any ESP8266 with a connected relay. The difference will be, that the EX-Store relay board is using a L9110 motor driver which needs two GPIO's to be switched. To change this behaviour simply edit the turnOn() or turnOff() functions.

Connect the push button to GND and IO14 to toggle the relay. The internal Pull-Up is used.

After first flashing this sketch, you could update the ESP via ArduinoOTA. The OTA name is set to the mqttClienName which is also used for the ESP-hostname. After an OTA update the ESP gets restarted.

Starting with 0.0.3 you can attach a DHT temperature/humidity sensor to IO04 (configurable). Please comment in the USE_DHT define to use this feature.

MQTT

  • The current state (1/0) of the relay is published to <topic-prefix>state.
  • The online status (online/offline) is published to <topic-prefix>status.
  • The IP of the device is published to <topic-prefix>ip.

These topics are retained and the status will be set to offline using the last will of MQTT. The mqtt connection is now non-blocking (finally)

To change the switch' state, publish 1 or 0 to <topic-prefix>do.

The temperature and humidity values (if used) will be read every 60 seconds (configurable), retained and put to this topics:

  • <topic-prefix>temperature
  • <topic-prefix>humidity

Config

Change the settings at the top of the .ino-file corresponding to your needs. Ensure that you choose a unique mqtt client id. If you do not need credentials just set user and password to an empty string.

The serial console is left open to debug and check the WiFi connection. Baudrate 115200, 8N1.

Problems

If you get error: 'class ArduinoOTAClass' has no member named 'getCommand' comment out the complete ArduinoOTA.onStart method. It only puts the OTA-Type to the serial console when OTA is happening, so not realy needed.

Also you can update ArduinoOTA.cpp and ArduinoOTA.h to the latest master from https://github.com/esp8266/Arduino/tree/master/libraries/ArduinoOTA

Created with

Misc.

Bear with me as C/C++ is not my first language. Any suggestions and pull requests are welcome.

esp-mqtt-btn-switch's People

Contributors

codmpm avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.