-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlora-sender.yaml
More file actions
190 lines (174 loc) · 4.73 KB
/
Copy pathlora-sender.yaml
File metadata and controls
190 lines (174 loc) · 4.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# LoRa Mailbox Sender v74 - Final Production
#
# Hardware: Heltec WiFi LoRa 32 V3 (ESP32-S3 + SX1262)
# Power: 6x 18650 Li-ion parallel (12000mAh)
# Deep sleep: ~2.6-3.4mA
# Expected battery life: ~4-6 months
#
# Wakeup: GPIO5 (reed switch/magnetic contact)
# Battery ADC: GPIO7 (voltage divider)
#
# Message format:
# 1|4.02 = Mail received, battery voltage
# 1|3.35|LOW_BAT = Mail received, low battery (<3.4V)
# W|4.02|LID_OPEN = Lid open for 5+ minutes
esphome:
name: lora-sender
friendly_name: LoRa Mailbox Sender
on_boot:
priority: -100
then:
- component.update: bat_voltage
esp32:
board: esp32-s3-devkitc-1
framework:
type: esp-idf
logger:
baud_rate: 0
# WiFi disabled for battery operation
# Uncomment for maintenance/debugging (flash via USB)
# wifi:
# ssid: !secret wifi_ssid
# password: !secret wifi_password
# api:
# encryption:
# key: "your-api-key-here"
# ota:
# - platform: esphome
# password: "your-ota-password"
globals:
- id: packets_sent
type: bool
restore_value: false
initial_value: 'false'
- id: warning_sent
type: bool
restore_value: false
initial_value: 'false'
deep_sleep:
id: deep_sleep_mode
wakeup_pin:
number: GPIO5
allow_other_uses: true
mode:
input: true
pullup: true
wakeup_pin_mode: KEEP_AWAKE
sensor:
- platform: adc
pin: GPIO7
id: bat_voltage
name: "Battery Voltage"
unit_of_measurement: V
update_interval: never
accuracy_decimals: 2
attenuation: 12db
filters:
- multiply: 2.0 # Voltage divider ratio
binary_sensor:
- platform: gpio
pin:
number: GPIO5
allow_other_uses: true
mode:
input: true
pullup: true
inverted: true
name: "Mailbox Lid"
id: mailbox_lid
device_class: door
filters:
- delayed_on: 100ms
- delayed_off: 100ms
spi:
clk_pin: GPIO9
mosi_pin: GPIO10
miso_pin: GPIO11
sx126x:
id: lora_radio
cs_pin: GPIO8
rst_pin: GPIO12
busy_pin: GPIO13
dio1_pin: GPIO14
hw_version: sx1262
tcxo_voltage: 1_8V
tcxo_delay: 30ms
rf_switch: true
modulation: LORA
sync_value: [0x14, 0x24]
frequency: 868000000 # EU868 band
bandwidth: 125_0kHz
spreading_factor: 12 # Max range
coding_rate: CR_4_8
preamble_size: 10
crc_enable: true
pa_power: 14 # dBm
output:
- platform: gpio
pin: GPIO35
id: status_led
interval:
# Heartbeat LED blink while awake
- interval: 30s
then:
- output.turn_on: status_led
- delay: 100ms
- output.turn_off: status_led
# Mail notification - sends 3x packets, then sleeps
- interval: 10s
startup_delay: 10s
then:
- if:
condition:
lambda: 'return !id(packets_sent);'
then:
- lambda: 'id(packets_sent) = true;'
- repeat:
count: 3
then:
- sx126x.send_packet:
id: lora_radio
data: !lambda |-
float voltage = id(bat_voltage).state;
char msg[24];
if (voltage < 3.4) {
snprintf(msg, sizeof(msg), "1|%.2f|LOW_BAT", voltage);
} else {
snprintf(msg, sizeof(msg), "1|%.2f", voltage);
}
std::string s(msg);
return std::vector<uint8_t>(s.begin(), s.end());
- output.turn_on: status_led
- delay: 150ms
- output.turn_off: status_led
- delay: 850ms
- sx126x.set_mode_sleep: lora_radio
- delay: 100ms
- deep_sleep.enter: deep_sleep_mode
# Lid open warning - if lid stays open 5 min, send warning
- interval: 60s
startup_delay: 300s
then:
- if:
condition:
lambda: 'return !id(warning_sent);'
then:
- lambda: 'id(warning_sent) = true;'
- repeat:
count: 3
then:
- sx126x.send_packet:
id: lora_radio
data: !lambda |-
float voltage = id(bat_voltage).state;
char msg[24];
snprintf(msg, sizeof(msg), "W|%.2f|LID_OPEN", voltage);
std::string s(msg);
return std::vector<uint8_t>(s.begin(), s.end());
- output.turn_on: status_led
- delay: 150ms
- output.turn_off: status_led
- delay: 850ms
- sx126x.set_mode_sleep: lora_radio
- delay: 100ms
- deep_sleep.enter: deep_sleep_mode