Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
2e20e75c35 |
29
README.md
29
README.md
@ -1,6 +1,6 @@
|
||||
# RF water leakage sensor
|
||||
|
||||
Water leakage sensor on ATmega168/328 + RF24.
|
||||
Water leakage sensor on ATmega168/328 + nRF24.
|
||||
|
||||
## Features
|
||||
|
||||
@ -11,29 +11,6 @@ Water leakage sensor on ATmega168/328 + RF24.
|
||||
|
||||
## Note
|
||||
|
||||
A gateway is required. For details see "RF Gateway".
|
||||
A gateway is required. For details see [RF Gateway](https://github.com/aZholtikov/RF-Gateway).
|
||||
|
||||
## Full config example for Home Assistant
|
||||
|
||||
```yml
|
||||
mqtt:
|
||||
sensor:
|
||||
- name: "NAME"
|
||||
device_class: "voltage"
|
||||
unit_of_measurement: "V"
|
||||
state_topic: "homeassistant/rf_sensor/ID/water_leakage"
|
||||
value_template: "{{ value_json.battery }}"
|
||||
expire_after: 4500
|
||||
force_update: true
|
||||
qos: 2
|
||||
binary_sensor:
|
||||
- name: "NAME"
|
||||
device_class: "moisture"
|
||||
state_topic: "homeassistant/rf_sensor/ID/water_leakage"
|
||||
value_template: "{{ value_json.state }}"
|
||||
payload_on: "ALARM"
|
||||
payload_off: "DRY"
|
||||
expire_after: 4500
|
||||
force_update: true
|
||||
qos: 2
|
||||
```
|
||||
Any feedback via [e-mail](mailto:github@zh.com.ru) would be appreciated. Or... [Buy me a coffee](https://paypal.me/aZholtikov).
|
||||
|
@ -6,10 +6,7 @@ board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ALARM=1
|
||||
-D DRY=0
|
||||
-D portUSE_WDTO=WDTO_1S
|
||||
-D WATER_LEAKAGE=5
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
@ -18,8 +15,9 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
feilipu/FreeRTOS@^10.5.0-0
|
||||
nrf24/RF24@^1.4.5
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega168P]
|
||||
platform = atmelavr
|
||||
@ -29,10 +27,7 @@ board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ALARM=1
|
||||
-D DRY=0
|
||||
-D portUSE_WDTO=WDTO_1S
|
||||
-D WATER_LEAKAGE=5
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
@ -41,8 +36,9 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
feilipu/FreeRTOS@^10.5.0-0
|
||||
nrf24/RF24@^1.4.5
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega168PB]
|
||||
platform = atmelavr
|
||||
@ -52,10 +48,7 @@ board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ALARM=1
|
||||
-D DRY=0
|
||||
-D portUSE_WDTO=WDTO_1S
|
||||
-D WATER_LEAKAGE=5
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
@ -64,8 +57,9 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
feilipu/FreeRTOS@^10.5.0-0
|
||||
nrf24/RF24@^1.4.5
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega328]
|
||||
platform = atmelavr
|
||||
@ -75,10 +69,7 @@ board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ALARM=1
|
||||
-D DRY=0
|
||||
-D portUSE_WDTO=WDTO_1S
|
||||
-D WATER_LEAKAGE=5
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
@ -87,8 +78,9 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
feilipu/FreeRTOS@^10.5.0-0
|
||||
nrf24/RF24@^1.4.5
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega328P]
|
||||
platform = atmelavr
|
||||
@ -98,10 +90,7 @@ board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ALARM=1
|
||||
-D DRY=0
|
||||
-D portUSE_WDTO=WDTO_1S
|
||||
-D WATER_LEAKAGE=5
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
@ -110,8 +99,9 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
feilipu/FreeRTOS@^10.5.0-0
|
||||
nrf24/RF24@^1.4.5
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
||||
|
||||
[env:ATmega328PB]
|
||||
platform = atmelavr
|
||||
@ -121,10 +111,7 @@ board_build.f_cpu = 8000000L
|
||||
framework = arduino
|
||||
upload_protocol = usbasp
|
||||
build_flags =
|
||||
-D ALARM=1
|
||||
-D DRY=0
|
||||
-D portUSE_WDTO=WDTO_1S
|
||||
-D WATER_LEAKAGE=5
|
||||
-D ID=$UNIX_TIME
|
||||
board_fuses.hfuse = 0xDE
|
||||
board_fuses.lfuse = 0xE2
|
||||
@ -133,5 +120,6 @@ upload_flags =
|
||||
-Pusb
|
||||
-e
|
||||
lib_deps =
|
||||
feilipu/FreeRTOS@^10.5.0-0
|
||||
nrf24/RF24@^1.4.5
|
||||
https://github.com/aZholtikov/ZHConfig
|
||||
https://github.com/feilipu/Arduino_FreeRTOS_Library
|
||||
https://github.com/nRF24/RF24
|
43
src/main.cpp
43
src/main.cpp
@ -3,27 +3,23 @@
|
||||
#include "RF24.h"
|
||||
#include "avr/interrupt.h"
|
||||
#include "semphr.h"
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int16_t sensor_id{0};
|
||||
int16_t sensor_type{0};
|
||||
int16_t value_1{0};
|
||||
int16_t value_2{0};
|
||||
int16_t value_3{0};
|
||||
int16_t value_4{0};
|
||||
int16_t value_5{0};
|
||||
} transmitted_data_t;
|
||||
#include "EEPROM.h"
|
||||
#include "ZHConfig.h"
|
||||
|
||||
void sendBatteryLevelCharge(void *pvParameters);
|
||||
void sendAlarmStatus(void *pvParameters);
|
||||
float getBatteryLevelCharge(void);
|
||||
void loadId(void);
|
||||
|
||||
int16_t id{abs((int16_t)ID)};
|
||||
|
||||
RF24 radio(9, 10);
|
||||
TaskHandle_t xSendBatteryLevelCharge;
|
||||
|
||||
void setup()
|
||||
{
|
||||
loadId();
|
||||
|
||||
EICRA |= (1 << ISC01) | (1 << ISC00);
|
||||
EIMSK |= (1 << INT0);
|
||||
ADCSRA &= ~(1 << ADEN);
|
||||
@ -55,12 +51,12 @@ void sendBatteryLevelCharge(void *pvParameters)
|
||||
(void)pvParameters;
|
||||
for (;;)
|
||||
{
|
||||
transmitted_data_t sensor{abs((int16_t)ID), WATER_LEAKAGE};
|
||||
rf_transmitted_data_t sensor{id, RFST_WATER_LEAKAGE};
|
||||
sensor.value_1 = getBatteryLevelCharge() * 100;
|
||||
sensor.value_2 = DRY;
|
||||
radio.powerUp();
|
||||
radio.flush_tx();
|
||||
radio.write(&sensor, sizeof(transmitted_data_t));
|
||||
radio.write(&sensor, sizeof(rf_transmitted_data_t));
|
||||
radio.powerDown();
|
||||
vTaskDelay(3600);
|
||||
}
|
||||
@ -72,11 +68,11 @@ void sendAlarmStatus(void *pvParameters)
|
||||
(void)pvParameters;
|
||||
for (;;)
|
||||
{
|
||||
transmitted_data_t sensor{abs((int16_t)ID), WATER_LEAKAGE};
|
||||
rf_transmitted_data_t sensor{id, RFST_WATER_LEAKAGE};
|
||||
sensor.value_2 = ALARM;
|
||||
radio.powerUp();
|
||||
radio.flush_tx();
|
||||
radio.write(&sensor, sizeof(transmitted_data_t));
|
||||
radio.write(&sensor, sizeof(rf_transmitted_data_t));
|
||||
radio.powerDown();
|
||||
vTaskDelay(60);
|
||||
}
|
||||
@ -92,8 +88,21 @@ float getBatteryLevelCharge()
|
||||
while (bit_is_set(ADCSRA, ADSC))
|
||||
;
|
||||
ADCSRA &= ~(1 << ADEN);
|
||||
float value = ((1024 * 1.1) / (ADCL + ADCH * 256));
|
||||
return value;
|
||||
return (1024 * 1.1) / (ADCL + ADCH * 256);
|
||||
}
|
||||
|
||||
void loadId()
|
||||
{
|
||||
cli();
|
||||
if (EEPROM.read(511) == 254)
|
||||
EEPROM.get(0, id);
|
||||
else
|
||||
{
|
||||
EEPROM.write(511, 254);
|
||||
EEPROM.put(0, id);
|
||||
}
|
||||
delay(50);
|
||||
sei();
|
||||
}
|
||||
|
||||
ISR(INT0_vect)
|
||||
|
Loading…
x
Reference in New Issue
Block a user