updates for simpler communication
+ peer book listing (debug) + no addressbook/peer list -> all go broadcast! + wifi_channel == 1 for later (https://github.com/espressif/arduino-esp32/issues/878#issuecomment-578885352)
This commit is contained in:
parent
7db9b9a374
commit
288ddd88d5
17 changed files with 92 additions and 85 deletions
|
|
@ -51,7 +51,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@
|
|||
#define MY_GROUP_ID (10000)
|
||||
#define MY_ID (MY_GROUP_ID + 1)
|
||||
#define MY_SIGN ("@POSTMAN|@SAMPLER")
|
||||
//
|
||||
#define ADDRESSBOOK_TITLE ("broadcast only")
|
||||
//
|
||||
//============</identities>============
|
||||
|
|
@ -51,6 +50,10 @@
|
|||
// 'HAVE_CLIENT_I2C'
|
||||
// --> i have a client w/ I2C i/f. enable the I2C client task.
|
||||
//
|
||||
// 'ADDRESSBOOK_TITLE'
|
||||
// --> peer list limited max. 20.
|
||||
// so, we might use different address books for each node to cover a network of more than 20 nodes.
|
||||
//
|
||||
//==========</list-of-configurations>==========
|
||||
//
|
||||
#define HAVE_CLIENT_I2C
|
||||
|
|
@ -64,7 +67,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
@ -370,32 +373,14 @@ void setup() {
|
|||
esp_now_register_send_cb(onDataSent);
|
||||
esp_now_register_recv_cb(onDataReceive);
|
||||
|
||||
//fetch & read addressbook
|
||||
String addressbook_title = ADDRESSBOOK_TITLE;
|
||||
// #if defined(ADDRESSBOOK_TITLE_CLI)
|
||||
// addressbook_title = ADDRESSBOOK_TITLE_CLI;
|
||||
// #endif
|
||||
//
|
||||
// NOTE: there is a way to give a define value here like:
|
||||
// export PLATFORMIO_SRC_BUILD_FLAGS="'-DADDRESSBOOK_TITLE_CLI=\"broadcast only\"'" && pio run
|
||||
// but, everytime i change this, whole arduino framework + libraries rebuild.
|
||||
// PLATFORMIO_SRC_BUILD_FLAGS supposed to work only to src/ but strange.
|
||||
// this takes up too much time, not really haptic. later, investigate the issues.
|
||||
//
|
||||
AddressBook * book = lib.getBookByTitle(addressbook_title);
|
||||
AddressBook * book = lib.getBookByTitle(ADDRESSBOOK_TITLE);
|
||||
if (book == NULL) {
|
||||
Serial.println("- ! wrong book !! :" + addressbook_title); while(1);
|
||||
} else {
|
||||
Serial.println("- ! reading book ....");
|
||||
Serial.println(" -----------------");
|
||||
Serial.println(" { " + addressbook_title + " }");
|
||||
Serial.println(" -----------------");
|
||||
Serial.println();
|
||||
Serial.println("- ! wrong book !! : \"" + String(ADDRESSBOOK_TITLE) + "\""); while(1);
|
||||
}
|
||||
for (int idx = 0; idx < book->list.size(); idx++) {
|
||||
Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'.");
|
||||
#if defined(ESP32)
|
||||
esp_now_peer_info_t peerInfo;
|
||||
esp_now_peer_info_t peerInfo = {};
|
||||
memcpy(peerInfo.peer_addr, book->list[idx].mac, 6);
|
||||
peerInfo.channel = 0;
|
||||
peerInfo.encrypt = false;
|
||||
|
|
@ -404,6 +389,8 @@ void setup() {
|
|||
esp_now_add_peer(book->list[idx].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
||||
#endif
|
||||
}
|
||||
// (DEBUG) fetch full peer list
|
||||
{ PeerLister a; a.print(); }
|
||||
//
|
||||
Serial.println("-");
|
||||
Serial.println("\".-.-.-. :)\"");
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
//
|
||||
#define SCREEN_PERIOD (200) //200ms = 5hz
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
@ -264,23 +264,10 @@ void repeat() {
|
|||
esp_now_send(broadcastmac, frm, frm_size);
|
||||
|
||||
// (DEBUG) fetch full peer list
|
||||
esp_now_peer_num_t num;
|
||||
esp_now_get_peer_num(&num);
|
||||
esp_now_peer_info_t peer_info;
|
||||
bool first = true;
|
||||
for (uint8_t ii = 0; ii < num.total_num; ii++) {
|
||||
esp_now_fetch_peer(first, &peer_info);
|
||||
if (first) first = false;
|
||||
MONITORING_SERIAL.printf("# peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
peer_info.peer_addr[0],
|
||||
peer_info.peer_addr[1],
|
||||
peer_info.peer_addr[2],
|
||||
peer_info.peer_addr[3],
|
||||
peer_info.peer_addr[4],
|
||||
peer_info.peer_addr[5]);
|
||||
}
|
||||
{ PeerLister a; a.print(); }
|
||||
|
||||
//
|
||||
MONITORING_SERIAL.print("repeat! ==> ");
|
||||
MONITORING_SERIAL.print("\nrepeat! ==> ");
|
||||
MONITORING_SERIAL.println(note_now.to_string());
|
||||
}
|
||||
Task repeat_task(0, TASK_ONCE, &repeat, &runner, false);
|
||||
|
|
@ -561,6 +548,9 @@ void setup() {
|
|||
// esp_now_add_peer(&peerInfo);
|
||||
|
||||
AddressBook * book = lib.getBookByTitle(ADDRESSBOOK_TITLE);
|
||||
if (book == NULL) {
|
||||
Serial.println("- ! wrong book !! : \"" + String(ADDRESSBOOK_TITLE) + "\""); while(1);
|
||||
}
|
||||
for (int idx = 0; idx < book->list.size(); idx++) {
|
||||
Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'.");
|
||||
esp_now_peer_info_t peerInfo = {};
|
||||
|
|
@ -569,6 +559,8 @@ void setup() {
|
|||
peerInfo.encrypt = false;
|
||||
esp_now_add_peer(&peerInfo);
|
||||
}
|
||||
// (DEBUG) fetch full peer list
|
||||
{ PeerLister a; a.print(); }
|
||||
//
|
||||
Serial.println("-");
|
||||
Serial.println("\".-.-.-. :)\"");
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
//============</parameters>===========
|
||||
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@
|
|||
//
|
||||
#define SCREEN_PERIOD (200) //200ms = 5hz
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
45
post.h
45
post.h
|
|
@ -8,6 +8,51 @@
|
|||
//esp-now
|
||||
#include <vector>
|
||||
|
||||
// (DEBUG) fetch full peer list
|
||||
#if defined(ARDUINO_ARCH_ESP32) // for esp32 API
|
||||
#include <esp_now.h>
|
||||
struct PeerLister {
|
||||
void print() {
|
||||
Serial.printf("\n# (DEBUG) peer list (NOTE: a broadcast peer won't be listed properly)\n");
|
||||
esp_now_peer_num_t num;
|
||||
esp_now_get_peer_num(&num);
|
||||
esp_now_peer_info_t peer_info = {};
|
||||
bool first = true;
|
||||
for (uint8_t ii = 0; ii < num.total_num; ii++) {
|
||||
esp_now_fetch_peer(first, &peer_info);
|
||||
if (first) first = false;
|
||||
Serial.printf("# peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
peer_info.peer_addr[0],
|
||||
peer_info.peer_addr[1],
|
||||
peer_info.peer_addr[2],
|
||||
peer_info.peer_addr[3],
|
||||
peer_info.peer_addr[4],
|
||||
peer_info.peer_addr[5]);
|
||||
}
|
||||
}
|
||||
};
|
||||
#elif defined(ARDUINO_ARCH_ESP8266) // for esp8266 API
|
||||
#include <espnow.h>
|
||||
struct PeerLister {
|
||||
void print() {
|
||||
Serial.printf("\n# (DEBUG) peer list\n");
|
||||
bool first = true;
|
||||
uint8_t * peer_addr = NULL;
|
||||
while((peer_addr = esp_now_fetch_peer(first)) != NULL) {
|
||||
first = false;
|
||||
Serial.printf("# peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
peer_addr[0],
|
||||
peer_addr[1],
|
||||
peer_addr[2],
|
||||
peer_addr[3],
|
||||
peer_addr[4],
|
||||
peer_addr[5]);
|
||||
}
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
// 'address'
|
||||
struct Address {
|
||||
String name;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@
|
|||
//
|
||||
#define SCREEN_PERIOD (200) //200ms = 5hz
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
@ -262,21 +262,7 @@ void screen() {
|
|||
esp_now_send(broadcastmac, frm, frm_size);
|
||||
|
||||
// (DEBUG) fetch full peer list
|
||||
esp_now_peer_num_t num;
|
||||
esp_now_get_peer_num(&num);
|
||||
esp_now_peer_info_t peer_info;
|
||||
bool first = true;
|
||||
for (uint8_t ii = 0; ii < num.total_num; ii++) {
|
||||
esp_now_fetch_peer(first, &peer_info);
|
||||
if (first) first = false;
|
||||
MONITORING_SERIAL.printf("# peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
peer_info.peer_addr[0],
|
||||
peer_info.peer_addr[1],
|
||||
peer_info.peer_addr[2],
|
||||
peer_info.peer_addr[3],
|
||||
peer_info.peer_addr[4],
|
||||
peer_info.peer_addr[5]);
|
||||
}
|
||||
{ PeerLister a; a.print(); }
|
||||
|
||||
//+ play start for myself
|
||||
sample_now = song_request;
|
||||
|
|
@ -457,21 +443,8 @@ void repeat() {
|
|||
esp_now_send(broadcastmac, frm, frm_size);
|
||||
|
||||
// (DEBUG) fetch full peer list
|
||||
esp_now_peer_num_t num;
|
||||
esp_now_get_peer_num(&num);
|
||||
esp_now_peer_info_t peer_info;
|
||||
bool first = true;
|
||||
for (uint8_t ii = 0; ii < num.total_num; ii++) {
|
||||
esp_now_fetch_peer(first, &peer_info);
|
||||
if (first) first = false;
|
||||
MONITORING_SERIAL.printf("# peer: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
peer_info.peer_addr[0],
|
||||
peer_info.peer_addr[1],
|
||||
peer_info.peer_addr[2],
|
||||
peer_info.peer_addr[3],
|
||||
peer_info.peer_addr[4],
|
||||
peer_info.peer_addr[5]);
|
||||
}
|
||||
{ PeerLister a; a.print(); }
|
||||
|
||||
//
|
||||
MONITORING_SERIAL.print("repeat! ==> ");
|
||||
MONITORING_SERIAL.println(note_now.to_string());
|
||||
|
|
@ -504,7 +477,12 @@ void hello() {
|
|||
memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
|
||||
frm[frm_size - 1] = '}';
|
||||
//
|
||||
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||
// strange but following didn't work as expected. (instead, i have to send one-by-one.)
|
||||
// esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||
|
||||
// so, forget about peer list -> just pick a broadcast peer to be sent.
|
||||
uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
esp_now_send(broadcastmac, frm, frm_size);
|
||||
//
|
||||
// MONITORING_SERIAL.write(frm, frm_size);
|
||||
// MONITORING_SERIAL.println(" ==(esp_now_send/0)==> ");
|
||||
|
|
@ -760,6 +738,9 @@ void setup() {
|
|||
// esp_now_add_peer(&peerInfo);
|
||||
|
||||
AddressBook * book = lib.getBookByTitle(ADDRESSBOOK_TITLE);
|
||||
if (book == NULL) {
|
||||
Serial.println("- ! wrong book !! : \"" + String(ADDRESSBOOK_TITLE) + "\""); while(1);
|
||||
}
|
||||
for (int idx = 0; idx < book->list.size(); idx++) {
|
||||
Serial.println("- ! (esp_now_add_peer) ==> add a '" + book->list[idx].name + "'.");
|
||||
esp_now_peer_info_t peerInfo = {};
|
||||
|
|
@ -768,6 +749,8 @@ void setup() {
|
|||
peerInfo.encrypt = false;
|
||||
esp_now_add_peer(&peerInfo);
|
||||
}
|
||||
// (DEBUG) fetch full peer list
|
||||
{ PeerLister a; a.print(); }
|
||||
//
|
||||
Serial.println("-");
|
||||
Serial.println("\".-.-.-. :)\"");
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@
|
|||
#define LED_ONTIME (1)
|
||||
#define LED_GAPTIME (222)
|
||||
//
|
||||
#define WIFI_CHANNEL 5
|
||||
#define WIFI_CHANNEL 1
|
||||
//
|
||||
// 'MONITORING_SERIAL'
|
||||
//
|
||||
|
|
|
|||
Loading…
Reference in a new issue