diff --git a/shinesp.ino b/shinesp.ino index 96a5df9..5fc5601 100644 --- a/shinesp.ino +++ b/shinesp.ino @@ -1,7 +1,7 @@ #define FASTLED_ESP8266_RAW_PIN_ORDER #include "FastLED.h" -#define NUM_LEDS 50 +#define NUM_LEDS 150 #define DATA_PIN 0 #define led 13 @@ -51,60 +51,60 @@ int connected = 0; // } // } // } -// Serial.println("Could not connect to any network"); +// Serial.println("Could not connect to any network"); // return false //} -bool connect(struct credential cred){ +bool connect(struct credential cred) { WiFi.mode(WIFI_STA); Serial.println("Trying to connect to " + cred.ssid + " with " + cred.pass); - if(cred.ssid.length()<1){ + if (cred.ssid.length() < 1) { return false; } Serial.println("Length " + cred.ssid.length()); - WiFi.begin(cred.ssid.c_str(), cred.pass.c_str()); - int c = 0; - while ( c < 20 ) { - if (WiFi.status() == WL_CONNECTED) { - Serial.println("Ready"); - Serial.print("IP address: "); - Serial.println(WiFi.localIP()); - return true; - } - delay(500); - Serial.print(WiFi.status()); - c++; + WiFi.begin(cred.ssid.c_str(), cred.pass.c_str()); + int c = 0; + while ( c < 20 ) { + if (WiFi.status() == WL_CONNECTED) { + Serial.println("Ready"); + Serial.print("IP address: "); + Serial.println(WiFi.localIP()); + return true; + } + delay(500); + Serial.print(WiFi.status()); + c++; } Serial.println("Connect timed out"); return false; } -void setCredentials(struct credential cred){ - String qsid = cred.ssid; - Serial.println(qsid); - Serial.println(""); - String qpass = cred.pass; - Serial.println(qpass); - Serial.println(""); - - Serial.println("writing eeprom ssid:"); - for (int i = 0; i < qsid.length(); ++i) - { - EEPROM.write(i, qsid[i]); - Serial.print("Wrote: "); - Serial.println(qsid[i]); - } - Serial.println("writing eeprom pass:"); - for (int i = 0; i < qpass.length(); ++i) - { - EEPROM.write(32+i, qpass[i]); - Serial.print("Wrote: "); - Serial.println(qpass[i]); - } - EEPROM.commit(); +void setCredentials(struct credential cred) { + String qsid = cred.ssid; + Serial.println(qsid); + Serial.println(""); + String qpass = cred.pass; + Serial.println(qpass); + Serial.println(""); + + Serial.println("writing eeprom ssid:"); + for (int i = 0; i < qsid.length(); ++i) + { + EEPROM.write(i, qsid[i]); + Serial.print("Wrote: "); + Serial.println(qsid[i]); + } + Serial.println("writing eeprom pass:"); + for (int i = 0; i < qpass.length(); ++i) + { + EEPROM.write(32 + i, qpass[i]); + Serial.print("Wrote: "); + Serial.println(qpass[i]); + } + EEPROM.commit(); } -void handleSetCredentials(){ +void handleSetCredentials() { struct credential cred; cred.ssid = ""; cred.pass = ""; @@ -112,7 +112,7 @@ void handleSetCredentials(){ cred.ssid = httpServer.arg("ssid"); cred.pass = httpServer.arg("pass"); - if (cred.ssid != "" && cred.pass != ""){ + if (cred.ssid != "" && cred.pass != "") { setCredentials(cred); String out = "Credentials set as: " + cred.ssid + " : " + cred.pass; httpServer.send(200, "text/plain", out); @@ -122,52 +122,65 @@ void handleSetCredentials(){ } } -void clearCredentials(){ - for (int i = 0; i < 96; ++i) { EEPROM.write(i, 0); } - EEPROM.commit(); +void clearCredentials() { + for (int i = 0; i < 96; ++i) { + EEPROM.write(i, 0); + } + EEPROM.commit(); } -void handleClearCredentials(){ +void handleClearCredentials() { clearCredentials(); httpServer.send(200, "text/plain", "Cleared!"); } -void handleWhite(){ - fill_solid(leds, NUM_LEDS, CRGB(255,255,255)); +void handleWhite() { + fill_solid(leds, NUM_LEDS, CRGB(255, 255, 255)); FastLED.show(); httpServer.send(200, "text/plain", "White!"); } -void handleOff(){ +void handleColor() { + int r = httpServer.arg("r").toInt(); + int g = httpServer.arg("g").toInt(); + int b = httpServer.arg("b").toInt(); + char msg[400]; + fill_solid( leds, NUM_LEDS, CRGB(r,g,b)); + FastLED.show(); + snprintf ( msg, 400, "RGB=(%d, %d, %d)", r, g, b); + httpServer.send(200, "text/plain", msg); +} + +void handleOff() { fill_solid( leds, NUM_LEDS, CRGB::Black); FastLED.show(); httpServer.send(200, "text/plain", "Off!"); } -void handleBrightness(){ +void handleBrightness() { int value = httpServer.arg("value").toInt(); - if(value>0){ + if (value > 0) { FastLED.setBrightness(value); httpServer.send(200, "text/plain", "Brightness set to " + String(value)); FastLED.show(); } else { - httpServer.send(400, "text/plain", "Invalid value"); + httpServer.send(400, "text/plain", "Invalid value"); } - + } - + void handleRoot() { - digitalWrite ( led, 1 ); - char temp[400]; - int sec = millis() / 1000; - int min = sec / 60; - int hr = min / 60; - - snprintf ( temp, 400, - - "\ + digitalWrite ( led, 1 ); + char temp[400]; + int sec = millis() / 1000; + int min = sec / 60; + int hr = min / 60; + + snprintf ( temp, 400, + + "\
\ \