yes, tried that now, works fine... odd, i´ll posting all of the code, maybe not so much my own but this is purly educational fun att the moment, regardless it bugs me not knowing WHY!?
it gives the "correct" value as specified in the code until rainfall++ then it goes bananas, but..... only when above part is used in if statement. other outpus are fine.

this is after one "bucket", one reading of the hall sensor, when placed in this if statement, whitout it prints "1".
#include "DHT.h"
#include <Wire.h>
#include <SFE_BMP180.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3
#define DHTPIN 2
#define DHTTYPE DHT11
#define I2C_ADDRESS 0x77
#define ALTITUDE 90.0
OneWire oneWire(ONE_WIRE_BUS);
DHT dht(DHTPIN, DHTTYPE);
SFE_BMP180 pressure;
DeviceAddress Temp = {0x28, 0xB2, 0x3C, 0x16, 0xA8, 0x0, 0x3C, 0x2D};
DallasTemperature sensors(&oneWire);
const int Rain = 9;
int rainfall;
const unsigned long eventTime_1_hum = 33000; //in ms
const unsigned long eventTime_2_temp = 32000; //in ms
const unsigned long eventTime_3_press = 31000; //in ms
const unsigned long eventTime_4_regn = 30000; //in ms
unsigned long previousTime_1 = 0;
unsigned long previousTime_2 = 0;
unsigned long previousTime_3 = 0;
unsigned long previousTime_4 = 0;
unsigned long currentTime = 0;
#define MAX_COMMAND_TIME 10000 // milliseconds
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
if(esp8266_test_communication() &&
esp8266_reset() &&
esp8266_client_mode() &&
esp8266_join_ap("WST_AP", "") &&
esp8266_start_udp("255.255.255.255", 5000)) {
// success, turn on LED
digitalWrite(LED_BUILTIN, HIGH);
} else {
// failure, blink LED
while(true) {
digitalWrite(LED_BUILTIN, HIGH);
delay(1000);
digitalWrite(LED_BUILTIN, LOW);
delay(1000);
}
}
pinMode(Rain, INPUT);
dht.begin();
pressure.begin();
sensors.begin();
sensors.setResolution(Temp, 12);
}
void loop() {
currentTime = millis();
if ( currentTime - previousTime_4 >= eventTime_4_regn) {
char text[50];
sprintf(text, "Regn %d \n", rainfall);
esp8266_transmit_udp(text);
previousTime_4 = currentTime;
}
if ( digitalRead(Rain) == LOW){ //hall sensor on "tipping bucket" (clean enough without deboounce)
rainfall++;
}
if ( currentTime - previousTime_1 >= eventTime_1_hum) {
char hum[25];
dtostrf(dht.readHumidity(), -2, 0, hum);
char text[50];
sprintf(text, " Hum: %s\n", (hum));
esp8266_transmit_udp(text);
previousTime_1 = currentTime;
}
if ( currentTime - previousTime_2 >= eventTime_2_temp) {
sensors.requestTemperatures();
char temp[25];
dtostrf(sensors.getTempC(Temp), -4, 2, temp);
char text[50];
sprintf(text, " Temp: %s\n", (temp));
esp8266_transmit_udp(text);
previousTime_2 = currentTime;
}
if ( currentTime - previousTime_3 >= eventTime_3_press) {
char status;
double T,P,p0,a;
status = pressure.startTemperature();
if (status != 0)
{
delay(status);
status = pressure.getTemperature(T);
if (status != 0)
{
status = pressure.startPressure(3);
if (status != 0)
{
delay(status);
status = pressure.getPressure(P,T);
if (status != 0)
{
p0 = pressure.sealevel(P,ALTITUDE);
a = pressure.altitude(P,p0);
char pres[25];
dtostrf((P) + 4, -4, 2, pres);
char presu[25];
dtostrf((p0 + 4), -4, 2, presu);
char text[50];
sprintf(text, " Press: %s sea: %s\n", (pres), (presu));
esp8266_transmit_udp(text);
previousTime_3 = currentTime;
}
}
}
}
}
}
bool esp8266_test_communication(void) {
delay(500); // wait for module to boot up
Serial.print("AT\r\n");
unsigned long startTime = millis();
while(true) {
if(Serial.find("OK"))
return true;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
}
bool esp8266_reset(void) {
Serial.print("AT+RST\r\n");
unsigned long startTime = millis();
while(true) {
if(Serial.find("ready"))
return true;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
}
bool esp8266_client_mode(void) {
Serial.print("AT+CWMODE=1\r\n");
unsigned long startTime = millis();
while(true) {
if(Serial.find("OK"))
return true;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
}
bool esp8266_join_ap(String ssid, String password) {
Serial.print("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"\r\n");
unsigned long startTime = millis();
while(true) {
if(Serial.find("WIFI CONNECTED"))
break;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
while(true) {
if(Serial.find("WIFI GOT IP"))
break;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
while(true) {
if(Serial.find("OK"))
return true;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
}
bool esp8266_start_udp(String ip_address, int port_number) {
Serial.print("AT+CIPSTART=\"UDP\",\"" + ip_address + "\"," + port_number + "\r\n");
unsigned long startTime = millis();
while(true) {
if(Serial.find("CONNECT"))
break;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
while(true) {
if(Serial.find("OK"))
return true;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
}
bool esp8266_transmit_udp(String text) {
Serial.print("AT+CIPSEND=" + String(text.length()) + "\r\n");
unsigned long startTime = millis();
while(true) {
if(Serial.find("OK"))
break;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
while(true) {
if(Serial.find(">"))
break;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
Serial.print(text);
while(true) {
if(Serial.find("SEND OK"))
return true;
if(millis() > startTime + MAX_COMMAND_TIME)
return false;
}
}