Compare commits
3 Commits
v2.x
..
86c6bb5a73
| Author | SHA1 | Date | |
|---|---|---|---|
| 86c6bb5a73 | |||
| 82bc9ed66d | |||
| a44aa86732 |
+11316
-10461
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"board": {
|
"board": {
|
||||||
"active_layer": 39,
|
"active_layer": 31,
|
||||||
"active_layer_preset": "",
|
"active_layer_preset": "",
|
||||||
"auto_track_width": false,
|
"auto_track_width": false,
|
||||||
"hidden_netclasses": [],
|
"hidden_netclasses": [],
|
||||||
|
|||||||
@@ -37,9 +37,9 @@
|
|||||||
"other_text_thickness": 0.15,
|
"other_text_thickness": 0.15,
|
||||||
"other_text_upright": false,
|
"other_text_upright": false,
|
||||||
"pads": {
|
"pads": {
|
||||||
"drill": 0.0,
|
"drill": 0.25,
|
||||||
"height": 3.0,
|
"height": 0.35,
|
||||||
"width": 1.6
|
"width": 0.35
|
||||||
},
|
},
|
||||||
"silk_line_width": 0.12,
|
"silk_line_width": 0.12,
|
||||||
"silk_text_italic": false,
|
"silk_text_italic": false,
|
||||||
@@ -58,13 +58,15 @@
|
|||||||
"width": 0.0
|
"width": 0.0
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"drc_exclusions": [],
|
"drc_exclusions": [
|
||||||
|
"courtyards_overlap|199080001|128865001|67ac55df-4a92-42f8-90ae-0f317d1fcee5|cfde0667-9234-45fc-8eda-14a18003cf8d"
|
||||||
|
],
|
||||||
"meta": {
|
"meta": {
|
||||||
"filename": "board_design_settings.json",
|
"filename": "board_design_settings.json",
|
||||||
"version": 2
|
"version": 2
|
||||||
},
|
},
|
||||||
"rule_severities": {
|
"rule_severities": {
|
||||||
"annular_width": "error",
|
"annular_width": "ignore",
|
||||||
"clearance": "error",
|
"clearance": "error",
|
||||||
"connection_width": "warning",
|
"connection_width": "warning",
|
||||||
"copper_edge_clearance": "error",
|
"copper_edge_clearance": "error",
|
||||||
|
|||||||
+2233
-1741
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,354 @@
|
|||||||
|
|
||||||
|
(kicad_symbol_lib (version 20211014) (generator kicad_symbol_editor)
|
||||||
|
(symbol "ESP32-C6-WROOM-1-N8" (pin_names (offset 1.016)) (in_bom yes) (on_board yes)
|
||||||
|
(property "Reference" "U" (id 0) (at -15.24 23.622 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom left))
|
||||||
|
)
|
||||||
|
(property "Value" "ESP32-C6-WROOM-1-N8" (id 1) (at -15.24 -25.4 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom left))
|
||||||
|
)
|
||||||
|
(property "Footprint" "ESP32-C6-WROOM-1-N8:XCVR_ESP32-C6-WROOM-1-N8" (id 2) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "MF" "Espressif Systems" (id 4) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "MAXIMUM_PACKAGE_HEIGHT" "3.25mm" (id 5) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "Package" "None" (id 6) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "Price" "None" (id 7) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "Check_prices" "https://www.snapeda.com/parts/ESP32-C6-WROOM-1-N8/Espressif+Systems/view-part/?ref=eda" (id 8) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "STANDARD" "Manufacturer Recommendations" (id 9) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "PARTREV" "1.0" (id 10) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "SnapEDA_Link" "https://www.snapeda.com/parts/ESP32-C6-WROOM-1-N8/Espressif+Systems/view-part/?ref=snap" (id 11) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "MP" "ESP32-C6-WROOM-1-N8" (id 12) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "Purchase-URL" "https://www.snapeda.com/api/url_track_click_mouser/?unipart_id=12616380&manufacturer=Espressif Systems&part_name=ESP32-C6-WROOM-1-N8&search_term=None" (id 13) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "Description" "\nMultiprotocol Modules ESP32-C6 module, Wi-Fi 6 in 2.4 GHz band, Bluetooth 5, Zigbee 3.0 and Thread. ESP34-WROOM Compatible - ENGINEERING SAMPLE\n" (id 14) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "Availability" "In Stock" (id 15) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(property "MANUFACTURER" "Espressif Systems" (id 16) (at 0 0 0)
|
||||||
|
(effects (font (size 1.27 1.27)) (justify bottom) hide)
|
||||||
|
)
|
||||||
|
(symbol "ESP32-C6-WROOM-1-N8_0_0"
|
||||||
|
(rectangle (start -15.24 -22.86) (end 15.24 22.86)
|
||||||
|
(stroke (width 0.254)) (fill (type background))
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "1"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "28"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_1"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_2"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_3"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_4"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_5"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_6"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_7"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_8"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 -20.32 180.0) (length 5.08)
|
||||||
|
(name "GND"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "29_9"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin power_in line (at 20.32 20.32 180.0) (length 5.08)
|
||||||
|
(name "3V3"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "2"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin input line (at -20.32 15.24 0) (length 5.08)
|
||||||
|
(name "EN"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "3"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 0.0 0) (length 5.08)
|
||||||
|
(name "IO4"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "4"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 -2.54 0) (length 5.08)
|
||||||
|
(name "IO5"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "5"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 -5.08 0) (length 5.08)
|
||||||
|
(name "IO6"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "6"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 -7.62 0) (length 5.08)
|
||||||
|
(name "IO7"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "7"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 10.16 0) (length 5.08)
|
||||||
|
(name "IO0"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "8"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 7.62 0) (length 5.08)
|
||||||
|
(name "IO1"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "9"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 -10.16 0) (length 5.08)
|
||||||
|
(name "IO8"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "10"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 15.24 180.0) (length 5.08)
|
||||||
|
(name "IO10"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "11"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 12.7 180.0) (length 5.08)
|
||||||
|
(name "IO11"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "12"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 10.16 180.0) (length 5.08)
|
||||||
|
(name "IO12"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "13"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 7.62 180.0) (length 5.08)
|
||||||
|
(name "IO13"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "14"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 5.08 0) (length 5.08)
|
||||||
|
(name "IO2"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "27"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 2.54 0) (length 5.08)
|
||||||
|
(name "IO3"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "26"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 2.54 180.0) (length 5.08)
|
||||||
|
(name "TXD0/GPIO16"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "25"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 0.0 180.0) (length 5.08)
|
||||||
|
(name "RXD0/GPIO17"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "24"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 5.08 180.0) (length 5.08)
|
||||||
|
(name "IO15"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "23"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin no_connect line (at -20.32 -17.78 0) (length 5.08)
|
||||||
|
(name "NC"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "22"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 -15.24 180.0) (length 5.08)
|
||||||
|
(name "IO23"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "21"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 -12.7 180.0) (length 5.08)
|
||||||
|
(name "IO22"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "20"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 -10.16 180.0) (length 5.08)
|
||||||
|
(name "IO21"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "19"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 -7.62 180.0) (length 5.08)
|
||||||
|
(name "IO20"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "18"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 -5.08 180.0) (length 5.08)
|
||||||
|
(name "IO19"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "17"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at 20.32 -2.54 180.0) (length 5.08)
|
||||||
|
(name "IO18"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "16"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(pin bidirectional line (at -20.32 -12.7 0) (length 5.08)
|
||||||
|
(name "IO9"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
(number "15"
|
||||||
|
(effects (font (size 1.016 1.016)))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
@@ -0,0 +1,104 @@
|
|||||||
|
|
||||||
|
(footprint XCVR_ESP32-C6-WROOM-1-N8 (layer F.Cu) (tedit 66216AE3)
|
||||||
|
(descr "")
|
||||||
|
(attr smd)
|
||||||
|
(fp_text reference REF** (at -5.825 -13.885 0) (layer F.SilkS)
|
||||||
|
(effects (font (size 1.0 1.0) (thickness 0.15)))
|
||||||
|
)
|
||||||
|
(fp_text value XCVR_ESP32-C6-WROOM-1-N8 (at 6.24 13.865 0) (layer F.Fab)
|
||||||
|
(effects (font (size 1.0 1.0) (thickness 0.15)))
|
||||||
|
)
|
||||||
|
(pad 1 smd rect (at -8.75 -5.26) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 2 smd rect (at -8.75 -3.99) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 3 smd rect (at -8.75 -2.72) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 4 smd rect (at -8.75 -1.45) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 5 smd rect (at -8.75 -0.18) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 6 smd rect (at -8.75 1.09) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 7 smd rect (at -8.75 2.36) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 8 smd rect (at -8.75 3.63) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 9 smd rect (at -8.75 4.9) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 10 smd rect (at -8.75 6.17) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 11 smd rect (at -8.75 7.44) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 12 smd rect (at -8.75 8.71) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 13 smd rect (at -8.75 9.98) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 14 smd rect (at -8.75 11.25) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 15 smd rect (at 8.75 11.25) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 16 smd rect (at 8.75 9.98) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 17 smd rect (at 8.75 8.71) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 18 smd rect (at 8.75 7.44) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 19 smd rect (at 8.75 6.17) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 20 smd rect (at 8.75 4.9) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 21 smd rect (at 8.75 3.63) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 22 smd rect (at 8.75 2.36) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 23 smd rect (at 8.75 1.09) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 24 smd rect (at 8.75 -0.18) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 25 smd rect (at 8.75 -1.45) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 26 smd rect (at 8.75 -2.72) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 27 smd rect (at 8.75 -3.99) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 28 smd rect (at 8.75 -5.26) (size 1.5 0.9) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_5 smd rect (at -1.505 0.46) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_1 smd rect (at -2.755 -0.79) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_2 smd rect (at -1.505 -0.79) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_3 smd rect (at -0.255 -0.79) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_4 smd rect (at -2.755 0.46) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_6 smd rect (at -0.255 0.46) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_7 smd rect (at -2.755 1.71) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_8 smd rect (at -1.505 1.71) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 29_9 smd rect (at -0.255 1.71) (size 0.8 0.8) (layers F.Cu F.Mask F.Paste) (solder_mask_margin 0.102))
|
||||||
|
(pad 30_1 thru_hole circle (at -2.13 -0.79) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_2 thru_hole circle (at -0.88 -0.79) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_3 thru_hole circle (at -2.755 -0.165) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_4 thru_hole circle (at -1.505 -0.165) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_5 thru_hole circle (at -0.255 -0.165) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_6 thru_hole circle (at -2.13 0.46) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_7 thru_hole circle (at -0.88 0.46) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_8 thru_hole circle (at -2.755 1.085) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_9 thru_hole circle (at -1.505 1.085) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_10 thru_hole circle (at -0.255 1.085) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_11 thru_hole circle (at -2.13 1.71) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(pad 30_12 thru_hole circle (at -0.88 1.71) (size 0.35 0.35) (drill 0.25) (layers *.Cu))
|
||||||
|
(fp_line (start -9.0 12.75) (end 9.0 12.75) (layer F.Fab) (width 0.127))
|
||||||
|
(fp_line (start -9.0 -12.75) (end 9.0 -12.75) (layer F.Fab) (width 0.127))
|
||||||
|
(fp_line (start 9.0 -12.75) (end 9.0 12.75) (layer F.Fab) (width 0.127))
|
||||||
|
(fp_line (start -9.0 12.75) (end 9.0 12.75) (layer F.SilkS) (width 0.127))
|
||||||
|
(fp_line (start -9.0 12.75) (end -9.0 12.02) (layer F.SilkS) (width 0.127))
|
||||||
|
(fp_line (start 9.0 12.02) (end 9.0 12.75) (layer F.SilkS) (width 0.127))
|
||||||
|
(fp_line (start -9.0 -6.03) (end -9.0 -12.75) (layer F.SilkS) (width 0.127))
|
||||||
|
(fp_line (start -9.0 -12.75) (end 9.0 -12.75) (layer F.SilkS) (width 0.127))
|
||||||
|
(fp_line (start 9.0 -12.75) (end 9.0 -6.03) (layer F.SilkS) (width 0.127))
|
||||||
|
(zone (net 0) (net_name "") (layers *.Cu) (hatch full 0.508)
|
||||||
|
(connect_pads (clearance 0))
|
||||||
|
(min_thickness 0.01)
|
||||||
|
(keepout (tracks allowed) (vias not_allowed) (pads allowed ) (copperpour allowed) (footprints allowed))
|
||||||
|
(fill (thermal_gap 0.508) (thermal_bridge_width 0.508))
|
||||||
|
(polygon
|
||||||
|
(pts
|
||||||
|
(xy -9.0 -12.75)
|
||||||
|
(xy 9.0 -12.75)
|
||||||
|
(xy 9.0 -6.75)
|
||||||
|
(xy -9.0 -6.75)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(zone (net 0) (net_name "") (layer F.Cu) (hatch full 0.508)
|
||||||
|
(connect_pads (clearance 0))
|
||||||
|
(min_thickness 0.01)
|
||||||
|
(keepout (tracks not_allowed) (vias not_allowed) (pads not_allowed ) (copperpour not_allowed) (footprints allowed))
|
||||||
|
(fill (thermal_gap 0.508) (thermal_bridge_width 0.508))
|
||||||
|
(polygon
|
||||||
|
(pts
|
||||||
|
(xy -9.0 -12.75)
|
||||||
|
(xy 9.0 -12.75)
|
||||||
|
(xy 9.0 -6.75)
|
||||||
|
(xy -9.0 -6.75)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
(fp_line (start -9.75 -13.0) (end -9.75 13.0) (layer F.CrtYd) (width 0.05))
|
||||||
|
(fp_line (start -9.75 13.0) (end 9.75 13.0) (layer F.CrtYd) (width 0.05))
|
||||||
|
(fp_line (start 9.75 13.0) (end 9.75 -13.0) (layer F.CrtYd) (width 0.05))
|
||||||
|
(fp_line (start 9.75 -13.0) (end -9.75 -13.0) (layer F.CrtYd) (width 0.05))
|
||||||
|
(fp_line (start -9.0 12.75) (end -9.0 -12.75) (layer F.Fab) (width 0.127))
|
||||||
|
(fp_circle (center -10.0 -5.25) (end -9.9 -5.25) (layer F.SilkS) (width 0.2))
|
||||||
|
(fp_circle (center -10.0 -5.25) (end -9.9 -5.25) (layer F.Fab) (width 0.2))
|
||||||
|
)
|
||||||
+8
-7
@@ -1,7 +1,8 @@
|
|||||||
(fp_lib_table
|
(fp_lib_table
|
||||||
(version 7)
|
(version 7)
|
||||||
(lib (name "misc_footprints")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/misc_footprints-master/misc_footprints.pretty")(options "")(descr ""))
|
(lib (name "misc_footprints")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/misc_footprints-master/misc_footprints.pretty")(options "")(descr ""))
|
||||||
(lib (name "ESP32")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/ESP32")(options "")(descr ""))
|
(lib (name "ESP32")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/ESP32")(options "")(descr ""))
|
||||||
(lib (name "kicad-stuff")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff")(options "")(descr ""))
|
(lib (name "kicad-stuff")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff")(options "")(descr ""))
|
||||||
(lib (name "board")(type "KiCad")(uri "${KIPRJMOD}/")(options "")(descr ""))
|
(lib (name "board")(type "KiCad")(uri "${KIPRJMOD}/")(options "")(descr ""))
|
||||||
)
|
(lib (name "esp32c6")(type "KiCad")(uri "${KIPRJMOD}/esp32c6")(options "")(descr ""))
|
||||||
|
)
|
||||||
|
|||||||
+12
-11
@@ -1,11 +1,12 @@
|
|||||||
(sym_lib_table
|
(sym_lib_table
|
||||||
(version 7)
|
(version 7)
|
||||||
(lib (name "LP38690DT-3.3")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/LP38690DT-3.3.kicad_sym")(options "")(descr ""))
|
(lib (name "LP38690DT-3.3")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/LP38690DT-3.3.kicad_sym")(options "")(descr ""))
|
||||||
(lib (name "ESP32-DEVKITC-32D")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/ESP32/ESP32-DEVKITC-32D.kicad_sym")(options "")(descr ""))
|
(lib (name "ESP32-DEVKITC-32D")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/ESP32/ESP32-DEVKITC-32D.kicad_sym")(options "")(descr ""))
|
||||||
(lib (name "DW01")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/DW01.kicad_sym")(options "")(descr ""))
|
(lib (name "DW01")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/DW01.kicad_sym")(options "")(descr ""))
|
||||||
(lib (name "SX1308")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/SX1308.kicad_sym")(options "")(descr ""))
|
(lib (name "SX1308")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/SX1308.kicad_sym")(options "")(descr ""))
|
||||||
(lib (name "ds2438")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/ds2438.kicad_sym")(options "")(descr ""))
|
(lib (name "ds2438")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/ds2438.kicad_sym")(options "")(descr ""))
|
||||||
(lib (name "CN3306")(type "KiCad")(uri "${KIPRJMOD}/CN3306.kicad_sym")(options "")(descr ""))
|
(lib (name "CN3306")(type "KiCad")(uri "${KIPRJMOD}/CN3306.kicad_sym")(options "")(descr ""))
|
||||||
(lib (name "CN3795")(type "KiCad")(uri "${KIPRJMOD}/CN3795.kicad_sym")(options "")(descr ""))
|
(lib (name "CN3795")(type "KiCad")(uri "${KIPRJMOD}/CN3795.kicad_sym")(options "")(descr ""))
|
||||||
(lib (name "BQ34Z100PWR-G1")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/BQ34Z100PWR-G1.kicad_sym")(options "")(descr ""))
|
(lib (name "BQ34Z100PWR-G1")(type "KiCad")(uri "${KIPRJMOD}/kicad-stuff/BQ34Z100PWR-G1.kicad_sym")(options "")(descr ""))
|
||||||
)
|
(lib (name "ESP32-C6-WROOM-1-N8")(type "KiCad")(uri "${KIPRJMOD}/esp32c6/ESP32-C6-WROOM-1-N8.kicad_sym")(options "")(descr ""))
|
||||||
|
)
|
||||||
|
|||||||
+13
-3
@@ -1,5 +1,14 @@
|
|||||||
[build]
|
[build]
|
||||||
target = "xtensa-esp32-espidf"
|
#target = "xtensa-esp32-espidf"
|
||||||
|
target = "riscv32imac-esp-espidf"
|
||||||
|
|
||||||
|
[target.riscv32imac-esp-espidf]
|
||||||
|
linker = "ldproxy"
|
||||||
|
#runner = "espflash flash --monitor --partition-table partitions.csv" # Select this runner for espflash v2.x.x
|
||||||
|
# runner = espflash erase-parts otadata
|
||||||
|
runner = "espflash flash --monitor --baud 921600 --partition-table partitions.csv" # Select this runner for espflash v2.x.x
|
||||||
|
# runner = "cargo runner"
|
||||||
|
rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https://github.com/esp-rs/rust/issues/110
|
||||||
|
|
||||||
[target.xtensa-esp32-espidf]
|
[target.xtensa-esp32-espidf]
|
||||||
linker = "ldproxy"
|
linker = "ldproxy"
|
||||||
@@ -13,8 +22,9 @@ rustflags = [ "--cfg", "espidf_time64"] # Extending time_t for ESP IDF 5: https
|
|||||||
build-std = ["std", "panic_abort"]
|
build-std = ["std", "panic_abort"]
|
||||||
|
|
||||||
[env]
|
[env]
|
||||||
MCU="esp32"
|
MCU="esp32c6"
|
||||||
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
|
# Note: this variable is not used by the pio builder (`cargo build --features pio`)
|
||||||
ESP_IDF_VERSION = "v5.1.1"
|
ESP_IDF_VERSION = "v5.2.1"
|
||||||
CHRONO_TZ_TIMEZONE_FILTER="UTC|Europe/Berlin"
|
CHRONO_TZ_TIMEZONE_FILTER="UTC|Europe/Berlin"
|
||||||
CARGO_WORKSPACE_DIR = { value = "", relative = true }
|
CARGO_WORKSPACE_DIR = { value = "", relative = true }
|
||||||
|
RUST_BACKTRACE = "full"
|
||||||
+8
-16
@@ -6,26 +6,18 @@ edition = "2021"
|
|||||||
resolver = "2"
|
resolver = "2"
|
||||||
rust-version = "1.71"
|
rust-version = "1.71"
|
||||||
|
|
||||||
[profile.release]
|
|
||||||
# Explicitly disable LTO which the Xtensa codegen backend has issues
|
|
||||||
#lto = "thin"
|
|
||||||
opt-level = "s"
|
|
||||||
strip = false
|
|
||||||
#codegen-units = 1
|
|
||||||
debug = true
|
|
||||||
overflow-checks = true
|
|
||||||
panic = "unwind"
|
|
||||||
incremental = true
|
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
# Explicitly disable LTO which the Xtensa codegen backend has issues
|
# Explicitly disable LTO which the Xtensa codegen backend has issues
|
||||||
#lto = "thin"
|
lto = true
|
||||||
opt-level = "s"
|
|
||||||
strip = false
|
strip = false
|
||||||
#codegen-units = 1
|
|
||||||
debug = true
|
debug = true
|
||||||
overflow-checks = true
|
overflow-checks = true
|
||||||
panic = "unwind"
|
panic = "abort"
|
||||||
|
incremental = true
|
||||||
|
opt-level = "s"
|
||||||
|
|
||||||
|
[profile.dev.build-override]
|
||||||
|
opt-level = 1
|
||||||
incremental = true
|
incremental = true
|
||||||
|
|
||||||
[package.metadata.cargo_runner]
|
[package.metadata.cargo_runner]
|
||||||
@@ -35,7 +27,7 @@ command = [
|
|||||||
"espflash",
|
"espflash",
|
||||||
"save-image",
|
"save-image",
|
||||||
"--chip",
|
"--chip",
|
||||||
"esp32",
|
"esp32c6",
|
||||||
"image.bin"
|
"image.bin"
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|||||||
Binary file not shown.
+201
-113
@@ -5,7 +5,11 @@ use chrono_tz::{Europe::Berlin, Tz};
|
|||||||
|
|
||||||
use esp_idf_hal::delay::Delay;
|
use esp_idf_hal::delay::Delay;
|
||||||
use esp_idf_sys::{
|
use esp_idf_sys::{
|
||||||
esp_deep_sleep, esp_ota_get_app_partition_count, esp_ota_get_running_partition, esp_ota_get_state_partition, esp_ota_img_states_t, esp_ota_img_states_t_ESP_OTA_IMG_ABORTED, esp_ota_img_states_t_ESP_OTA_IMG_INVALID, esp_ota_img_states_t_ESP_OTA_IMG_NEW, esp_ota_img_states_t_ESP_OTA_IMG_PENDING_VERIFY, esp_ota_img_states_t_ESP_OTA_IMG_UNDEFINED, esp_ota_img_states_t_ESP_OTA_IMG_VALID, esp_restart, gpio_deep_sleep_hold_dis, gpio_deep_sleep_hold_en, vTaskDelay, CONFIG_FREERTOS_HZ
|
esp_deep_sleep, esp_ota_get_app_partition_count, esp_ota_get_running_partition,
|
||||||
|
esp_ota_get_state_partition, esp_ota_img_states_t, esp_ota_img_states_t_ESP_OTA_IMG_ABORTED,
|
||||||
|
esp_ota_img_states_t_ESP_OTA_IMG_INVALID, esp_ota_img_states_t_ESP_OTA_IMG_NEW,
|
||||||
|
esp_ota_img_states_t_ESP_OTA_IMG_PENDING_VERIFY, esp_ota_img_states_t_ESP_OTA_IMG_UNDEFINED,
|
||||||
|
esp_ota_img_states_t_ESP_OTA_IMG_VALID, esp_restart, vTaskDelay, CONFIG_FREERTOS_HZ,
|
||||||
};
|
};
|
||||||
use log::error;
|
use log::error;
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
@@ -127,12 +131,9 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
println!("Partition count is {}", count);
|
println!("Partition count is {}", count);
|
||||||
let mut ota_state: esp_ota_img_states_t = 0;
|
let mut ota_state: esp_ota_img_states_t = 0;
|
||||||
let running_partition = unsafe { esp_ota_get_running_partition() };
|
let running_partition = unsafe { esp_ota_get_running_partition() };
|
||||||
let address = unsafe {
|
let address = unsafe { (*running_partition).address };
|
||||||
(*running_partition).address
|
|
||||||
|
|
||||||
};
|
|
||||||
println!("Partition address is {}", address);
|
println!("Partition address is {}", address);
|
||||||
|
|
||||||
let ota_state_string = unsafe {
|
let ota_state_string = unsafe {
|
||||||
esp_ota_get_state_partition(running_partition, &mut ota_state);
|
esp_ota_get_state_partition(running_partition, &mut ota_state);
|
||||||
if ota_state == esp_ota_img_states_t_ESP_OTA_IMG_NEW {
|
if ota_state == esp_ota_img_states_t_ESP_OTA_IMG_NEW {
|
||||||
@@ -237,10 +238,10 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
println!("attempting to connect wifi");
|
println!("attempting to connect wifi");
|
||||||
let mut ip_address: Option<String> = None;
|
let mut ip_address: Option<String> = None;
|
||||||
match board.wifi(wifi.ssid, wifi.password, 10000) {
|
match board.wifi(wifi.ssid, wifi.password, 10000) {
|
||||||
Ok(ip_info) => {
|
Ok(ip_info) => {
|
||||||
ip_address = Some(ip_info.ip.to_string());
|
ip_address = Some(ip_info.ip.to_string());
|
||||||
online_mode = OnlineMode::Wifi;
|
online_mode = OnlineMode::Wifi;
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@@ -298,16 +299,24 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
match ip_address {
|
match ip_address {
|
||||||
Some(add_some) => {
|
Some(add_some) => {
|
||||||
let _ = board.mqtt_publish(&config, "/firmware/address", add_some.as_bytes());
|
let _ = board.mqtt_publish(&config, "/firmware/address", add_some.as_bytes());
|
||||||
},
|
}
|
||||||
None => {
|
None => {
|
||||||
let _ = board.mqtt_publish(&config, "/firmware/address", "N/A?".as_bytes());
|
let _ = board.mqtt_publish(&config, "/firmware/address", "N/A?".as_bytes());
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
let _ = board.mqtt_publish(&config, "/firmware/githash", git_hash.as_bytes());
|
let _ = board.mqtt_publish(&config, "/firmware/githash", git_hash.as_bytes());
|
||||||
let _ = board.mqtt_publish(&config, "/firmware/buildtime", build_timestamp.as_bytes());
|
let _ = board.mqtt_publish(&config, "/firmware/buildtime", build_timestamp.as_bytes());
|
||||||
let _ = board.mqtt_publish(&config, "/firmware/last_online", europe_time.to_rfc3339().as_bytes());
|
let _ = board.mqtt_publish(
|
||||||
|
&config,
|
||||||
|
"/firmware/last_online",
|
||||||
|
europe_time.to_rfc3339().as_bytes(),
|
||||||
|
);
|
||||||
let _ = board.mqtt_publish(&config, "/firmware/ota_state", ota_state_string.as_bytes());
|
let _ = board.mqtt_publish(&config, "/firmware/ota_state", ota_state_string.as_bytes());
|
||||||
let _ = board.mqtt_publish(&config, "/firmware/partition_address", format!("{:#06x}",address).as_bytes());
|
let _ = board.mqtt_publish(
|
||||||
|
&config,
|
||||||
|
"/firmware/partition_address",
|
||||||
|
format!("{:#06x}", address).as_bytes(),
|
||||||
|
);
|
||||||
let _ = board.mqtt_publish(&config, "/state", "online".as_bytes());
|
let _ = board.mqtt_publish(&config, "/state", "online".as_bytes());
|
||||||
|
|
||||||
publish_battery_state(&mut board, &config);
|
publish_battery_state(&mut board, &config);
|
||||||
@@ -318,15 +327,23 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
if tank_state.sensor_error {
|
if tank_state.sensor_error {
|
||||||
let _ = board.mqtt_publish(&config, "/water/ml", "error".to_string().as_bytes());
|
let _ = board.mqtt_publish(&config, "/water/ml", "error".to_string().as_bytes());
|
||||||
} else {
|
} else {
|
||||||
let _ = board.mqtt_publish(&config, "/water/ml", tank_state.left_ml.to_string().as_bytes());
|
let _ = board.mqtt_publish(
|
||||||
let _ = board.mqtt_publish(&config, "/water/enough_water", tank_state.enough_water.to_string().as_bytes());
|
&config,
|
||||||
let _ = board.mqtt_publish(&config, "/water/raw", tank_state.raw.to_string().as_bytes());
|
"/water/ml",
|
||||||
}
|
tank_state.left_ml.to_string().as_bytes(),
|
||||||
|
);
|
||||||
|
let _ = board.mqtt_publish(
|
||||||
|
&config,
|
||||||
|
"/water/enough_water",
|
||||||
|
tank_state.enough_water.to_string().as_bytes(),
|
||||||
|
);
|
||||||
|
let _ =
|
||||||
|
board.mqtt_publish(&config, "/water/raw", tank_state.raw.to_string().as_bytes());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let mut water_frozen = false;
|
let mut water_frozen = false;
|
||||||
let mut temp:Option<f32> = None;
|
let mut temp: Option<f32> = None;
|
||||||
for _attempt in 0..5 {
|
for _attempt in 0..5 {
|
||||||
let water_temperature = board.water_temperature_c();
|
let water_temperature = board.water_temperature_c();
|
||||||
match water_temperature {
|
match water_temperature {
|
||||||
@@ -346,25 +363,17 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
water_frozen = true;
|
water_frozen = true;
|
||||||
}
|
}
|
||||||
if online_mode == OnlineMode::Online {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(
|
let _ =
|
||||||
&config,
|
board.mqtt_publish(&config, "/water/temperature", res.to_string().as_bytes());
|
||||||
"/water/temperature",
|
|
||||||
res.to_string().as_bytes(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
None => {
|
None => {
|
||||||
if online_mode == OnlineMode::Online {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(&config, "/water/temperature", "Error".as_bytes());
|
let _ = board.mqtt_publish(&config, "/water/temperature", "Error".as_bytes());
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
let mut plantstate = [PlantState {
|
let mut plantstate = [PlantState {
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}; PLANT_COUNT];
|
}; PLANT_COUNT];
|
||||||
@@ -525,46 +534,26 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
//relatch
|
|
||||||
unsafe { gpio_deep_sleep_hold_dis() };
|
|
||||||
unsafe { gpio_deep_sleep_hold_en() };
|
|
||||||
|
|
||||||
let deep_sleep_duration_minutes: u32 = if state_of_charge < 10 {
|
let deep_sleep_duration_minutes: u32 = if state_of_charge < 10 {
|
||||||
if online_mode == OnlineMode::Online {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(
|
let _ = board.mqtt_publish(&config, "/deepsleep", "low Volt 12h".as_bytes());
|
||||||
&config,
|
|
||||||
"/deepsleep",
|
|
||||||
"low Volt 12h".as_bytes(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
12 * 60
|
12 * 60
|
||||||
} else if is_day {
|
} else if is_day {
|
||||||
if did_pump {
|
if did_pump {
|
||||||
if online_mode == OnlineMode::Online {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(
|
let _ = board.mqtt_publish(&config, "/deepsleep", "after pump".as_bytes());
|
||||||
&config,
|
|
||||||
"/deepsleep",
|
|
||||||
"after pump".as_bytes(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
if online_mode == OnlineMode::Online {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(
|
let _ = board.mqtt_publish(&config, "/deepsleep", "normal 20m".as_bytes());
|
||||||
&config,
|
|
||||||
"/deepsleep",
|
|
||||||
"normal 20m".as_bytes(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
20
|
20
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if online_mode == OnlineMode::Online {
|
if online_mode == OnlineMode::Online {
|
||||||
let _ = board.mqtt_publish(
|
let _ = board.mqtt_publish(&config, "/deepsleep", "night 1h".as_bytes());
|
||||||
&config,
|
|
||||||
"/deepsleep",
|
|
||||||
"night 1h".as_bytes(),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
60
|
60
|
||||||
};
|
};
|
||||||
@@ -572,7 +561,6 @@ fn safe_main() -> anyhow::Result<()> {
|
|||||||
let _ = board.mqtt_publish(&config, "/state", "sleep".as_bytes());
|
let _ = board.mqtt_publish(&config, "/state", "sleep".as_bytes());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//determine next event
|
//determine next event
|
||||||
//is light out of work trigger soon?
|
//is light out of work trigger soon?
|
||||||
//is battery low ??
|
//is battery low ??
|
||||||
@@ -857,18 +845,31 @@ fn determine_state_target_moisture_for_plant(
|
|||||||
state.dry = true;
|
state.dry = true;
|
||||||
if tank_state.sensor_error && !config.tank_allow_pumping_if_sensor_error {
|
if tank_state.sensor_error && !config.tank_allow_pumping_if_sensor_error {
|
||||||
//ignore is ok
|
//ignore is ok
|
||||||
}
|
} else if !tank_state.enough_water {
|
||||||
else if !tank_state.enough_water {
|
|
||||||
state.no_water = true;
|
state.no_water = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
||||||
let next_pump = board.last_pump_time(plant) + duration;
|
let last_pump = board.last_pump_time(plant);
|
||||||
if next_pump > cur {
|
match last_pump {
|
||||||
let europe_time = next_pump.with_timezone(&Berlin);
|
Some(last_pump) => {
|
||||||
state.next_pump = Some(europe_time);
|
let next_pump = last_pump + duration;
|
||||||
state.cooldown = true;
|
if next_pump > cur {
|
||||||
|
let europe_time = next_pump.with_timezone(&Berlin);
|
||||||
|
state.next_pump = Some(europe_time);
|
||||||
|
state.cooldown = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
println!(
|
||||||
|
"Could not restore last pump for plant {}, restoring",
|
||||||
|
plant + 1
|
||||||
|
);
|
||||||
|
board.store_last_pump_time(plant, DateTime::from_timestamp_millis(0).unwrap());
|
||||||
|
state.pump_error = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !in_time_range(
|
if !in_time_range(
|
||||||
cur,
|
cur,
|
||||||
plant_config.pump_hour_start,
|
plant_config.pump_hour_start,
|
||||||
@@ -888,6 +889,100 @@ fn determine_state_target_moisture_for_plant(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn determine_state_timer_only_for_plant(
|
||||||
|
board: &mut std::sync::MutexGuard<'_, PlantCtrlBoard<'_>>,
|
||||||
|
plant: usize,
|
||||||
|
state: &mut PlantState,
|
||||||
|
config: &Config,
|
||||||
|
tank_state: &TankState,
|
||||||
|
water_frozen: bool,
|
||||||
|
cur: DateTime<Tz>,
|
||||||
|
) {
|
||||||
|
let plant_config = &config.plants[plant];
|
||||||
|
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
||||||
|
|
||||||
|
let last_pump = board.last_pump_time(plant);
|
||||||
|
match last_pump {
|
||||||
|
Some(last_pump) => {
|
||||||
|
let next_pump = last_pump + duration;
|
||||||
|
if next_pump > cur {
|
||||||
|
let europe_time = next_pump.with_timezone(&Berlin);
|
||||||
|
state.next_pump = Some(europe_time);
|
||||||
|
state.cooldown = true;
|
||||||
|
} else {
|
||||||
|
if water_frozen {
|
||||||
|
state.frozen = true;
|
||||||
|
} else {
|
||||||
|
if tank_state.sensor_error && !config.tank_allow_pumping_if_sensor_error {
|
||||||
|
state.do_water = true;
|
||||||
|
} else if !tank_state.enough_water {
|
||||||
|
state.no_water = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
println!(
|
||||||
|
"Could not restore last pump for plant {}, restoring",
|
||||||
|
plant + 1
|
||||||
|
);
|
||||||
|
board.store_last_pump_time(plant, DateTime::from_timestamp_millis(0).unwrap());
|
||||||
|
state.pump_error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn determine_state_timer_and_deadzone_for_plant(
|
||||||
|
board: &mut std::sync::MutexGuard<'_, PlantCtrlBoard<'_>>,
|
||||||
|
plant: usize,
|
||||||
|
state: &mut PlantState,
|
||||||
|
config: &Config,
|
||||||
|
tank_state: &TankState,
|
||||||
|
water_frozen: bool,
|
||||||
|
cur: DateTime<Tz>,
|
||||||
|
) {
|
||||||
|
let plant_config = &config.plants[plant];
|
||||||
|
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
||||||
|
|
||||||
|
let last_pump = board.last_pump_time(plant);
|
||||||
|
match last_pump {
|
||||||
|
Some(last_pump) => {
|
||||||
|
let next_pump = last_pump + duration;
|
||||||
|
if next_pump > cur {
|
||||||
|
let europe_time = next_pump.with_timezone(&Berlin);
|
||||||
|
state.next_pump = Some(europe_time);
|
||||||
|
state.cooldown = true;
|
||||||
|
}
|
||||||
|
if !in_time_range(
|
||||||
|
cur,
|
||||||
|
plant_config.pump_hour_start,
|
||||||
|
plant_config.pump_hour_end,
|
||||||
|
) {
|
||||||
|
state.out_of_work_hour = true;
|
||||||
|
}
|
||||||
|
if !state.cooldown && !state.out_of_work_hour {
|
||||||
|
if water_frozen {
|
||||||
|
state.frozen = true;
|
||||||
|
} else {
|
||||||
|
if tank_state.sensor_error && !config.tank_allow_pumping_if_sensor_error {
|
||||||
|
state.do_water = true;
|
||||||
|
} else if !tank_state.enough_water {
|
||||||
|
state.no_water = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
println!(
|
||||||
|
"Could not restore last pump for plant {}, restoring",
|
||||||
|
plant + 1
|
||||||
|
);
|
||||||
|
board.store_last_pump_time(plant, DateTime::from_timestamp_millis(0).unwrap());
|
||||||
|
state.pump_error = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn determine_next_plant(
|
fn determine_next_plant(
|
||||||
plantstate: &mut [PlantState; PLANT_COUNT],
|
plantstate: &mut [PlantState; PLANT_COUNT],
|
||||||
cur: DateTime<Tz>,
|
cur: DateTime<Tz>,
|
||||||
@@ -913,42 +1008,26 @@ fn determine_next_plant(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
config::Mode::TimerOnly => {
|
config::Mode::TimerOnly => {
|
||||||
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
determine_state_timer_only_for_plant(
|
||||||
let next_pump = board.last_pump_time(plant) + duration;
|
board,
|
||||||
if next_pump > cur {
|
plant,
|
||||||
let europe_time = next_pump.with_timezone(&Berlin);
|
state,
|
||||||
state.next_pump = Some(europe_time);
|
config,
|
||||||
state.cooldown = true;
|
tank_state,
|
||||||
} else {
|
water_frozen,
|
||||||
if water_frozen {
|
cur,
|
||||||
state.frozen = true;
|
);
|
||||||
} else {
|
|
||||||
state.do_water = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
config::Mode::TimerAndDeadzone => {
|
config::Mode::TimerAndDeadzone => {
|
||||||
let duration = TimeDelta::try_minutes(plant_config.pump_cooldown_min as i64).unwrap();
|
determine_state_timer_and_deadzone_for_plant(
|
||||||
let next_pump = board.last_pump_time(plant) + duration;
|
board,
|
||||||
if next_pump > cur {
|
plant,
|
||||||
let europe_time = next_pump.with_timezone(&Berlin);
|
state,
|
||||||
state.next_pump = Some(europe_time);
|
config,
|
||||||
state.cooldown = true;
|
tank_state,
|
||||||
}
|
water_frozen,
|
||||||
if !in_time_range(
|
|
||||||
cur,
|
cur,
|
||||||
plant_config.pump_hour_start,
|
);
|
||||||
plant_config.pump_hour_end,
|
|
||||||
) {
|
|
||||||
state.out_of_work_hour = true;
|
|
||||||
}
|
|
||||||
if !state.cooldown && !state.out_of_work_hour {
|
|
||||||
if water_frozen {
|
|
||||||
state.frozen = true;
|
|
||||||
} else {
|
|
||||||
state.do_water = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -999,20 +1078,31 @@ fn update_plant_state(
|
|||||||
);
|
);
|
||||||
|
|
||||||
let last_time = board.last_pump_time(plant);
|
let last_time = board.last_pump_time(plant);
|
||||||
let europe_time = last_time.with_timezone(&Berlin);
|
match last_time {
|
||||||
if europe_time.year() > 2023 {
|
Some(last_time) => {
|
||||||
let time = europe_time.to_rfc3339();
|
let europe_time = last_time.with_timezone(&Berlin);
|
||||||
let _ = board.mqtt_publish(
|
if europe_time.year() > 2023 {
|
||||||
&config,
|
let time = europe_time.to_rfc3339();
|
||||||
format!("/plant{}/last pump", plant + 1).as_str(),
|
let _ = board.mqtt_publish(
|
||||||
time.as_bytes(),
|
&config,
|
||||||
);
|
format!("/plant{}/last pump", plant + 1).as_str(),
|
||||||
} else {
|
time.as_bytes(),
|
||||||
let _ = board.mqtt_publish(
|
);
|
||||||
&config,
|
} else {
|
||||||
format!("/plant{}/last pump", plant + 1).as_str(),
|
let _ = board.mqtt_publish(
|
||||||
"N/A".as_bytes(),
|
&config,
|
||||||
);
|
format!("/plant{}/last pump", plant + 1).as_str(),
|
||||||
|
"N/A".as_bytes(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let _ = board.mqtt_publish(
|
||||||
|
&config,
|
||||||
|
format!("/plant{}/last pump", plant + 1).as_str(),
|
||||||
|
"N/A".as_bytes(),
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
match state.next_pump {
|
match state.next_pump {
|
||||||
@@ -1125,8 +1215,6 @@ fn update_plant_state(
|
|||||||
format!("/plant{}/consecutive pump count", plant + 1).as_str(),
|
format!("/plant{}/consecutive pump count", plant + 1).as_str(),
|
||||||
state.consecutive_pump_count.to_string().as_bytes(),
|
state.consecutive_pump_count.to_string().as_bytes(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1175,13 +1263,13 @@ fn main() {
|
|||||||
Ok(_) => {
|
Ok(_) => {
|
||||||
println!("Main app finished, restarting");
|
println!("Main app finished, restarting");
|
||||||
unsafe { esp_restart() };
|
unsafe { esp_restart() };
|
||||||
},
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
println!("Failed main {}", err);
|
println!("Failed main {}", err);
|
||||||
let rollback_successful = rollback_and_reboot();
|
let rollback_successful = rollback_and_reboot();
|
||||||
println!("Failed to rollback :(");
|
println!("Failed to rollback :(");
|
||||||
rollback_successful.unwrap();
|
rollback_successful.unwrap();
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//error codes
|
//error codes
|
||||||
|
|||||||
+222
-142
@@ -14,7 +14,7 @@ use esp_idf_svc::mqtt::client::{EspMqttClient, LwtConfiguration, MqttClientConfi
|
|||||||
use esp_idf_svc::nvs::EspDefaultNvsPartition;
|
use esp_idf_svc::nvs::EspDefaultNvsPartition;
|
||||||
use esp_idf_svc::wifi::config::{ScanConfig, ScanType};
|
use esp_idf_svc::wifi::config::{ScanConfig, ScanType};
|
||||||
use esp_idf_svc::wifi::EspWifi;
|
use esp_idf_svc::wifi::EspWifi;
|
||||||
use measurements::Temperature;
|
use measurements::{Frequency, Temperature};
|
||||||
use plant_ctrl2::sipo::ShiftRegister40;
|
use plant_ctrl2::sipo::ShiftRegister40;
|
||||||
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
@@ -34,7 +34,7 @@ use std::time::Duration;
|
|||||||
use embedded_hal::digital::OutputPin;
|
use embedded_hal::digital::OutputPin;
|
||||||
use esp_idf_hal::adc::{attenuation, AdcChannelDriver, AdcDriver};
|
use esp_idf_hal::adc::{attenuation, AdcChannelDriver, AdcDriver};
|
||||||
use esp_idf_hal::delay::Delay;
|
use esp_idf_hal::delay::Delay;
|
||||||
use esp_idf_hal::gpio::{AnyInputPin, Gpio39, Gpio4, InputOutput, Level, PinDriver, Pull};
|
use esp_idf_hal::gpio::{AnyInputPin, Gpio18, Gpio5, InputOutput, Level, PinDriver, Pull};
|
||||||
use esp_idf_hal::pcnt::{
|
use esp_idf_hal::pcnt::{
|
||||||
PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex,
|
PcntChannel, PcntChannelConfig, PcntControlMode, PcntCountMode, PcntDriver, PinIndex,
|
||||||
};
|
};
|
||||||
@@ -42,7 +42,7 @@ use esp_idf_hal::prelude::Peripherals;
|
|||||||
use esp_idf_hal::reset::ResetReason;
|
use esp_idf_hal::reset::ResetReason;
|
||||||
use esp_idf_svc::sntp::{self, SyncStatus};
|
use esp_idf_svc::sntp::{self, SyncStatus};
|
||||||
use esp_idf_svc::systime::EspSystemTime;
|
use esp_idf_svc::systime::EspSystemTime;
|
||||||
use esp_idf_sys::{esp, gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError};
|
use esp_idf_sys::{gpio_hold_dis, gpio_hold_en, vTaskDelay, EspError};
|
||||||
use one_wire_bus::OneWire;
|
use one_wire_bus::OneWire;
|
||||||
|
|
||||||
use crate::config::{self, Config, WifiConfig};
|
use crate::config::{self, Config, WifiConfig};
|
||||||
@@ -82,8 +82,7 @@ pub enum ClearConfigType {
|
|||||||
None,
|
None,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, PartialEq)]
|
||||||
#[derive(PartialEq)]
|
|
||||||
pub enum Sensor {
|
pub enum Sensor {
|
||||||
A,
|
A,
|
||||||
B,
|
B,
|
||||||
@@ -126,7 +125,7 @@ pub trait PlantCtrlBoardInteraction {
|
|||||||
|
|
||||||
fn measure_moisture_hz(&self, plant: usize, sensor: Sensor) -> Result<i32>;
|
fn measure_moisture_hz(&self, plant: usize, sensor: Sensor) -> Result<i32>;
|
||||||
fn pump(&self, plant: usize, enable: bool) -> Result<()>;
|
fn pump(&self, plant: usize, enable: bool) -> Result<()>;
|
||||||
fn last_pump_time(&self, plant: usize) -> chrono::DateTime<Utc>;
|
fn last_pump_time(&self, plant: usize) -> Option<chrono::DateTime<Utc>>;
|
||||||
fn store_last_pump_time(&mut self, plant: usize, time: chrono::DateTime<Utc>);
|
fn store_last_pump_time(&mut self, plant: usize, time: chrono::DateTime<Utc>);
|
||||||
fn store_consecutive_pump_count(&mut self, plant: usize, count: u32);
|
fn store_consecutive_pump_count(&mut self, plant: usize, count: u32);
|
||||||
fn consecutive_pump_count(&mut self, plant: usize) -> u32;
|
fn consecutive_pump_count(&mut self, plant: usize) -> u32;
|
||||||
@@ -144,7 +143,7 @@ pub trait PlantCtrlBoardInteraction {
|
|||||||
fn wifi_ap(&mut self) -> Result<()>;
|
fn wifi_ap(&mut self) -> Result<()>;
|
||||||
fn wifi_scan(&mut self) -> Result<Vec<AccessPointInfo>>;
|
fn wifi_scan(&mut self) -> Result<Vec<AccessPointInfo>>;
|
||||||
fn test(&mut self) -> Result<()>;
|
fn test(&mut self) -> Result<()>;
|
||||||
fn test_pump(&mut self, plant:usize) -> Result<()>;
|
fn test_pump(&mut self, plant: usize) -> Result<()>;
|
||||||
fn is_wifi_config_file_existant(&mut self) -> bool;
|
fn is_wifi_config_file_existant(&mut self) -> bool;
|
||||||
fn mqtt(&mut self, config: &Config) -> Result<()>;
|
fn mqtt(&mut self, config: &Config) -> Result<()>;
|
||||||
fn mqtt_publish(&mut self, config: &Config, subtopic: &str, message: &[u8]) -> Result<()>;
|
fn mqtt_publish(&mut self, config: &Config, subtopic: &str, message: &[u8]) -> Result<()>;
|
||||||
@@ -158,23 +157,23 @@ pub struct PlantHal {}
|
|||||||
|
|
||||||
pub struct PlantCtrlBoard<'a> {
|
pub struct PlantCtrlBoard<'a> {
|
||||||
shift_register: ShiftRegister40<
|
shift_register: ShiftRegister40<
|
||||||
PinDriver<'a, esp_idf_hal::gpio::Gpio21, InputOutput>,
|
PinDriver<'a, esp_idf_hal::gpio::Gpio15, InputOutput>,
|
||||||
PinDriver<'a, esp_idf_hal::gpio::Gpio22, InputOutput>,
|
PinDriver<'a, esp_idf_hal::gpio::Gpio3, InputOutput>,
|
||||||
PinDriver<'a, esp_idf_hal::gpio::Gpio19, InputOutput>,
|
PinDriver<'a, esp_idf_hal::gpio::Gpio23, InputOutput>,
|
||||||
>,
|
>,
|
||||||
tank_driver: AdcDriver<'a, esp_idf_hal::adc::ADC1>,
|
tank_driver: AdcDriver<'a, esp_idf_hal::adc::ADC1>,
|
||||||
tank_channel: esp_idf_hal::adc::AdcChannelDriver<'a, { attenuation::DB_11 }, Gpio39>,
|
tank_channel: esp_idf_hal::adc::AdcChannelDriver<'a, { attenuation::DB_11 }, Gpio5>,
|
||||||
solar_is_day: PinDriver<'a, esp_idf_hal::gpio::Gpio25, esp_idf_hal::gpio::Input>,
|
solar_is_day: PinDriver<'a, esp_idf_hal::gpio::Gpio8, esp_idf_hal::gpio::Input>,
|
||||||
boot_button: PinDriver<'a, esp_idf_hal::gpio::Gpio0, esp_idf_hal::gpio::Input>,
|
boot_button: PinDriver<'a, esp_idf_hal::gpio::Gpio9, esp_idf_hal::gpio::Input>,
|
||||||
signal_counter: PcntDriver<'a>,
|
signal_counter: PcntDriver<'a>,
|
||||||
light: PinDriver<'a, esp_idf_hal::gpio::Gpio26, InputOutput>,
|
light: PinDriver<'a, esp_idf_hal::gpio::Gpio10, InputOutput>,
|
||||||
main_pump: PinDriver<'a, esp_idf_hal::gpio::Gpio23, InputOutput>,
|
main_pump: PinDriver<'a, esp_idf_hal::gpio::Gpio2, InputOutput>,
|
||||||
tank_power: PinDriver<'a, esp_idf_hal::gpio::Gpio27, InputOutput>,
|
tank_power: PinDriver<'a, esp_idf_hal::gpio::Gpio11, InputOutput>,
|
||||||
general_fault: PinDriver<'a, esp_idf_hal::gpio::Gpio13, InputOutput>,
|
general_fault: PinDriver<'a, esp_idf_hal::gpio::Gpio6, InputOutput>,
|
||||||
pub wifi_driver: EspWifi<'a>,
|
pub wifi_driver: EspWifi<'a>,
|
||||||
one_wire_bus: OneWire<PinDriver<'a, Gpio4, esp_idf_hal::gpio::InputOutput>>,
|
one_wire_bus: OneWire<PinDriver<'a, Gpio18, esp_idf_hal::gpio::InputOutput>>,
|
||||||
mqtt_client: Option<EspMqttClient<'a>>,
|
mqtt_client: Option<EspMqttClient<'a>>,
|
||||||
battery_driver: Bq34z100g1Driver<I2cDriver<'a>, Delay>,
|
battery_driver: Option<Bq34z100g1Driver<I2cDriver<'a>, Delay>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
||||||
@@ -242,10 +241,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
let mut percent = r2 / 190_f32 * 100_f32;
|
let mut percent = r2 / 190_f32 * 100_f32;
|
||||||
percent = percent.clamp(0.0, 100.0);
|
percent = percent.clamp(0.0, 100.0);
|
||||||
|
|
||||||
println!(
|
println!("Tank sensor raw {} percent {}", median, percent);
|
||||||
"Tank sensor raw {} percent {}",
|
|
||||||
median, percent
|
|
||||||
);
|
|
||||||
return Ok(percent as u16);
|
return Ok(percent as u16);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -271,15 +267,13 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
fn pump(&self, plant: usize, enable: bool) -> Result<()> {
|
fn pump(&self, plant: usize, enable: bool) -> Result<()> {
|
||||||
let index = plant * PINS_PER_PLANT + PLANT_PUMP_OFFSET;
|
let index = plant * PINS_PER_PLANT + PLANT_PUMP_OFFSET;
|
||||||
//currently infailable error, keep for future as result anyway
|
//currently infailable error, keep for future as result anyway
|
||||||
self.shift_register.decompose()[index]
|
self.shift_register.decompose()[index].set_state(enable.into())?;
|
||||||
.set_state(enable.into())
|
|
||||||
.unwrap();
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn last_pump_time(&self, plant: usize) -> chrono::DateTime<Utc> {
|
fn last_pump_time(&self, plant: usize) -> Option<chrono::DateTime<Utc>> {
|
||||||
let ts = unsafe { LAST_WATERING_TIMESTAMP }[plant];
|
let ts = unsafe { LAST_WATERING_TIMESTAMP }[plant];
|
||||||
return DateTime::from_timestamp_millis(ts).unwrap();
|
return Some(DateTime::from_timestamp_millis(ts)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn store_last_pump_time(&mut self, plant: usize, time: chrono::DateTime<Utc>) {
|
fn store_last_pump_time(&mut self, plant: usize, time: chrono::DateTime<Utc>) {
|
||||||
@@ -359,20 +353,12 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
let factor = 1000 as f32 / measurement as f32;
|
let factor = 1000 as f32 / measurement as f32;
|
||||||
|
|
||||||
self.shift_register.decompose()[index].set_high().unwrap();
|
self.shift_register.decompose()[index].set_high().unwrap();
|
||||||
if plant == 0 && sensor == Sensor::A {
|
|
||||||
let index = plant * PINS_PER_PLANT + PLANT_MOIST_PUMP_OFFSET;
|
|
||||||
//self.shift_register.decompose()[index].set_high().unwrap();
|
|
||||||
}
|
|
||||||
//give some time to stabilize
|
//give some time to stabilize
|
||||||
delay.delay_ms(10);
|
delay.delay_ms(10);
|
||||||
self.signal_counter.counter_resume()?;
|
self.signal_counter.counter_resume()?;
|
||||||
delay.delay_ms(measurement);
|
delay.delay_ms(measurement);
|
||||||
self.signal_counter.counter_pause()?;
|
self.signal_counter.counter_pause()?;
|
||||||
self.shift_register.decompose()[index].set_low().unwrap();
|
self.shift_register.decompose()[index].set_low().unwrap();
|
||||||
if plant == 0 && sensor == Sensor::A {
|
|
||||||
let index = plant * PINS_PER_PLANT + PLANT_MOIST_PUMP_OFFSET;
|
|
||||||
//self.shift_register.decompose()[index].set_low().unwrap();
|
|
||||||
}
|
|
||||||
let unscaled = self.signal_counter.get_counter_value()? as i32;
|
let unscaled = self.signal_counter.get_counter_value()? as i32;
|
||||||
let hz = (unscaled as f32 * factor) as i32;
|
let hz = (unscaled as f32 * factor) as i32;
|
||||||
println!("Measuring {:?} @ {} with {}", sensor, plant, hz);
|
println!("Measuring {:?} @ {} with {}", sensor, plant, hz);
|
||||||
@@ -415,13 +401,13 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
self.wifi_driver
|
self.wifi_driver.set_configuration(&Configuration::Client(
|
||||||
.set_configuration(&Configuration::Client(ClientConfiguration {
|
ClientConfiguration {
|
||||||
ssid: ssid,
|
ssid: ssid,
|
||||||
auth_method: AuthMethod::None,
|
auth_method: AuthMethod::None,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
}))
|
},
|
||||||
.unwrap();
|
))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +429,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
}
|
}
|
||||||
println!("Should be connected now");
|
println!("Should be connected now");
|
||||||
|
|
||||||
while !self.wifi_driver.is_up().unwrap() {
|
while !self.wifi_driver.is_up()? {
|
||||||
println!("Waiting for network being up");
|
println!("Waiting for network being up");
|
||||||
delay.delay_ms(250);
|
delay.delay_ms(250);
|
||||||
counter += 250;
|
counter += 250;
|
||||||
@@ -455,7 +441,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
//update freertos registers ;)
|
//update freertos registers ;)
|
||||||
let address = self.wifi_driver.sta_netif().get_ip_info().unwrap();
|
let address = self.wifi_driver.sta_netif().get_ip_info()?;
|
||||||
println!("IP info: {:?}", address);
|
println!("IP info: {:?}", address);
|
||||||
Ok(address)
|
Ok(address)
|
||||||
}
|
}
|
||||||
@@ -576,7 +562,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
Ok(self.wifi_driver.get_scan_result()?)
|
Ok(self.wifi_driver.get_scan_result()?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_pump(&mut self, plant:usize) -> Result<()> {
|
fn test_pump(&mut self, plant: usize) -> Result<()> {
|
||||||
self.any_pump(true)?;
|
self.any_pump(true)?;
|
||||||
self.pump(plant, true)?;
|
self.pump(plant, true)?;
|
||||||
unsafe { vTaskDelay(30000) };
|
unsafe { vTaskDelay(30000) };
|
||||||
@@ -630,7 +616,6 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
|
|
||||||
fn mqtt(&mut self, config: &Config) -> Result<()> {
|
fn mqtt(&mut self, config: &Config) -> Result<()> {
|
||||||
let last_will_topic = format!("{}/state", config.base_topic);
|
let last_will_topic = format!("{}/state", config.base_topic);
|
||||||
|
|
||||||
let mqtt_client_config = MqttClientConfiguration {
|
let mqtt_client_config = MqttClientConfiguration {
|
||||||
lwt: Some(LwtConfiguration {
|
lwt: Some(LwtConfiguration {
|
||||||
topic: &last_will_topic,
|
topic: &last_will_topic,
|
||||||
@@ -639,23 +624,34 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
retain: true,
|
retain: true,
|
||||||
}),
|
}),
|
||||||
client_id: Some("plantctrl"),
|
client_id: Some("plantctrl"),
|
||||||
keep_alive_interval : Some(Duration::from_secs(60*60*2)),
|
keep_alive_interval: Some(Duration::from_secs(60 * 60 * 2)),
|
||||||
//room for improvement
|
//room for improvement
|
||||||
..Default::default()
|
..Default::default()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let mqtt_connected_event_received = Arc::new(AtomicBool::new(false));
|
||||||
|
let mqtt_connected_event_ok = Arc::new(AtomicBool::new(false));
|
||||||
|
|
||||||
let round_trip_ok = Arc::new(AtomicBool::new(false));
|
let round_trip_ok = Arc::new(AtomicBool::new(false));
|
||||||
let round_trip_topic = format!("{}/internal/roundtrip", config.base_topic);
|
let round_trip_topic = format!("{}/internal/roundtrip", config.base_topic);
|
||||||
let stay_alive_topic = format!("{}/stay_alive", config.base_topic);
|
let stay_alive_topic = format!("{}/stay_alive", config.base_topic);
|
||||||
println!("Round trip topic is {}", round_trip_topic);
|
println!("Round trip topic is {}", round_trip_topic);
|
||||||
println!("Stay alive topic is {}", stay_alive_topic);
|
println!("Stay alive topic is {}", stay_alive_topic);
|
||||||
|
|
||||||
|
let mqtt_connected_event_received_copy = mqtt_connected_event_received.clone();
|
||||||
|
let mqtt_connected_event_ok_copy = mqtt_connected_event_ok.clone();
|
||||||
let stay_alive_topic_copy = stay_alive_topic.clone();
|
let stay_alive_topic_copy = stay_alive_topic.clone();
|
||||||
let round_trip_topic_copy = round_trip_topic.clone();
|
let round_trip_topic_copy = round_trip_topic.clone();
|
||||||
let round_trip_ok_copy = round_trip_ok.clone();
|
let round_trip_ok_copy = round_trip_ok.clone();
|
||||||
|
println!(
|
||||||
|
"Connecting mqtt {} with id {}",
|
||||||
|
config.mqtt_url,
|
||||||
|
mqtt_client_config.client_id.unwrap_or("not set")
|
||||||
|
);
|
||||||
let mut client =
|
let mut client =
|
||||||
EspMqttClient::new_cb(&config.mqtt_url, &mqtt_client_config, move |event| {
|
EspMqttClient::new_cb(&config.mqtt_url, &mqtt_client_config, move |event| {
|
||||||
let payload = event.payload();
|
let payload = event.payload();
|
||||||
|
println!("received mqtt event {:?}", payload);
|
||||||
match payload {
|
match payload {
|
||||||
embedded_svc::mqtt::client::EventPayload::Received {
|
embedded_svc::mqtt::client::EventPayload::Received {
|
||||||
id: _,
|
id: _,
|
||||||
@@ -663,6 +659,7 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
data,
|
data,
|
||||||
details: _,
|
details: _,
|
||||||
} => {
|
} => {
|
||||||
|
println!("Received something");
|
||||||
let data = String::from_utf8_lossy(data);
|
let data = String::from_utf8_lossy(data);
|
||||||
if let Some(topic) = topic {
|
if let Some(topic) = topic {
|
||||||
//todo use enums
|
//todo use enums
|
||||||
@@ -679,38 +676,82 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
_ => {}
|
embedded_svc::mqtt::client::EventPayload::Connected(session_present) => {
|
||||||
|
mqtt_connected_event_received_copy
|
||||||
|
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
mqtt_connected_event_ok_copy
|
||||||
|
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
println!("Mqtt connected");
|
||||||
|
}
|
||||||
|
embedded_svc::mqtt::client::EventPayload::Disconnected => {
|
||||||
|
mqtt_connected_event_received_copy
|
||||||
|
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
mqtt_connected_event_ok_copy
|
||||||
|
.store(false, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
println!("Mqtt disconnected");
|
||||||
|
}
|
||||||
|
embedded_svc::mqtt::client::EventPayload::Error(espError) => {
|
||||||
|
mqtt_connected_event_received_copy
|
||||||
|
.store(true, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
mqtt_connected_event_ok_copy
|
||||||
|
.store(false, std::sync::atomic::Ordering::Relaxed);
|
||||||
|
println!("Mqtt error");
|
||||||
|
}
|
||||||
|
_ => {
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})?;
|
})?;
|
||||||
//subscribe to roundtrip
|
|
||||||
|
|
||||||
client.subscribe(round_trip_topic.as_str(), ExactlyOnce)?;
|
let wait_for_connections_event = 0;
|
||||||
client.subscribe(stay_alive_topic.as_str(), ExactlyOnce)?;
|
while wait_for_connections_event < 100 {
|
||||||
//publish to roundtrip
|
match true { //mqtt_connected_event_received.load(std::sync::atomic::Ordering::Relaxed) {
|
||||||
client.publish(
|
|
||||||
round_trip_topic.as_str(),
|
|
||||||
ExactlyOnce,
|
|
||||||
false,
|
|
||||||
"online_test".as_bytes(),
|
|
||||||
)?;
|
|
||||||
|
|
||||||
let wait_for_roundtrip = 0;
|
|
||||||
while wait_for_roundtrip < 100 {
|
|
||||||
match round_trip_ok.load(std::sync::atomic::Ordering::Relaxed) {
|
|
||||||
true => {
|
true => {
|
||||||
println!("Round trip registered, proceeding");
|
println!("Mqtt connection callback received, progressing");
|
||||||
self.mqtt_client = Some(client);
|
match mqtt_connected_event_ok.load(std::sync::atomic::Ordering::Relaxed) {
|
||||||
return Ok(());
|
true => {
|
||||||
|
println!("Mqtt did callback as connected, testing with roundtrip now");
|
||||||
|
//subscribe to roundtrip
|
||||||
|
client.subscribe(round_trip_topic.as_str(), ExactlyOnce)?;
|
||||||
|
client.subscribe(stay_alive_topic.as_str(), ExactlyOnce)?;
|
||||||
|
//publish to roundtrip
|
||||||
|
client.publish(
|
||||||
|
round_trip_topic.as_str(),
|
||||||
|
ExactlyOnce,
|
||||||
|
false,
|
||||||
|
"online_test".as_bytes(),
|
||||||
|
)?;
|
||||||
|
|
||||||
|
let wait_for_roundtrip = 0;
|
||||||
|
while wait_for_roundtrip < 100 {
|
||||||
|
match round_trip_ok.load(std::sync::atomic::Ordering::Relaxed) {
|
||||||
|
true => {
|
||||||
|
println!("Round trip registered, proceeding");
|
||||||
|
self.mqtt_client = Some(client);
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
unsafe { vTaskDelay(10) };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bail!("Mqtt did not complete roundtrip in time");
|
||||||
|
}
|
||||||
|
false => {
|
||||||
|
bail!("Mqtt did respond but with failure")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
false => {
|
false => {
|
||||||
unsafe { vTaskDelay(10) };
|
unsafe { vTaskDelay(10) };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bail!("Mqtt did not complete roundtrip in time");
|
bail!("Mqtt did not fire connection callback in time");
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mqtt_publish(&mut self, config: &Config, subtopic: &str, message: &[u8]) -> Result<()> {
|
fn mqtt_publish(&mut self, config: &Config, subtopic: &str, message: &[u8]) -> Result<()> {
|
||||||
|
println!("Publishing mqtt {} content {:?}", subtopic, message);
|
||||||
if !subtopic.starts_with("/") {
|
if !subtopic.starts_with("/") {
|
||||||
println!("Subtopic without / at start {}", subtopic);
|
println!("Subtopic without / at start {}", subtopic);
|
||||||
bail!("Subtopic without / at start {}", subtopic);
|
bail!("Subtopic without / at start {}", subtopic);
|
||||||
@@ -723,94 +764,130 @@ impl PlantCtrlBoardInteraction for PlantCtrlBoard<'_> {
|
|||||||
println!("Not connected to mqtt");
|
println!("Not connected to mqtt");
|
||||||
bail!("Not connected to mqtt");
|
bail!("Not connected to mqtt");
|
||||||
}
|
}
|
||||||
let client = self.mqtt_client.as_mut().unwrap();
|
match &mut self.mqtt_client {
|
||||||
|
Some(client) => {
|
||||||
let mut full_topic: heapless::String<256> = heapless::String::new();
|
let mut full_topic: heapless::String<256> = heapless::String::new();
|
||||||
if full_topic.push_str(&config.base_topic).is_err() {
|
if full_topic.push_str(&config.base_topic).is_err() {
|
||||||
println!("Some error assembling full_topic 1");
|
println!("Some error assembling full_topic 1");
|
||||||
bail!("Some error assembling full_topic 1")
|
bail!("Some error assembling full_topic 1")
|
||||||
};
|
};
|
||||||
if full_topic.push_str(subtopic).is_err() {
|
if full_topic.push_str(subtopic).is_err() {
|
||||||
println!("Some error assembling full_topic 2");
|
println!("Some error assembling full_topic 2");
|
||||||
bail!("Some error assembling full_topic 2")
|
bail!("Some error assembling full_topic 2")
|
||||||
};
|
};
|
||||||
let publish = client.publish(
|
let publish = client.publish(
|
||||||
&full_topic,
|
&full_topic,
|
||||||
embedded_svc::mqtt::client::QoS::ExactlyOnce,
|
embedded_svc::mqtt::client::QoS::ExactlyOnce,
|
||||||
true,
|
true,
|
||||||
message,
|
message,
|
||||||
);
|
);
|
||||||
Delay::new(10).delay_ms(50);
|
Delay::new(10).delay_ms(50);
|
||||||
match publish {
|
match publish {
|
||||||
OkStd(message_id) => {
|
OkStd(message_id) => {
|
||||||
println!("Published mqtt topic {} with message {:#?} msgid is {:?}",full_topic, String::from_utf8_lossy(message), message_id);
|
println!(
|
||||||
return Ok(())
|
"Published mqtt topic {} with message {:#?} msgid is {:?}",
|
||||||
},
|
full_topic,
|
||||||
Err(err) => {
|
String::from_utf8_lossy(message),
|
||||||
println!("Error during mqtt send on topic {} with message {:#?} error is {:?}",full_topic, String::from_utf8_lossy(message), err);
|
message_id
|
||||||
return Err(err)?
|
);
|
||||||
},
|
return Ok(());
|
||||||
|
}
|
||||||
|
Err(err) => {
|
||||||
|
println!(
|
||||||
|
"Error during mqtt send on topic {} with message {:#?} error is {:?}",
|
||||||
|
full_topic,
|
||||||
|
String::from_utf8_lossy(message),
|
||||||
|
err
|
||||||
|
);
|
||||||
|
return Err(err)?;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
bail!("No mqtt client, aborting publish");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state_charge_percent(&mut self) -> Result<u8> {
|
fn state_charge_percent(&mut self) -> Result<u8> {
|
||||||
match self.battery_driver.state_of_charge() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r),
|
Some(driver) => match driver.state_of_charge() {
|
||||||
Err(err) => bail!("Error reading SoC {:?}", err),
|
OkStd(r) => Ok(r),
|
||||||
|
Err(err) => bail!("Error reading SoC {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading SoC bq34z100 not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn remaining_milli_ampere_hour(&mut self) -> Result<u16> {
|
fn remaining_milli_ampere_hour(&mut self) -> Result<u16> {
|
||||||
match self.battery_driver.remaining_capacity() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r),
|
Some(driver) => match driver.remaining_capacity() {
|
||||||
Err(err) => bail!("Error reading Remaining Capacity {:?}", err),
|
OkStd(r) => Ok(r),
|
||||||
|
Err(err) => bail!("Error reading Remaining Capacity {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading Remaining Capacity bq34z100 not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn max_milli_ampere_hour(&mut self) -> Result<u16> {
|
fn max_milli_ampere_hour(&mut self) -> Result<u16> {
|
||||||
match self.battery_driver.full_charge_capacity() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r),
|
Some(driver) => match driver.full_charge_capacity() {
|
||||||
Err(err) => bail!("Error reading Full Charge Capacity {:?}", err),
|
OkStd(r) => Ok(r),
|
||||||
|
Err(err) => bail!("Error reading Full Charge Capacity {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading Full Charge Capacity bq34z100 not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn design_milli_ampere_hour(&mut self) -> Result<u16> {
|
fn design_milli_ampere_hour(&mut self) -> Result<u16> {
|
||||||
match self.battery_driver.design_capacity() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r),
|
Some(driver) => match driver.design_capacity() {
|
||||||
Err(err) => bail!("Error reading Design Capacity {:?}", err),
|
OkStd(r) => Ok(r),
|
||||||
|
Err(err) => bail!("Error reading Design Capacity {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading Design Capacity bq34z100 not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn voltage_milli_volt(&mut self) -> Result<u16> {
|
fn voltage_milli_volt(&mut self) -> Result<u16> {
|
||||||
return match self.battery_driver.voltage() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r),
|
Some(driver) => match driver.voltage() {
|
||||||
Err(err) => bail!("Error reading voltage {:?}", err),
|
OkStd(r) => Ok(r),
|
||||||
};
|
Err(err) => bail!("Error reading voltage {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading voltage bq34z100 not found"),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn average_current_milli_ampere(&mut self) -> Result<i16> {
|
fn average_current_milli_ampere(&mut self) -> Result<i16> {
|
||||||
match self.battery_driver.average_current() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r),
|
Some(driver) => match driver.average_current() {
|
||||||
Err(err) => bail!("Error reading Average Current {:?}", err),
|
OkStd(r) => Ok(r),
|
||||||
|
Err(err) => bail!("Error reading Average Current {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading Average Current bq34z100 not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cycle_count(&mut self) -> Result<u16> {
|
fn cycle_count(&mut self) -> Result<u16> {
|
||||||
match self.battery_driver.cycle_count() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r),
|
Some(driver) => match driver.cycle_count() {
|
||||||
Err(err) => bail!("Error reading Cycle Count {:?}", err),
|
OkStd(r) => Ok(r),
|
||||||
|
Err(err) => bail!("Error reading Cycle Count {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading Cycle Count bq34z100 not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn state_health_percent(&mut self) -> Result<u8> {
|
fn state_health_percent(&mut self) -> Result<u8> {
|
||||||
match self.battery_driver.state_of_health() {
|
match &mut self.battery_driver {
|
||||||
OkStd(r) => Ok(r as u8),
|
Some(driver) => match driver.state_of_health() {
|
||||||
Err(err) => bail!("Error reading State of Health {:?}", err),
|
OkStd(r) => Ok(r as u8),
|
||||||
|
Err(err) => bail!("Error reading State of Health {:?}", err),
|
||||||
|
},
|
||||||
|
None => bail!("Error reading State of Health bq34z100 not found"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_battery(
|
fn print_battery(
|
||||||
@@ -874,18 +951,18 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
fn create() -> Result<Mutex<PlantCtrlBoard<'static>>> {
|
fn create() -> Result<Mutex<PlantCtrlBoard<'static>>> {
|
||||||
let peripherals = Peripherals::take()?;
|
let peripherals = Peripherals::take()?;
|
||||||
|
|
||||||
let i2c = peripherals.i2c1;
|
let i2c = peripherals.i2c0;
|
||||||
let config = I2cConfig::new()
|
let config = I2cConfig::new()
|
||||||
.scl_enable_pullup(false)
|
.scl_enable_pullup(false)
|
||||||
.sda_enable_pullup(false)
|
.sda_enable_pullup(false)
|
||||||
.baudrate(10_u32.kHz().into());
|
.baudrate(10_u32.kHz().into());
|
||||||
let scl = peripherals.pins.gpio16;
|
let scl = peripherals.pins.gpio19;
|
||||||
let sda = peripherals.pins.gpio17;
|
let sda = peripherals.pins.gpio20;
|
||||||
|
|
||||||
let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap();
|
let driver = I2cDriver::new(i2c, sda, scl, &config).unwrap();
|
||||||
|
|
||||||
let i2c_port = driver.port();
|
//let i2c_port = driver.port();
|
||||||
esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 1048000) }).unwrap();
|
//esp!(unsafe { esp_idf_sys::i2c_set_timeout(i2c_port, 2)}).unwrap();
|
||||||
|
|
||||||
let mut battery_driver: Bq34z100g1Driver<I2cDriver, Delay> = Bq34z100g1Driver {
|
let mut battery_driver: Bq34z100g1Driver<I2cDriver, Delay> = Bq34z100g1Driver {
|
||||||
i2c: driver,
|
i2c: driver,
|
||||||
@@ -893,18 +970,18 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
flash_block_data: [0; 32],
|
flash_block_data: [0; 32],
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut clock = PinDriver::input_output(peripherals.pins.gpio21)?;
|
let mut clock = PinDriver::input_output(peripherals.pins.gpio15)?;
|
||||||
clock.set_pull(Pull::Floating).unwrap();
|
clock.set_pull(Pull::Floating).unwrap();
|
||||||
let mut latch = PinDriver::input_output(peripherals.pins.gpio22)?;
|
let mut latch = PinDriver::input_output(peripherals.pins.gpio3)?;
|
||||||
latch.set_pull(Pull::Floating).unwrap();
|
latch.set_pull(Pull::Floating).unwrap();
|
||||||
let mut data = PinDriver::input_output(peripherals.pins.gpio19)?;
|
let mut data = PinDriver::input_output(peripherals.pins.gpio23)?;
|
||||||
data.set_pull(Pull::Floating).unwrap();
|
data.set_pull(Pull::Floating).unwrap();
|
||||||
let shift_register = ShiftRegister40::new(clock.into(), latch.into(), data.into());
|
let shift_register = ShiftRegister40::new(clock.into(), latch.into(), data.into());
|
||||||
for mut pin in shift_register.decompose() {
|
for mut pin in shift_register.decompose() {
|
||||||
pin.set_low().unwrap();
|
pin.set_low().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut one_wire_pin = PinDriver::input_output_od(peripherals.pins.gpio4)?;
|
let mut one_wire_pin = PinDriver::input_output_od(peripherals.pins.gpio18)?;
|
||||||
one_wire_pin.set_pull(Pull::Floating).unwrap();
|
one_wire_pin.set_pull(Pull::Floating).unwrap();
|
||||||
//TODO make to none if not possible to init
|
//TODO make to none if not possible to init
|
||||||
|
|
||||||
@@ -959,7 +1036,7 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
|
|
||||||
let mut counter_unit1 = PcntDriver::new(
|
let mut counter_unit1 = PcntDriver::new(
|
||||||
peripherals.pcnt0,
|
peripherals.pcnt0,
|
||||||
Some(peripherals.pins.gpio18),
|
Some(peripherals.pins.gpio22),
|
||||||
Option::<AnyInputPin>::None,
|
Option::<AnyInputPin>::None,
|
||||||
Option::<AnyInputPin>::None,
|
Option::<AnyInputPin>::None,
|
||||||
Option::<AnyInputPin>::None,
|
Option::<AnyInputPin>::None,
|
||||||
@@ -998,24 +1075,24 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
calibration: true,
|
calibration: true,
|
||||||
};
|
};
|
||||||
let tank_driver = AdcDriver::new(peripherals.adc1, &adc_config)?;
|
let tank_driver = AdcDriver::new(peripherals.adc1, &adc_config)?;
|
||||||
let tank_channel: AdcChannelDriver<'_, { attenuation::DB_11 }, Gpio39> =
|
let tank_channel: AdcChannelDriver<'_, { attenuation::DB_11 }, Gpio5> =
|
||||||
AdcChannelDriver::new(peripherals.pins.gpio39)?;
|
AdcChannelDriver::new(peripherals.pins.gpio5)?;
|
||||||
|
|
||||||
let mut solar_is_day = PinDriver::input(peripherals.pins.gpio25)?;
|
let mut solar_is_day = PinDriver::input(peripherals.pins.gpio8)?;
|
||||||
solar_is_day.set_pull(Pull::Floating)?;
|
solar_is_day.set_pull(Pull::Floating)?;
|
||||||
|
|
||||||
let mut boot_button = PinDriver::input(peripherals.pins.gpio0)?;
|
let mut boot_button = PinDriver::input(peripherals.pins.gpio9)?;
|
||||||
boot_button.set_pull(Pull::Floating)?;
|
boot_button.set_pull(Pull::Floating)?;
|
||||||
|
|
||||||
let mut light = PinDriver::input_output(peripherals.pins.gpio26)?;
|
let mut light = PinDriver::input_output(peripherals.pins.gpio10)?;
|
||||||
light.set_pull(Pull::Floating).unwrap();
|
light.set_pull(Pull::Floating).unwrap();
|
||||||
|
|
||||||
let mut main_pump = PinDriver::input_output(peripherals.pins.gpio23)?;
|
let mut main_pump = PinDriver::input_output(peripherals.pins.gpio2)?;
|
||||||
main_pump.set_pull(Pull::Floating)?;
|
main_pump.set_pull(Pull::Floating)?;
|
||||||
main_pump.set_low()?;
|
main_pump.set_low()?;
|
||||||
let mut tank_power = PinDriver::input_output(peripherals.pins.gpio27)?;
|
let mut tank_power = PinDriver::input_output(peripherals.pins.gpio11)?;
|
||||||
tank_power.set_pull(Pull::Floating)?;
|
tank_power.set_pull(Pull::Floating)?;
|
||||||
let mut general_fault = PinDriver::input_output(peripherals.pins.gpio13)?;
|
let mut general_fault = PinDriver::input_output(peripherals.pins.gpio6)?;
|
||||||
general_fault.set_pull(Pull::Floating)?;
|
general_fault.set_pull(Pull::Floating)?;
|
||||||
general_fault.set_low()?;
|
general_fault.set_low()?;
|
||||||
let one_wire_bus = OneWire::new(one_wire_pin)
|
let one_wire_bus = OneWire::new(one_wire_pin)
|
||||||
@@ -1023,10 +1100,12 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
|
|
||||||
println!("After stuff");
|
println!("After stuff");
|
||||||
|
|
||||||
let status = print_battery(&mut battery_driver);
|
//let status = print_battery(&mut battery_driver);
|
||||||
if status.is_err() {
|
//if status.is_err() {
|
||||||
println!("Error communicating with battery!! {:?}", status.err());
|
// println!("Error communicating with battery!! {:?}", status.err());
|
||||||
}
|
//} else {
|
||||||
|
// println!("Managed to comunnicate with battery");
|
||||||
|
//}
|
||||||
let rv = Mutex::new(PlantCtrlBoard {
|
let rv = Mutex::new(PlantCtrlBoard {
|
||||||
shift_register,
|
shift_register,
|
||||||
tank_driver,
|
tank_driver,
|
||||||
@@ -1041,7 +1120,8 @@ impl CreatePlantHal<'_> for PlantHal {
|
|||||||
signal_counter: counter_unit1,
|
signal_counter: counter_unit1,
|
||||||
wifi_driver,
|
wifi_driver,
|
||||||
mqtt_client: None,
|
mqtt_client: None,
|
||||||
battery_driver,
|
battery_driver: None,
|
||||||
|
//Some(battery_driver),
|
||||||
});
|
});
|
||||||
Ok(rv)
|
Ok(rv)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,12 @@ struct SSIDList<'a> {
|
|||||||
#[derive(Serialize, Debug)]
|
#[derive(Serialize, Debug)]
|
||||||
struct VersionInfo<'a> {
|
struct VersionInfo<'a> {
|
||||||
git_hash: &'a str,
|
git_hash: &'a str,
|
||||||
build_time: &'a str
|
build_time: &'a str,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq)]
|
||||||
pub struct TestPump{
|
pub struct TestPump {
|
||||||
pump: usize
|
pump: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn httpd_initial(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
pub fn httpd_initial(reboot_now: Arc<AtomicBool>) -> Box<EspHttpServer<'static>> {
|
||||||
@@ -174,7 +174,7 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
|
|||||||
let mut response = request.into_ok_response()?;
|
let mut response = request.into_ok_response()?;
|
||||||
let git_hash = env!("VERGEN_GIT_DESCRIBE");
|
let git_hash = env!("VERGEN_GIT_DESCRIBE");
|
||||||
let build_time = env!("VERGEN_BUILD_TIMESTAMP");
|
let build_time = env!("VERGEN_BUILD_TIMESTAMP");
|
||||||
let version_info = VersionInfo{
|
let version_info = VersionInfo {
|
||||||
git_hash,
|
git_hash,
|
||||||
build_time,
|
build_time,
|
||||||
};
|
};
|
||||||
@@ -253,39 +253,40 @@ pub fn shared() -> Box<EspHttpServer<'static>> {
|
|||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
server
|
server
|
||||||
.fn_handler("/boardtest", Method::Post, move |_| {
|
.fn_handler("/boardtest", Method::Post, move |_| {
|
||||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||||
board.test()?;
|
board.test()?;
|
||||||
anyhow::Ok(())
|
anyhow::Ok(())
|
||||||
})
|
})
|
||||||
.unwrap();
|
.unwrap();
|
||||||
server
|
server
|
||||||
.fn_handler("/pumptest", Method::Post, |mut request| {
|
.fn_handler("/pumptest", Method::Post, |mut request| {
|
||||||
let mut buf = [0_u8; 3072];
|
let mut buf = [0_u8; 3072];
|
||||||
let read = request.read(&mut buf);
|
let read = request.read(&mut buf);
|
||||||
if read.is_err() {
|
if read.is_err() {
|
||||||
let error_text = read.unwrap_err().to_string();
|
let error_text = read.unwrap_err().to_string();
|
||||||
println!("Could not parse testrequest {}", error_text);
|
println!("Could not parse testrequest {}", error_text);
|
||||||
request
|
request
|
||||||
.into_status_response(500)?
|
.into_status_response(500)?
|
||||||
.write(error_text.as_bytes())?;
|
.write(error_text.as_bytes())?;
|
||||||
return anyhow::Ok(());
|
return anyhow::Ok(());
|
||||||
}
|
}
|
||||||
let actual_data = &buf[0..read.unwrap()];
|
let actual_data = &buf[0..read.unwrap()];
|
||||||
println!("Raw data {}", from_utf8(actual_data).unwrap());
|
println!("Raw data {}", from_utf8(actual_data).unwrap());
|
||||||
let pump_test: Result<TestPump, serde_json::Error> = serde_json::from_slice(actual_data);
|
let pump_test: Result<TestPump, serde_json::Error> =
|
||||||
if pump_test.is_err() {
|
serde_json::from_slice(actual_data);
|
||||||
let error_text = pump_test.unwrap_err().to_string();
|
if pump_test.is_err() {
|
||||||
println!("Could not parse TestPump {}", error_text);
|
let error_text = pump_test.unwrap_err().to_string();
|
||||||
request
|
println!("Could not parse TestPump {}", error_text);
|
||||||
.into_status_response(500)?
|
request
|
||||||
.write(error_text.as_bytes())?;
|
.into_status_response(500)?
|
||||||
return Ok(());
|
.write(error_text.as_bytes())?;
|
||||||
}
|
return Ok(());
|
||||||
let mut board = BOARD_ACCESS.lock().unwrap();
|
}
|
||||||
board.test_pump(pump_test.unwrap().pump)?;
|
let mut board = BOARD_ACCESS.lock().unwrap();
|
||||||
anyhow::Ok(())
|
board.test_pump(pump_test.unwrap().pump)?;
|
||||||
})
|
anyhow::Ok(())
|
||||||
.unwrap();
|
})
|
||||||
|
.unwrap();
|
||||||
server
|
server
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user