Hi zusammen,
ich habe eine kleine Wetterstation mit dem Arduino 33 IOT programmiert. Ich lasse mir darauf auch die Außentemperatur anzeigen; die lese ich aus meiner Heizung aus.
Seit ein paar Wochen habe ich auch drei IOTs im Keller mit einem Temepratur/Feuchte Sensor laufen, und lese von denen die Luftfeuchtigkeit aus. Grundsätzlich läuft das ganze, aber die Sensoren im Keller hängen sich regelmäßig auf; ich weiß allerdings nichts warum. Ich lasse sie jetzt mit einem Watchdog ca. alle 24h neu starten, aber eine wirklich Lösung ist das nicht. Folgend der Code der Sensoren. Hat einer von Euch eine Idee, woran das liegen kann?:
#include <WiFiNINA.h>
#include "WLAN_Daten.h"
#include "Adafruit_Si7021.h"
#include <Interrupt.h>
/////// Changelog
//1.2 Regelmäßiger Reset hinzugefügt
bool enableHeater = false;
uint8_t loopCnt = 0;
Adafruit_Si7021 sensor = Adafruit_Si7021();
///////////////////////////////
//globale Variablen Deklaration
///////////////////////////////
uint32_t sampleRate = 100000; //sample rate in milliseconds, determines how often TC5_Handler is called
static char ssid_intra[] = SECRET_SSID_Intra; // your network SSID (name)
static char pass_intra[] = SECRET_PASS_Intra; // your network password (use for WPA, or use as key for WEP)
static char ssid_inter[] = SECRET_SSID_Inter;
static char pass_inter[] = SECRET_PASS_Inter;
static char ssid_ap[] = SECRET_SSID_AP;
static char pass_ap[] = SECRET_PASS_AP;
//static IPAddress IP_Arduino (192, 168, 2, 42); //IP des Tempsensor Vorräte
//static IPAddress IP_Arduino (192, 168, 2, 43); //IP des Tempsensor Lukas
static IPAddress IP_Arduino (192, 168, 2, 44); //IP des Tempsensor Werkraum
static IPAddress IP_Gateway (192, 168, 2, 1); //IP des Gateway
static IPAddress dns (192, 168, 2, 1);
static IPAddress Subnet (255, 255, 255, 0); //Subnet
int status = WL_IDLE_STATUS;//Status Variable für Netzwerkverbindung
unsigned long t1;
unsigned long t2 = 86400000;//Schwelle für neustart alle 24h
bool kein_Fehler = true;
static bool debug = false;
WiFiClient client;//WIFI Client initialisieren
WiFiServer server(80);
void verbinde_Netzwerk(char WL_SSID[], char PASS[], IPAddress IP, IPAddress GATEWAY, IPAddress SUBNET) {
while (status != WL_CONNECTED) {
WiFi.config(IP_Arduino, dns, IP_Gateway, Subnet); //, GATEWAY, SUBNET);
status = WiFi.begin(WL_SSID, PASS);
delay(100);
}
}
void print_debug(bool hatdebug, String Text) {
if (hatdebug) {
Serial.println(Text);
}
}
void setup() {
//debug = false;
if (debug) {
Serial.begin(9600);
}
tcConfigure(sampleRate); //configure the timer to run at <sampleRate>Hertz
tcStartCounter(); //starts the timere:
sensor.begin();
delay(2000);
//verbinde_Netzwerk(ssid_ap, pass_ap, IP_Arduino, IP_Gateway, Subnet);
print_debug(debug, "nach netzwerk verbinden inter");
if (debug) {
printWifiStatus();
}
verbinde_Netzwerk(ssid_ap, pass_ap, IP_Arduino, IP_Gateway, Subnet);
//verbinde_Netzwerk(ssid_intra, pass_intra, IP_Arduino, IP_Gateway, Subnet);
delay(100);
server.begin();
delay(10);
}
void loop(void) {
//
verbinde_Netzwerk(ssid_ap, pass_ap, IP_Arduino, IP_Gateway, Subnet);
t1 = millis();
client = server.available();
if (client) {
print_debug(debug, "new client");
// an HTTP request ends with a blank line
boolean currentLineIsBlank = true;
t1 = millis();
while (client.connected()) {
if (client.available()) {
char c = client.read();
// if you've gotten to the end of the line (received a newline
// character) and the line is blank, the HTTP request has ended,
// so you can send a reply
if (c == '\n' && currentLineIsBlank) {
// send a standard HTTP response header
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close"); // the connection will be closed after completion of the response
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
client.print("Luftfeuchtigkeit: ");
client.print(sensor.readHumidity(), 0);
client.print("% ");
client.print("Temperatur: ");
client.print(sensor.readTemperature(), 0);
client.print(" Grad");
client.println("</html>");
break;
}
if (c == '\n') {
// you're starting a new line
currentLineIsBlank = true;
} else if (c != '\r') {
// you've gotten a character on the current line
currentLineIsBlank = false;
}
}
//Abbrucbedingung, falls nicht getrennt werden kann
if ((millis() - t1) > 5000) {
client.stop();
}
}
// give the web browser time to receive the data
delay(1);
// close the connection:
client.stop();
print_debug(debug, "client disconnected");
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
print_debug(debug, "SSID: ");
print_debug(debug, WiFi.SSID());
// print your board's IP address:
IPAddress ip = WiFi.localIP();
print_debug(debug, "IP Address: ");
print_debug(debug, IpAddress2String(ip));
// print the received signal strength:
long rssi = WiFi.RSSI();
print_debug(debug, "signal strength (RSSI):");
print_debug(debug, String(rssi));
print_debug(debug, " dBm");
}
String IpAddress2String(const IPAddress& ipAddress)
{
return String(ipAddress[0]) + String(".") + \
String(ipAddress[1]) + String(".") + \
String(ipAddress[2]) + String(".") + \
String(ipAddress[3]) ;
}
void TC5_Handler (void) {
//Restart alle 24h
if ((millis() )> t2) {
Serial.println("starte neu");
Serial.println(millis());
NVIC_SystemReset();
}
TC5->COUNT16.INTFLAG.bit.MC0 = 1; //Writing a 1 to INTFLAG.bit.MC0 clears the interrupt so that it will run again
}
Sorry für die Formatierung; bekomme es einfach nicht hin den Code mit Einrückungen und Zeilenumbrüchen hier richtig darzustellen...