blob: 46050c5a44fd8d1b5a6c63724ab0d2438d6c6970 (
plain)
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
|
# hello-t-energy-s3
T-Energy-S3 MQTT battery monitor. Connects to WiFi and publishes battery voltage over MQTT/TLS.
## Setup (one-time)
```bash
# Add ESP32 board manager
arduino-cli config init
arduino-cli config add board_manager.additional_urls https://espressif.github.io/arduino-esp32/package_esp32_index.json
# Install ESP32 core
arduino-cli core update-index
arduino-cli core install esp32:esp32
# Install PubSubClient library
arduino-cli lib install "PubSubClient"
```
## Configuration
Copy `config.example.h` to `config.h` and fill in your values:
```bash
cp config.example.h config.h
```
Then edit `config.h` with your WiFi and MQTT settings.
## Build & Upload
```bash
make compile # compile only
make upload # upload only
make monitor # serial monitor
make flash # compile + upload
make all # compile + upload + monitor
```
If your port differs from `/dev/ttyACM0`, override it:
```bash
make flash PORT=/dev/ttyUSB0
```
## Behavior
1. On boot: connects to WiFi and MQTT, publishes voltage 3 times
2. Enters deep sleep
3. Press BOOT button to wake
4. Repeat
## Expected Output
```
=== T-Energy-S3 MQTT Monitor ===
Initial boot
MAC Address: AA:BB:CC:DD:EE:FF
Connecting to MyNetwork...
Connected! IP: 192.168.1.100
Connecting to MQTT mqtt.example.com:8883...
MQTT connected!
Battery: 4200 mV
Published to my/topic: 4200
Battery: 4200 mV
Published to my/topic: 4200
Battery: 4200 mV
Published to my/topic: 4200
Entering deep sleep... press button to wake
```
|