battery status, sleep interval
This commit is contained in:
parent
97bb091ae5
commit
c50cb8acc2
|
|
@ -66,7 +66,7 @@ void handleRoot(); // function prototypes for HTTP handlers
|
|||
void handleNotFound();
|
||||
void reconnect();
|
||||
String SendHTML(float Temperaturestat, float Humiditystat);
|
||||
void publishData(float temp, float humid, float soil);
|
||||
void publishData(float temp, float humid, float soil, long battery);
|
||||
void callback(char *inTopic, byte *payload, unsigned int length);
|
||||
|
||||
void configModeCallback(WiFiManager *myWiFiManager)
|
||||
|
|
@ -185,7 +185,7 @@ void loop()
|
|||
|
||||
if (ms - lastMillis > 5000 && Temperature != 0.0 && Humidity != 0.0 && SoilHumidity != 0.0)
|
||||
{
|
||||
publishData(Temperature, Humidity,SoilHumidity);
|
||||
publishData(Temperature, Humidity, SoilHumidity, battery);
|
||||
lastMillis = ms;
|
||||
}
|
||||
|
||||
|
|
@ -242,7 +242,7 @@ void handleNotFound()
|
|||
}
|
||||
|
||||
// function called to publish the temperature and the humidity
|
||||
void publishData(float temp, float humid, float soil)
|
||||
void publishData(float temp, float humid, float soil, long battery)
|
||||
{
|
||||
// create a JSON object
|
||||
// doc : https://github.com/bblanchon/ArduinoJson/wiki/API%20Reference
|
||||
|
|
@ -251,6 +251,7 @@ void publishData(float temp, float humid, float soil)
|
|||
doc["temperature"] = (String)temp;
|
||||
doc["humidity"] = (String)humid;
|
||||
doc["soilhumidity"] = (String)soil;
|
||||
doc["battery"] = (String)battery;
|
||||
|
||||
serializeJson(doc, Serial);
|
||||
Serial.println("");
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@
|
|||
|
||||
2021 Stefan Ostermann based on several source from the internetz.
|
||||
|
||||
*NOT working in platformio right now!*
|
||||
|
||||
Sources:
|
||||
https://git.cryhost.de/crycode/attiny85-radiohead-dht22-weather-sensor/-/tree/master
|
||||
*/
|
||||
|
|
@ -25,12 +23,17 @@
|
|||
// the own RadioHead address
|
||||
#define RH_OWN_ADDR 0xca // 202
|
||||
|
||||
// the server RadioHead address
|
||||
#define RH_SERVER_ADDR 0x01
|
||||
|
||||
// RadioHead bitrate in bit/s
|
||||
#define RH_SPEED 1000
|
||||
|
||||
/*
|
||||
define when to wake up
|
||||
0=16ms, 1=32ms,2=64ms,3=128ms,4=250ms,5=500ms
|
||||
6=1 sec,7=2 sec, 8=4 sec, 9= 8sec
|
||||
*/
|
||||
#define WATCHDOG_WAKEUP 9
|
||||
|
||||
|
||||
// pins for the radio hardware
|
||||
#define RH_RX_PIN 6 // not used, set to a non-existent pin
|
||||
#define RH_TX_PIN 3
|
||||
|
|
@ -123,7 +126,7 @@ void setup() {
|
|||
rh_buf[0] = MSG_START;
|
||||
rh_send(1);
|
||||
|
||||
setup_watchdog(6); // approximately 4 seconds sleep
|
||||
setup_watchdog(WATCHDOG_WAKEUP);
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -136,7 +139,7 @@ void loop() {
|
|||
digitalWrite(LED_PIN, HIGH);
|
||||
|
||||
// temperature and humidity
|
||||
float t = 0;//float is 32bit = 1byte
|
||||
float t = 0;//float is 32bit = 4 byte
|
||||
float h = 0;
|
||||
int soil = 0;
|
||||
long battery = 0;
|
||||
|
|
@ -170,7 +173,6 @@ void loop() {
|
|||
// turn off the LED
|
||||
digitalWrite(LED_PIN, LOW);
|
||||
system_sleep();
|
||||
//_delay_ms(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -230,10 +232,17 @@ void setup_watchdog(int ii) {
|
|||
From https://github.com/cano64/ArduinoSystemStatus/blob/master/SystemStatus.cpp
|
||||
*/
|
||||
int getVcc() {
|
||||
//reads internal 1V1 reference against VCC
|
||||
ADMUX = _BV(MUX3) | _BV(MUX2); // For ATtiny85/45
|
||||
|
||||
_delay_ms(5);; // Wait for Vref to settle
|
||||
//reads internal 1V1 reference against VCC
|
||||
#if defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny44__)
|
||||
ADMUX = _BV(MUX5) | _BV(MUX0); // For ATtiny84
|
||||
#elif defined(__AVR_ATtiny85__) || defined(__AVR_ATtiny45__)
|
||||
ADMUX = _BV(MUX3) | _BV(MUX2); // For ATtiny85/45
|
||||
#elif defined(__AVR_ATmega1284P__)
|
||||
ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega1284
|
||||
#else
|
||||
ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); // For ATmega328
|
||||
#endif
|
||||
delay(2); // Wait for Vref to settle
|
||||
ADCSRA |= _BV(ADSC); // Convert
|
||||
while (bit_is_set(ADCSRA, ADSC));
|
||||
uint8_t low = ADCL;
|
||||
|
|
@ -243,6 +252,6 @@ int getVcc() {
|
|||
while (bit_is_set(ADCSRA, ADSC));
|
||||
low = ADCL;
|
||||
val = (ADCH << 8) | low;
|
||||
|
||||
return (long)val;
|
||||
|
||||
return ((long)1024 * 1100) / val;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue