AddressLibrary added

This commit is contained in:
Dooho Yi 2021-02-21 12:58:32 +09:00
parent 591888b611
commit 774865b639
12 changed files with 346 additions and 199 deletions

View file

@ -26,7 +26,6 @@ default_envs = d1_mini_pro
framework = arduino
upload_port = /dev/ttyUSB0
lib_deps =
5825 ; Vector
721 ; TaskScheduler
[env:nodemcuv2]

View file

@ -59,6 +59,12 @@
//============<parameters>============
//
#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 <ESP8266WiFi.h>
@ -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,8 +288,30 @@ 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();
//
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
@ -297,6 +323,11 @@ void setup() {
// 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' ========");

View file

@ -26,7 +26,6 @@ default_envs = d1_mini_pro
framework = arduino
upload_port = /dev/ttyUSB0
lib_deps =
5825 ; Vector
721 ; TaskScheduler
[env:nodemcuv2]

View file

@ -54,6 +54,12 @@
//============<parameters>============
//
#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 <ESP8266WiFi.h>
@ -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,8 +423,30 @@ 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();
//
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
@ -432,6 +458,11 @@ void setup() {
// 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);

View file

@ -14,7 +14,6 @@ env_default = teensy36
[common]
lib_deps =
721@3.0.2 ; TaskScheduler
5825 ; Vector
; osc -> (already included in "framework-arduinoteensy")

136
post.h
View file

@ -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 <vector>
// '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 <Vector.h>
struct AddressBook {
Vector<Address> list;
String title;
std::vector<Address> 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) {
void add(Address addr) {
list.push_back(addr);
}
};
//
// with a 'booktitle' to select which addressebook to get.
// UNIMPLEMENTED
struct AddressLibrary {
//
std::vector<AddressBook> lib;
//
list.setStorage(lst);
AddressLibrary() {
// book #1
{
AddressBook book = AddressBook("root");
//
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"));
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 + ']'

View file

@ -26,7 +26,6 @@ default_envs = d1_mini_pro
framework = arduino
upload_port = /dev/ttyUSB0
lib_deps =
5825 ; Vector
721 ; TaskScheduler
[env:nodemcuv2]

View file

@ -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 @@
//============<parameters>============
//
// #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 <ESP8266WiFi.h>
@ -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,8 +282,30 @@ 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();
//
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
@ -296,6 +317,11 @@ void setup() {
// 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' ========");

View file

@ -26,7 +26,6 @@ default_envs = d1_mini_pro
framework = arduino
upload_port = /dev/ttyUSB0
lib_deps =
5825 ; Vector
721 ; TaskScheduler
[env:nodemcuv2]

View file

@ -59,6 +59,12 @@
//============<parameters>============
//
#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 <ESP8266WiFi.h>
@ -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,8 +346,30 @@ 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();
//
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
@ -355,6 +381,11 @@ void setup() {
// 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' ========");

View file

@ -26,7 +26,6 @@ default_envs = d1_mini_pro
framework = arduino
upload_port = /dev/ttyUSB0
lib_deps =
5825 ; Vector
721 ; TaskScheduler
[env:nodemcuv2]

View file

@ -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.
//==========<configurations>===========
//
@ -81,6 +59,12 @@
//============<parameters>============
//
#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 <ESP8266WiFi.h>
@ -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,8 +324,30 @@ 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();
//
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
@ -355,6 +359,11 @@ void setup() {
// 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' ========");