Skip to content

Commit df4723e

Browse files
committed
integrated pio libraries
1 parent d09be29 commit df4723e

File tree

14 files changed

+153
-13
lines changed

14 files changed

+153
-13
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"wifi":{
3+
"mode":"AP",
4+
"channel":8
5+
},
6+
"espnow":{
7+
"gateway":true
8+
},
9+
"mqtt" : {
10+
"host":"10.0.0.42",
11+
"port":1883,
12+
"client_id":"esp_now_g"
13+
}
14+
}

09_esp_now/platformio.ini renamed to 09_esp_now_broadcast/platformio.ini

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ lib_deps =
55
66
77
[email protected] #MQTT 256dpi/arduino-mqtt
8+
9+
810
lib_ldf_mode = deep+
911
[env:esp32dev]
1012
1113
platform_packages =
1214
1315
monitor_speed = 115200
1416
upload_speed = 460800
15-
upload_port = COM11
17+
upload_port = COM17

09_esp_now/src/main.cpp renamed to 09_esp_now_broadcast/src/main.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <ConfigUtils.h>
77
#include <EspNowWrapper.h>
8+
#include <ESPStringUtils.h>
89

910
DynamicJsonDocument config(5*1024);//5 KB
1011
DynamicJsonDocument secret(1*1024);//1 KB
@@ -14,8 +15,13 @@ NowApp espnow;
1415

1516
uint32_t cycle_count = 0;
1617

18+
//https://esp32.com/viewtopic.php?t=12992
19+
20+
String topic;
21+
1722
void meshMessage(String &payload,String from){
1823
Serial.printf("RX> from(%s) => [%s]\n",from.c_str(),payload.c_str());
24+
mqtt.publish("espnow/"+from,payload);
1925
}
2026

2127
void mqtt_start(DynamicJsonDocument &config){
@@ -25,6 +31,7 @@ void mqtt_start(DynamicJsonDocument &config){
2531
}
2632
}
2733

34+
2835
void setup() {
2936

3037
Serial.begin(115200);
@@ -36,19 +43,19 @@ void setup() {
3643

3744
String ssid = secret["wifi"]["access_point"];
3845
String pass = secret["wifi"]["password"];
39-
WiFi.begin(ssid.c_str(),pass.c_str());
40-
while (WiFi.status() != WL_CONNECTED) {
41-
Serial.print(".");
42-
delay(1000);
43-
}
46+
WiFi.mode(WIFI_MODE_STA);
4447
timelog("config loaded");
45-
mqtt_start(config);
46-
mqtt.publish("espnow","test");
47-
mqtt.loop();
48+
49+
50+
byte mac[6];
51+
WiFi.macAddress(mac);
52+
topic = "espnow/"+hextab_to_string(mac);
4853

4954
espnow.start(config,secret);
5055
espnow.onMessage(meshMessage);
5156

57+
espnow.set_channel(config["wifi"]["channel"]);
58+
5259
timelog("setup() done");
5360

5461
}
@@ -57,8 +64,6 @@ void loop() {
5764
cycle_count++;
5865
Serial.printf("\n\n");
5966
timelog("loop start cycle ("+String(cycle_count)+")");
60-
mqtt.publish("espnow","Mqtt("+String(cycle_count)+")");
61-
delay(1000);
6267
espnow.print_info();
6368
espnow.broadcast("Hello Everyone ("+String(cycle_count)+")");
6469
delay(5000);

10_esp_now_mqtt_gateway/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.pio
2+
.vscode
3+
*.log
4+
lib

10_esp_now_mqtt_gateway/README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
## Usage
2+
in terminal
3+
```console
4+
> pio lib install
5+
> pio run
6+
> pio run -t upload
7+
> pio run -t uploadfs
8+
> pio run -t monitor
9+
```
10+
11+
# References
12+
* [docs.espressif esp32 api-reference esp-now](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/network/esp_now.html)
13+
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
secret.json

0 commit comments

Comments
 (0)