Lights and Temperature controller for Home using ESP8266
This library is used to create and manage communication between server and client.
To install this library go to Sketch > Include Library > Add .ZIP Libraries
in your Arduino IDE and then select arduinoWebSockets.zip
file from root folder of project.
Saving data is done by SPIFFS. To store data directly from your PC you must have istalled flashing tool.
To install this tool open explorer in Arduino folder. This is usually in
<drive>:\Users\<username>\Documents\Arduino
Into this folder paste uncompressed tools.zip
folder from root folder of project and restart Arduino IDE.
Now you should have in tools
menu ESP8266 Sketch Data Upload
option.
You can create by default up to 10 rooms (Can be changed in server.ino
> maxRooms
).
To manage these you have to point into /server/data/data.txt
.
Format is following:
Name_Of_Room;RED_VALUE;GREEN_VALUE;BLUE_VALUE
Example:
Bedroom;200;255;255
NOTE: Make sure there is no new line character \n
at the end of the file. This can lead to unexpected behavior.
NOTE: This settings are default for first run and after changing values by Control Panel, they get overwritten!
INFO: Try to avoid using long names for room because of text owerflow in Control Panel.
Go to Tools > Flash Size
and select 1M (64K SPIFFS)
. Then select tools > ESP8266 Sketch Data Upload
.
Change your SSID and Password in Server.ino
at the top of the source code.
Now is time to upload sketch.
To access Control Panel, make sure you are connect to same WiFi network as your ESP8266 Server (or you can use to port forwarding for accessing from differnt network; Server listens on port 80). ESP after connecting to WiFi network always prints out it's Local IP Address into Serial Port. In any web browser (Google Chrome preffered) just go to that IP Address and you are connected!
You can add custom calls into eventHandler
function.
Default code prints out events and values:
void eventHandler(String data[10]) {
String command = data[0];
if(command == "light") {
String name = data[1]; //Name of the room
String rgb[4] = {data[2], data[3], data[4], data[5]};
updateRoom(name, rgb);
Serial.print("\nUpdate: " + name + " > rgb(" + rgb[0] + "," + rgb[1] + "," + rgb[2] + "," + rgb[3] + ")");
} else if(command == "temp") {
String mode = data[2]; //Temperature mode
Serial.print("\nUpdate: " + data[1] + " > Temperature mode = " + mode);
}
}
First element (index 0) in data array is always event name!
Event occurs when color, brightness or switching is done in Control Panel.
light
- Name of room
- Red channel
- Green channel
- Blue channel
- Alpha channel
0
- Off1
- On
Event occurs when temperature mode is changed.
temp
- Name of room
- mode
-1
- None0
- Heating1
- Cooling
- Jaroslav Louma - @jaroslav.louma