teensy/esp8266 update
+ replicate msg. added.
This commit is contained in:
parent
40f7c3503e
commit
f66d5315f7
2 changed files with 95 additions and 15 deletions
|
|
@ -40,6 +40,12 @@
|
||||||
// 'DISABLE_AP'
|
// 'DISABLE_AP'
|
||||||
// --> (questioning)...
|
// --> (questioning)...
|
||||||
//
|
//
|
||||||
|
// 'REPLICATE_NOTE_REQ' (+ N_SEC_BLOCKING_NOTE_REQ)
|
||||||
|
// --> for supporting wider area with simple esp_now protocol,
|
||||||
|
// all receipents will replicate NOTE msg. when they are newly appeared.
|
||||||
|
// + then, network would be flooded by infinite duplicating msg.,
|
||||||
|
// unless they stop reacting to 'known' req. for some seconds. (e.g. 3 seconds)
|
||||||
|
|
||||||
// 'HAVE_CLIENT_I2C'
|
// 'HAVE_CLIENT_I2C'
|
||||||
// --> i have a client w/ I2C i/f. enable the I2C client task.
|
// --> i have a client w/ I2C i/f. enable the I2C client task.
|
||||||
//
|
//
|
||||||
|
|
@ -47,6 +53,7 @@
|
||||||
//
|
//
|
||||||
#define HAVE_CLIENT_I2C
|
#define HAVE_CLIENT_I2C
|
||||||
#define DISABLE_AP
|
#define DISABLE_AP
|
||||||
|
#define REPLICATE_NOTE_REQ
|
||||||
|
|
||||||
//============<parameters>============
|
//============<parameters>============
|
||||||
//
|
//
|
||||||
|
|
@ -91,11 +98,44 @@
|
||||||
//espnow
|
//espnow
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <espnow.h>
|
#include <espnow.h>
|
||||||
|
AddressLibrary lib;
|
||||||
|
|
||||||
//task
|
//task
|
||||||
#include <TaskScheduler.h>
|
#include <TaskScheduler.h>
|
||||||
Scheduler runner;
|
Scheduler runner;
|
||||||
|
|
||||||
|
//
|
||||||
|
#if defined(REPLICATE_NOTE_REQ)
|
||||||
|
Note note_now = {
|
||||||
|
-1, // int32_t id;
|
||||||
|
-1, // float pitch;
|
||||||
|
-1, // float velocity;
|
||||||
|
-1, // float onoff;
|
||||||
|
-1, // float x1;
|
||||||
|
-1, // float x2;
|
||||||
|
-1, // float x3;
|
||||||
|
-1, // float x4;
|
||||||
|
-1 // float ps;
|
||||||
|
};
|
||||||
|
#define NEW_NOTE_TIMEOUT (3000)
|
||||||
|
static unsigned long new_note_time = (-1*NEW_NOTE_TIMEOUT);
|
||||||
|
void repeat() {
|
||||||
|
//
|
||||||
|
uint8_t frm_size = sizeof(Note) + 2;
|
||||||
|
uint8_t frm[frm_size];
|
||||||
|
frm[0] = '[';
|
||||||
|
memcpy(frm + 1, (uint8_t *) ¬e_now, sizeof(Note));
|
||||||
|
frm[frm_size - 1] = ']';
|
||||||
|
//
|
||||||
|
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||||
|
//
|
||||||
|
MONITORING_SERIAL.print("repeat! ==> ");
|
||||||
|
MONITORING_SERIAL.println(note_now.to_string());
|
||||||
|
}
|
||||||
|
Task repeat_task(0, TASK_ONCE, &repeat, &runner, false);
|
||||||
|
#endif
|
||||||
|
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
|
|
||||||
//
|
//
|
||||||
extern Task hello_task;
|
extern Task hello_task;
|
||||||
static int hello_delay = 0;
|
static int hello_delay = 0;
|
||||||
|
|
@ -122,8 +162,8 @@ void hello() {
|
||||||
//
|
//
|
||||||
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
||||||
//
|
//
|
||||||
MONITORING_SERIAL.write(frm, frm_size);
|
// MONITORING_SERIAL.write(frm, frm_size);
|
||||||
MONITORING_SERIAL.println(" ==(esp_now_send/0)==> ");
|
// MONITORING_SERIAL.println(" ==(esp_now_send/0)==> ");
|
||||||
//
|
//
|
||||||
if (hello_delay > 0) {
|
if (hello_delay > 0) {
|
||||||
if (hello_delay < 100) hello_delay = 100;
|
if (hello_delay < 100) hello_delay = 100;
|
||||||
|
|
@ -188,6 +228,14 @@ void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
MONITORING_SERIAL.println(note.to_string());
|
MONITORING_SERIAL.println(note.to_string());
|
||||||
//
|
//
|
||||||
|
|
||||||
|
#if defined(REPLICATE_NOTE_REQ)
|
||||||
|
if (millis() - new_note_time > NEW_NOTE_TIMEOUT) {
|
||||||
|
note_now = note;
|
||||||
|
repeat_task.restart();
|
||||||
|
new_note_time = millis();
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(HAVE_CLIENT_I2C)
|
#if defined(HAVE_CLIENT_I2C)
|
||||||
|
|
||||||
//is this for me & my client?
|
//is this for me & my client?
|
||||||
|
|
@ -230,21 +278,15 @@ void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
hello_task.restart();
|
hello_task.restart();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//-*-*-*-*-*-*-*-*-*-
|
|
||||||
// use 'note' here...
|
|
||||||
// ==> N.B.: "callback function runs from a high-priority Wi-Fi task.
|
|
||||||
// So, do not do lengthy operations in the callback function.
|
|
||||||
// Instead, post the necessary data to a queue and handle it from a lower priority task."
|
|
||||||
//-*-*-*-*-*-*-*-*-*-
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
void onDataSent(uint8_t *mac_addr, uint8_t sendStatus) {
|
||||||
if (sendStatus != 0) MONITORING_SERIAL.println("Delivery failed!");
|
char buff[256] = "";
|
||||||
|
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac_addr[0], mac_addr[1], mac_addr[2], mac_addr[3], mac_addr[4], mac_addr[5]);
|
||||||
|
if (sendStatus != 0) MONITORING_SERIAL.println(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -275,6 +317,9 @@ void setup() {
|
||||||
#endif
|
#endif
|
||||||
#if defined(HAVE_CLIENT_I2C)
|
#if defined(HAVE_CLIENT_I2C)
|
||||||
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
|
Serial.println("- ======== 'HAVE_CLIENT_I2C' ========");
|
||||||
|
#endif
|
||||||
|
#if defined(REPLICATE_NOTE_REQ)
|
||||||
|
Serial.println("- ======== 'REPLICATE_NOTE_REQ' ========");
|
||||||
#endif
|
#endif
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
|
|
@ -295,10 +340,29 @@ void setup() {
|
||||||
esp_now_register_send_cb(onDataSent);
|
esp_now_register_send_cb(onDataSent);
|
||||||
esp_now_register_recv_cb(onDataReceive);
|
esp_now_register_recv_cb(onDataReceive);
|
||||||
//
|
//
|
||||||
Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
|
// Serial.println("- ! (esp_now_add_peer) ==> add a 'broadcast peer' (FF:FF:FF:FF:FF:FF).");
|
||||||
uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
// uint8_t broadcastmac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||||
esp_now_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
//
|
||||||
|
// //
|
||||||
|
// esp_now_peer_info_t peerInfo;
|
||||||
|
// memcpy(peerInfo.peer_addr, broadcastmac, 6);
|
||||||
|
// peerInfo.channel = 0;
|
||||||
|
// peerInfo.encrypt = false;
|
||||||
|
// esp_now_add_peer(&peerInfo);
|
||||||
|
|
||||||
|
AddressBook * book = lib.getBookByTitle("audioooo");
|
||||||
|
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;
|
||||||
|
memcpy(peerInfo.peer_addr, book->list[idx].mac, 6);
|
||||||
|
peerInfo.channel = 0;
|
||||||
|
peerInfo.encrypt = false;
|
||||||
|
esp_now_add_peer(&peerInfo);
|
||||||
|
#else
|
||||||
|
esp_now_add_peer(book->list[idx].mac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
//
|
//
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
|
|
|
||||||
18
post.h
18
post.h
|
|
@ -113,11 +113,27 @@ struct AddressLibrary {
|
||||||
//
|
//
|
||||||
// samplers don't have ID_KEY, they will just get all messages,
|
// samplers don't have ID_KEY, they will just get all messages,
|
||||||
// then open the content to get **midi** 'key' in the 'note' message.
|
// then open the content to get **midi** 'key' in the 'note' message.
|
||||||
book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAE, 0x0C, "audioooo #1")); //WROOM
|
book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAE, 0x0C, "audioooo #1 (Q)")); //WROOM
|
||||||
book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAD, 0xB0, "audioooo #2")); //WROOM
|
book.add(Address(0xAC, 0x67, 0xB2, 0x0B, 0xAD, 0xB0, "audioooo #2")); //WROOM
|
||||||
book.add(Address(0xA8, 0x03, 0x2A, 0x6C, 0x88, 0x78, "audioooo #3")); //WROVER
|
book.add(Address(0xA8, 0x03, 0x2A, 0x6C, 0x88, 0x78, "audioooo #3")); //WROVER
|
||||||
|
book.add(Address(0xA8, 0x03, 0x2A, 0x6C, 0x88, 0x5C, "audioooo #4")); //WROVER
|
||||||
|
book.add(Address(0xA8, 0x03, 0x2A, 0x75, 0xD0, 0x68, "audioooo #5")); //WROVER
|
||||||
//
|
//
|
||||||
book.add(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB4, 0xDD, "sampler #1")); //TEENSY+ESP8266
|
book.add(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB4, 0xDD, "sampler #1")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0xB4, 0xE6, 0x2D, 0x37, 0x37, 0xAE, "sampler #2")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0xEC, 0xFA, 0xBC, 0x63, 0x19, 0x84, "sampler #3")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB4, 0x19, "sampler #4")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0xDC, 0x4F, 0x22, 0x18, 0xD9, 0x1E, "sampler #5")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0x98, 0xF4, 0xAB, 0xB3, 0xB5, 0xC2, "sampler #6")); //TEENSY+ESP8266 (WIP)
|
||||||
|
book.add(Address(0xDC, 0x4F, 0x22, 0x19, 0xA5, 0x1C, "sampler #7")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0x68, 0xC6, 0x3A, 0xD5, 0x3E, 0xF3, "sampler #8")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0xB4, 0xE6, 0x2D, 0x37, 0x45, 0xF5, "sampler #9")); //TEENSY+ESP8266
|
||||||
|
book.add(Address(0xBC, 0xDD, 0xC2, 0xB2, 0xAF, 0xD4, "sampler #A")); //TEENSY+ESP8266 // <== 15 sets
|
||||||
|
// B
|
||||||
|
book.add(Address(0xDC, 0x4F, 0x22, 0x19, 0xA0, 0xAC, "sampler #C")); //TEENSY+ESP8266 (WIP)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
lib.push_back(book);
|
lib.push_back(book);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue