diff --git a/ESP8266HueEmulator/ESP8266HueEmulator.ino b/ESP8266HueEmulator/ESP8266HueEmulator.ino index 178d20d..e474717 100644 --- a/ESP8266HueEmulator/ESP8266HueEmulator.ino +++ b/ESP8266HueEmulator/ESP8266HueEmulator.ino @@ -34,6 +34,7 @@ RgbColor black = RgbColor(0); #define pixelPin 2 // Strip is attached to GPIO2 on ESP-01 NeoPixelBus strip(MAX_LIGHT_HANDLERS * NUM_PIXELS_PER_LIGHT, pixelPin); NeoPixelAnimator animator(MAX_LIGHT_HANDLERS * NUM_PIXELS_PER_LIGHT, NEO_MILLISECONDS); // NeoPixel animation management object +LightServiceClass LightService; HsbColor getHsb(int hue, int sat, int bri) { float H, S, B; diff --git a/ESP8266HueEmulator/LightService.cpp b/ESP8266HueEmulator/LightService.cpp index b6b1914..1bc062d 100644 --- a/ESP8266HueEmulator/LightService.cpp +++ b/ESP8266HueEmulator/LightService.cpp @@ -17,6 +17,7 @@ String bridgeIDString; String ipString; String netmaskString; String gatewayString; +const char * friendlyName; // The username of the client (currently we authorize all clients simulating a pressed button on the bridge) String client; @@ -188,11 +189,15 @@ class WcFnRequestHandler : public RequestHandler { char _wildcard; }; -LightServiceClass LightService; - LightHandler *lightHandlers[MAX_LIGHT_HANDLERS] = {}; // interfaces exposed to the outside world -LightServiceClass::LightServiceClass() { } +LightServiceClass::LightServiceClass() { + friendlyName = "hue emulator"; +} + +LightServiceClass::LightServiceClass(const char* friendlyNameArg) { + friendlyName = friendlyNameArg; +} bool LightServiceClass::setLightHandler(int index, LightHandler *handler) { if (index >= currentNumLights || index < 0) return false; @@ -265,7 +270,7 @@ static const char* _ssdp_xml_template = "" "http://{ip}:80/" "" "urn:schemas-upnp-org:device:Basic:1" - "Philips hue ( {ip} )" + "Philips hue ({ip})" "Royal Philips Electronics" "http://www.philips.com" "Philips hue Personal Wireless Lighting" @@ -275,7 +280,22 @@ static const char* _ssdp_xml_template = "" "{mac}" "uuid:2f402f80-da50-11e1-9b23-{mac}" "index.html" - //"image/png484824hue_logo_0.pngimage/png12012024hue_logo_3.png" + "" + " " + " image/png" + " 48" + " 48" + " 24" + " hue_logo_0.png" + " " + " " + " image/png" + " 120" + " 120" + " 24" + " hue_logo_3.png" + " " + "" "" ""; @@ -374,6 +394,30 @@ void on(HandlerFunction fn, const String &wcUri, HTTPMethod method, char wildcar HTTP->addHandler(new WcFnRequestHandler(fn, wcUri, method, wildcard)); } +void indexPageFn() { + String response = "" + "

Philips HUE - {name} ( {ip} )

" + "

Available lights:

" + "" + ""; + + String lights = ""; + + for (int i = 0; i < LightService.getLightsAvailable(); i++) { + if (!lightHandlers[i]) { + continue; + } + + lights += "
  • " + lightHandlers[i]->getFriendlyName(i) + "
  • "; + } + + response.replace("{ip}", ipString); + response.replace("{lights}", lights); + response.replace("{name}", friendlyName); + + HTTP->send(200, "text/html", response); +} + void descriptionFn() { String response = _ssdp_xml_template; @@ -757,6 +801,7 @@ void LightServiceClass::begin(ESP8266WebServer *svr) { Serial.print(":"); Serial.println(80); + HTTP->on("/index.html", HTTP_GET, indexPageFn); HTTP->on("/description.xml", HTTP_GET, descriptionFn); on(configFn, "/api/*/config", HTTP_ANY); on(configFn, "/api/config", HTTP_GET); @@ -1060,10 +1105,8 @@ void addSingleLightJson(aJsonObject* light, int numberOfTheLight, LightHandler * aJson.addStringToObject(light, "swversion", "0.1"); // type of lamp (all "Extended colour light" for now) aJson.addStringToObject(light, "type", "Extended color light"); // type of lamp (all "Extended colour light" for now) aJson.addStringToObject(light, "uniqueid", ((String) (numberOfTheLight + 1)).c_str()); - } - void addLightJson(aJsonObject* root, int numberOfTheLight, LightHandler *lightHandler) { if (!lightHandler) return; @@ -1126,7 +1169,7 @@ static String format2Digits(int num) { void addConfigJson(aJsonObject *root) { - aJson.addStringToObject(root, "name", "hue emulator"); + aJson.addStringToObject(root, "name", friendlyName); aJson.addStringToObject(root, "swversion", "81012917"); aJson.addStringToObject(root, "bridgeid", bridgeIDString.c_str()); aJson.addBooleanToObject(root, "portalservices", false); diff --git a/ESP8266HueEmulator/LightService.h b/ESP8266HueEmulator/LightService.h index 3eb19a6..e0502f2 100644 --- a/ESP8266HueEmulator/LightService.h +++ b/ESP8266HueEmulator/LightService.h @@ -51,10 +51,9 @@ class LightHandler { class ESP8266WebServer; class LightServiceClass { - const char* _friendlyName; - public: LightServiceClass(); + LightServiceClass(const char* friendlyName); LightHandler *getLightHandler(int numberOfTheLight); bool setLightsAvailable(int numLights); int getLightsAvailable();