From 3d21c87dd60133aa3859974b519dfb1426f87e8d Mon Sep 17 00:00:00 2001 From: Olli Graf Date: Mon, 13 May 2024 09:07:20 +0200 Subject: [PATCH] =?UTF-8?q?Beispiele=20f=C3=BCr=20Arduino=20Uno=20R4=20Wif?= =?UTF-8?q?i.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- arduino/uno-r4-wifi/wifi/arduino_secrets.h | 3 + arduino/uno-r4-wifi/wifi/wifi.ino | 91 ++++++++++++++++++++++ 2 files changed, 94 insertions(+) create mode 100644 arduino/uno-r4-wifi/wifi/arduino_secrets.h create mode 100644 arduino/uno-r4-wifi/wifi/wifi.ino diff --git a/arduino/uno-r4-wifi/wifi/arduino_secrets.h b/arduino/uno-r4-wifi/wifi/arduino_secrets.h new file mode 100644 index 0000000..4ca3af7 --- /dev/null +++ b/arduino/uno-r4-wifi/wifi/arduino_secrets.h @@ -0,0 +1,3 @@ + +#define SECRET_SSID "" +#define SECRET_PASS "" diff --git a/arduino/uno-r4-wifi/wifi/wifi.ino b/arduino/uno-r4-wifi/wifi/wifi.ino new file mode 100644 index 0000000..c9310bf --- /dev/null +++ b/arduino/uno-r4-wifi/wifi/wifi.ino @@ -0,0 +1,91 @@ +#include "Arduino_LED_Matrix.h" +#include "WiFiS3.h" +#include "arduino_secrets.h" + +char ssid[] = SECRET_SSID; +char pw[] = SECRET_PASS; + +WiFiServer server(80); + + void debug(char * msg, char *var) { + Serial.print(msg); + Serial.println(var); + } +void setup() { + Serial.begin(9600); // initialize serial communication + + // 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"); + } + + long count = 0; + + // 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() { +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 to the serial monitor + if (c == '\n') { // if the byte is a newline character + digitalWrite(LED_BUILTIN, LOW); // GET /L turns the LED off + } + } + + } + // 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: + 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); +} \ No newline at end of file