+#include <ESP8266WiFi.h>
+ * This bespoke "hack" code is for the H801 (LIXADA) control module.
+ * The H801 module is based on an ESP8266 and can drive a RGB LED strip of lights.
+ * This code responds to HTTP commands, but it could easily be converted to respond to MQTT etc - up to you
+ * N.B. You have to solder 6 header pins on the H801 - this is so you can connect a cheap FDTI USB for programming.
+ * N.B. You have to store your network SSID and password in the code variables *ssid and *pass (see below in code)
+ * When all is done and the module connected and powered up, you will see a new IP (server) appear in your network.
+ * If you access this new IP (server) with a web browser, you can control the lights as follows :
+ * To turn all three RGB outputs ON, use http://192.168.1.xxx/rgb/ffffff
+ * To turn all three RGB outputs OFF, use http://192.168.1.xxx/rgb/000000
+ * To turn on GREEN a little bit, use http://192.168.1.xxx/rgb/003300
+ * To turn on RED and BLUE a bit, with max GREEN, use http://192.168.1.xxx/rgb/33ff33
+int convertToInt(char upper,char lower);
+int gamma_table[PWM_VALUE+1] = {
+ 0, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 7, 8, 9, 10,
+ 11, 12, 13, 15, 17, 19, 21, 23, 26, 29, 32, 36, 40, 44, 49, 55,
+ 61, 68, 76, 85, 94, 105, 117, 131, 146, 162, 181, 202, 225, 250,
+ 279, 311, 346, 386, 430, 479, 534, 595, 663, 739, 824, 918, 1023
+#define greenPIN 13 //15
+// TX GPIO2 @Serial1 (Serial ONE)
+#define LEDoff digitalWrite(LEDPIN,HIGH)
+#define LEDon digitalWrite(LEDPIN,LOW)
+#define LED2off digitalWrite(LED2PIN,HIGH)
+#define LED2on digitalWrite(LED2PIN,LOW)
+int led_delay_green = 0;
+#define time_at_colour 1300
+unsigned long TIME_LED_RED = 0;
+unsigned long TIME_LED_GREEN = 0;
+unsigned long TIME_LED_BLUE = 0;
+const char *ssid = "Your network SSID here";
+const char *pass = "Your network password here";
+ pinMode(LEDPIN, OUTPUT);
+ pinMode(LED2PIN, OUTPUT);
+ pinMode(redPIN, OUTPUT);
+ pinMode(greenPIN, OUTPUT);
+ pinMode(bluePIN, OUTPUT);
+ //client.set_callback(callback);
+ WiFi.begin(ssid, pass);
+ while (WiFi.status() != WL_CONNECTED) {
+ Serial1.println("WiFi connected");
+ Serial1.println("IP address: ");
+ Serial1.println(WiFi.localIP());
+ Serial1.println("Webserver started");
+ // Check if a client has connected
+ WiFiClient client = server.available();
+ // Read the first line of the request
+ String req = client.readStringUntil('\r');
+ // Prepare the response. Start with the common header:
+ String s = "HTTP/1.1 200 OK\r\n";
+ s += "Content-Type: text/html\r\n\r\n";
+ s += "<!DOCTYPE HTML>\r\n<html>\r\n";
+ if((req.indexOf("/rgb/") != -1)) {
+ int pos = req.length();
+ int ind1 = req.indexOf("/rgb/") + 5;
+ String teststring = req.substring(ind1, pos);
+ int ind2 = teststring.indexOf("/");
+ String hexRGB = req.substring(ind1, ind2+ind1);
+ hexRGB.toCharArray(c,7);
+ long r = convertToInt(c[0],c[1]); //red
+ long g = convertToInt(c[2],c[3]); //green
+ long b = convertToInt(c[4],c[5]); //blue
+ // set value of RGB controller
+ int red = map(r,0,255,0,PWM_VALUE);
+ red = constrain(red,0,PWM_VALUE);
+ int green = map(g,0,255,0,PWM_VALUE);
+ green = constrain(green, 0, PWM_VALUE);
+ int blue = map(b,0,255,0,PWM_VALUE);
+ blue = constrain(blue,0,PWM_VALUE);
+ RED = gamma_table[red];
+ GREEN = gamma_table[green];
+ BLUE = gamma_table[blue];
+ s += "RGB value changed to ";
+ s += "<br>"; // Go to the next line.
+ // Send the response to the client
+ Serial1.println("Client disconnected");
+ // The client will actually be disconnected
+ // when the function returns and 'client' object is destroyed
+ if ((RED != RED_A) or (GREEN != GREEN_A) or (BLUE != BLUE_A)) {
+ if(millis() - TIME_LED_RED >= led_delay_red){
+ TIME_LED_RED = millis();
+ if(millis() - TIME_LED_GREEN >= led_delay_green){
+ TIME_LED_GREEN = millis();
+ if(millis() - TIME_LED_BLUE >= led_delay_blue){
+ TIME_LED_BLUE = millis();
+ delayMicroseconds(200);
+// Put normal code here!!
+ int diff_red = abs(RED-RED_A);
+ led_delay_red = time_at_colour / abs(RED-RED_A);
+ led_delay_red = time_at_colour / 1023;
+ int diff_green = abs(GREEN-GREEN_A);
+ led_delay_green = time_at_colour / abs(GREEN-GREEN_A);
+ led_delay_green = time_at_colour / 1023;
+ int diff_blue = abs(BLUE-BLUE_A);
+ led_delay_blue = time_at_colour / abs(BLUE-BLUE_A);
+ led_delay_blue = time_at_colour / 1023;
+ if(RED_A > RED) RED_A = RED_A - 1;
+ if(RED_A < RED) RED_A++;
+ analogWrite(redPIN, RED_A);
+ if(GREEN_A > GREEN) GREEN_A = GREEN_A - 1;
+ if(GREEN_A < GREEN) GREEN_A++;
+ analogWrite(greenPIN, GREEN_A);
+ if(BLUE_A > BLUE) BLUE_A = BLUE_A - 1;
+ if(BLUE_A < BLUE) BLUE_A++;
+ analogWrite(bluePIN, BLUE_A);
+int convertToInt(char upper,char lower)
+ uVal = uVal >64 ? uVal - 55 : uVal - 48;
+ lVal = lVal >64 ? lVal - 55 : lVal - 48;