Hi all,
finally i rewrite a code for myself. There is no More EEPROM usage at all.
I'm using MajorDoMo (http://majordomohome.com/) and it more suitable for me to have a 10 minutes counts from Rain Gauge.
Here is my new code:
#define MY_RFM69_ENABLE_ENCRYPTION
/**
*
Author: Sergey E. Yakovlev
Date: 2017/02/25 u001
* The MySensors Arduino library handles the wireless radio link and protocol
* between your home built sensors/actuators and HA controller of choice.
* The sensors forms a self healing radio network with optional repeaters. Each
* repeater and gateway builds a routing tables in EEPROM which keeps track of the
* network topology allowing messages to be routed to nodes.
*
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
* Copyright (C) 2013-2015 Sensnology AB
* Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors
*
* Documentation: http://www.mysensors.org
* Support Forum: http://forum.mysensors.org
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* version 2 as published by the Free Software Foundation.
*
*/
#define SKETCH_NAME "Enic Rain Gauge"
#define SKETCH_VERSION "0.1"
#define DWELL_TIME 40 // this allows for radio to come back to power after a transmission, ideally 0
#define DHT_ON // uncomment out this line to enable DHT sensor
// Enable debug prints to serial monitor
//#define MY_DEBUG
//#define MY_DEBUG_VERBOSE
//#define MY_NODE_ID AUTO
#define MY_NODE_ID 15
#define MY_RADIO_RFM69
#define MY_IS_RFM69HW
#define MY_RFM69_FREQUENCY RF69_433MHZ
#define MY_RFM69_NETWORKID 100
#define MY_RFM69_TX_POWER 31
#include <MySensors.h>
#include <Adafruit_Sensor.h>
#include <DHT_U.h>
#define CHILD_ID_HUM 0
#define CHILD_ID_TEMP 1
#define CHILD_ID_RAIN_LOG 3 // Keeps track of accumulated rainfall
int tipSensorPin = 3; // Pin the tipping bucket is connected to. Must be interrupt capable pin
int ledPin = 5; // Pin the LED is connected to. PWM capable pin required
#define DHTPIN 8 // Pin which is connected to the DHT sensor.
// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
char buff[10];
unsigned long SEND_FREQUENCY = 60000*10; // Minimum time between send (in milliseconds). We don't wnat to spam the gateway.
DHT_Unified dht(DHTPIN, DHTTYPE);
#define TIP_SENSOR_PIN 3
//d=112 mm
//11689.863832 mm2 = 116,89863832 cm2
//42,77209787776081 mm
//88 89 91 91 90 = 89,8
//0,4763039852757329
#define CALIBRATE_FACTOR 48 // amount of rain per rain bucket tip e.g. 5 is .05mm
MyMessage msgHum(CHILD_ID_HUM, V_HUM);
MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
MyMessage msgRain(CHILD_ID_RAIN_LOG, V_RAIN);
sensors_event_t event;
unsigned long lastSend; //Last Send millis()
unsigned long lastTipTime=millis();
volatile unsigned int rainBucket=0;
void presentation() {
// Register all sensors to gw (they will be created as child devices)
sendSketchInfo(SKETCH_NAME, SKETCH_VERSION);
wait(DWELL_TIME);
present(CHILD_ID_RAIN_LOG, S_RAIN);
wait(DWELL_TIME);
#ifdef DHT_ON
present(CHILD_ID_HUM, S_HUM);
wait(DWELL_TIME);
present(CHILD_ID_TEMP, S_TEMP);
wait(DWELL_TIME);
#endif
// M_DEBUG_PRINTLN(F("Sensor Presentation Complete"));
}
void setup()
{
// Set up the IO
pinMode(TIP_SENSOR_PIN, INPUT);
attachInterrupt (digitalPinToInterrupt(TIP_SENSOR_PIN), sensorTipped, FALLING); // depending on location of the hall effect sensor may need CHANGE
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
}
void loop(){
unsigned long now = millis();
if (now - lastSend > SEND_FREQUENCY) {
send(msgRain.set((float)rainBucket / 100, 1));
rainBucket=0;
wait(DWELL_TIME);
// Get temperature event and print its value.
double t = -1;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
debug(PSTR("!USR:DHT:Error reading temperature!\n"));
} else {
t = event.temperature;
dtostrf(t,6,(uint8_t)2,buff);
debug(PSTR("USR:DHT:t=%s\n"),buff);
send(msgTemp.set(buff));
}
// Get humidity event and print its value.
double h = -1;
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
debug(PSTR("!USR:DHT:Error reading humidity!\n"));
} else {
h = event.relative_humidity;
dtostrf(h,6,(uint8_t)2,buff);
debug(PSTR("USR:DHT:h=%s\n"),buff);
send(msgHum.set(buff));
}
lastSend=now;
}
}
void sensorTipped()
{
unsigned long thisTipTime = millis();
if (thisTipTime - lastTipTime > 100UL)
{
rainBucket += CALIBRATE_FACTOR; // adds CALIBRATE_FACTOR hundredths of unit each tip
}
lastTipTime = thisTipTime;
}
And now i able to see when it was a rain and how strong it was
SY
Sergey