Browse Source

Version fonctionnelle

master
scayac 4 years ago
parent
commit
b1b1a614bf
  1. 27
      Raingauge-MySensors.ino

27
Raingauge-MySensors.ino

@ -1,6 +1,7 @@
// Enable debug prints to serial monitor // Enable debug prints to serial monitor
#define MY_DEBUG #define MY_DEBUG
#define MY_RADIO_NRF24 #define MY_RADIO_NRF24
#define MY_RF24_PA_LEVEL RF24_PA_MAX
//#define MY_NODE_ID 7 //#define MY_NODE_ID 7
#include <SPI.h> #include <SPI.h>
@ -15,8 +16,8 @@
#define SKETCH_NAME "Rain Gauge" // Change to a fancy name you like #define SKETCH_NAME "Rain Gauge" // Change to a fancy name you like
#define SKETCH_VERSION "1.1" // Your version #define SKETCH_VERSION "1.1" // Your version
//unsigned long SLEEP_TIME = 18*60000; // Sleep time (in milliseconds). unsigned long SLEEP_TIME = 20*60000; // Sleep time (in milliseconds).
unsigned long SLEEP_TIME = 20000; // use this instead for debug //unsigned long SLEEP_TIME = 20000; // use this instead for debug
float hwRainVolume = 0; // Current rainvolume calculated in hardware. float hwRainVolume = 0; // Current rainvolume calculated in hardware.
int hwPulseCounter = 0; // Pulsecount recieved from GW int hwPulseCounter = 0; // Pulsecount recieved from GW
@ -34,10 +35,10 @@ MyMessage lastCounterMsg(CHILD_ID,V_VAR1);
// BATTERY VOLTAGE DIVIDER SETUP // BATTERY VOLTAGE DIVIDER SETUP
// 1M, 470K divider across battery and using internal ADC ref of 1.1V // 1M, 470K divider across battery and using internal ADC ref of 1.1V
// Sense point is bypassed with 0.1 uF cap to reduce noise at that point // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
// ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts // ((100e3+35e3)/35e3)*1.1 = Vmax = 4,24 Volts
// 3.44/1023 = Volts per bit = 0.003363075 // 4,24/1023 = Volts per bit = 0.004144673
#define VBAT_PER_BITS 0.003363075 #define VBAT_PER_BITS 0.004144673
#define VMIN 2.0 // Vmin (radio Min Volt)=1.9V (564v) #define VMIN 3.0 // Vmin (radio Min Volt)=1.9V (564v)
#define VMAX 4.2 // Vmax = (2xAA bat)=3.0V (892v) #define VMAX 4.2 // Vmax = (2xAA bat)=3.0V (892v)
int batteryPcnt = 0; // Calc value for battery % int batteryPcnt = 0; // Calc value for battery %
int batLoop = 0; // Loop to help calc average int batLoop = 0; // Loop to help calc average
@ -108,7 +109,7 @@ boolean tipped = oldReedState != reedState;
if (tipped==false) { if (tipped==false) {
//No bucket tipped over last sleep-period, check battery then... //No bucket tipped over last sleep-period, check battery then...
//batM(); batM();
} }
lastSend=currentTime; lastSend=currentTime;
@ -137,6 +138,14 @@ void batM(){ //The battery calculations
// Calculate the battery in % // Calculate the battery in %
float Vbat = sensorValue * VBAT_PER_BITS; float Vbat = sensorValue * VBAT_PER_BITS;
int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.); int batteryPcnt = static_cast<int>(((Vbat-VMIN)/(VMAX-VMIN))*100.);
if (batteryPcnt > 100) {
batteryPcnt=100;
}
if (batteryPcnt < 0) {
batteryPcnt=0;
}
Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %"); Serial.print("Battery percent: "); Serial.print(batteryPcnt); Serial.println(" %");
// Add it to array so we get an average of 3 (3x20min) // Add it to array so we get an average of 3 (3x20min)
@ -146,10 +155,6 @@ void batM(){ //The battery calculations
batteryPcnt = (batArray[0] + batArray[1] + batArray[2]); batteryPcnt = (batArray[0] + batArray[1] + batArray[2]);
batteryPcnt = batteryPcnt / 3; batteryPcnt = batteryPcnt / 3;
if (batteryPcnt > 100) {
batteryPcnt=100;
}
Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %"); Serial.print("Battery Average (Send): "); Serial.print(batteryPcnt); Serial.println(" %");
sendBatteryLevel(batteryPcnt); sendBatteryLevel(batteryPcnt);
batLoop = 0; batLoop = 0;

Loading…
Cancel
Save