Coder Social home page Coder Social logo

tplink_control's Introduction

TPLink_Control

Using NodeMCU to control TPLink smart bulb

Written using Arduino, and ESP8266 libraries

Requires NodeMCU Arduino library from http://arduino.esp8266.com/stable/package_esp8266com_index.json

Background

The TPLink bulb is controllable by phone app or Alexa, but in this case the location was inconvenient to use either of those methods.

So this project was created to use the NodeMCU board, and fit inside a large pushbutton switch. The light can then be switched on or off remotely.

Unfortunately the connect time of the NodemMCU meant it is impractical to just power the button when required, then go back to sleep. This would be ideal and allow it to be run on batteries, but the lag for the connection is between 200ms and 5 seconds, which is unacceptable.

So the device must be continuously powered, monitoring for the push switch. It does mean that it is responsive and the light is switched within 300ms.

Operation

WiFiManager is used to manage the connection. This library (from https://github.com/tzapu/WiFiManager) provides an AP when powered up for configuring the connection, but afterwards it will automatically connect to the stored router. If the wifi point is not available, it will automatically show the AP again.

The switch input is connected to GPIO.5, with a pullup resistor.

When the NodeMCU powers up, it checks this switch state, and if the switch is active the AP will be shown, otherwise the NodeMCU will connect to the stored wifi.

Additionally a LED is connected to GPIO.13, which flashes while the NodeMCU is in the AP mode.

To simplify operation, the bulb has a static address set in the router. Future enhancement will allow a scan of the network to locate bulbs attached.

When the switch is pressed, the command to get the light status is sent out.

The bulb replies in typically 200ms with its current state. The NodeMCU can then send a command to turn the light on or off correspondingly.

Acknowledgements

Most information was gained from project https://github.com/konsumer/tplink-lightbulb. Commands were tested, and sniffed using Wireshark to obtain the basic commands.

Some commands were simply guesses until it worked (status)

Currently only the On, Off and Status commands are implemented.

A possible future enhancement is to use the length of switch press as a brightness control, ramping up and down.

tplink_control's People

Contributors

davekelly63 avatar

Watchers

 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.