Skip to content

Commit

Permalink
update README
Browse files Browse the repository at this point in the history
  • Loading branch information
pragyad3188 authored Apr 17, 2023
1 parent 578bc46 commit 43c07a8
Showing 1 changed file with 91 additions and 0 deletions.
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ This project seeks to improve the user experience by making lighting control mor

Here the Push Button acts as a manual switch for the LED Strip.

## Software Components Used
- FastLED.h library
- Wifi.h library for wifi provisioning
- SinricPro, SinricProLight
- SinricPro / ESP Rainmaker web platform and apps
- AsyncElegantOTA.h, ArduinoOTA.h (for OTA functionality)
- UbidotsESPMQTT.h
- AsyncMqttClient
- Arduino IDE
- Alexa, Google home app

Most of IoT devices use lightweight **MQTT** protocol to exchange messages with IoT clouds. On the other hand Alexa /Google Assistant use **REST APIs** services. In such scenario platforms like ESP Rainmaker, SinricPro provides users with interface that can understand REST as well as MQTT. We are using Sinric Pro Library.

*Sincric Pro* Library provides us with a higher level interface to connect to IoT Cloud without knowing specifics of MQTT protocol.

## Circuit Diagram
![Circuit diagram](/Circuit.png)

Expand All @@ -42,3 +57,79 @@ The Push Button is powered using the ESP8266 3.3V, thus ESP8266 3.3V is connecte
- If turned ON, it keeps reducing the brightness by 50% for every inactive interval of 60 seconds
- **Data Analysis using Ubidots integration**
- These plots can be used to analyze the usage of the LEDs

## Code Setup

### Install ESP8266
- Include library <ESP8266WiFi.h> and install ESP8266 Board in Arduino IDE. For installation, go to Arduino IDE and follow the path File/preferences and open the preference tab. Paste the link http://arduino.esp8266.com/stable/package_esp8266com_index.json in the additional board manager URL box.
- After this, go to Tool/ Board Tools/board/board manager and type ESP8266.
- You will find a board of ESP8266 click on the install option to get the board installed.

### For Smart Bulb
1. Sign up in Sinric Pro
- Click on Devices, then click on Add Device
- Add the Device Name(corresponding to the LED strip), description and Device Type(Smart Light Bulb)
- Sinric Pro associates every Device with a DeviceID(let's call it *Light_ID*)
2. Now update the *Light_ID*, your App key and App secret and the Wifi credentials in the code.


## Working
This section shows the workflow of the project.
### Smart Bulb
| ![Arduino Script Design for Smart Bulb](/Arduino-design-2.png) |
|:--:|
| *Arduino Script Design for Smart Bulb* |
1. The ESP8266 first connects to the WIFI using the specified credentials.
2. We have created a new Light Device using Sinric Pro library. Like: `SinricProLight &myLight = SinricPro[*Light_ID*]`
- This is the Light Device associated with the Smart Bulb we created on the Sinric Pro library.
3. This library has callback functions that are called every time a variable is changed. We define the callback function for this light device.
4. *onPowerState* callback function will be called everytime *PowerState* of the *myLight* will change on the Cloud.

`bool onPowerState(const String &deviceId, bool &state) {
powerState = state;
if (state) {
FastLED.setBrightness(map(globalBrightness, 0, 100, 0, 255)); // Turn ON the LEDs
} else {
FastLED.setBrightness(0); // Turn OFF the LEDs
}
FastLED.show();
return true;
}`

6. *onBrightness*, *onAdjustBrightness* and *onColor" callback functions are also defined.
7. We have also integrated Ubidots where we send the `PowerState` variable's values to the cloud.
8. Now the following code runs in loop
- The function `handleButtonPress` which handles the push button. It checks if the push button is being pressed or not, if yes then it toggles the Power state of the LEDs.
- To update the *PowerState* back to the Cloud, we use the function `sendPowerStateEvent()` provided by the Sinric Pro library with the newly updated value of *PowerState*.
- Then it checks if its been more than 10 seconds that we sent an update to *Ubidots*, if yes then it sents the updated *PowerState* to Ubidots.
- Then it handles any updates from the Sinric Pro platform which includes updates from Alexa/ Google Home aap and the Sinric Pro app.
- If user turns OFF the Smart Bulb using any of the above specified platform
- The callback function corresponding to *PowerState* i.e *onPowerState* is called and the FastLED finally turns OFF the LED.
- If user changed the color of the Smart Bulb using any of the above specified platform
- The callback function corresponding to *color* i.e *onColor* is called and the FastLED finally sets the color to the specified one.


### Smart LED
|![Arduino Script Design for Smart LED](/Arduino-design-1.png)|
|:--:|
| *Arduino Script Design for Smart LED* |

## Extensions
### Power Saver
It is an option which we can enable. If this option is enabled, it reduces the brightness by 50% for every inactive interval of 60 seconds.
For this we have created a C server `analyser.c` which makes use of `MQTTClient.h` library.

### OTA functionality
We have added OTA feature so that user can upload a new sketch whenever required without the necessity of having the serial connection with the ESP8266 board.
We have used AsyncElegantOTA library in out **Smart Bulb** code. For this we included the `AsyncElegantOTA.h` library. We have created a AsyncWebServer on the port 80 namely *OTA_server*. Then we setup the AsyncOTA and begin this *OTA_server*. To upload a new sketch go to `localhost/update`. The below image is the update page.
![OTA update page](/ElegantOTAUpdate.png)

### Data Integration with Ubidots
We have integrated Ubidots using the MQTT protocol in the *Smart Bulb* code. It sends the updated value of the *PowerState* variable to the Ubidots after every 10 seconds. This data can be analyzed to better understand the usage of the bulb and how it is related to time for a individual person. This can be later used to set Night Modes, Power Saver mode at some scheduled time that statifies the user's light pattern.
| ![Power State Data Plot using Ubidots](/Power.png) |
|:--:|
| *Power State Data Plot using Ubidots* |

| ![Power State Data Plot using Ubidots](/Power-Plot-CSV.png) |
|:--:|
| *Power State Data Plot using Ubidots* |

0 comments on commit 43c07a8

Please sign in to comment.