WiFi RGB Lamp Web Server

Dependencies:   mbed ESP8266_WebServer

RGB WiFi Lamp

Firmware

This is the official firmware repository for the BinarySpace RGB WiFi Lamp project. This firmware is still in alpha stage, and subject to change.

Planned changes include:

  • Configure the WiFi Lamp to connect onto your SSID
  • Variety of operating modes like
    • Fixed colour operation
    • Rainbow gradient
    • Time-based colour changing
    • API-based colour changing

Connecting to the WiFi lamp

To connect to the WiFi lamp web server, scan for an open WiFi network using your cellphone, tablet or laptop that begins with the letters ESP_xxxxxx. This is the automatically created SSID of the ESP8266 WiFi module used in the lamp. Your WiFi client needs to be configured to use DHCP.

Once connected, simply point your browser at http://192.168.4.1 and you should see the rudementary web interface allowing you to switch the WiFi lamp on in the red colour or off.

A second option is to enter the following URL
http://192.168.4.1/setcolor?r=x&g=x&b=x
where x is a number between 0 and 255 for the intensity of (r)ed, (g)reen and (b)lue respectively. Any of the r,g,b parts not specified will automatically default to 0

Supported Platforms

  • ST Nucleo F103RB
  • ST Nucleo F302R8
  • ST Nucleo L152RE
  • ST Nucleo F401RE

Unsupported Platforms

  • ST Nucleo F030R8 (unsupported due to insufficient registers for PololuLed library)

How to update your firmware

One of the best things about the ST Nucleo series is that they enumerate as a USB Mass Storage device when plugged in. Updating the firmware is as simple as compiling it using mbed compiler(free registration required to use) for your selected platform, plugging in your Nucleo and copying the .bin file created by the compiler to the USB drive enumerated by the Nucleo. That's it!

Code is fully Open Source

Please feel free to fork this repository and to submit pull requests if you make any cool additions/changes.

If you are developing changes to the firmware and monitoring via serial console for debugging purposes, note than you can simply comment out the #define DEBUG_WIFI line at the top of the main.cpp file to make the output much less verbose. This effectively disables debugging of the WebServer library code and echoing of communications between the Nucleo and the ESP. It also makes the web server noticeably faster, as it doesn't have to output a lot of serial data before handling requests.

LED Strip colour inconsistency

If you are experiencing problems with the LED's not all changing colour, or perhaps flickering or incorrect colour, there could be 2 potential problems we have identified.

  • Power Supply problems - If the power supply is not providing enough power, or not clean enough power, you may experience flickering or random colour changes. Ensure that your power supply can provide enough power (1A @ 5V recommended). If this does not solve your problem, soldering a capacitor over the power supply lines(5V, GND) may help to clean out any noise from the power supply. (100uF minimum)
  • Depending on cable lengths and connectors, noise on the data line may also be a problem. Try soldering a 100Ω - 500Ω resistor in line on the Din pin of the LED strip

Firmware update for the ESP8266 Module

We suggest you upgrade the firmware on the ESP8266 module to the latest official AT firmware from Espressif. Click Here for a detailed upgrade quide.

Committer:
sschocke
Date:
Sat Dec 27 05:56:47 2014 +0000
Revision:
9:319aeb6e0123
Parent:
8:f819de1946a7
Child:
10:f48a9f923271
Child:
11:3ab606a42227
Updated ESP8266 Web Server to handle multiple requests better, and to automatically analyze and populate GET parameters

Who changed what in which revision?

UserRevisionLine numberNew contents of line
sschocke 0:d21e3e1c0a4b 1 #include "mbed.h"
sschocke 1:f07afcffeb5a 2 #include "PololuLedStrip.h"
sschocke 7:f15c81074400 3 #include "ESP8266_WebServer.h"
sschocke 0:d21e3e1c0a4b 4 #include <string>
sschocke 0:d21e3e1c0a4b 5 #define DEBUG_WIFI
sschocke 0:d21e3e1c0a4b 6
sschocke 8:f819de1946a7 7 PololuLedStrip ledStrip(D11);
sschocke 1:f07afcffeb5a 8
sschocke 8:f819de1946a7 9 #define LED_COUNT 8
sschocke 1:f07afcffeb5a 10 rgb_color colors[LED_COUNT];
sschocke 1:f07afcffeb5a 11
sschocke 0:d21e3e1c0a4b 12 DigitalOut wifiCHPD(D4);
sschocke 0:d21e3e1c0a4b 13 DigitalOut wifiReset(D9);
sschocke 0:d21e3e1c0a4b 14
sschocke 0:d21e3e1c0a4b 15 int wifiOn = 0;
sschocke 0:d21e3e1c0a4b 16
sschocke 0:d21e3e1c0a4b 17 Serial wifiSerial(D8,D2);
sschocke 0:d21e3e1c0a4b 18 Serial pc(USBTX,USBRX);
sschocke 7:f15c81074400 19 ESP8266_WebServer server(&wifiSerial);
sschocke 0:d21e3e1c0a4b 20
sschocke 7:f15c81074400 21 void rxint(void) {
sschocke 7:f15c81074400 22 server.rxint();
sschocke 0:d21e3e1c0a4b 23 }
sschocke 0:d21e3e1c0a4b 24
tomvdb 4:4a502f72cbe3 25 void setColor( uint8_t r, uint8_t g, uint8_t b )
tomvdb 4:4a502f72cbe3 26 {
tomvdb 4:4a502f72cbe3 27 for ( int c = 0; c < LED_COUNT; c++ )
tomvdb 4:4a502f72cbe3 28 {
tomvdb 4:4a502f72cbe3 29 colors[c].red = r;
tomvdb 4:4a502f72cbe3 30 colors[c].green = g;
tomvdb 4:4a502f72cbe3 31 colors[c].blue = b;
tomvdb 4:4a502f72cbe3 32 }
tomvdb 4:4a502f72cbe3 33
tomvdb 4:4a502f72cbe3 34 ledStrip.write(colors, LED_COUNT);
tomvdb 4:4a502f72cbe3 35 }
tomvdb 4:4a502f72cbe3 36
sschocke 0:d21e3e1c0a4b 37 int main() {
sschocke 0:d21e3e1c0a4b 38 pc.printf("WiFi Lamp Test...\r\n");
tomvdb 4:4a502f72cbe3 39
tomvdb 4:4a502f72cbe3 40 setColor( 250, 0, 0);
tomvdb 4:4a502f72cbe3 41
sschocke 0:d21e3e1c0a4b 42 wifiCHPD = 0;
sschocke 0:d21e3e1c0a4b 43 wifiReset = 0;
sschocke 0:d21e3e1c0a4b 44 wifiSerial.baud(9600);
sschocke 0:d21e3e1c0a4b 45 wifiSerial.attach(&rxint);
sschocke 7:f15c81074400 46 #ifdef DEBUG_WIFI
sschocke 7:f15c81074400 47 server.debugSerial = &pc;
sschocke 7:f15c81074400 48 #endif
sschocke 0:d21e3e1c0a4b 49 wait_ms(1000);
sschocke 0:d21e3e1c0a4b 50
sschocke 0:d21e3e1c0a4b 51 pc.printf("Powering WiFi...\r\n");
sschocke 0:d21e3e1c0a4b 52 wifiCHPD = 1;
sschocke 0:d21e3e1c0a4b 53 wait_ms(250);
sschocke 0:d21e3e1c0a4b 54 pc.printf("Hardware Reset WiFi...\r\n");
sschocke 0:d21e3e1c0a4b 55 wifiReset = 1;
sschocke 0:d21e3e1c0a4b 56 wifiOn = 1;
sschocke 0:d21e3e1c0a4b 57
sschocke 7:f15c81074400 58 pc.printf("Starting Web Server...\r\n");
sschocke 7:f15c81074400 59 server.Initialize();
sschocke 0:d21e3e1c0a4b 60 pc.printf("Done\r\n");
sschocke 0:d21e3e1c0a4b 61
tomvdb 4:4a502f72cbe3 62 setColor( 0, 250, 0);
tomvdb 4:4a502f72cbe3 63 wait_ms(500);
tomvdb 4:4a502f72cbe3 64 setColor( 0, 0, 0);
tomvdb 4:4a502f72cbe3 65
sschocke 0:d21e3e1c0a4b 66 while(true) {
sschocke 9:319aeb6e0123 67 ESP8266_WebRequest* request = server.GetRequest();
sschocke 9:319aeb6e0123 68 if( request != NULL ) {
sschocke 9:319aeb6e0123 69 pc.printf("HTTP %s %s\r\n", request->Method.c_str(), request->URI.c_str());
sschocke 9:319aeb6e0123 70 for( std::map<std::string,std::string>::iterator it = request->Parameters.begin(); it!=request->Parameters.end(); ++it ) {
sschocke 9:319aeb6e0123 71 pc.printf("HTTP Parameter %s = %s\r\n", it->first.c_str(), it->second.c_str());
sschocke 9:319aeb6e0123 72 }
sschocke 7:f15c81074400 73 std::string httpReply;
sschocke 9:319aeb6e0123 74 if( request->URI == "/" ) {
sschocke 7:f15c81074400 75 httpReply = "<html><head><title>WiFi Lamp</title></head><body><h1>The WiFi Lamp is alive(<a href='/red'>Red</a>)</h1></body></html>";
sschocke 7:f15c81074400 76 setColor(0,0,0);
sschocke 9:319aeb6e0123 77 server.SendHTMLReply(request->LinkID, httpReply);
sschocke 9:319aeb6e0123 78 } else if( request->URI == "/red" ) {
sschocke 7:f15c81074400 79 httpReply = "<html><head><title>WiFi Lamp</title></head><body><h1>The WiFi Lamp(Red) is alive(<a href='/'>Off</a>)</h1></body></html>";
sschocke 7:f15c81074400 80 setColor(100, 0, 0);
sschocke 9:319aeb6e0123 81 server.SendHTMLReply(request->LinkID, httpReply);
sschocke 9:319aeb6e0123 82 } else if ( request->URI == "/setcolor" ) {
sschocke 7:f15c81074400 83 int r=0, g=0, b=0;
sschocke 9:319aeb6e0123 84
sschocke 9:319aeb6e0123 85 if(request->Parameters.count("r") > 0) r=atoi(request->Parameters["r"].c_str());
sschocke 9:319aeb6e0123 86 if(request->Parameters.count("g") > 0) g=atoi(request->Parameters["g"].c_str());
sschocke 9:319aeb6e0123 87 if(request->Parameters.count("b") > 0) b=atoi(request->Parameters["b"].c_str());
sschocke 7:f15c81074400 88
sschocke 7:f15c81074400 89 pc.printf( "Set color to (%i, %i, %i)\r\n", r,g,b);
sschocke 0:d21e3e1c0a4b 90
sschocke 7:f15c81074400 91 setColor( r,g,b );
sschocke 7:f15c81074400 92
sschocke 7:f15c81074400 93 httpReply = "<html><head><title>WiFi Lamp</title></head><body>ok</body></html>";
sschocke 9:319aeb6e0123 94 server.SendHTMLReply(request->LinkID, httpReply);
sschocke 7:f15c81074400 95 } else {
sschocke 9:319aeb6e0123 96 server.Send404Reply(request->LinkID);
sschocke 0:d21e3e1c0a4b 97 }
sschocke 7:f15c81074400 98 pc.printf("\r\nHTTP Reply Sent\r\n");
sschocke 9:319aeb6e0123 99 delete request;
sschocke 0:d21e3e1c0a4b 100 }
sschocke 1:f07afcffeb5a 101
sschocke 0:d21e3e1c0a4b 102 wait_ms(10);
sschocke 0:d21e3e1c0a4b 103 }
sschocke 0:d21e3e1c0a4b 104 }