diff --git a/crickets/platformio.ini b/crickets/platformio.ini index c141c6c..bfecb36 100755 --- a/crickets/platformio.ini +++ b/crickets/platformio.ini @@ -26,7 +26,6 @@ default_envs = d1_mini_pro framework = arduino upload_port = /dev/ttyUSB0 lib_deps = - 5825 ; Vector 721 ; TaskScheduler [env:nodemcuv2] diff --git a/crickets/src/main.cpp b/crickets/src/main.cpp index 4c14426..c6b07bd 100755 --- a/crickets/src/main.cpp +++ b/crickets/src/main.cpp @@ -59,6 +59,12 @@ //======================== // +#define MY_BOOK ("root") +// #define MY_BOOK ("friend") +// #define MY_BOOK ("sampler") +// +#define PEER_COUNT_MAX (20) +// #define LED_PERIOD (11111) #define LED_ONTIME (1) #define LED_GAPTIME (222) @@ -93,7 +99,7 @@ //post & addresses #include "../../post.h" -AddressBook members; +AddressLibrary library; //espnow #include @@ -253,16 +259,14 @@ void setup() { Serial.println("- ======== 'DISABLE_AP' ========"); #endif Serial.println("-"); - Serial.println("- * addresses >>>"); - for (uint32_t i = 0; i < members.list.size(); i++) { - Serial.print("- #" + String(i) + " : "); - Serial.print(members.list[i].mac[0], HEX); - for (int j = 1; j < 6; j++) { - Serial.print(":"); - Serial.print(members.list[i].mac[j], HEX); + Serial.println("- * address library >>>"); + for (uint32_t j = 0; j < library.lib.size(); j++) { + Serial.println("-"); + Serial.println("- * (" + String(j + 1) + ") - \"" + library.lib[j].title + "\" >>>"); + Serial.println("-"); + for (uint32_t i = 0; i < library.lib[j].list.size(); i++) { + Serial.println("- " + library.lib[j].list[i].to_string()); } - Serial.print(" ==> " + members.list[i].name); - Serial.println(); } Serial.println("-"); Serial.println("\".-.-.-. :)\""); @@ -284,19 +288,46 @@ void setup() { esp_now_set_self_role(ESP_NOW_ROLE_COMBO); esp_now_register_send_cb(onDataSent); esp_now_register_recv_cb(onDataReceive); - for (uint32_t i = 0; i < members.list.size(); i++) { - esp_now_add_peer(members.list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + + // + AddressBook* members = library.getBookByTitle(MY_BOOK); + Serial.println("! registering peers in the book titled: \"" + String(MY_BOOK) + "\""); + + // + if (members == NULL) { + //oh, no such book! + Serial.println("---- :( oh, no such book! ===> " + String(MY_BOOK)); + Serial.println(" .... no peer will be registered. come back with different 'title' !"); + } else { + Serial.println("---- :) oki-doki, found it!"); + Serial.println(); // - // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) - // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf - // - // "Channel does not affect any function, but only stores the channel information - // for the application layer. The value is defined by the application layer. For - // example, 0 means that the channel is not defined; 1 ~ 14 mean valid - // channels; all the rest values can be assigned functions that are specified - // by the application layer." - // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + for (uint32_t i = 0; i < members->list.size(); i++) { + if (i >= PEER_COUNT_MAX) { + Serial.println("(!) @@@@ Hey, no more free-slot. @@@@ ==> " + members->list[i].to_string() + " ==> IGNORED :("); + } else { + //some decoration? + Serial.print("" + String((i + 1)%10) + "_ "); + for (uint32_t k = 0; k < i; k++) Serial.print(" "); + // + Serial.println("~~>> 'esp_now_add_peer' with ... " + members->list[i].to_string()); + esp_now_add_peer(members->list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + // + // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) + // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf + // + // "Channel does not affect any function, but only stores the channel information + // for the application layer. The value is defined by the application layer. For + // example, 0 means that the channel is not defined; 1 ~ 14 mean valid + // channels; all the rest values can be assigned functions that are specified + // by the application layer." + // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + } + } } + Serial.println("-"); + Serial.println("\".-.-.-. :)\""); + Serial.println(); #if defined(SERIAL_SWAP) Serial.println("- ======== 'SERIAL_SWAP' ========"); diff --git a/gonggong/platformio.ini b/gonggong/platformio.ini index c141c6c..bfecb36 100644 --- a/gonggong/platformio.ini +++ b/gonggong/platformio.ini @@ -26,7 +26,6 @@ default_envs = d1_mini_pro framework = arduino upload_port = /dev/ttyUSB0 lib_deps = - 5825 ; Vector 721 ; TaskScheduler [env:nodemcuv2] diff --git a/gonggong/src/main.cpp b/gonggong/src/main.cpp index 3903f0e..a27b114 100644 --- a/gonggong/src/main.cpp +++ b/gonggong/src/main.cpp @@ -54,6 +54,12 @@ //======================== // +#define MY_BOOK ("root") +// #define MY_BOOK ("friend") +// #define MY_BOOK ("sampler") +// +#define PEER_COUNT_MAX (20) +// #define LED_PERIOD (11111) #define LED_ONTIME (1) #define LED_GAPTIME (222) @@ -88,7 +94,7 @@ //post & addresses #include "../../post.h" -AddressBook members; +AddressLibrary library; //espnow #include @@ -388,16 +394,14 @@ void setup() { Serial.println("- ======== 'DISABLE_AP' ========"); #endif Serial.println("-"); - Serial.println("- * addresses >>>"); - for (uint32_t i = 0; i < members.list.size(); i++) { - Serial.print("- #" + String(i) + " : "); - Serial.print(members.list[i].mac[0], HEX); - for (int j = 1; j < 6; j++) { - Serial.print(":"); - Serial.print(members.list[i].mac[j], HEX); + Serial.println("- * address library >>>"); + for (uint32_t j = 0; j < library.lib.size(); j++) { + Serial.println("-"); + Serial.println("- * (" + String(j + 1) + ") - \"" + library.lib[j].title + "\" >>>"); + Serial.println("-"); + for (uint32_t i = 0; i < library.lib[j].list.size(); i++) { + Serial.println("- " + library.lib[j].list[i].to_string()); } - Serial.print(" ==> " + members.list[i].name); - Serial.println(); } Serial.println("-"); Serial.println("\".-.-.-. :)\""); @@ -419,19 +423,46 @@ void setup() { esp_now_set_self_role(ESP_NOW_ROLE_COMBO); esp_now_register_send_cb(onDataSent); esp_now_register_recv_cb(onDataReceive); - for (uint32_t i = 0; i < members.list.size(); i++) { - esp_now_add_peer(members.list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + + // + AddressBook* members = library.getBookByTitle(MY_BOOK); + Serial.println("! registering peers in the book titled: \"" + String(MY_BOOK) + "\""); + + // + if (members == NULL) { + //oh, no such book! + Serial.println("---- :( oh, no such book! ===> " + String(MY_BOOK)); + Serial.println(" .... no peer will be registered. come back with different 'title' !"); + } else { + Serial.println("---- :) oki-doki, found it!"); + Serial.println(); // - // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) - // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf - // - // "Channel does not affect any function, but only stores the channel information - // for the application layer. The value is defined by the application layer. For - // example, 0 means that the channel is not defined; 1 ~ 14 mean valid - // channels; all the rest values can be assigned functions that are specified - // by the application layer." - // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + for (uint32_t i = 0; i < members->list.size(); i++) { + if (i >= PEER_COUNT_MAX) { + Serial.println("(!) @@@@ Hey, no more free-slot. @@@@ ==> " + members->list[i].to_string() + " ==> IGNORED :("); + } else { + //some decoration? + Serial.print("" + String((i + 1)%10) + "_ "); + for (uint32_t k = 0; k < i; k++) Serial.print(" "); + // + Serial.println("~~>> 'esp_now_add_peer' with ... " + members->list[i].to_string()); + esp_now_add_peer(members->list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + // + // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) + // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf + // + // "Channel does not affect any function, but only stores the channel information + // for the application layer. The value is defined by the application layer. For + // example, 0 means that the channel is not defined; 1 ~ 14 mean valid + // channels; all the rest values can be assigned functions that are specified + // by the application layer." + // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + } + } } + Serial.println("-"); + Serial.println("\".-.-.-. :)\""); + Serial.println(); #if defined(SERIAL_SWAP) Serial.println("- ======== 'SERIAL_SWAP' ========"); @@ -447,6 +478,9 @@ void setup() { delay(100); // wait re-initialization of the 'Serial' #endif + //random seed + randomSeed(analogRead(0)); + //tasks runner.addTask(ring_side_task); runner.addTask(ring_side_move_task); diff --git a/osc/platformio.ini b/osc/platformio.ini index 8efef27..3fa1016 100644 --- a/osc/platformio.ini +++ b/osc/platformio.ini @@ -14,7 +14,6 @@ env_default = teensy36 [common] lib_deps = 721@3.0.2 ; TaskScheduler - 5825 ; Vector ; osc -> (already included in "framework-arduinoteensy") diff --git a/post.h b/post.h index 2d151ee..1a1a1d9 100644 --- a/post.h +++ b/post.h @@ -1,12 +1,14 @@ #pragma once -//obsolete +//obsolete (@sampler still ues this) #define I2C_ADDR 3 #define POST_LENGTH 32 #define POST_BUFF_LEN (POST_LENGTH + 1) //esp-now -#define MEMBER_COUNT_MAX (20) +#include + +// 'address' struct Address { String name; uint8_t mac[6]; @@ -28,74 +30,94 @@ struct Address { mac[5] = f; name = n; } + // + String to_string() { + char mac_cstr[18]; // "AA:BB:CC:AA:BB:CC" + snprintf(mac_cstr, 18, "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + return (String(mac_cstr) + " ==> " + name); + } }; -#include struct AddressBook { - Vector
list; + String title; + std::vector
list; // - AddressBook() { - // - list.setStorage(lst); - // - // list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0x21, "Enchovy")); - // list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB3, 0xC5, "Schpaarow")); - // - - //roots - list.push_back(Address(0xB4, 0xE6, 0x2D, 0x37, 0x3B, 0x90, "root/osc")); - list.push_back(Address(0x68, 0xC6, 0x3A, 0xD7, 0x4D, 0x97, "root(2)/osc")); - - //green suitcase - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB4, 0x47, "cricket/124")); - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0x32, "cricket/127")); - - //gastank - list.push_back(Address(0x84, 0xCC, 0xA8, 0xAA, 0x56, 0x11, "taak/150")); - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0xCC, "cricket/128")); - - //roundlys - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB4, 0x64, "roundly/2000")); - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB8, 0x1E, "roundly/2001")); - - //buoyflys - list.push_back(Address(0x80, 0x7D, 0x3A, 0x58, 0x80, 0x30, "cricket/121")); - list.push_back(Address(0x84, 0xCC, 0xA8, 0xAA, 0x4A, 0xCC, "cricket/122")); - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB3, 0xD4, "cricket/123")); - - //blue drummer - list.push_back(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB4, 0xB8, "cricket/120")); - list.push_back(Address(0x84, 0xCC, 0xA8, 0xA3, 0x83, 0x80, "taak/154")); - - //frog eyes - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0xCF, "taak/151")); - - //untitled - yet - list.push_back(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB9, 0xB4, "gonggong/1000")); - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB4, 0x28, "taak/157")); - - //yellow - list.push_back(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB3, 0xEF, "cricket/125")); - list.push_back(Address(0x84, 0xCC, 0xA8, 0xAA, 0x78, 0x87, "cricket/126")); - + AddressBook (String title_ = "") { + title = title_; } // - AddressBook(String booktitle) { - // - // with a 'booktitle' to select which addressebook to get. - // UNIMPLEMENTED - // - // - list.setStorage(lst); - // - if (booktitle == "root") { - list.push_back(Address(0xB4, 0xE6, 0x2D, 0x37, 0x3B, 0x90, "root/osc")); - list.push_back(Address(0x68, 0xC6, 0x3A, 0xD7, 0x4D, 0x97, "root(2)/osc")); + void add(Address addr) { + list.push_back(addr); + } +}; + +// +struct AddressLibrary { + // + std::vector lib; + // + AddressLibrary() { + + // book #1 + { + AddressBook book = AddressBook("root"); + // + book.add(Address(0xB4, 0xE6, 0x2D, 0x37, 0x3B, 0x90, "root/osc")); + book.add(Address(0x68, 0xC6, 0x3A, 0xD7, 0x4D, 0x97, "root(2)/osc")); + // + lib.push_back(book); + } + // book #2 + { + AddressBook book = AddressBook("friend"); + // + // 01 - 10 + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB4, 0x47, "green suitcase - cricket/124")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0x32, "green suitcase - cricket/127")); + book.add(Address(0x84, 0xCC, 0xA8, 0xAA, 0x56, 0x11, "gastank - taak/150")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0xCC, "gastank - cricket/128")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB4, 0x64, "roundlys - roundly/2000")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB8, 0x1E, "roundlys - roundly/2001")); + book.add(Address(0x80, 0x7D, 0x3A, 0x58, 0x80, 0x30, "buoyfly - cricket/121")); + book.add(Address(0x84, 0xCC, 0xA8, 0xAA, 0x4A, 0xCC, "buoyfly - cricket/122")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB3, 0xD4, "buoyfly - cricket/123")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB3, 0xE2, "buoyfly - cricket/129")); + // 11 - 20 + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB6, 0xC6, "buoyfly - cricket/130")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0xA3, "buoyfly - cricket/131")); + book.add(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB4, 0xB8, "blue drummer - cricket/120")); + book.add(Address(0x84, 0xCC, 0xA8, 0xA3, 0x83, 0x80, "blue drummer - taak/154")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB7, 0xCF, "blue drummer - taak/153")); + book.add(Address(0x84, 0xCC, 0xA8, 0xAA, 0x17, 0x8D, "frog eyes - taak/151")); + book.add(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB9, 0xB4, "untitled - gonggong/1000")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB4, 0x28, "beak - taak/157")); + book.add(Address(0xF4, 0xCF, 0xA2, 0xED, 0xB3, 0xEF, "yellow - cricket/125")); + book.add(Address(0x84, 0xCC, 0xA8, 0xAA, 0x78, 0x87, "yellow - cricket/126")); + // + lib.push_back(book); + } + // book #3 + { + AddressBook book = AddressBook("sampler"); + // + // samplers don't have ID_KEY, they will just get all messages, + // then open the content to get **midi** 'key' in the 'note' message. + book.add(Address(0xBC, 0xDD, 0xC2, 0xB2, 0xAF, 0xD4, "@postman for @sampler")); + // + lib.push_back(book); } } -private: - Address lst[MEMBER_COUNT_MAX]; //<-- the storage array of 'list' + // + AddressBook* getBookByTitle(String title_) { + for (uint32_t i = 0; i < lib.size(); i++) { + if (lib[i].title == title_) { + return &(lib[i]); + } + } + // + return NULL; + } }; //message type Note : '[' + Note + ']' diff --git a/postman/platformio.ini b/postman/platformio.ini index c141c6c..bfecb36 100644 --- a/postman/platformio.ini +++ b/postman/platformio.ini @@ -26,7 +26,6 @@ default_envs = d1_mini_pro framework = arduino upload_port = /dev/ttyUSB0 lib_deps = - 5825 ; Vector 721 ; TaskScheduler [env:nodemcuv2] diff --git a/postman/src/main.cpp b/postman/src/main.cpp index 83adee5..0027795 100644 --- a/postman/src/main.cpp +++ b/postman/src/main.cpp @@ -52,11 +52,6 @@ #elif 1 #define SERIAL_SWAP #define HAVE_CLIENT -// (3) sampler client -#elif 0 -#define SERIAL_SWAP -#define HAVE_CLIENT -#define DISABLE_AP // #endif // @@ -64,6 +59,12 @@ //======================== // +// #define MY_BOOK ("root") +// #define MY_BOOK ("friend") +#define MY_BOOK ("sampler") +// +#define PEER_COUNT_MAX (20) +// #define LED_PERIOD (11111) #define LED_ONTIME (1) #define LED_GAPTIME (222) @@ -98,7 +99,7 @@ //post & addresses #include "../../post.h" -AddressBook members; +AddressLibrary library; //espnow #include @@ -252,16 +253,14 @@ void setup() { Serial.println("- ======== 'DISABLE_AP' ========"); #endif Serial.println("-"); - Serial.println("- * addresses >>>"); - for (uint32_t i = 0; i < members.list.size(); i++) { - Serial.print("- #" + String(i) + " : "); - Serial.print(members.list[i].mac[0], HEX); - for (int j = 1; j < 6; j++) { - Serial.print(":"); - Serial.print(members.list[i].mac[j], HEX); + Serial.println("- * address library >>>"); + for (uint32_t j = 0; j < library.lib.size(); j++) { + Serial.println("-"); + Serial.println("- * (" + String(j + 1) + ") - \"" + library.lib[j].title + "\" >>>"); + Serial.println("-"); + for (uint32_t i = 0; i < library.lib[j].list.size(); i++) { + Serial.println("- " + library.lib[j].list[i].to_string()); } - Serial.print(" ==> " + members.list[i].name); - Serial.println(); } Serial.println("-"); Serial.println("\".-.-.-. :)\""); @@ -283,19 +282,46 @@ void setup() { esp_now_set_self_role(ESP_NOW_ROLE_COMBO); esp_now_register_send_cb(onDataSent); esp_now_register_recv_cb(onDataReceive); - for (uint32_t i = 0; i < members.list.size(); i++) { - esp_now_add_peer(members.list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + + // + AddressBook* members = library.getBookByTitle(MY_BOOK); + Serial.println("! registering peers in the book titled: \"" + String(MY_BOOK) + "\""); + + // + if (members == NULL) { + //oh, no such book! + Serial.println("---- :( oh, no such book! ===> " + String(MY_BOOK)); + Serial.println(" .... no peer will be registered. come back with different 'title' !"); + } else { + Serial.println("---- :) oki-doki, found it!"); + Serial.println(); // - // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) - // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf - // - // "Channel does not affect any function, but only stores the channel information - // for the application layer. The value is defined by the application layer. For - // example, 0 means that the channel is not defined; 1 ~ 14 mean valid - // channels; all the rest values can be assigned functions that are specified - // by the application layer." - // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + for (uint32_t i = 0; i < members->list.size(); i++) { + if (i >= PEER_COUNT_MAX) { + Serial.println("(!) @@@@ Hey, no more free-slot. @@@@ ==> " + members->list[i].to_string() + " ==> IGNORED :("); + } else { + //some decoration? + Serial.print("" + String((i + 1)%10) + "_ "); + for (uint32_t k = 0; k < i; k++) Serial.print(" "); + // + Serial.println("~~>> 'esp_now_add_peer' with ... " + members->list[i].to_string()); + esp_now_add_peer(members->list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + // + // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) + // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf + // + // "Channel does not affect any function, but only stores the channel information + // for the application layer. The value is defined by the application layer. For + // example, 0 means that the channel is not defined; 1 ~ 14 mean valid + // channels; all the rest values can be assigned functions that are specified + // by the application layer." + // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + } + } } + Serial.println("-"); + Serial.println("\".-.-.-. :)\""); + Serial.println(); #if defined(SERIAL_SWAP) Serial.println("- ======== 'SERIAL_SWAP' ========"); diff --git a/roundly/platformio.ini b/roundly/platformio.ini index c141c6c..bfecb36 100644 --- a/roundly/platformio.ini +++ b/roundly/platformio.ini @@ -26,7 +26,6 @@ default_envs = d1_mini_pro framework = arduino upload_port = /dev/ttyUSB0 lib_deps = - 5825 ; Vector 721 ; TaskScheduler [env:nodemcuv2] diff --git a/roundly/src/main.cpp b/roundly/src/main.cpp index a8c52bc..231e994 100644 --- a/roundly/src/main.cpp +++ b/roundly/src/main.cpp @@ -59,6 +59,12 @@ //======================== // +#define MY_BOOK ("root") +// #define MY_BOOK ("friend") +// #define MY_BOOK ("sampler") +// +#define PEER_COUNT_MAX (20) +// #define LED_PERIOD (11111) #define LED_ONTIME (1) #define LED_GAPTIME (222) @@ -93,7 +99,7 @@ //post & addresses #include "../../post.h" -AddressBook members; +AddressLibrary library; //espnow #include @@ -311,16 +317,14 @@ void setup() { Serial.println("- ======== 'DISABLE_AP' ========"); #endif Serial.println("-"); - Serial.println("- * addresses >>>"); - for (uint32_t i = 0; i < members.list.size(); i++) { - Serial.print("- #" + String(i) + " : "); - Serial.print(members.list[i].mac[0], HEX); - for (int j = 1; j < 6; j++) { - Serial.print(":"); - Serial.print(members.list[i].mac[j], HEX); + Serial.println("- * address library >>>"); + for (uint32_t j = 0; j < library.lib.size(); j++) { + Serial.println("-"); + Serial.println("- * (" + String(j + 1) + ") - \"" + library.lib[j].title + "\" >>>"); + Serial.println("-"); + for (uint32_t i = 0; i < library.lib[j].list.size(); i++) { + Serial.println("- " + library.lib[j].list[i].to_string()); } - Serial.print(" ==> " + members.list[i].name); - Serial.println(); } Serial.println("-"); Serial.println("\".-.-.-. :)\""); @@ -342,19 +346,46 @@ void setup() { esp_now_set_self_role(ESP_NOW_ROLE_COMBO); esp_now_register_send_cb(onDataSent); esp_now_register_recv_cb(onDataReceive); - for (uint32_t i = 0; i < members.list.size(); i++) { - esp_now_add_peer(members.list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + + // + AddressBook* members = library.getBookByTitle(MY_BOOK); + Serial.println("! registering peers in the book titled: \"" + String(MY_BOOK) + "\""); + + // + if (members == NULL) { + //oh, no such book! + Serial.println("---- :( oh, no such book! ===> " + String(MY_BOOK)); + Serial.println(" .... no peer will be registered. come back with different 'title' !"); + } else { + Serial.println("---- :) oki-doki, found it!"); + Serial.println(); // - // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) - // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf - // - // "Channel does not affect any function, but only stores the channel information - // for the application layer. The value is defined by the application layer. For - // example, 0 means that the channel is not defined; 1 ~ 14 mean valid - // channels; all the rest values can be assigned functions that are specified - // by the application layer." - // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + for (uint32_t i = 0; i < members->list.size(); i++) { + if (i >= PEER_COUNT_MAX) { + Serial.println("(!) @@@@ Hey, no more free-slot. @@@@ ==> " + members->list[i].to_string() + " ==> IGNORED :("); + } else { + //some decoration? + Serial.print("" + String((i + 1)%10) + "_ "); + for (uint32_t k = 0; k < i; k++) Serial.print(" "); + // + Serial.println("~~>> 'esp_now_add_peer' with ... " + members->list[i].to_string()); + esp_now_add_peer(members->list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + // + // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) + // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf + // + // "Channel does not affect any function, but only stores the channel information + // for the application layer. The value is defined by the application layer. For + // example, 0 means that the channel is not defined; 1 ~ 14 mean valid + // channels; all the rest values can be assigned functions that are specified + // by the application layer." + // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + } + } } + Serial.println("-"); + Serial.println("\".-.-.-. :)\""); + Serial.println(); #if defined(SERIAL_SWAP) Serial.println("- ======== 'SERIAL_SWAP' ========"); diff --git a/taak/platformio.ini b/taak/platformio.ini index c141c6c..bfecb36 100644 --- a/taak/platformio.ini +++ b/taak/platformio.ini @@ -26,7 +26,6 @@ default_envs = d1_mini_pro framework = arduino upload_port = /dev/ttyUSB0 lib_deps = - 5825 ; Vector 721 ; TaskScheduler [env:nodemcuv2] diff --git a/taak/src/main.cpp b/taak/src/main.cpp index 711fa1c..3485713 100644 --- a/taak/src/main.cpp +++ b/taak/src/main.cpp @@ -9,28 +9,6 @@ // // 2021 02 15 // -// (part-1) esp8266 : 'postman' (the esp-now network nodes) -// -// this module will be an esp-now node in a group. -// like, a bird in a group of birds. -// -// esp-now @ esp8266 DO support broadcast address (FF:FF:FF:FF:FF:FF) -// w/ NONOS-SDK of espressif -// and you can enable that w/ Platformio, applying some special build flags. -// --> https://github.com/esp8266/Arduino/issues/6174#issuecomment-509115454 -// (yet, w/ Arduino, this is not available yet.) -// -// so, at first, we will simply/stably go w/o broadcasting. -// and, if broadcast is really needed we can activate (@Platformio) -// - - -// we want to first osc -> esp-now -// then, esp-now based taak -// then, let is save a value in EEPROM (object with memory) -// no broadcast for now. if needed we can achieve that too. - - //===================== // @@ -81,6 +59,12 @@ //======================== // +#define MY_BOOK ("root") +// #define MY_BOOK ("friend") +// #define MY_BOOK ("sampler") +// +#define PEER_COUNT_MAX (20) +// #define LED_PERIOD (11111) #define LED_ONTIME (1) #define LED_GAPTIME (222) @@ -115,7 +99,7 @@ //post & addresses #include "../../post.h" -AddressBook members; +AddressLibrary library; //espnow #include @@ -311,16 +295,14 @@ void setup() { Serial.println("- ======== 'DISABLE_AP' ========"); #endif Serial.println("-"); - Serial.println("- * addresses >>>"); - for (uint32_t i = 0; i < members.list.size(); i++) { - Serial.print("- #" + String(i) + " : "); - Serial.print(members.list[i].mac[0], HEX); - for (int j = 1; j < 6; j++) { - Serial.print(":"); - Serial.print(members.list[i].mac[j], HEX); + Serial.println("- * address library >>>"); + for (uint32_t j = 0; j < library.lib.size(); j++) { + Serial.println("-"); + Serial.println("- * (" + String(j + 1) + ") - \"" + library.lib[j].title + "\" >>>"); + Serial.println("-"); + for (uint32_t i = 0; i < library.lib[j].list.size(); i++) { + Serial.println("- " + library.lib[j].list[i].to_string()); } - Serial.print(" ==> " + members.list[i].name); - Serial.println(); } Serial.println("-"); Serial.println("\".-.-.-. :)\""); @@ -342,19 +324,46 @@ void setup() { esp_now_set_self_role(ESP_NOW_ROLE_COMBO); esp_now_register_send_cb(onDataSent); esp_now_register_recv_cb(onDataReceive); - for (uint32_t i = 0; i < members.list.size(); i++) { - esp_now_add_peer(members.list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + + // + AddressBook* members = library.getBookByTitle(MY_BOOK); + Serial.println("! registering peers in the book titled: \"" + String(MY_BOOK) + "\""); + + // + if (members == NULL) { + //oh, no such book! + Serial.println("---- :( oh, no such book! ===> " + String(MY_BOOK)); + Serial.println(" .... no peer will be registered. come back with different 'title' !"); + } else { + Serial.println("---- :) oki-doki, found it!"); + Serial.println(); // - // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) - // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf - // - // "Channel does not affect any function, but only stores the channel information - // for the application layer. The value is defined by the application layer. For - // example, 0 means that the channel is not defined; 1 ~ 14 mean valid - // channels; all the rest values can be assigned functions that are specified - // by the application layer." - // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + for (uint32_t i = 0; i < members->list.size(); i++) { + if (i >= PEER_COUNT_MAX) { + Serial.println("(!) @@@@ Hey, no more free-slot. @@@@ ==> " + members->list[i].to_string() + " ==> IGNORED :("); + } else { + //some decoration? + Serial.print("" + String((i + 1)%10) + "_ "); + for (uint32_t k = 0; k < i; k++) Serial.print(" "); + // + Serial.println("~~>> 'esp_now_add_peer' with ... " + members->list[i].to_string()); + esp_now_add_peer(members->list[i].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0); // <-- '1' : "Channel does not affect any function" ... *.-a + // + // int esp_now_add_peer(u8 *mac_addr, u8 role, u8 channel, u8 *key, u8 key_len) + // - https://www.espressif.com/sites/default/files/documentation/2c-esp8266_non_os_sdk_api_reference_en.pdf + // + // "Channel does not affect any function, but only stores the channel information + // for the application layer. The value is defined by the application layer. For + // example, 0 means that the channel is not defined; 1 ~ 14 mean valid + // channels; all the rest values can be assigned functions that are specified + // by the application layer." + // - https://www.espressif.com/sites/default/files/documentation/esp-now_user_guide_en.pdf + } + } } + Serial.println("-"); + Serial.println("\".-.-.-. :)\""); + Serial.println(); #if defined(SERIAL_SWAP) Serial.println("- ======== 'SERIAL_SWAP' ========");