I have a program that sends environmental data to a webpage. It works fine and sends data for a few minutes. Then it just stops. The Arduino is still on and running, there is just no output. My code is below. If anyone has any suggestions, I would be grateful.
#include <UIPEthernet.h>
#include <Wire.h>
#include <BH1750.h>
#include <BME280.h>
#include <avr/wdt.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(10,1,110,15);
static uint32_t tempTimer = millis() + 30000;
EthernetClient client;
BME280 bme;
BH1750 lightMeter;
const int floodSensor1 = A6;
const int floodSensor2 = A7;
int count = 0;
bool leak = false;
bool lightOn = false;
void setup() {
Serial.begin(115200);
while (!Serial) {
;
}
Serial.println("Start ethernet");
Ethernet.begin(mac);
delay(1000);
Serial.println("connecting...");
while(!bme.begin()){
Serial.println("Could not find temp/humidity sensor!");
delay(1000);
}
lightMeter.begin();
delay(1000);
sendData("light", "off");
pinMode(floodSensor1, INPUT);
pinMode(floodSensor2, INPUT);
wdt_disable();
wdt_enable(WDTO_8S);
}
void loop() {
if (millis() > tempTimer) {
tempTimer = millis() + 30000;
int temp = bme.ReadTemperature(false);
int hum = bme.ReadHumidity();
String tempHum = String(temp-3) + ":" + String(hum);
sendData("tempHum", tempHum);
}
uint16_t lux = lightMeter.readLightLevel();
if (lux > 50){
if (!lightOn){
sendData("light", "on");
}
lightOn = true;
} else {
if (lightOn){
sendData("light", "off");
}
lightOn = false;
}
//Serial.println(analogRead(floodSensor1) + String(" - ") + analogRead(floodSensor2));
//Serial.println(count);
if (analogRead(floodSensor1) > 100 || analogRead(floodSensor2) > 100) {
count += 1;
} else {
count = 0;
}
if (count < 5){
if (leak){
sendData("leakDetected", "ok");
}
leak = false;
} else {
if (!leak) {
Serial.println("Leak Detected");
sendData("leakDetected", "leak");
}
leak = true;
}
wdt_reset();
delay(1000);
}
void sendData(String where, String what){
if (client.connect(server, 3000)) {
client.print("POST /");
client.print(where);
client.print("/");
client.print(what);
client.println(" HTTP/1.1");
client.println("Host: batman");
client.println("User-Agent: Arduino/1.0");
client.println("Connection: close");
client.print("Content-Length: ");
client.println("2");
client.println();
client.println("go");
client.println();
//client.stop();
}
delay(1000);
if (client.connected()) {
//Serial.println();
//Serial.println("disconnecting.");
client.stop();
}
}