Webserver lauffähig.

This commit is contained in:
Olli Graf
2024-05-20 15:23:49 +02:00
parent 3d21c87dd6
commit a1e3b559ab
3 changed files with 184 additions and 72 deletions

61
arduino/uno-r3/ampel.ino Normal file
View File

@@ -0,0 +1,61 @@
int ledRot = 10;
int ledGelb = 11;
int ledGruen = 12;
boolean blinkmode = false;
int phase = 1;// Ampelphase
void setup() {
// put your setup code here, to run once:
pinMode(ledRot, OUTPUT);
pinMode(ledGelb, OUTPUT);
pinMode(ledGruen, OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
if(blinkmode) {
// Blinkmodus
digitalWrite(ledRot, HIGH);
digitalWrite(ledGelb, HIGH);
digitalWrite(ledGruen, HIGH);
delay(1500);
digitalWrite(ledRot, LOW);
digitalWrite(ledGelb, LOW);
digitalWrite(ledGruen, LOW);
delay(200);
}
else {
// Ampelmodus
switch(phase) {
case 1: // Phase rot
digitalWrite(ledRot, HIGH);
digitalWrite(ledGelb, LOW);
digitalWrite(ledGruen, LOW);
delay(1500);
phase = 2;
break;
case 2: // Phase Rot/Gelb
digitalWrite(ledRot, HIGH);
digitalWrite(ledGelb, HIGH);
digitalWrite(ledGruen, LOW);
delay(1000);
phase = 3;
break;
case 3: // Phase Grün
digitalWrite(ledRot, LOW);
digitalWrite(ledGelb, LOW);
digitalWrite(ledGruen, HIGH);
delay(2000);
phase = 4;
break;
case 4: // Phase Gelb
digitalWrite(ledRot, LOW);
digitalWrite(ledGelb, HIGH);
digitalWrite(ledGruen, LOW);
delay(1500);
phase = 1;
break;
}
}
}

View File

@@ -0,0 +1,57 @@
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;
/*byte frame[8][12] = {
{ 0, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0 },
{ 0, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0 },
{ 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0 },
{ 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0 },
{ 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0 },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }
};
*/
/* byte frame[8][12] ={
{ 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, }
};
*/
byte frame[8][12] ={
{ 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, },
{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
{ 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, },
{ 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, },
{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, },
};
/*unsigned long frame[] = {
0x3184a444,
0x42081100,
0xa0040000
};
*/
void setup() {
Serial.begin(115200);
matrix.begin();
}
void loop() {
// put your main code here, to run repeatedly:
matrix.renderBitmap(frame, 8, 12);
}

View File

@@ -1,91 +1,85 @@
#include "Arduino_LED_Matrix.h" #include <WiFiS3.h>
#include "WiFiS3.h" #include <Arduino.h>
#include "arduino_secrets.h" #include "arduino_secrets.h"
char ssid[] = SECRET_SSID; // Netzwerk ws_ssid und Passwort
char pw[] = SECRET_PASS; const char* ws_ssid = SECRET_SSID;
const char* ws_pass = SECRET_PASS;
WiFiServer server(80); // WiFiServer-Objekt erstellen, das auf Port 80 hört
WiFiServer webserver(80);
void debug(char * msg, char *var) {
Serial.print(msg);
Serial.println(var);
}
void setup() { void setup() {
Serial.begin(9600); // initialize serial communication // Serielle Kommunikation starten
Serial.begin(9600);
while (!Serial);
// check for the WiFi module: // Mit dem WLAN verbinden
if (WiFi.status() == WL_NO_MODULE) { Serial.print("Verbinde mit ");
Serial.println("Communication with WiFi module failed!"); Serial.println(ws_ssid);
// don't continue WiFi.begin(ws_ssid, ws_pass);
while (true);
// Warten, bis die Verbindung hergestellt ist
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
} }
String fv = WiFi.firmwareVersion(); // Verbunden, IP-Adresse ausgeben
if (fv < WIFI_FIRMWARE_LATEST_VERSION) { Serial.println("");
Serial.println("Please upgrade the firmware"); Serial.println("WiFi verbunden.");
} Serial.print("IP Adresse: ");
Serial.println(WiFi.localIP());
long count = 0; // Webserver starten
webserver.begin();
// attempt to connect to WiFi network:
int status = WL_IDLE_STATUS;
while (status != WL_CONNECTED) {
debug("trying to connect to ",ssid);
status = WiFi.begin(ssid, pw);
// Serial.print("status =");
// Serial.println(WiFi.status());
char scount[10];
sprintf(scount, "%d", count);
debug("Retry count: ", scount);
count++;
// wait 10 seconds for connection:
delay(5000);
}
Serial.println("erzeuge Server");
server.begin(); // start the web server on port 80
printWifiStatus(); // you're connected now, so print out the status
} }
void loop() { void loop() {
WiFiClient client = server.available(); // listen for incoming clients // Auf einen neuen Client warten
WiFiClient client = webserver.available();
if (client) { // if you get a client, if (client) {
Serial.println("new client"); // print a message out the serial port Serial.println("Neuer Client verbunden");
String currentLine = ""; // make a String to hold incoming data from the client String currentLine = "";
while (client.connected()) { // loop while the client's connected String header = "";
if (client.available()) { // if there's bytes to read from the client,
char c = client.read(); // read a byte, then // Aktuelle Zeit erfassen
Serial.write(c); // print it out to the serial monitor unsigned long currentTime = millis();
if (c == '\n') { // if the byte is a newline character unsigned long previousTime = currentTime;
digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off
// Zeitüberschreitung für die Verbindung (2000 ms)
const unsigned long timeoutTime = 2000;
while (client.connected() && (currentTime - previousTime <= timeoutTime)) {
currentTime = millis();
if (client.available()) {
char c = client.read();
Serial.write(c);
header += c;
if (c == '\n') {
if (currentLine.length() == 0) {
client.println("HTTP/1.1 200 OK");
client.println("Content-type:text/html");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.println("<head><title>Arduino Webserver</title></head>");
client.println("<body><h1>Hallo vom Arduino Uno R4 WiFi!</h1></body>");
client.println("</html>");
break;
} else {
currentLine = "";
}
} else if (c != '\r') {
currentLine += c;
}
} }
} }
} // Header und Client-Verbindung schließen
// close the connection: header = "";
client.stop(); client.stop();
Serial.println("client disconnected"); Serial.println("Client-Verbindung geschlossen");
} }
} }
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);
}