Merge branch 'master' of github.com:0110/PlantCtrl

This commit is contained in:
Ollo 2021-06-02 22:14:43 +02:00
commit 8cbd96adda
10 changed files with 9005 additions and 8781 deletions

File diff suppressed because it is too large Load Diff

View File

@ -32,15 +32,15 @@ Lipo
$Comp
L Connector_Generic:Conn_01x03 1WIRE1
U 1 1 5F109CD6
P 4800 1150
F 0 "1WIRE1" H 4718 825 50 0000 C CNN
F 1 "Conn_01x03" H 4718 916 50 0000 C CNN
F 2 "Connector_JST:JST_EH_B3B-EH-A_1x03_P2.50mm_Vertical" H 4800 1150 50 0001 C CNN
F 3 "~" H 4800 1150 50 0001 C CNN
1 4800 1150
P 5200 1100
F 0 "1WIRE1" H 5118 775 50 0000 C CNN
F 1 "Conn_01x03" H 5118 866 50 0000 C CNN
F 2 "Connector_JST:JST_EH_B3B-EH-A_1x03_P2.50mm_Vertical" H 5200 1100 50 0001 C CNN
F 3 "~" H 5200 1100 50 0001 C CNN
1 5200 1100
-1 0 0 1
$EndComp
Text GLabel 5000 1150 2 50 Input ~ 0
Text GLabel 5400 1100 2 50 Input ~ 0
Temp
$Comp
L Transistor_FET:BSS84 Q_PWR1
@ -442,9 +442,7 @@ F 3 "~" H 18100 2250 50 0001 C CNN
$EndComp
Text GLabel 18550 2600 2 50 Input ~ 0
VCC
Wire Wire Line
16400 9350 16400 9300
Text GLabel 16400 9350 3 50 Input ~ 0
Text GLabel 16400 9600 3 50 Input ~ 0
VCC
Text GLabel 18300 2150 2 50 Input ~ 0
PUMP_PWR
@ -488,13 +486,13 @@ Wire Wire Line
Wire Wire Line
6350 2600 6400 2600
Connection ~ 6400 2600
Text GLabel 5050 1250 2 50 Input ~ 0
Text GLabel 5450 1200 2 50 Input ~ 0
GND
Wire Wire Line
5050 1250 5000 1250
5450 1200 5400 1200
Text GLabel 9350 2000 3 50 Input ~ 0
GND
Text GLabel 16750 9500 3 50 Input ~ 0
Text GLabel 16750 9550 2 50 Input ~ 0
GND
Text GLabel 10650 15150 3 50 Input ~ 0
GND
@ -607,8 +605,6 @@ Wire Wire Line
16150 5750 16150 6100
Wire Wire Line
15500 5750 16150 5750
Wire Wire Line
15050 5750 15050 6100
Wire Wire Line
15200 5750 15050 5750
$Comp
@ -628,9 +624,6 @@ Wire Wire Line
Connection ~ 14750 6800
Wire Wire Line
14750 6600 14750 6800
Wire Wire Line
14750 6100 15050 6100
Connection ~ 14750 6100
Wire Wire Line
14750 6300 14750 6100
$Comp
@ -652,8 +645,6 @@ Wire Wire Line
14700 6100 14750 6100
Text GLabel 14700 6800 0 50 Input ~ 0
GND
Text GLabel 14700 6100 0 50 Input ~ 0
PWR_PUMP_CONVERTER
$Comp
L Connector_Generic:Conn_01x04 DCDC1
U 1 1 5F837F50
@ -704,7 +695,7 @@ L Device:R R26
U 1 1 5EE03137
P 4150 1200
F 0 "R26" H 4220 1246 50 0000 L CNN
F 1 "4k7" H 4220 1155 50 0000 L CNN
F 1 "2.2k" H 4220 1155 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 4080 1200 50 0001 C CNN
F 3 "~" H 4150 1200 50 0001 C CNN
F 4 "C17673" H 4150 1200 50 0001 C CNN "LCSC_PART_NUMBER"
@ -741,25 +732,18 @@ F 4 "C17590" H 7900 11100 50 0001 C CNN "LCSC_PART_NUMBER"
$EndComp
Wire Wire Line
2150 14500 2150 14850
Connection ~ 2150 14500
Wire Wire Line
2900 14500 2900 14850
Connection ~ 2900 14500
Wire Wire Line
5250 14500 5250 14850
Connection ~ 5250 14500
Wire Wire Line
3700 14500 3700 14850
Connection ~ 3700 14500
Wire Wire Line
4500 14500 4500 14850
Connection ~ 4500 14500
Wire Wire Line
6050 14500 6050 14850
Connection ~ 6050 14500
Wire Wire Line
6850 14500 6850 14850
Connection ~ 6850 14500
Wire Wire Line
7050 14150 7050 14200
Wire Wire Line
@ -858,16 +842,6 @@ Text GLabel 3900 14150 2 50 Input ~ 0
GND
Text GLabel 3900 14850 2 50 Input ~ 0
3_3V
Wire Wire Line
6850 14100 6850 14500
Wire Wire Line
6050 14100 6050 14500
Wire Wire Line
5250 14100 5250 14500
Wire Wire Line
4500 14100 4500 14500
Wire Wire Line
3700 14100 3700 14500
Wire Wire Line
3100 14150 3100 14200
Wire Wire Line
@ -908,10 +882,6 @@ Text GLabel 2350 14150 2 50 Input ~ 0
GND
Text GLabel 2350 14850 2 50 Input ~ 0
3_3V
Wire Wire Line
2900 14100 2900 14500
Wire Wire Line
2150 14100 2150 14500
Text GLabel 6950 15150 3 50 Input ~ 0
GND
Text GLabel 6150 15150 3 50 Input ~ 0
@ -938,7 +908,7 @@ Text GLabel 3800 13800 3 50 Input ~ 0
GND
Text GLabel 3000 13800 3 50 Input ~ 0
GND
Text GLabel 2250 13800 3 50 Input ~ 0
Text GLabel 2300 13750 3 50 Input ~ 0
GND
Text GLabel 9250 12100 3 50 Input ~ 0
GND
@ -958,7 +928,7 @@ Text Notes 5100 13050 2 207 ~ 0
Sensors
Text GLabel 2900 15000 3 50 Input ~ 0
PLANT1_MOIST
Text GLabel 2050 15000 3 50 Input ~ 0
Text GLabel 2200 13750 3 50 Input ~ 0
PWR_SENSORS
Text GLabel 3700 15000 3 50 Input ~ 0
PLANT2_MOIST
@ -972,25 +942,25 @@ Text GLabel 6850 15000 3 50 Input ~ 0
PLANT6_MOIST
Text GLabel 2150 15000 3 50 Input ~ 0
PLANT0_MOIST
Text GLabel 2800 15000 3 50 Input ~ 0
Text GLabel 2900 13800 3 50 Input ~ 0
PWR_SENSORS
Text GLabel 3600 15000 3 50 Input ~ 0
Text GLabel 3700 13800 3 50 Input ~ 0
PWR_SENSORS
Text GLabel 4400 15000 3 50 Input ~ 0
Text GLabel 4500 13800 3 50 Input ~ 0
PWR_SENSORS
Text GLabel 5150 15000 3 50 Input ~ 0
Text GLabel 5250 13800 3 50 Input ~ 0
PWR_SENSORS
Text GLabel 5950 15000 3 50 Input ~ 0
Text GLabel 6050 13800 3 50 Input ~ 0
PWR_SENSORS
$Comp
L Connector:Conn_01x03_Male S0
U 1 1 5F6785CE
P 2150 13550
F 0 "S0" H 2122 13482 50 0000 R CNN
F 1 "Conn_01x03_Male" H 2750 13350 50 0000 R CNN
F 2 "Connector_JST:JST_EH_B3B-EH-A_1x03_P2.50mm_Vertical" H 2150 13550 50 0001 C CNN
F 3 "~" H 2150 13550 50 0001 C CNN
1 2150 13550
P 2200 13550
F 0 "S0" H 2172 13482 50 0000 R CNN
F 1 "Conn_01x03_Male" H 2800 13350 50 0000 R CNN
F 2 "Connector_JST:JST_EH_B3B-EH-A_1x03_P2.50mm_Vertical" H 2200 13550 50 0001 C CNN
F 3 "~" H 2200 13550 50 0001 C CNN
1 2200 13550
0 1 1 0
$EndComp
$Comp
@ -1048,7 +1018,7 @@ F 3 "~" H 6050 13550 50 0001 C CNN
1 6050 13550
0 1 1 0
$EndComp
Text GLabel 6750 15000 3 50 Input ~ 0
Text GLabel 6850 13800 3 50 Input ~ 0
PWR_SENSORS
$Comp
L Connector:Conn_01x03_Male S6
@ -1061,64 +1031,52 @@ F 3 "~" H 6850 13550 50 0001 C CNN
1 6850 13550
0 1 1 0
$EndComp
Wire Wire Line
2800 13750 2800 15000
Wire Wire Line
3600 13750 3600 15000
Wire Wire Line
4400 13750 4400 15000
Wire Wire Line
5150 13750 5150 15000
Wire Wire Line
5950 13750 5950 15000
Wire Wire Line
6750 13750 6750 15000
$Comp
L Device:R R41
U 1 1 5F99C5A6
P 4500 13950
F 0 "R41" H 4570 13996 50 0000 L CNN
F 1 "1k" H 4570 13905 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 4430 13950 50 0001 C CNN
F 3 "~" H 4500 13950 50 0001 C CNN
F 4 "C95781" H 4500 13950 50 0001 C CNN "LCSC_PART_NUMBER"
1 4500 13950
P 4400 13900
F 0 "R41" H 4470 13946 50 0000 L CNN
F 1 "1k" H 4470 13855 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 4330 13900 50 0001 C CNN
F 3 "~" H 4400 13900 50 0001 C CNN
F 4 "C95781" H 4400 13900 50 0001 C CNN "LCSC_PART_NUMBER"
1 4400 13900
1 0 0 -1
$EndComp
$Comp
L Device:R R43
U 1 1 5F99C828
P 5250 13950
F 0 "R43" H 5320 13996 50 0000 L CNN
F 1 "1k" H 5320 13905 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 5180 13950 50 0001 C CNN
F 3 "~" H 5250 13950 50 0001 C CNN
F 4 "C95781" H 5250 13950 50 0001 C CNN "LCSC_PART_NUMBER"
1 5250 13950
P 5150 13900
F 0 "R43" H 5220 13946 50 0000 L CNN
F 1 "1k" H 5220 13855 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 5080 13900 50 0001 C CNN
F 3 "~" H 5150 13900 50 0001 C CNN
F 4 "C95781" H 5150 13900 50 0001 C CNN "LCSC_PART_NUMBER"
1 5150 13900
1 0 0 -1
$EndComp
$Comp
L Device:R R45
U 1 1 5F99CBD3
P 6050 13950
F 0 "R45" H 6120 13996 50 0000 L CNN
F 1 "1k" H 6120 13905 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 5980 13950 50 0001 C CNN
F 3 "~" H 6050 13950 50 0001 C CNN
F 4 "C95781" H 6050 13950 50 0001 C CNN "LCSC_PART_NUMBER"
1 6050 13950
P 5950 13900
F 0 "R45" H 6020 13946 50 0000 L CNN
F 1 "1k" H 6020 13855 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 5880 13900 50 0001 C CNN
F 3 "~" H 5950 13900 50 0001 C CNN
F 4 "C95781" H 5950 13900 50 0001 C CNN "LCSC_PART_NUMBER"
1 5950 13900
1 0 0 -1
$EndComp
$Comp
L Device:R R49
U 1 1 5F99CEF5
P 6850 13950
F 0 "R49" H 6920 13996 50 0000 L CNN
F 1 "1k" H 6920 13905 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 6780 13950 50 0001 C CNN
F 3 "~" H 6850 13950 50 0001 C CNN
F 4 "C95781" H 6850 13950 50 0001 C CNN "LCSC_PART_NUMBER"
1 6850 13950
P 6750 13900
F 0 "R49" H 6820 13946 50 0000 L CNN
F 1 "1k" H 6820 13855 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 6680 13900 50 0001 C CNN
F 3 "~" H 6750 13900 50 0001 C CNN
F 4 "C95781" H 6750 13900 50 0001 C CNN "LCSC_PART_NUMBER"
1 6750 13900
1 0 0 -1
$EndComp
$Comp
@ -1138,12 +1096,6 @@ Wire Wire Line
2150 14850 2150 15000
Wire Wire Line
2150 14850 2250 14850
Wire Wire Line
2150 13750 2150 13800
Wire Wire Line
2250 13750 2250 13800
Wire Wire Line
2050 13750 2050 15000
Wire Wire Line
2900 13750 2900 13800
Wire Wire Line
@ -1273,37 +1225,37 @@ Wire Wire Line
$Comp
L Device:R R39
U 1 1 5F99C2BC
P 3700 13950
F 0 "R39" H 3770 13996 50 0000 L CNN
F 1 "1k" H 3770 13905 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 3630 13950 50 0001 C CNN
F 3 "~" H 3700 13950 50 0001 C CNN
F 4 "C95781" H 3700 13950 50 0001 C CNN "LCSC_PART_NUMBER"
1 3700 13950
P 3600 13900
F 0 "R39" H 3670 13946 50 0000 L CNN
F 1 "1k" H 3670 13855 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 3530 13900 50 0001 C CNN
F 3 "~" H 3600 13900 50 0001 C CNN
F 4 "C95781" H 3600 13900 50 0001 C CNN "LCSC_PART_NUMBER"
1 3600 13900
1 0 0 -1
$EndComp
$Comp
L Device:R R37
U 1 1 5F99BE26
P 2900 13950
F 0 "R37" H 2970 13996 50 0000 L CNN
F 1 "1k" H 2970 13905 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 2830 13950 50 0001 C CNN
F 3 "~" H 2900 13950 50 0001 C CNN
F 4 "C95781" H 2900 13950 50 0001 C CNN "LCSC_PART_NUMBER"
1 2900 13950
P 2800 13900
F 0 "R37" H 2870 13946 50 0000 L CNN
F 1 "1k" H 2870 13855 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 2730 13900 50 0001 C CNN
F 3 "~" H 2800 13900 50 0001 C CNN
F 4 "C95781" H 2800 13900 50 0001 C CNN "LCSC_PART_NUMBER"
1 2800 13900
1 0 0 -1
$EndComp
$Comp
L Device:R R35
U 1 1 5F993C00
P 2150 13950
F 0 "R35" H 2220 13996 50 0000 L CNN
F 1 "1k" H 2220 13905 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 2080 13950 50 0001 C CNN
F 3 "~" H 2150 13950 50 0001 C CNN
F 4 "C95781" H 2150 13950 50 0001 C CNN "LCSC_PART_NUMBER"
1 2150 13950
P 2100 13900
F 0 "R35" H 2170 13946 50 0000 L CNN
F 1 "1k" H 2170 13855 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 2030 13900 50 0001 C CNN
F 3 "~" H 2100 13900 50 0001 C CNN
F 4 "C95781" H 2100 13900 50 0001 C CNN "LCSC_PART_NUMBER"
1 2100 13900
1 0 0 -1
$EndComp
Wire Wire Line
@ -2105,7 +2057,7 @@ U 1 1 603DF238
P 8550 5750
F 0 "Reset1" H 8550 6035 50 0000 C CNN
F 1 "SW_Push" H 8550 5944 50 0000 C CNN
F 2 "Button_Switch_SMD:SW_Push_1P1T_NO_CK_KMR2" H 8550 5950 50 0001 C CNN
F 2 "Button_Switch_SMD:SW_SPST_CK_RS282G05A3" H 8550 5950 50 0001 C CNN
F 3 "~" H 8550 5950 50 0001 C CNN
F 4 "C72443" H 8550 5750 50 0001 C CNN "LCSC_PART_NUMBER"
1 8550 5750
@ -2253,7 +2205,7 @@ U 1 1 60983DAC
P 11650 4150
F 0 "Boot1" H 11650 4435 50 0000 C CNN
F 1 "Boot" H 11650 4344 50 0000 C CNN
F 2 "Button_Switch_SMD:SW_Push_1P1T_NO_CK_KMR2" H 11650 4350 50 0001 C CNN
F 2 "Button_Switch_SMD:SW_SPST_CK_RS282G05A3" H 11650 4350 50 0001 C CNN
F 3 "~" H 11650 4350 50 0001 C CNN
F 4 "C72443" H 11650 4150 50 0001 C CNN "LCSC_PART_NUMBER"
1 11650 4150
@ -2322,7 +2274,7 @@ L Device:R R2
U 1 1 60983DD4
P 11800 5450
F 0 "R2" V 11593 5450 50 0000 C CNN
F 1 "10k" V 11684 5450 50 0000 C CNN
F 1 "1k" V 11684 5450 50 0000 C CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 11730 5450 50 0001 C CNN
F 3 "~" H 11800 5450 50 0001 C CNN
F 4 "C212284" H 11800 5450 50 0001 C CNN "LCSC_PART_NUMBER"
@ -2517,7 +2469,7 @@ Wire Wire Line
19350 10500 19400 10500
Text GLabel 3650 900 0 50 Input ~ 0
3_3V
Text GLabel 5000 1050 2 50 Input ~ 0
Text GLabel 5400 1000 2 50 Input ~ 0
3_3V
$Comp
L Device:R R4
@ -2536,7 +2488,7 @@ L Device:R R48
U 1 1 60592B8B
P 19000 11550
F 0 "R48" V 18793 11550 50 0000 C CNN
F 1 "10k" V 18884 11550 50 0000 C CNN
F 1 "1k" V 18884 11550 50 0000 C CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 18930 11550 50 0001 C CNN
F 3 "~" H 19000 11550 50 0001 C CNN
F 4 "C212284" H 19000 11550 50 0001 C CNN "LCSC_PART_NUMBER"
@ -2609,18 +2561,6 @@ Wire Wire Line
Wire Wire Line
19500 10300 19450 10300
$Comp
L Device:R R54
U 1 1 60B3E4F0
P 19300 11400
F 0 "R54" H 19230 11354 50 0000 R CNN
F 1 "100k" H 19230 11445 50 0000 R CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 19230 11400 50 0001 C CNN
F 3 "~" H 19300 11400 50 0001 C CNN
F 4 "C702859" H 19300 11400 50 0001 C CNN "LCSC_PART_NUMBER"
1 19300 11400
0 -1 -1 0
$EndComp
$Comp
L Device:C C21
U 1 1 60B3E4F7
P 19750 11150
@ -2632,11 +2572,7 @@ F 4 "C49678" H 19750 11150 50 0001 C CNN "LCSC_PART_NUMBER"
1 19750 11150
0 -1 -1 0
$EndComp
Wire Wire Line
19000 11400 19150 11400
Connection ~ 19000 11400
Wire Wire Line
19450 11400 19600 11400
Wire Wire Line
19600 11400 19600 11150
Wire Wire Line
@ -2677,8 +2613,6 @@ Wire Wire Line
Wire Wire Line
21900 7700 21850 7700
Connection ~ 21850 7700
Text Notes 4900 1400 0 50 ~ 0
todo: Add DIODEs for onewire
Wire Wire Line
11300 6350 11400 6350
Connection ~ 3700 900
@ -2750,164 +2684,8 @@ Wire Wire Line
11300 5850 11400 5850
Wire Wire Line
11300 6050 11400 6050
Text GLabel 1500 3600 0 50 Input ~ 0
ESP_TX
Text GLabel 1500 3700 0 50 Input ~ 0
ESP_RX
$Comp
L Transistor_BJT:BC337 Q13
U 1 1 602B8D19
P 1200 4800
F 0 "Q13" H 1391 4846 50 0000 L CNN
F 1 "BC817" H 1391 4755 50 0000 L CNN
F 2 "Package_TO_SOT_SMD:SOT-23" H 1400 4725 50 0001 L CIN
F 3 "" H 1200 4800 50 0001 L CNN
F 4 "C908259" H 1200 4800 50 0001 C CNN "LCSC_PART_NUMBER"
1 1200 4800
-1 0 0 -1
$EndComp
$Comp
L Transistor_BJT:BC337 Q14
U 1 1 6031A86F
P 1200 5600
F 0 "Q14" H 1391 5554 50 0000 L CNN
F 1 "BC817" H 1391 5645 50 0000 L CNN
F 2 "Package_TO_SOT_SMD:SOT-23" H 1400 5525 50 0001 L CIN
F 3 "" H 1200 5600 50 0001 L CNN
F 4 "C908259" H 1200 5600 50 0001 C CNN "LCSC_PART_NUMBER"
1 1200 5600
-1 0 0 1
$EndComp
$Comp
L Device:R R20
U 1 1 6031B230
P 1650 4800
F 0 "R20" V 1443 4800 50 0000 C CNN
F 1 "10k" V 1534 4800 50 0000 C CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 1580 4800 50 0001 C CNN
F 3 "~" H 1650 4800 50 0001 C CNN
F 4 "C212284" H 1650 4800 50 0001 C CNN "LCSC_PART_NUMBER"
1 1650 4800
0 -1 -1 0
$EndComp
$Comp
L Device:R R56
U 1 1 6031B7FB
P 1650 5600
F 0 "R56" V 1443 5600 50 0000 C CNN
F 1 "10k" V 1534 5600 50 0000 C CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 1580 5600 50 0001 C CNN
F 3 "~" H 1650 5600 50 0001 C CNN
F 4 "C212284" H 1650 5600 50 0001 C CNN "LCSC_PART_NUMBER"
1 1650 5600
0 -1 -1 0
$EndComp
Text GLabel 2000 4800 2 50 Input ~ 0
DTR
Text GLabel 1950 5600 2 50 Input ~ 0
RTS
Wire Wire Line
1400 4800 1500 4800
Wire Wire Line
1800 4800 1900 4800
Wire Wire Line
1800 5600 1850 5600
Wire Wire Line
1100 5000 1100 5200
Wire Wire Line
1100 5200 1850 5200
Wire Wire Line
1850 5200 1850 5600
Connection ~ 1850 5600
Wire Wire Line
1850 5600 1950 5600
Wire Wire Line
1400 5600 1500 5600
Wire Wire Line
1100 5400 1100 5300
Wire Wire Line
1900 5300 1900 4800
Wire Wire Line
1100 5300 1900 5300
Connection ~ 1900 4800
Wire Wire Line
1900 4800 2000 4800
Wire Wire Line
1100 4600 1100 4450
Wire Wire Line
1100 4450 950 4450
Wire Wire Line
1100 5800 1100 5900
Wire Wire Line
1100 5900 1000 5900
Text GLabel 1000 5900 0 50 Input ~ 0
IO0
Text GLabel 950 4450 0 50 Input ~ 0
EN
Text GLabel 12100 5150 2 50 Input ~ 0
IO0
Wire Wire Line
11650 4950 11650 5150
Wire Wire Line
11800 5150 11650 5150
Connection ~ 11650 5150
Wire Wire Line
11650 5150 11650 5450
Wire Wire Line
9350 5750 9500 5750
Text GLabel 9500 5450 1 50 Input ~ 0
EN
$Comp
L Jumper:SolderJumper_2_Bridged EN1
U 1 1 605896D0
P 9500 5600
F 0 "EN1" V 9454 5668 50 0000 L CNN
F 1 "NC" V 9545 5668 50 0000 L CNN
F 2 "Jumper:SolderJumper-2_P1.3mm_Bridged_Pad1.0x1.5mm" H 9500 5600 50 0001 C CNN
F 3 "~" H 9500 5600 50 0001 C CNN
1 9500 5600
0 -1 -1 0
$EndComp
$Comp
L Jumper:SolderJumper_2_Bridged IO0_1
U 1 1 60596D62
P 11950 5150
F 0 "IO0_1" V 11904 5218 50 0000 L CNN
F 1 "NC" V 11995 5218 50 0000 L CNN
F 2 "Jumper:SolderJumper-2_P1.3mm_Bridged_Pad1.0x1.5mm" H 11950 5150 50 0001 C CNN
F 3 "~" H 11950 5150 50 0001 C CNN
1 11950 5150
1 0 0 -1
$EndComp
Connection ~ 9500 5750
Wire Wire Line
9500 5750 9800 5750
Text GLabel 1500 3500 0 50 Input ~ 0
DTR
Text GLabel 1500 3900 0 50 Input ~ 0
RTS
$Comp
L Connector:Conn_01x06_Female J1
U 1 1 6068F329
P 1700 3700
F 0 "J1" H 1728 3676 50 0000 L CNN
F 1 "Conn_01x06_Female" H 1728 3585 50 0000 L CNN
F 2 "Connector_PinHeader_2.54mm:PinHeader_1x06_P2.54mm_Vertical" H 1700 3700 50 0001 C CNN
F 3 "~" H 1700 3700 50 0001 C CNN
1 1700 3700
1 0 0 -1
$EndComp
Text GLabel 1500 4000 0 50 Input ~ 0
GND
NoConn ~ 1500 3800
Text Notes 1150 3300 0 105 ~ 0
ESP32 UART
Text Notes 800 4350 0 105 ~ 0
UART Automatic Download
Text Notes 2950 3300 0 105 ~ 0
Hall Sensor Serial2|Trigger/Echo
Text Notes 1050 6750 0 50 ~ 0
Enable = 0 -> ESP32 is off\nEnable = 1 -> ESP32 is running\nGPIO0 = 0 -> Download mode\nGPIO0 = 1 -> "normal" boot\n\nDTR RTS | EN IO0\n1 1 | 1 1\n1 0 | 0 1\n0 1 | 1 0\n0 0 | 1 1
Wire Wire Line
10550 4850 10650 4850
Wire Wire Line
@ -2968,11 +2746,9 @@ Wire Wire Line
3950 3750 4000 3750
Wire Wire Line
4000 4050 3950 4050
Wire Wire Line
8400 1550 8350 1550
Text GLabel 9050 1550 1 50 Input ~ 0
3_3V
Text GLabel 8350 1550 0 50 Input ~ 0
Text GLabel 8200 1550 0 50 Input ~ 0
GND
$Comp
L Diode:BAS40-04 D16
@ -3020,10 +2796,8 @@ Wire Wire Line
11300 5950 11400 5950
Text GLabel 8900 2900 3 50 Input ~ 0
GPIO2
Text GLabel 8650 1750 0 50 Input ~ 0
Text GLabel 8350 1750 0 50 Input ~ 0
CUSTOM_GPIO1
Wire Wire Line
8650 1750 8700 1750
Connection ~ 8700 1750
Wire Wire Line
8700 1750 9500 1750
@ -3321,8 +3095,138 @@ Wire Wire Line
11950 8050 12350 8050
Text Notes 16600 7300 0 207 ~ 0
TODO: Richtige Shot-Diode bestellen
Text Notes 7800 4150 0 129 ~ 0
TODO: Button mit nur zwei Pins nutzen, statt den 4pin-varianten
Text Notes 3100 5200 0 129 ~ 0
TODO: Stiftleisten bestellen!!!!!!!!!!!!!!\n\nPumpe LED einen Mililmeter nach links aufm PCB schieben\n\nHW- An&Ausschalter
Wire Wire Line
15050 5750 15050 6100
Connection ~ 14750 6100
Wire Wire Line
14750 6100 15050 6100
Text GLabel 14700 6100 0 50 Input ~ 0
PWR_PUMP_CONVERTER
Wire Wire Line
5250 1700 5300 1700
Text GLabel 5300 1700 2 50 Input ~ 0
GND
$Comp
L Diode:BAS40-04 D28
U 1 1 60B6BC6E
P 4950 1600
F 0 "D28" H 4950 1925 50 0000 C CNN
F 1 "BAS40-04" H 4950 1834 50 0000 C CNN
F 2 "Package_TO_SOT_SMD:SOT-23" H 4700 1900 50 0001 L CNN
F 3 "http://www.vishay.com/docs/85701/bas40v.pdf" H 4830 1700 50 0001 C CNN
F 4 "C397601" H 4950 1600 50 0001 C CNN "LCSC_PART_NUMBER"
1 4950 1600
-1 0 0 1
$EndComp
Wire Wire Line
4650 1700 4600 1700
Text GLabel 4950 1500 1 50 Input ~ 0
Temp
Text GLabel 4600 1700 3 50 Input ~ 0
3_3V
$Comp
L Device:CP C26
U 1 1 60BF7877
P 16600 9500
F 0 "C26" H 16715 9546 50 0000 L CNN
F 1 "1000uF" H 16715 9455 50 0000 L CNN
F 2 "Capacitor_THT:CP_Radial_D10.0mm_P5.00mm" H 16638 9350 50 0001 C CNN
F 3 "~" H 16600 9500 50 0001 C CNN
F 4 "C503217" H 16600 9500 50 0001 C CNN "LCSC_PART_NUMBER"
1 16600 9500
0 -1 -1 0
$EndComp
Wire Wire Line
16450 9500 16400 9500
Connection ~ 16400 9500
Wire Wire Line
16400 9500 16400 9600
Wire Wire Line
16750 9500 16750 9550
Wire Wire Line
16400 9300 16400 9500
Connection ~ 16750 9500
Wire Wire Line
19000 11400 19600 11400
$Comp
L Device:R R54
U 1 1 60C0C50E
P 8350 1650
F 0 "R54" V 8550 1600 50 0000 L CNN
F 1 "10k" V 8450 1550 50 0000 L CNN
F 2 "Resistor_SMD:R_0805_2012Metric" V 8280 1650 50 0001 C CNN
F 3 "~" H 8350 1650 50 0001 C CNN
F 4 "C212284" H 8350 1650 50 0001 C CNN "LCSC_PART_NUMBER"
1 8350 1650
0 1 1 0
$EndComp
Wire Wire Line
8200 1550 8200 1650
Wire Wire Line
8200 1550 8400 1550
Wire Wire Line
8350 1750 8500 1750
Wire Wire Line
8500 1650 8500 1750
Connection ~ 8500 1750
Wire Wire Line
8500 1750 8700 1750
Wire Wire Line
9350 5750 9800 5750
Wire Wire Line
11650 4950 11650 5450
Text Notes 1150 3300 0 105 ~ 0
ESP32 UART
Text GLabel 1550 3550 2 50 Input ~ 0
GND
$Comp
L Connector:Conn_01x03_Male J1
U 1 1 6068F329
P 1350 3650
F 0 "J1" H 1378 3626 50 0000 L CNN
F 1 "Conn_01x03_Female" H 950 3450 50 0000 L CNN
F 2 "Connector_PinHeader_2.54mm:PinHeader_1x03_P2.54mm_Vertical" H 1350 3650 50 0001 C CNN
F 3 "~" H 1350 3650 50 0001 C CNN
1 1350 3650
1 0 0 -1
$EndComp
Text GLabel 1550 3750 2 50 Input ~ 0
ESP_RX
Text GLabel 1550 3650 2 50 Input ~ 0
ESP_TX
Wire Wire Line
2100 14050 2100 14500
Wire Wire Line
2100 14500 2150 14500
Connection ~ 2150 14500
Wire Wire Line
2800 14050 2800 14500
Wire Wire Line
2800 14500 2900 14500
Connection ~ 2900 14500
Wire Wire Line
3600 14050 3600 14500
Wire Wire Line
3600 14500 3700 14500
Connection ~ 3700 14500
Wire Wire Line
4500 14500 4400 14500
Wire Wire Line
4400 14500 4400 14050
Connection ~ 4500 14500
Wire Wire Line
5950 14050 5950 14500
Wire Wire Line
5950 14500 6050 14500
Connection ~ 6050 14500
Wire Wire Line
6850 14500 6750 14500
Wire Wire Line
6750 14500 6750 14050
Connection ~ 6850 14500
Wire Wire Line
5150 14050 5150 14500
Wire Wire Line
5150 14500 5250 14500
Connection ~ 5250 14500
$EndSCHEMATC

View File

@ -18,7 +18,10 @@
"string": "cpp",
"typeinfo": "cpp",
"cmath": "cpp",
"iterator": "cpp"
"iterator": "cpp",
"array": "cpp",
"tuple": "cpp",
"utility": "cpp"
}
}
}

View File

@ -46,39 +46,39 @@
/** \addtogroup GPIO Settings
* @{
*/
#define SENSOR_PLANT0 32 /**< GPIO 32 (ADC1) */
#define SENSOR_PLANT1 33 /**< GPIO 33 (ADC1) */
#define SENSOR_PLANT2 25 /**< GPIO 25 (ADC2) */
#define SENSOR_PLANT3 26 /**< GPIO 26 (ADC2) */
#define SENSOR_PLANT4 27 /**< GPIO 27 (ADC2) */
#define SENSOR_PLANT5 39 /**< SENSOR_VIN */
#define SENSOR_PLANT6 36 /**< SENSOR_VP */
#define SENSOR_PLANT0 GPIO_NUM_32 /**< GPIO 32 (ADC1) */
#define SENSOR_PLANT1 GPIO_NUM_33 /**< GPIO 33 (ADC1) */
#define SENSOR_PLANT2 GPIO_NUM_25 /**< GPIO 25 (ADC2) */
#define SENSOR_PLANT3 GPIO_NUM_26 /**< GPIO 26 (ADC2) */
#define SENSOR_PLANT4 GPIO_NUM_27 /**< GPIO 27 (ADC2) */
#define SENSOR_PLANT5 GPIO_NUM_39 /**< SENSOR_VIN */
#define SENSOR_PLANT6 GPIO_NUM_36 /**< SENSOR_VP */
#define OUTPUT_PUMP0 15 /**< GPIO 15 */
#define OUTPUT_PUMP1 5 /**< GPIO 5 */
#define OUTPUT_PUMP2 18 /**< GPIO 18 */
#define OUTPUT_PUMP3 19 /**< GPIO 19 */
#define OUTPUT_PUMP4 21 /**< GPIO 21 */
#define OUTPUT_PUMP5 22 /**< GPIO 22 */
#define OUTPUT_PUMP6 23 /**< GPIO 23 */
#define OUTPUT_PUMP0 GPIO_NUM_15 /**< GPIO 15 */
#define OUTPUT_PUMP1 GPIO_NUM_5 /**< GPIO 5 */
#define OUTPUT_PUMP2 GPIO_NUM_18 /**< GPIO 18 */
#define OUTPUT_PUMP3 GPIO_NUM_19 /**< GPIO 19 */
#define OUTPUT_PUMP4 GPIO_NUM_21 /**< GPIO 21 */
#define OUTPUT_PUMP5 GPIO_NUM_22 /**< GPIO 22 */
#define OUTPUT_PUMP6 GPIO_NUM_23 /**< GPIO 23 */
#define OUTPUT_ENABLE_SENSOR 14 /**< GPIO 14 - Enable Sensors */
#define OUTPUT_ENABLE_PUMP 13 /**< GPIO 13 - Enable Pumps */
#define OUTPUT_ENABLE_SENSOR GPIO_NUM_14 /**< GPIO 14 - Enable Sensors */
#define OUTPUT_ENABLE_PUMP GPIO_NUM_13 /**< GPIO 13 - Enable Pumps */
#define SENSOR_ONEWIRE 4 /**< GPIO 12 - Temperatur sensor, Battery and other cool onewire stuff */
#define SENSOR_TANK_ECHO 16 /**< GPIO 16 - echo feedback of water sensor */
#define SENSOR_TANK_TRG 17 /**< GPIO 17 - trigger for water sensor */
#define BUTTON 0 /**< GPIO 0 - Fix button of NodeMCU */
#define CUSTOM1_PIN3 2 /**< GPIO 2 - Custom GPIO controlling a MOSFET, connected to GND */
#define CUSTOM1_PIN2 12 /**< GPIO 4 - custom GPIO directly connected to GPIO header */
#define I2C1_PIN2 34 /**< GPIO 34 - I2C */
#define I2C1_PIN3 35 /**< GPIO 35 - I2C */
#define SENSOR_ONEWIRE GPIO_NUM_4 /**< GPIO 12 - Temperatur sensor, Battery and other cool onewire stuff */
#define SENSOR_TANK_ECHO GPIO_NUM_16 /**< GPIO 16 - echo feedback of water sensor */
#define SENSOR_TANK_TRG GPIO_NUM_17 /**< GPIO 17 - trigger for water sensor */
#define BUTTON GPIO_NUM_0 /**< GPIO 0 - Fix button of NodeMCU */
#define CUSTOM1_PIN3 GPIO_NUM_2 /**< GPIO 2 - Custom GPIO controlling a MOSFET, connected to GND */
#define CUSTOM1_PIN2 GPIO_NUM_12 /**< GPIO 4 - custom GPIO directly connected to GPIO header */
#define I2C1_PIN2 GPIO_NUM_34 /**< GPIO 34 - I2C */
#define I2C1_PIN3 GPIO_NUM_35 /**< GPIO 35 - I2C */
/* @} */
/** \addtogroup Configuration
* @{
*/
#define FIRMWARE_VERSION "1.1.0"
#define FIRMWARE_VERSION "sw 1.2 hw 0.9"
#define MOIST_SENSOR_MAX_ADC (85 * 4095 / 100)
#define MOIST_SENSOR_MIN_ADC (25 * 4095 / 100)

View File

@ -67,8 +67,7 @@ typedef uint8_t DeviceAddress[8];
class DS2438 {
public:
DS2438(OneWire *ow, float currentShunt);
DS2438(OneWire *ow, uint8_t *address);
DS2438(OneWire *ow, float currentShunt, int retryOnCRCError);
void begin();
void update();
@ -94,6 +93,7 @@ class DS2438 {
float _voltageB;
float _current;
float _currentShunt;
int _retryOnCRCError;
long _CCA;
long _DCA;
long _ICA;

View File

@ -17,9 +17,9 @@ board_build.partitions = defaultWithSmallerSpiffs.csv
; the latest development brankitchen-lightch (convention V3.0.x)
lib_deps = ArduinoJson@6.16.1
https://github.com/homieiot/homie-esp8266.git#v3.0
OneWire
DallasTemperature
https://github.com/homieiot/homie-esp8266.git#develop
[platformio]

View File

@ -24,9 +24,10 @@
#define DS2438MODEL 0x26
DS2438::DS2438(OneWire *ow, float currentShunt = 1.0f) {
DS2438::DS2438(OneWire *ow, float currentShunt, int retryOnCRCError) {
_ow = ow;
_currentShunt = currentShunt;
_retryOnCRCError = retryOnCRCError;
};
void DS2438::begin(){
@ -234,22 +235,26 @@ void DS2438::writePage(int page, uint8_t *data) {
}
boolean DS2438::readPage(int page, uint8_t *data) {
//TODO if all data is 0 0 is a valid crc, but most likly not as intended
_ow->reset();
_ow->select(_address);
_ow->write(DS2438_RECALL_MEMORY_COMMAND, 0);
if ((page >= PAGE_MIN) && (page <= PAGE_MAX)) {
bool valid = false;
for(int retry = 0;retry < this->_retryOnCRCError && !valid; retry ++){
//TODO if all data is 0 0 is a valid crc, but most likly not as intended
_ow->reset();
_ow->select(_address);
_ow->write(DS2438_RECALL_MEMORY_COMMAND, 0);
if ((page >= PAGE_MIN) && (page <= PAGE_MAX)) {
_ow->write(page, 0);
} else {
return false;
}
_ow->reset();
_ow->select(_address);
_ow->write(DS2438_READ_SCRATCHPAD_COMMAND, 0);
_ow->write(page, 0);
} else {
return false;
for (int i = 0; i < 9; i++){
data[i] = _ow->read();
}
valid = _ow->crc8(data, 8) == data[8];
}
_ow->reset();
_ow->select(_address);
_ow->write(DS2438_READ_SCRATCHPAD_COMMAND, 0);
_ow->write(page, 0);
for (int i = 0; i < 9; i++){
data[i] = _ow->read();
}
return _ow->crc8(data, 8) == data[8];
return valid;
}

View File

@ -44,8 +44,14 @@ void Plant::init(void)
});
/* Initialize Hardware */
Serial.println("Set GPIO mode " + String(mPinPump) + "=" + String(OUTPUT));
Serial.flush();
pinMode(this->mPinPump, OUTPUT);
Serial.println("Set GPIO mode " + String(mPinSensor) + "=" + String(ANALOG));
Serial.flush();
pinMode(this->mPinSensor, ANALOG);
Serial.println("Set GPIO " + String(mPinPump) + "=" + String(LOW));
Serial.flush();
digitalWrite(this->mPinPump, LOW);
}
@ -69,6 +75,8 @@ void Plant::postMQTTconnection(void)
void Plant::deactivatePump(void)
{
int plantId = this->mPlantId;
Serial << "deactivating pump " << plantId << endl;
digitalWrite(this->mPinPump, LOW);
if (this->mConnected)
{
@ -79,6 +87,8 @@ void Plant::deactivatePump(void)
void Plant::activatePump(void)
{
int plantId = this->mPlantId;
Serial << "activating pump " << plantId << endl;
digitalWrite(this->mPinPump, HIGH);
if (this->mConnected)
{

View File

@ -26,48 +26,62 @@
#include <math.h>
#include <OneWire.h>
#include "DS2438.h"
#include "soc/soc.h"
#include "soc/rtc_cntl_reg.h"
/******************************************************************************
* DEFINES
******************************************************************************/
#define AMOUNT_SENOR_QUERYS 8
#define MAX_TANK_DEPTH 1000
#define TEST_TOPIC "roundtrip\0"
#define BACKUP_TOPIC "$implementation/config/backup/set\0"
#define BACKUP_STATUS_TOPIC "$implementation/config/backup\0"
#define getTopic(test, topic) \
char *topic = new char[strlen(Homie.getConfiguration().mqtt.baseTopic) + strlen(Homie.getConfiguration().deviceId) + 1 + strlen(test) + 1]; \
strcpy(topic, Homie.getConfiguration().mqtt.baseTopic); \
strcat(topic, Homie.getConfiguration().deviceId); \
strcat(topic, "/"); \
strcat(topic, test);
/******************************************************************************
* FUNCTION PROTOTYPES
******************************************************************************/
int determineNextPump();
int readTemp();
void plantcontrol();
void plantcontrol(boolean withHomie);
void readPowerSwitchedSensors();
/******************************************************************************
* NON VOLATILE VARIABLES in DEEP SLEEP
******************************************************************************/
RTC_DATA_ATTR int lastPumpRunning = 0; /**< store last successfully waterd plant */
RTC_DATA_ATTR long lastWaterValue = 0; /**< to calculate the used water per plant */
RTC_SLOW_ATTR int lastPumpRunning = -1; /**< store last successfully waterd plant */
RTC_SLOW_ATTR long lastWaterValue = 0; /**< to calculate the used water per plant */
RTC_DATA_ATTR long rtcLastWateringPlant[MAX_PLANTS] = { 0 };
RTC_SLOW_ATTR long rtcLastWateringPlant[MAX_PLANTS] = {0};
/******************************************************************************
* LOCAL VARIABLES
******************************************************************************/
bool volatile mDownloadMode = false; /**< Controller must not sleep */
bool volatile mDeepsleep = false; /**< about to sleep, clearing the todolist of the controller */
bool volatile mSensorsRead = false; /**< Sensors are read without Wifi or MQTT */
bool volatile mSensorsRead = false; /**< Sensors are read without Wifi or MQTT */
bool volatile mAliveWasRead = false;
bool volatile mMQTTReady = false;
bool mConfigured = false;
long nextBlink = 0; /**< Time needed in main loop to support expected blink code */
RunningMedian waterRawSensor = RunningMedian(5);
float mSolarVoltage = 0.0f; /**< Voltage from solar panels */
float mSolarVoltage = 0.0f; /**< Voltage from solar panels */
unsigned long setupFinishedTimestamp;
/*************************** Hardware abstraction *****************************/
OneWire oneWire(SENSOR_ONEWIRE);
DallasTemperature sensors(&oneWire);
DS2438 battery(&oneWire, 0.1f);
DS2438 battery(&oneWire, 0.0333333f, AMOUNT_SENOR_QUERYS);
Plant mPlants[MAX_PLANTS] = {
Plant(SENSOR_PLANT0, OUTPUT_PUMP0, 0, &plant0, &mSetting0),
@ -97,40 +111,42 @@ int getCurrentHour()
return info.tm_hour;
}
void espDeepSleepFor(long seconds, bool activatePump = false)
void espDeepSleepFor(long seconds, bool activatePump, bool withHomieShutdown)
{
if (mDownloadMode)
{
Serial << "abort deepsleep, DownloadMode active" << endl;
return;
}
for (int i = 0; i < 10; i++)
if (withHomieShutdown)
{
long cTime = getCurrentTime();
if (cTime < 100000)
for (int i = 0; i < 10; i++)
{
Serial << "Wait for ntp" << endl;
delay(100);
}
else
{
break;
long cTime = getCurrentTime();
if (cTime < 100000)
{
Serial << "Wait for ntp" << endl;
delay(100);
}
else
{
break;
}
}
}
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_PERIPH, ESP_PD_OPTION_OFF);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_SLOW_MEM, ESP_PD_OPTION_ON);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_ON);
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
if (activatePump)
{
esp_sleep_pd_config(ESP_PD_DOMAIN_XTAL, ESP_PD_OPTION_ON);
gpio_deep_sleep_hold_en();
gpio_hold_en(GPIO_NUM_13); //pump pwr
gpio_hold_en(OUTPUT_ENABLE_PUMP); //pump pwr
}
else
{
esp_sleep_pd_config(ESP_PD_DOMAIN_RTC_FAST_MEM, ESP_PD_OPTION_OFF);
gpio_hold_dis(GPIO_NUM_13); //pump pwr
gpio_hold_dis(OUTPUT_ENABLE_PUMP); //pump pwr
gpio_deep_sleep_hold_dis();
digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
digitalWrite(OUTPUT_ENABLE_SENSOR, LOW);
@ -139,64 +155,68 @@ void espDeepSleepFor(long seconds, bool activatePump = false)
mPlants[i].deactivatePump();
}
}
//gpio_hold_en(GPIO_NUM_23); //p0
gpio_hold_en(OUTPUT_PUMP0);
gpio_hold_en(OUTPUT_PUMP1);
gpio_hold_en(OUTPUT_PUMP2);
gpio_hold_en(OUTPUT_PUMP3);
gpio_hold_en(OUTPUT_PUMP4);
gpio_hold_en(OUTPUT_PUMP5);
gpio_hold_en(OUTPUT_PUMP6);
//FIXME fix for outher outputs
Serial.print("Trying to sleep for ");
Serial.print(seconds);
Serial.println(" seconds");
esp_sleep_enable_timer_wakeup((seconds * 1000U * 1000U));
mDeepsleep = true;
}
/**
* @brief Read ultra sensor JSN-SR04T-2.0
* Read the distance of the water level.
*/
void readDistance()
{
for (int i = 0; i < AMOUNT_SENOR_QUERYS; i++)
Serial.flush();
if (withHomieShutdown)
{
unsigned long duration = 0;
digitalWrite(SENSOR_TANK_TRG, HIGH);
delayMicroseconds(20);
cli();
digitalWrite(SENSOR_TANK_TRG, LOW);
duration = pulseIn(SENSOR_TANK_ECHO, HIGH);
sei();
int mmDis = duration * 0.3432 / 2;
if (mmDis > MAX_TANK_DEPTH)
{
waterRawSensor.add(0);
}
else
{
waterRawSensor.add(mmDis);
}
Homie.prepareToSleep();
}
else
{
Serial << "Bye offline mode" << endl;
Serial.flush();
esp_deep_sleep_start();
}
}
/**
* @brief Sensors, that are connected to GPIOs, mandatory for WIFI.
* These sensors (ADC2) can only be read when no Wifi is used.
*/
void readSensors()
//requires homie being started
void readOneWireSensors(bool withMQTT)
{
int sensorCount = sensors.getDS18Count();
Serial << "Read Sensors" << endl;
/* activate all sensors */
digitalWrite(OUTPUT_ENABLE_SENSOR, HIGH);
for (uint8_t i = 0; i < sensorCount; i++)
Serial << "Read OneWire" << endl;
Serial.flush();
for (uint8_t i = 0; i < sensors.getDeviceCount(); i++)
{
DeviceAddress ds18b20Address;
sensors.getAddress(ds18b20Address, i);
float temp = sensors.getTempC(ds18b20Address);
Serial << "OneWire sensor " << i << " has value " << temp << endl;
char buf[sizeof(DeviceAddress) * 2];
uint8_t ds18b20Address[8];
bool valid = false;
float temp = -127;
for (int retry = 0; retry < AMOUNT_SENOR_QUERYS && !valid; retry++)
{
bool validAddress = sensors.getAddress(ds18b20Address, i);
if (validAddress && sensors.validFamily(ds18b20Address))
{
temp = sensors.getTempC(ds18b20Address);
if (temp != -127)
{
valid = true;
}
else
{
delay(10);
}
}
}
if(!valid){
//wrong family or crc errors on each retry
continue;
}
char buf[sizeof(ds18b20Address) * 2];
snprintf(buf, sizeof(buf), "%.2X%.2X%.2X%.2X%.2X%.2X%.2X%.2X",
ds18b20Address[0],
ds18b20Address[1],
@ -207,22 +227,51 @@ void readSensors()
ds18b20Address[6],
ds18b20Address[7]);
if (String(lipoSensorAddr.get()).compareTo(String(buf))) {
sensorTemp.setProperty(TEMPERATUR_SENSOR_LIPO).send(String(temp));
if (valid)
{
Serial << "DS18S20 Temperatur " << String(buf) << " : " << temp << " °C " << endl;
if (strcmp(lipoSensorAddr.get(),buf) == 0)
{
if (withMQTT)
{
sensorTemp.setProperty(TEMPERATUR_SENSOR_LIPO).send(String(temp));
}
Serial << "Lipo Temperatur " << temp << " °C " << endl;
} else if (String(waterSensorAddr.get()).compareTo(String(buf))) {
sensorTemp.setProperty(TEMPERATUR_SENSOR_WATER).send(String(temp));
}
if (strcmp(waterSensorAddr.get(),buf) == 0)
{
if (withMQTT)
{
sensorTemp.setProperty(TEMPERATUR_SENSOR_WATER).send(String(temp));
}
Serial << "Water Temperatur " << temp << " °C " << endl;
}
/* Always send the sensor address with the temperatur value */
sensorTemp.setProperty(String(buf)).send(String(temp));
Serial << "Temperatur " << String(buf) << " : " << temp << " °C " << endl;
if (withMQTT)
{
sensorTemp.setProperty(String(buf)).send(String(temp));
}
}
else
{
Serial << "DS18S20 sensor " << String(buf) << " could not be read " << temp << endl;
}
}
// Update battery chip data
battery.update();
mSolarVoltage = battery.getVoltage(BATTSENSOR_INDEX_SOLAR) * SOLAR_VOLT_FACTOR;
Serial.flush();
}
/**
* @brief Sensors, that are connected to GPIOs, mandatory for WIFI.
* These sensors (ADC2) can only be read when no Wifi is used.
*/
void readPowerSwitchedSensors()
{
digitalWrite(OUTPUT_ENABLE_SENSOR, HIGH);
delay(10);
for (int readCnt = 0; readCnt < AMOUNT_SENOR_QUERYS; readCnt++)
{
for (int i = 0; i < MAX_PLANTS; i++)
@ -233,21 +282,119 @@ void readSensors()
}
/* Read the distance and give the temperature sensors some time */
readDistance();
{
for (int i = 0; i < AMOUNT_SENOR_QUERYS; i++)
{
unsigned long duration = 0;
digitalWrite(SENSOR_TANK_TRG, HIGH);
delayMicroseconds(20);
cli();
digitalWrite(SENSOR_TANK_TRG, LOW);
//10ms is > 2m tank depth
duration = pulseIn(SENSOR_TANK_ECHO, HIGH, 10);
sei();
int mmDis = duration * 0.3432 / 2;
if (mmDis > MAX_TANK_DEPTH)
{
waterRawSensor.add(0);
}
else
{
waterRawSensor.add(mmDis);
}
}
}
Serial << "Distance sensor " << waterRawSensor.getAverage() << " cm" << endl;
/* deactivate the sensors */
digitalWrite(OUTPUT_ENABLE_SENSOR, LOW);
}
bool copyFile(const char *source, const char *target)
{
Serial << "copy started " << source << " -> " << target << endl;
byte buffer[512];
if (!SPIFFS.begin())
{
return false;
}
File file = SPIFFS.open(source, FILE_READ);
File file2 = SPIFFS.open(target, FILE_WRITE);
Serial.flush();
if (!file)
{
Serial << "There was an error opening " << source << " for reading" << endl;
SPIFFS.end();
return false;
}
if (!file2)
{
Serial << "There was an error opening " << target << " for reading" << endl;
file.close();
SPIFFS.end();
return false;
}
while (file.available())
{
int read = file.read(buffer, 512);
if (read < 0)
{
Serial << "copy file is fucked" << endl;
file.close();
file2.close();
SPIFFS.end();
return false;
}
else
{
file.write(buffer, read);
}
}
file2.flush();
Serial << "copy finished " << source << " -> " << target << endl;
file.close();
file2.close();
SPIFFS.end();
return true;
}
void onMessage(char *incoming, char *payload, AsyncMqttClientMessageProperties properties, size_t len, size_t index, size_t total)
{
getTopic(TEST_TOPIC, testTopic);
if (strcmp(incoming, testTopic) == 0)
{
mAliveWasRead = true;
}
delete testTopic;
getTopic(BACKUP_TOPIC, backupTopic);
if (strcmp(incoming, backupTopic) == 0)
{
bool backupSucessful = copyFile("/homie/config.json", "/homie/config.old");
getTopic(BACKUP_STATUS_TOPIC, backupStatusTopic);
Homie.getMqttClient().publish(backupStatusTopic, 2, true, backupSucessful ? "true" : "false");
delete backupStatusTopic;
}
delete backupTopic;
}
void onHomieEvent(const HomieEvent &event)
{
switch (event.type)
{
case HomieEventType::READY_TO_SLEEP:
Serial << "Bye homie mode" << endl;
Serial.flush();
esp_deep_sleep_start();
break;
case HomieEventType::SENDING_STATISTICS:
break;
case HomieEventType::MQTT_READY:
if (mSensorsRead) {
if (mSensorsRead)
{
Serial.printf("Timeout occured... too late!\r\n");
return;
}
@ -256,28 +403,39 @@ void onHomieEvent(const HomieEvent &event)
Serial.printf("NTP Setup with server %s\r\n", ntpServer.get());
configTime(0, 0, ntpServer.get());
Serial << "Setup plants" << endl;
Serial << "publish plants mqtt" << endl;
for (int i = 0; i < MAX_PLANTS; i++)
{
mPlants[i].postMQTTconnection();
}
{
getTopic(TEST_TOPIC, testopic)
Homie.getMqttClient()
.subscribe(testopic, 2);
Homie.getMqttClient().publish(testopic, 2, false, "ping");
Homie.getMqttClient().onMessage(onMessage);
getTopic(BACKUP_TOPIC, backupTopic)
Homie.getMqttClient()
.subscribe(backupTopic, 2);
}
mMQTTReady = true;
plantcontrol();
break;
case HomieEventType::OTA_STARTED:
Homie.getLogger() << "OTA started" << endl;
digitalWrite(OUTPUT_ENABLE_SENSOR, HIGH);
digitalWrite(OUTPUT_ENABLE_PUMP, HIGH);
gpio_hold_dis(GPIO_NUM_13); //pump pwr
gpio_deep_sleep_hold_dis();
for (int i = 0; i < MAX_PLANTS; i++)
{
mPlants[i].deactivatePump();
}
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
digitalWrite(OUTPUT_ENABLE_PUMP, HIGH);
delay(100);
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1);
mDownloadMode = true;
break;
case HomieEventType::OTA_SUCCESSFUL:
Homie.getLogger() << "OTA successfull" << endl;
Homie.getLogger() << "OTA successful" << endl;
digitalWrite(OUTPUT_ENABLE_SENSOR, LOW);
digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
ESP.restart();
@ -299,8 +457,8 @@ int determineNextPump()
Serial.printf("%d Skip deactivated pump\r\n", i);
continue;
}
if ((rtcLastWateringPlant[i] > 0)
&& ((rtcLastWateringPlant[i] + plant.getCooldownInSeconds()) < getCurrentTime())) {
if ((rtcLastWateringPlant[i] > 0) && ((rtcLastWateringPlant[i] + plant.getCooldownInSeconds()) < getCurrentTime()))
{
Serial.printf("%d Skipping due to cooldown %ld / %ld \r\n", i, rtcLastWateringPlant[i], plant.getCooldownInSeconds());
continue;
}
@ -316,12 +474,20 @@ int determineNextPump()
}
if (plant.isPumpRequired())
{
if ((plant.getHoursStart() > getCurrentHour() && plant.getHoursEnd() < getCurrentHour()) ||
(getCurrentTime() < 10000) /* no time from NTP received */)
/* Handle e.g. start = 21, end = 8 */
if (((plant.getHoursStart() > plant.getHoursEnd()) &&
(getCurrentHour() >= plant.getHoursStart() || getCurrentHour() <= plant.getHoursEnd())) ||
/* Handle e.g. start = 8, end = 21 */
((plant.getHoursStart() < plant.getHoursEnd()) &&
(getCurrentHour() >= plant.getHoursStart() && getCurrentHour() <= plant.getHoursEnd())) ||
/* no time from NTP received */
(getCurrentTime() < 10000))
{
Serial.printf("%d Requested pumping\r\n", i);
pumpToUse = i;
} else {
}
else
{
Serial.printf("%d ignored due to time boundary: %d to %d (current %d)\r\n", i, plant.getHoursStart(), plant.getHoursEnd(), getCurrentHour());
}
continue;
@ -346,21 +512,33 @@ bool aliveHandler(const HomieRange &range, const String &value)
{
if (range.isRange)
return false; // only one controller is present
Serial.println("aliuve handler");
Serial.flush();
if (value.equals("ON") || value.equals("On") || value.equals("1"))
{
mDownloadMode = true;
}
else
{
if (mDownloadMode)
{
esp_restart();
}
mDownloadMode = false;
}
return true;
}
bool notStarted = true;
void homieLoop()
{
if (mMQTTReady && mAliveWasRead && notStarted)
{
Serial.println("received alive & mqtt is ready");
notStarted = false;
plantcontrol(true);
}
}
/**
@ -373,33 +551,41 @@ void setup()
setCpuFrequencyMhz(80);
Serial.begin(115200);
Serial << endl
<< endl;
Serial << "Wifi mode set to " << WIFI_OFF << " to allow analog2 useage " << endl;
WiFi.mode(WIFI_OFF);
Serial.flush();
/* Intialize Plant */
for (int i = 0; i < MAX_PLANTS; i++)
{
mPlants[i].init();
}
Serial.println("plants init");
Serial.flush();
// read button
pinMode(BUTTON, INPUT);
// Power pins
pinMode(OUTPUT_ENABLE_PUMP, OUTPUT);
digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
pinMode(OUTPUT_ENABLE_SENSOR, OUTPUT);
if (HomieInternals::MAX_CONFIG_SETTING_SIZE < MAX_CONFIG_SETTING_ITEMS)
{
//increase the config settings to 50 and the json to 3000
Serial << "Limits.hpp" << endl;
Serial << "Limits.hpp is not adjusted, please search for this string and increase" << endl;
return;
}
/************************* Start One-Wire bus ***************/
int timeoutTemp = millis() + TEMPERATUR_TIMEOUT;
int tempInitStartTime = millis();
uint8_t sensorCount = 0U;
/* Required to read the temperature at least once */
while ((sensorCount == 0 || !battery.isFound()) && millis() < timeoutTemp)
while ((sensorCount == 0 || !battery.isFound()) && millis() < tempInitStartTime + TEMPERATUR_TIMEOUT)
{
sensors.begin();
battery.begin();
@ -407,25 +593,27 @@ void setup()
delay(50);
}
Serial << "One wire count: " << sensorCount << " found in " << (millis() - timeoutTemp) << "ms" << endl;
Serial << "DS18S20 count: " << sensorCount << " found in " << (millis() - tempInitStartTime) << " ms" << endl;
Serial.flush();
/* Measure temperature TODO idea: move this into setup */
if (sensorCount > 0)
{
sensors.setResolution(DS18B20_RESOLUTION);
//sensors.setResolution(DS18B20_RESOLUTION);
sensors.requestTemperatures();
}
Serial << "Reading sensors start" << endl;
Serial.flush();
readPowerSwitchedSensors();
Serial << "Reading sensors end" << endl;
Serial.flush();
/************************* Start Homie Framework ***************/
WiFi.mode(WIFI_STA);
Homie_setFirmware("PlantControl", FIRMWARE_VERSION);
// Set default values
//in seconds
deepSleepTime.setDefaultValue(600).setValidator([](long candidate) {
return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */);
});
deepSleepTime.setDefaultValue(600).setValidator([](long candidate)
{ return (candidate > 0) && (candidate < (60 * 60 * 2) /** 2h max sleep */); });
deepSleepNightTime.setDefaultValue(600);
wateringDeepSleep.setDefaultValue(5);
ntpServer.setDefaultValue("pool.ntp.org");
@ -439,11 +627,15 @@ void setup()
Homie.setLoopFunction(homieLoop);
Homie.onEvent(onHomieEvent);
//Homie.disableLogging();
Homie.setup();
mConfigured = Homie.isConfigured();
if (mConfigured)
{
Serial << "Wifi mode set to " << WIFI_STA << endl;
WiFi.mode(WIFI_STA);
for (int i = 0; i < MAX_PLANTS; i++)
{
mPlants[i].advertise();
@ -479,11 +671,19 @@ void setup()
.setDatatype(NUMBER_TYPE)
.setUnit("V");
sensorWater.advertise("remaining").setDatatype(NUMBER_TYPE).setUnit("%");
} else {
}
else
{
readOneWireSensors(false);
digitalWrite(OUTPUT_ENABLE_PUMP, HIGH);
delay(100);
Serial << "Wifi mode set to " << WIFI_AP_STA << endl;
WiFi.mode(WIFI_AP_STA);
Serial.println("Initial Setup. Start Accesspoint...");
mDownloadMode = true;
}
stayAlive.advertise("alive").setName("Alive").setDatatype(NUMBER_TYPE).settable(aliveHandler);
setupFinishedTimestamp = millis();
}
/**
@ -492,35 +692,56 @@ void setup()
*/
void loop()
{
Homie.loop();
/* Toggel Senor LED to visualize mode 3 */
if (mDownloadMode)
{
if (nextBlink < millis())
{
nextBlink = millis() + 500;
digitalWrite(OUTPUT_ENABLE_SENSOR, !digitalRead(OUTPUT_ENABLE_SENSOR));
}
}
else if (!mDeepsleep)
{
Homie.loop();
if ((millis() > MQTT_TIMEOUT) && (!mSensorsRead)) {
mSensorsRead = true;
/* Disable Wifi and put modem into sleep mode */
WiFi.mode(WIFI_OFF);
Serial << (millis() / 1000) << "s passed, read sensors manually" << endl;
plantcontrol();
if (mConfigured)
{
nextBlink = millis() + 500;
}
else
{
if (lastPumpRunning >= 0 && lastPumpRunning < MAX_PLANTS)
{
mPlants[lastPumpRunning].deactivatePump();
}
if (lastPumpRunning >= MAX_PLANTS)
{
digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
nextBlink = millis() + 500;
}
else
{
lastPumpRunning++;
nextBlink = millis() + 5000;
}
if (lastPumpRunning < MAX_PLANTS)
{
mPlants[lastPumpRunning].activatePump();
}
}
}
}
else
{
Serial << "Bye" << endl;
Serial.flush();
esp_deep_sleep_start();
unsigned long timeSinceSetup = millis() - setupFinishedTimestamp;
if ((timeSinceSetup > MQTT_TIMEOUT) && (!mSensorsRead))
{
mSensorsRead = true;
/* Disable Wifi and put modem into sleep mode */
WiFi.mode(WIFI_OFF);
Serial << "Wifi mode set to " << WIFI_OFF << " mqqt was no reached within " << timeSinceSetup << "ms , fallback to offline mode " << endl;
Serial.flush();
plantcontrol(false);
}
}
/** Timeout always stopping the ESP -> no endless power consumption */
if (millis() > 30000 && !mDownloadMode)
if (millis() > 60000 && !mDownloadMode)
{
Serial << (millis() / 1000) << "not terminated watchdog reset" << endl;
Serial.flush();
@ -528,21 +749,12 @@ void loop()
}
}
/***
* @fn plantcontrol
* Main function, doing the logic
*/
void plantcontrol()
void plantcontrol(bool withHomie)
{
digitalWrite(OUTPUT_ENABLE_PUMP, LOW);
for (int i = 0; i < MAX_PLANTS; i++)
{
mPlants[i].deactivatePump();
}
readSensors();
if (lastPumpRunning != -1)
{
long waterDiff = waterRawSensor.getAverage() - lastWaterValue;
@ -551,6 +763,8 @@ void plantcontrol()
Serial << "Plant" << lastPumpRunning << ": Water diff " << waterDiff << " mm" << endl;
}
readOneWireSensors(true);
for (int i = 0; i < MAX_PLANTS; i++)
{
long raw = mPlants[i].getCurrentMoisture();
@ -571,26 +785,33 @@ void plantcontrol()
mPlants[i].setProperty("moist").send(String(pct));
mPlants[i].setProperty("moistraw").send(String(raw));
}
sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - waterRawSensor.getAverage()));
Serial << "W : " << waterRawSensor.getAverage() << " cm (" << String(waterLevelMax.get() - waterRawSensor.getAverage()) << "%)" << endl;
lastWaterValue = waterRawSensor.getAverage();
float batteryVoltage = battery.getVoltage(BATTSENSOR_INDEX_BATTERY);
float chipTemp = battery.getTemperature();
sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT));
sensorLipo.setProperty("volt").send(String(batteryVoltage));
sensorLipo.setProperty("current").send(String(battery.getCurrent()));
sensorLipo.setProperty("Ah").send(String(battery.getAh()));
sensorLipo.setProperty("ICA").send(String(battery.getICA()));
sensorLipo.setProperty("DCA").send(String(battery.getDCA()));
sensorLipo.setProperty("CCA").send(String(battery.getCCA()));
sensorSolar.setProperty("volt").send(String(mSolarVoltage));
sensorTemp.setProperty(TEMPERATUR_SENSOR_CHIP).send(String(chipTemp));
Serial << "Chip Temperatur " << chipTemp << " °C " << endl;
if (withHomie)
{
sensorWater.setProperty("remaining").send(String(waterLevelMax.get() - waterRawSensor.getAverage()));
sensorLipo.setProperty("percent").send(String(100 * batteryVoltage / VOLT_MAX_BATT));
sensorLipo.setProperty("volt").send(String(batteryVoltage));
sensorLipo.setProperty("current").send(String(battery.getCurrent()));
sensorLipo.setProperty("Ah").send(String(battery.getAh()));
sensorLipo.setProperty("ICA").send(String(battery.getICA()));
sensorLipo.setProperty("DCA").send(String(battery.getDCA()));
sensorLipo.setProperty("CCA").send(String(battery.getCCA()));
sensorSolar.setProperty("volt").send(String(mSolarVoltage));
sensorTemp.setProperty(TEMPERATUR_SENSOR_CHIP).send(String(chipTemp));
}
else
{
Serial.println("Skipping MQTT, offline mode");
Serial.flush();
}
bool hasWater = true; //FIXMEmWaterGone > waterLevelMin.get();
//FIXME no water warning message
lastPumpRunning = determineNextPump();
@ -606,7 +827,12 @@ void plantcontrol()
}
else
{
//prevent BOD to be paranoid
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0);
digitalWrite(OUTPUT_ENABLE_PUMP, HIGH);
delay(100);
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 1);
rtcLastWateringPlant[lastPumpRunning] = getCurrentTime();
mPlants[lastPumpRunning].activatePump();
}
@ -619,18 +845,18 @@ void plantcontrol()
{
Serial.print(mSolarVoltage);
Serial.println("V! No pumps to activate and low light, deepSleepNight");
espDeepSleepFor(deepSleepNightTime.get());
espDeepSleepFor(deepSleepNightTime.get(), false, withHomie);
}
else
{
Serial.println("No pumps to activate, deepSleep");
espDeepSleepFor(deepSleepTime.get());
espDeepSleepFor(deepSleepTime.get(), false, withHomie);
}
}
else
{
Serial.println("Running pump, watering deepsleep");
espDeepSleepFor(wateringDeepSleep.get(), true);
espDeepSleepFor(wateringDeepSleep.get(), true, withHomie);
}
}

View File

@ -15,5 +15,3 @@ framework = arduino
build_flags = -DPIO_FRAMEWORK_ARDUINO_LWIP2_LOW_MEMORY
lib_deps = OneWire
DallasTemperature
upload_port = /dev/ttyUSB1