Browse Source

Webserver lauffähig.

master 1.0
Olli Graf 5 months ago
parent
commit
a1e3b559ab
  1. 61
      arduino/uno-r3/ampel.ino
  2. 57
      arduino/uno-r4-wifi/led_matrix/led_matrix.ino
  3. 136
      arduino/uno-r4-wifi/wifi/wifi.ino

61
arduino/uno-r3/ampel.ino

@ -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;
}
}
}

57
arduino/uno-r4-wifi/led_matrix/led_matrix.ino

@ -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);
}

136
arduino/uno-r4-wifi/wifi/wifi.ino

@ -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);
}
String fv = WiFi.firmwareVersion(); // Warten, bis die Verbindung hergestellt ist
if (fv < WIFI_FIRMWARE_LATEST_VERSION) { while (WiFi.status() != WL_CONNECTED) {
Serial.println("Please upgrade the firmware"); delay(500);
Serial.print(".");
} }
long count = 0; // Verbunden, IP-Adresse ausgeben
Serial.println("");
// attempt to connect to WiFi network: Serial.println("WiFi verbunden.");
Serial.print("IP Adresse: ");
int status = WL_IDLE_STATUS; Serial.println(WiFi.localIP());
while (status != WL_CONNECTED) { // Webserver starten
debug("trying to connect to ",ssid); webserver.begin();
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) {
Serial.println("Neuer Client verbunden");
String currentLine = "";
String header = "";
// Aktuelle Zeit erfassen
unsigned long currentTime = millis();
unsigned long previousTime = currentTime;
if (client) { // if you get a client, // Zeitüberschreitung für die Verbindung (2000 ms)
Serial.println("new client"); // print a message out the serial port const unsigned long timeoutTime = 2000;
String currentLine = ""; // make a String to hold incoming data from the client
while (client.connected()) { // loop while the client's connected while (client.connected() && (currentTime - previousTime <= timeoutTime)) {
if (client.available()) { // if there's bytes to read from the client, currentTime = millis();
char c = client.read(); // read a byte, then if (client.available()) {
Serial.write(c); // print it out to the serial monitor char c = client.read();
if (c == '\n') { // if the byte is a newline character Serial.write(c);
digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off 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;
} }
} }
// close the connection:
client.stop();
Serial.println("client disconnected");
} }
}
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: // Header und Client-Verbindung schließen
IPAddress ip = WiFi.localIP(); header = "";
Serial.print("IP Address: "); client.stop();
Serial.println(ip); Serial.println("Client-Verbindung geschlossen");
}
// 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);
} }
Loading…
Cancel
Save