#include #include #include #include "arduino_secrets.h" // Sensitive information in arduino_secrets.h char ssid[] = SECRET_SSID; // network SSID (name) char pass[] = SECRET_PASS; // network password (use for WPA, or use as key for WEP) int keyIndex = 0; // network key index number (needed only for WEP) #define LED_PIN 15 // Pin where NeoPixels are connected - Do not use PIN 25 (D2) - possible conflict with WiFi #define LED_COUNT 60 // How many NeoPixels? int status = WL_IDLE_STATUS; WiFiServer server(80); Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); #define SEQ_ALLOFF 0 #define SEQ_ALLON 1 int colorR = 0; int colorG = 0; int colorB = 0; void setup() { pinMode(LEDR, OUTPUT); pinMode(LEDG, OUTPUT); pinMode(LEDB, OUTPUT); Serial.begin(9600); // initialize serial communication WiFi.config({192,168,0,44}, {8,8,8,8}, {192,168,0,1}, {255,255,255,0}); // check for the WiFi module: if (WiFi.status() == WL_NO_MODULE) { Serial.println("Communication with WiFi module failed!"); // don't continue while (true); } String fv = WiFi.firmwareVersion(); if (fv < WIFI_FIRMWARE_LATEST_VERSION) { Serial.println("Please upgrade the firmware"); } // attempt to connect to WiFi network: while (status != WL_CONNECTED) { Serial.print("Attempting to connect to Network named: "); Serial.println(ssid); // print the network name (SSID); // Connect to WPA/WPA2 network. Change this line if using open or WEP network: status = WiFi.begin(ssid, pass); // wait 10 seconds for connection: delay(10000); } server.begin(); // start the web server on port 80 printWifiStatus(); // you're connected now, so print out the status // Now setup NeoPixels strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED) strip.show(); // Turn OFF all pixels ASAP strip.setBrightness(50); // Set BRIGHTNESS to about 1/5 (max = 255) } void loop() { WiFiClient client = server.available(); // listen for incoming clients if (client) { // if you get a client, Serial.println("new client"); // print a message out the serial port String currentLine = ""; // make a String to hold incoming data from the client while (client.connected()) { // loop while the client's connected if (client.available()) { // if there's bytes to read from the client, char c = client.read(); // read a byte, then Serial.write(c); // print it out the serial monitor if (c == '\n') { // if the byte is a newline character // if the current line is blank, you got two newline characters in a row. // that's the end of the client HTTP request, so send a response: if (currentLine.length() == 0) { showWebPage(client); // break out of the while loop: break; } else { // if you got a newline, then clear currentLine: currentLine = ""; } } else if (c != '\r') { // if you got anything else but a carriage return character, currentLine += c; // add it to the end of the currentLine } // Check to see if the client request was /X if (currentLine.endsWith("GET /RH")) { colorR = 255; digitalWrite(LEDR, HIGH); } if (currentLine.endsWith("GET /RL")) { colorR = 0; digitalWrite(LEDR, LOW); } if (currentLine.endsWith("GET /GH")) { colorG = 255; digitalWrite(LEDG, HIGH); } if (currentLine.endsWith("GET /GL")) { colorG = 0; digitalWrite(LEDG, LOW); } if (currentLine.endsWith("GET /BH")) { colorB = 255; digitalWrite(LEDB, HIGH); } if (currentLine.endsWith("GET /BL")) { colorB = 0; digitalWrite(LEDB, LOW); } } } // close the connection: client.stop(); Serial.println("client disconnected"); } setPixels(SEQ_ALLON, strip.Color(colorR, colorG, colorB)); } void setPixels(int sequence, uint32_t color) { if (sequence == SEQ_ALLON) { allOn (color); } } void allOn(uint32_t color) { for(int i=0; i"); client.print(".container {margin: 0 auto; text-align: center; margin-top: 100px;}"); client.print("button {color: white; width: 100px; height: 100px;"); client.print("border-radius: 50%; margin: 20px; border: none; font-size: 20px; outline: none; transition: all 0.2s;}"); client.print(".red{background-color: rgb(196, 39, 39);}"); client.print(".green{background-color: rgb(39, 121, 39);}"); client.print(".blue {background-color: rgb(5, 87, 180);}"); client.print(".off{background-color: grey;}"); client.print("button:hover{cursor: pointer; opacity: 0.7;}"); client.print(""); client.print("
"); client.print(""); client.print("
"); client.print(""); client.print("
"); client.print(""); client.print(""); client.print("
"); // The HTTP response ends with another blank line: client.println(); } void printWifiStatus() { // print the SSID of the network you're attached to: Serial.print("SSID: "); Serial.println(WiFi.SSID()); // print your board's IP address: IPAddress ip = WiFi.localIP(); Serial.print("IP Address: "); Serial.println(ip); // print the received signal strength: long rssi = WiFi.RSSI(); Serial.print("signal strength (RSSI):"); Serial.print(rssi); Serial.println(" dBm"); // print where to go in a browser: Serial.print("To see this page in action, open a browser to http://"); Serial.println(ip); }