Last active
August 28, 2018 11:17
-
-
Save paulcdb/fb97ee75f2f0a87848d430553b6fcd62 to your computer and use it in GitHub Desktop.
Wemos D1 Mini Lolin - Wifi Streaming Status Dot Matrix
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <ESP8266WiFi.h> | |
#include <WEMOS_Matrix_LED.h> | |
MLED mled(5); //set intensity=5 | |
const char* ssid = "Your Wifi Name"; | |
const char* password = "Your Wifi Password"; | |
// IPAddress ip(x, x, x, x); // Not always needed but if Serial console says 10.0.0.x, uncomment and add your IP | |
int Status = 0; | |
WiFiServer server(80); | |
void setup() { | |
Serial.begin(115200); | |
delay(10); | |
// Connect to WiFi network | |
Serial.println(); | |
Serial.println(); | |
mled.dot(4,4); | |
mled.dot(3,3); | |
mled.display(); | |
Serial.print("Connecting to "); | |
Serial.println(ssid); | |
WiFi.begin(ssid, password); | |
while (WiFi.status() != WL_CONNECTED) { | |
delay(500); | |
Serial.print("."); | |
} | |
Serial.println(""); | |
Serial.println("WiFi connected"); | |
mled.dot(3,3); | |
mled.dot(3,4); | |
mled.dot(4,3); | |
mled.dot(4,4); | |
mled.display(); | |
// Start the server | |
server.begin(); | |
Serial.println("Server started"); | |
mled.dot(0,0); | |
mled.dot(0,7); | |
mled.dot(7,0); | |
mled.dot(7,7); | |
mled.display(); | |
// Print the IP address | |
Serial.print("Use this URL : "); | |
Serial.print("http://"); | |
Serial.print(WiFi.localIP()); | |
Serial.println("/"); | |
} | |
void loop() { | |
// Check if a client has connected | |
WiFiClient client = server.available(); | |
if (!client) { | |
return; | |
} | |
// Wait until the client sends some data | |
Serial.println("new client"); | |
while(!client.available()){ | |
delay(1); | |
} | |
// Clear O | |
// Read the first line of the request | |
String request = client.readStringUntil('\r'); | |
Serial.println(request); | |
client.flush(); | |
if (request.indexOf("/Status=0") != 1) { | |
// Clear Startup and O LEDs | |
mled.dot(3,3,0); | |
mled.dot(3,4,0); | |
mled.dot(4,3,0); | |
mled.dot(4,4,0); | |
mled.dot(0,0,0); | |
mled.dot(0,7,0); | |
mled.dot(7,0,0); | |
mled.dot(7,7,0); | |
mled.dot(0,1,0); | |
mled.dot(0,2,0); | |
mled.dot(0,3,0); | |
mled.dot(0,4,0); | |
mled.dot(0,5,0); | |
mled.dot(0,6,0); | |
mled.dot(7,1,0); | |
mled.dot(7,2,0); | |
mled.dot(7,3,0); | |
mled.dot(7,4,0); | |
mled.dot(7,5,0); | |
mled.dot(7,6,0); | |
mled.dot(1,7,0); | |
mled.dot(2,7,0); | |
mled.dot(3,7,0); | |
mled.dot(4,7,0); | |
mled.dot(5,7,0); | |
mled.dot(6,7,0); | |
mled.dot(1,0,0); | |
mled.dot(2,0,0); | |
mled.dot(3,0,0); | |
mled.dot(4,0,0); | |
mled.dot(5,0,0); | |
mled.dot(6,0,0); | |
// Draw X | |
mled.dot(0, 0); | |
mled.dot(1, 1); | |
mled.dot(2, 2); | |
mled.dot(3, 3); | |
mled.dot(4, 4); | |
mled.dot(5, 5); | |
mled.dot(6, 6); | |
mled.dot(7, 7); | |
mled.dot(7, 0); | |
mled.dot(6, 1); | |
mled.dot(5, 2); | |
mled.dot(4, 3); | |
mled.dot(3, 4); | |
mled.dot(2, 5); | |
mled.dot(1, 6); | |
mled.dot(0, 7); | |
mled.display(); | |
delay(200); | |
} | |
if (request.indexOf("/Status=1") != -1){ | |
// Clear X and Startup LEDs | |
mled.dot(3,3,0); | |
mled.dot(3,4,0); | |
mled.dot(4,3,0); | |
mled.dot(4,4,0); | |
mled.dot(0,0,0); | |
mled.dot(0,7,0); | |
mled.dot(7,0,0); | |
mled.dot(7,7,0); | |
mled.dot(0,0,0); | |
mled.dot(1,1,0); | |
mled.dot(2,2,0); | |
mled.dot(3,3,0); | |
mled.dot(4,4,0); | |
mled.dot(5,5,0); | |
mled.dot(6,6,0); | |
mled.dot(7,7,0); | |
mled.dot(7,0,0); | |
mled.dot(6,1,0); | |
mled.dot(5,2,0); | |
mled.dot(4,3,0); | |
mled.dot(3,4,0); | |
mled.dot(2,5,0); | |
mled.dot(1,6,0); | |
mled.dot(0,7,0); | |
/* Draw the O */ | |
mled.dot(0, 1); | |
mled.dot(0, 2); | |
mled.dot(0, 3); | |
mled.dot(0, 4); | |
mled.dot(0, 5); | |
mled.dot(0, 6); | |
mled.dot(7, 1); | |
mled.dot(7, 2); | |
mled.dot(7, 3); | |
mled.dot(7, 4); | |
mled.dot(7, 5); | |
mled.dot(7, 6); | |
mled.dot(1, 7); | |
mled.dot(2, 7); | |
mled.dot(3, 7); | |
mled.dot(4, 7); | |
mled.dot(5, 7); | |
mled.dot(6, 7); | |
mled.dot(1, 0); | |
mled.dot(2, 0); | |
mled.dot(3, 0); | |
mled.dot(4, 0); | |
mled.dot(5, 0); | |
mled.dot(6, 0); | |
mled.display(); | |
mled.display(); | |
delay(200); | |
} | |
// Return the response | |
client.println("HTTP/1.1 200 OK"); | |
client.println("Content-Type: text/html"); | |
client.println(""); // do not forget this one | |
client.println("<!DOCTYPE HTML>"); | |
client.println("<html>"); | |
client.print("Stream is now: "); | |
if (request.indexOf("/Status=1") != -1){ | |
client.print("ONLINE"); | |
} else { | |
client.print("OFFLINE"); | |
} | |
client.println("<br><br>"); | |
client.println("<p>Click <a href=\"/Status=1\">here</a> Set stream to ONLINE</p>"); | |
client.println("<p>Click <a href=\"/Status=0\">here</a> Set stream to OFFLINE</p>"); | |
client.println("</html>"); | |
delay(1); | |
Serial.println("Client disconnected"); | |
Serial.println(""); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If it's connected to Wifi, the inner LED's should be lite and when the server is up and running, the outer LED's should be lit.
It usually lights up both at the same time since it's pretty quick once its connected.
If it can't connect to the Wifi, only 2 LED's will light up since there doesn't seem to be a builtin LED so using 2 LED's on the dot matrix display as a work around power LED for when it can't connect.