Arduino Eviroment Kit / MKR Wifi 1010

Moin Leute,

ich versuche im Moment eine Wetterstation mit dem Arduino Environmental Kit zu Realisieren.
Die gemessenen Daten sollen auf einer HTML Seite Live angezeigt werden.

Falls ein Grenzwert überschritten wird soll eine Email im internen Netz verschickt werden.

Zum aktuellen Zeitpunkt funktioniert das anzeigen der Messwerte auf der HTML Seite über einige umwege Gut.

Das Problem ist jedoch das der Arduino nach ca. 8 Stunden die Verbindung verliert und somit keine Messwerte mehr sendet. hat von euch jemand eine Idee woran das liegen könnte?

Vorschläge zur Problem Behebung nehme ich dankend an, zudem wäre da noch das Problem mit dem Email Versand der auch noch in das Skript mit eingebaut werden müsste.

Vielen Dank im Voraus!

Hier das aktuelle Skript:

#include <SPI.h>
#include <WiFiNINA.h>
#include <Arduino_MKRENV.h>
#include <utility/wifi_drv.h>


    ///////please enter your sensitive data in the Secret tab/arduino_secrets.h

    //char ssid[] = "XXX";    // your network SSID (name)
    //char pass[] = "XXX";    // your network password (use for WPA, or use as key for WEP)
    //int keyIndex = 0;       // your network key Index number (needed only for WEP)


float _temperature;
float _humidity;
float _pressure;
float _lux;

byte mac[6];

int debug = 0;

int status = WL_IDLE_STATUS;
WiFiServer server(80);


  void printWifiStatus() {


    //Zeigt auf der Board LED ein Grünes Blinken falls die Verbindung mit dem Netz erfolgreich war
    //----------------------------------------------------------------------
    WiFiDrv::digitalWrite(26, LOW); //<-- Rote LED Geht aus

    WiFiDrv::digitalWrite(25, HIGH); //<-- Grün geht für 0,5 Sek an
    delay(1000);
    WiFiDrv::digitalWrite(25, LOW); //<<-- Grün geht nach einer 0,5 Sek aus
    delay(500);
    WiFiDrv::digitalWrite(25, HIGH); //<-- Grün geht für 0,5 Sek an
    delay(1000);
    WiFiDrv::digitalWrite(25, LOW); //<<-- Grün geht nach einer 0,5 Sek aus
    delay(500);
    WiFiDrv::digitalWrite(25, HIGH); //<-- Grün geht für 0,5 Sek an
    delay(1000);
    WiFiDrv::digitalWrite(25, LOW); //<<-- Grün geht nach einer 0,5 Sek aus
    //----------------------------------------------------------------------
    
    
    // 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);

    WiFi.macAddress(mac);
    Serial.print("MAC: ");
    Serial.print(mac[5],HEX);
    Serial.print(":");
    Serial.print(mac[4],HEX);
    Serial.print(":");
    Serial.print(mac[3],HEX);
    Serial.print(":");
    Serial.print(mac[2],HEX);
    Serial.print(":");
    Serial.print(mac[1],HEX);
    Serial.print(":");
    Serial.println(mac[0],HEX);
  
  }

  void readSensors()
  {
    _temperature = ENV.readTemperature();
    _humidity = ENV.readHumidity();
    _pressure = ENV.readPressure();
    _lux = ENV.readLux();
  }


  void setup() {
    
    Serial.begin(9600);      // initialize serial communication
    pinMode(9, OUTPUT);      // set the LED pin mode

    WiFiDrv::pinMode(25, OUTPUT); //GREEN
    WiFiDrv::pinMode(26, OUTPUT); //RED
    WiFiDrv::pinMode(27, OUTPUT); //BLUE

    WiFiDrv::digitalWrite(26, HIGH);

    if (!ENV.begin()) {
      Serial.println("Failed to initialize MKR ENV shield!");
      while (1);
    }

    // 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 5 seconds for connection:
      delay(5000);
    }
    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 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) {
              // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
              // and a content-type so the client knows what's coming, then a blank line:
              client.println("HTTP/1.1 200 OK");
              client.println("Content-type:text/html");
              client.println();
            
              readSensors();

              
              client.print("Temp. = ");
              client.print(_temperature);
              client.println("&#186C.");
              //client.println("\n");
    
              //client.print("Illuminance = ");
              //client.print(_lux);
              //client.println(" lx");
    
              client.print("     Luftf. = ");
              client.print(_humidity);
              client.println("%");
              //client.println("\n");

              client.println("<meta http-equiv=\"refresh\" content=\"5\">");

              // The HTTP response ends with another blank line:
              client.println();
              // 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
          }
        }
      }
      // close the connection:
      client.stop();
      Serial.println("client disonnected");
    }
   }

Du benutzt den Datentyp String für die Variable currentTime. Der Datentyp String verbraucht bei jeder neuen Zuweisung neues RAM. Im Laufe der Zeit wird so alles RAM verbraucht. Dann fängt das Programm an Speicherbereiche von anderen Variablen zu überschreiben. Das ist mein Verdacht für die Ursache auf die Schnelle.

Dein Programm fügt dem String einzelne Zeichen hinzu. Das kann man auch mit einem cstring realisieren.

Ich persönlich bevorzuge eine library namens PString.
Variablen vom Type "PString" muss man in der Länge vordefinieren. Der Vorteil ist, das PStrings niemals zusätzliches RAM verbrauchen. Wenn das Programm versucht mehr Zeichen in einen PString zu schreiben als hineinpassen werden die überzähligen Zeichen einfach abgeschnitten.

PString kann man über den library-manager installieren.

viele Grüße Stefan