LED State Control IoT Case Study
Aim
IoT project to control sensors via Internet. Project included development of User Interface/ Server Scripting and Electronics control. ESP8266 WiFi Micro controller was used to interact with sensors and connect to internet. User Interface was developed in AngularJS , Server side and API was developed in PHP with MYSQL.
Project Overview
User can control the state of the LED ( on and off) and RBG LED Color Control from the Website. Color selector is used to pass RGB values. ESP8266 is reading values from API, parsing it and then controller the LEDs.
Development Environment
- User Interface - AngularJS provides easy data binding while performing API call backs, this reactive feature was very useful in passing user inputs to server while keeping the page responsive. Bootstrap was used for page design and formatting.
- Server Scripting - PHP provides an awesome environment to test out and deploy code. Wamp stack was used for development and GIT was used to deploy code to production environment. PHP was used to store values in MYSQL passed by AngularJS and create API which is consumed by ESP8266.
- Development IDE- Atom is an tool, its power to look simple yet provide rich features makes it an ideal lightweight development environment. Arduino is used for microcontroller programming.
Programming
Architecture
User Interface consist of two input controls
- Button to control LED switch state on and off
- Color selector to choose color.
Change of state is send as a POST request to PHP which stores these values in MYSQL database.
API - API is developed which when invoked will pass integer values , 10 Digit 1st digit a 0 or 1 for LED State on and off. Rest 9 Digits are RGB values , which can be parsed to pass to the sensor.
Arduino sketch - connects to the internet then calls the API every 10 seconds ( this lag will take into account DB/ Network Lags) a smaller lag might make it hard to see the result if data is changed continuously. Upon successful receipt of the values, sensor state are switched.
Lesson Learnt
- Code was also implemented to do a callback to read back database stored value( same api could be use for same purpose), this was rejected as multiple users could change LED state and hence page will never show the exact state of the values. This code was removed from the production version.
- A lot of time went into controller color of the RGB LED. I had an anode LED and I was not aware of it so programming it using cathode circuit consumed a lot of time. Always ensure the specs of hardware at hand.