diff --git a/@bell/src/main.cpp b/@bell/src/main.cpp index 09b123a..1657350 100644 --- a/@bell/src/main.cpp +++ b/@bell/src/main.cpp @@ -51,7 +51,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/@postman/src/main.cpp b/@postman/src/main.cpp index 317e12c..b290260 100644 --- a/@postman/src/main.cpp +++ b/@postman/src/main.cpp @@ -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") // //======================== @@ -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. +// //==================== // #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("\".-.-.-. :)\""); diff --git a/audioooo/src/main.cpp b/audioooo/src/main.cpp index bb486c4..2e67aed 100644 --- a/audioooo/src/main.cpp +++ b/audioooo/src/main.cpp @@ -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("\".-.-.-. :)\""); diff --git a/broadcast/src/main.cpp b/broadcast/src/main.cpp index 26d639e..e778cdc 100644 --- a/broadcast/src/main.cpp +++ b/broadcast/src/main.cpp @@ -18,7 +18,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // //======================= diff --git a/crickets/src/main.cpp b/crickets/src/main.cpp index 1ec1fe7..90e63ad 100755 --- a/crickets/src/main.cpp +++ b/crickets/src/main.cpp @@ -51,7 +51,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/gong1/src/main.cpp b/gong1/src/main.cpp index f64a764..9db2354 100644 --- a/gong1/src/main.cpp +++ b/gong1/src/main.cpp @@ -57,7 +57,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/gonggong/src/main.cpp b/gonggong/src/main.cpp index 1649746..6fb2ff3 100644 --- a/gonggong/src/main.cpp +++ b/gonggong/src/main.cpp @@ -57,7 +57,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/osc8266/src/main.cpp b/osc8266/src/main.cpp index 52079d6..d85867b 100644 --- a/osc8266/src/main.cpp +++ b/osc8266/src/main.cpp @@ -57,7 +57,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/p/src/main.cpp b/p/src/main.cpp index 9a1fa50..a118234 100644 --- a/p/src/main.cpp +++ b/p/src/main.cpp @@ -39,7 +39,7 @@ // #define SCREEN_PERIOD (200) //200ms = 5hz // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/post.h b/post.h index 628e094..0b44bcd 100644 --- a/post.h +++ b/post.h @@ -8,6 +8,51 @@ //esp-now #include +// (DEBUG) fetch full peer list +#if defined(ARDUINO_ARCH_ESP32) // for esp32 API +#include +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 +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; diff --git a/postman/src/main.cpp b/postman/src/main.cpp index 809dd36..a364dc8 100644 --- a/postman/src/main.cpp +++ b/postman/src/main.cpp @@ -54,7 +54,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/q/src/main.cpp b/q/src/main.cpp index be93ba5..8b4b1c9 100644 --- a/q/src/main.cpp +++ b/q/src/main.cpp @@ -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("\".-.-.-. :)\""); diff --git a/roller/src/main.cpp b/roller/src/main.cpp index 8174dee..4560202 100644 --- a/roller/src/main.cpp +++ b/roller/src/main.cpp @@ -51,7 +51,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/roller2/src/main.cpp b/roller2/src/main.cpp index 2c58967..880a9ce 100644 --- a/roller2/src/main.cpp +++ b/roller2/src/main.cpp @@ -51,7 +51,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/roundly/src/main.cpp b/roundly/src/main.cpp index d646f22..1c48d0b 100644 --- a/roundly/src/main.cpp +++ b/roundly/src/main.cpp @@ -51,7 +51,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/taak/src/main.cpp b/taak/src/main.cpp index 721e000..b1461b4 100644 --- a/taak/src/main.cpp +++ b/taak/src/main.cpp @@ -52,7 +52,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' // diff --git a/taak3/src/main.cpp b/taak3/src/main.cpp index 45a1f5f..c9b6d23 100644 --- a/taak3/src/main.cpp +++ b/taak3/src/main.cpp @@ -58,7 +58,7 @@ #define LED_ONTIME (1) #define LED_GAPTIME (222) // -#define WIFI_CHANNEL 5 +#define WIFI_CHANNEL 1 // // 'MONITORING_SERIAL' //