I have built two cistern sensors that both seem to have this ailment. They stop replying on port 80, but still ping. The amount of time that this happens in seems to be very random from an hour or so to almost a day.
They aren’t in cisterns or waterproof enclosures, as they are still in development.
The device is powered by PoE so they only have one wire. When they mess up, I can turn PoE off and back on, for that port from the switch and they come back to life.
It’s a super simple design of a Uno, W5100 ethernet module, an ultrasonic range finder on pins 2&3, and a DHT22 on pin 4
When they have problems, they still ping, so I know there are not network problems. Both devices are identical physically and in code. One is connected to a Cisco 3750G, the other is connected to a Cisco 3750.
They both have unique MAC addresses by REMark-ing out the line for the other device’s MAC address.
One of them performed flawlessly for 3 days before it had a problem. They are configured to reboot every 24 hours to prevent memory fragmentation etc…
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#include <SPI.h>
#include <Ethernet.h>
// Remember Ethernet uses pins 10-13, so they can not be used
#define TRIGGER_PIN 3 // Pin to trigger rangefinder
#define PWM_OUTPUT_PIN 2 // Pin to listen to Rangefinder
#define DHTPIN 4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
long duration; // Time for ping to reply (ms)
float distance; // Distance calculated by time to reply (inches)
float Volume_Current; // Current Volume of water
float Gallons_Per_Inch; // Calculated how many gallons per inch of water depth
float Temperature; // Temperature at top of Cistern
float Volume_Total = 1800; // Total capacity when full (gallons)
float Distance_Bottom = 61; // Distance to sensor when empty (inches)
float Distance_Top = 12; //Distance to Sensor when full (inches)
//Remark out whichever this is not
//byte mac[] = { 0x00, 0x0C, 0xE2, 0xDE, 0xC0, 0x8D }; // Byte Array of MAC address Irrigaiton
byte mac[] = { 0x00, 0x0C, 0xE2, 0xAB, 0x0F, 0x46 }; // Byte Array of MAC address Fresh
unsigned long DHT22_Check_Time; // When (Millis) did you check the DHT22 last?
EthernetServer server(80);
DHT dht(DHTPIN, DHTTYPE);
void setup()
{
dht.begin();
Ethernet.begin(mac);
server.begin();
Serial.begin(9600);
Serial.println(Ethernet.localIP());
pinMode(TRIGGER_PIN, OUTPUT);
pinMode(PWM_OUTPUT_PIN, INPUT);
Gallons_Per_Inch = Volume_Total / (Distance_Bottom - Distance_Top);
delay(2000); // Make sure the DHT is initialized before you start
DHT22_Check_Time = 0; // Make sure we start at 0
}
void(* resetFunc) (void) = 0; //declare reset function at address 0
void loop()
{
EthernetClient client = server.available();
if (client) {
while (client.connected()) {
if (client.available()) {
client.print(millis()/1000); // For Testing
client.println(" Sec Uptime"); // For Testing
// The sensor is triggered by a falling edge of a HIGH pulse that
// is more than 60 microseconds in duration.
// Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
digitalWrite(TRIGGER_PIN, LOW);
delayMicroseconds(5);
digitalWrite(TRIGGER_PIN, HIGH);
delayMicroseconds(100);
digitalWrite(TRIGGER_PIN, LOW);
// Read the signal from the sensor: a HIGH pulse whose
// duration is the time (in microseconds) from the sending
// of the ping to the reception of its echo off of an object.
// If no object detected, fixed pulse width of 35ms is sent
// by the sensor.
pinMode(PWM_OUTPUT_PIN, INPUT);
duration = pulseIn(PWM_OUTPUT_PIN, HIGH);
// Convert the pulse width duration into a distance
distance = duration;
distance = (distance / 58)/2.54;
Volume_Current = (Distance_Bottom - distance) * Gallons_Per_Inch;
client.print(distance);
client.println(" in");
client.print(Volume_Current);
client.println(" gal");
client.print(Temperature);
client.println(" F");
client.println("Empty");
client.println("Empty");
client.println("Empty");
client.println("Empty");
client.println("Empty");
client.println("Empty");
}
break;
}
}
client.stop();
if (millis() > 86400000) resetFunc(); //call reset when it's been up for over 24 hours to renew DHCP and maintain stability make this shorter if your DHCP leases < 24H or use ethernet.maintain()
if (millis() > (DHT22_Check_Time + 300000)) { // Make sure we donly do this every 5 min because it takes along time
Temperature = (dht.readTemperature(true)); // read temperature. The true makes it F
DHT22_Check_Time = millis(); // Reset our read time to the current time since we just checked it
}
}