indentation changes + sketch.yaml added (for arduino-cli)
This commit is contained in:
parent
83fdb707ef
commit
b50946cabd
11 changed files with 680 additions and 668 deletions
|
|
@ -44,37 +44,37 @@ Scheduler runner;
|
||||||
int button_pin = D5;
|
int button_pin = D5;
|
||||||
bool button_pullup = false;
|
bool button_pullup = false;
|
||||||
void button_read() {
|
void button_read() {
|
||||||
//
|
|
||||||
if (button_pullup) pinMode(button_pin, INPUT_PULLUP);
|
|
||||||
else pinMode(button_pin, INPUT);
|
|
||||||
//
|
|
||||||
static int last = 0;
|
|
||||||
int val = digitalRead(button_pin);
|
|
||||||
if (val != last) {
|
|
||||||
//
|
//
|
||||||
byte mac[6];
|
if (button_pullup) pinMode(button_pin, INPUT_PULLUP);
|
||||||
WiFi.macAddress(mac);
|
else pinMode(button_pin, INPUT);
|
||||||
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
|
||||||
//
|
//
|
||||||
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
static int last = 0;
|
||||||
// and you can append some floats
|
int val = digitalRead(button_pin);
|
||||||
static int count = 0;
|
if (val != last) {
|
||||||
count++;
|
//
|
||||||
hello.h1 = (count % 1000);
|
byte mac[6];
|
||||||
hello.h2 = val;
|
WiFi.macAddress(mac);
|
||||||
// hello.h3 = 0;
|
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
||||||
// hello.h4 = 0;
|
//
|
||||||
//
|
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
// and you can append some floats
|
||||||
uint8_t frm[frm_size];
|
static int count = 0;
|
||||||
frm[0] = '{';
|
count++;
|
||||||
memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
|
hello.h1 = (count % 1000);
|
||||||
frm[frm_size - 1] = '}';
|
hello.h2 = val;
|
||||||
//
|
// hello.h3 = 0;
|
||||||
esp_now_send(NULL, frm, frm_size); // to all peers in the list.
|
// hello.h4 = 0;
|
||||||
//
|
//
|
||||||
last = val;
|
uint8_t frm_size = sizeof(Hello) + 2;
|
||||||
}
|
uint8_t frm[frm_size];
|
||||||
|
frm[0] = '{';
|
||||||
|
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.
|
||||||
|
//
|
||||||
|
last = val;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Task button_read_task(1, TASK_FOREVER, &button_read, &runner, true); // every 1 ms
|
Task button_read_task(1, TASK_FOREVER, &button_read, &runner, true); // every 1 ms
|
||||||
|
|
||||||
|
|
@ -87,124 +87,124 @@ Task button_read_task(1, TASK_FOREVER, &button_read, &runner, true); // every 1
|
||||||
#define LED_PIN 2
|
#define LED_PIN 2
|
||||||
extern Task blink_task;
|
extern Task blink_task;
|
||||||
void blink() {
|
void blink() {
|
||||||
//
|
//
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
//
|
//
|
||||||
switch (count % 4) {
|
switch (count % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
digitalWrite(LED_PIN, LOW); // first ON
|
digitalWrite(LED_PIN, LOW); // first ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
digitalWrite(LED_PIN, HIGH); // first OFF
|
||||||
blink_task.delay(LED_GAPTIME);
|
blink_task.delay(LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
digitalWrite(LED_PIN, LOW); // second ON
|
digitalWrite(LED_PIN, LOW); // second ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
digitalWrite(LED_PIN, HIGH); // second OFF
|
||||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
||||||
|
|
||||||
// on 'Note'
|
// on 'Note'
|
||||||
void onNoteHandler(Note & n) {
|
void onNoteHandler(Note & n) {
|
||||||
//is it for me?
|
//is it for me?
|
||||||
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
||||||
//
|
//
|
||||||
if (n.velocity < 0) n.velocity = 0;
|
if (n.velocity < 0) n.velocity = 0;
|
||||||
//
|
//
|
||||||
if (n.pitch < 0) n.pitch = 0;
|
if (n.pitch < 0) n.pitch = 0;
|
||||||
button_pin = n.pitch;
|
button_pin = n.pitch;
|
||||||
//button_pullup
|
//button_pullup
|
||||||
if (n.onoff == 1) {
|
if (n.onoff == 1) {
|
||||||
button_pullup = true;
|
button_pullup = true;
|
||||||
} else {
|
} else {
|
||||||
button_pullup = false;
|
button_pullup = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'receive'
|
// on 'receive'
|
||||||
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
|
|
||||||
//
|
|
||||||
Serial.write(incomingData, len);
|
|
||||||
|
|
||||||
// open => identify => use.
|
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
|
||||||
Hello hello("");
|
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
|
||||||
//
|
//
|
||||||
Serial.println(hello.to_string());
|
Serial.write(incomingData, len);
|
||||||
}
|
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
||||||
Note note;
|
Hello hello("");
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
||||||
onNoteHandler(note);
|
//
|
||||||
//
|
Serial.println(hello.to_string());
|
||||||
Serial.println(note.to_string());
|
}
|
||||||
}
|
|
||||||
|
// open => identify => use.
|
||||||
|
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||||
|
Note note;
|
||||||
|
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||||
|
onNoteHandler(note);
|
||||||
|
//
|
||||||
|
Serial.println(note.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
||||||
char buff[256] = "";
|
char buff[256] = "";
|
||||||
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (sendStatus != 0) Serial.println(buff);
|
if (sendStatus != 0) Serial.println(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
//led
|
//led
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
//serial
|
//serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
//info
|
//info
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
Serial.println("\"hi, i m your postman.\"");
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
//wifi - disabled
|
//wifi - disabled
|
||||||
system_phy_set_max_tpw(0);
|
system_phy_set_max_tpw(0);
|
||||||
WiFiMode_t node_type = WIFI_STA;
|
WiFiMode_t node_type = WIFI_STA;
|
||||||
WiFi.mode(node_type);
|
WiFi.mode(node_type);
|
||||||
|
|
||||||
//esp-now
|
//esp-now
|
||||||
if (esp_now_init() != 0) {
|
if (esp_now_init() != 0) {
|
||||||
Serial.println("Error initializing ESP-NOW");
|
Serial.println("Error initializing ESP-NOW");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||||
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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
||||||
|
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//
|
//
|
||||||
runner.execute();
|
runner.execute();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
faa_button/sketch.yaml
Normal file
2
faa_button/sketch.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
|
||||||
|
default_port: /dev/tty.SLAB_USBtoUART
|
||||||
|
|
@ -42,19 +42,49 @@ Scheduler runner;
|
||||||
|
|
||||||
//-*-*-*-*-*-*-*-*-*-*-*-*-
|
//-*-*-*-*-*-*-*-*-*-*-*-*-
|
||||||
void port_read() {
|
void port_read() {
|
||||||
//
|
//
|
||||||
byte port = 0;
|
byte port = 0;
|
||||||
static byte port_prev = 0;
|
static byte port_prev = 0;
|
||||||
port = 0x00;
|
port = 0x00;
|
||||||
port |= (digitalRead(D1) ? 0x01 : 0x00);
|
port |= (digitalRead(D1) ? 0x01 : 0x00);
|
||||||
port |= (digitalRead(D2) ? 0x02 : 0x00);
|
port |= (digitalRead(D2) ? 0x02 : 0x00);
|
||||||
port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
|
port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
|
||||||
port |= (0 ? 0x08 : 0x00); // LED pin, skip
|
port |= (0 ? 0x08 : 0x00); // LED pin, skip
|
||||||
port |= (digitalRead(D5) ? 0x10 : 0x00);
|
port |= (digitalRead(D5) ? 0x10 : 0x00);
|
||||||
port |= (digitalRead(D6) ? 0x20 : 0x00);
|
port |= (digitalRead(D6) ? 0x20 : 0x00);
|
||||||
port |= (digitalRead(D7) ? 0x40 : 0x00);
|
port |= (digitalRead(D7) ? 0x40 : 0x00);
|
||||||
port |= (digitalRead(D8) ? 0x80 : 0x00);
|
port |= (digitalRead(D8) ? 0x80 : 0x00);
|
||||||
if (port_prev != port) {
|
if (port_prev != port) {
|
||||||
|
//
|
||||||
|
byte mac[6];
|
||||||
|
WiFi.macAddress(mac);
|
||||||
|
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
||||||
|
//
|
||||||
|
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
||||||
|
// and you can append some floats
|
||||||
|
static int count = 0;
|
||||||
|
count++;
|
||||||
|
hello.h1 = (count % 1000);
|
||||||
|
hello.h2 = 1; // 1:digital
|
||||||
|
hello.h3 = port;
|
||||||
|
// hello.h4 = 0;
|
||||||
|
//
|
||||||
|
uint8_t frm_size = sizeof(Hello) + 2;
|
||||||
|
uint8_t frm[frm_size];
|
||||||
|
frm[0] = '{';
|
||||||
|
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.
|
||||||
|
//
|
||||||
|
port_prev = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
|
||||||
|
//
|
||||||
|
void volume_read() {
|
||||||
|
//
|
||||||
|
int val = analogRead(A0);
|
||||||
//
|
//
|
||||||
byte mac[6];
|
byte mac[6];
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
|
|
@ -65,8 +95,8 @@ void port_read() {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
hello.h1 = (count % 1000);
|
hello.h1 = (count % 1000);
|
||||||
hello.h2 = 1; // 1:digital
|
hello.h2 = 2; //2: analog
|
||||||
hello.h3 = port;
|
hello.h3 = val;
|
||||||
// hello.h4 = 0;
|
// hello.h4 = 0;
|
||||||
//
|
//
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
uint8_t frm_size = sizeof(Hello) + 2;
|
||||||
|
|
@ -77,36 +107,6 @@ void port_read() {
|
||||||
//
|
//
|
||||||
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.
|
||||||
//
|
//
|
||||||
port_prev = port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
|
|
||||||
//
|
|
||||||
void volume_read() {
|
|
||||||
//
|
|
||||||
int val = analogRead(A0);
|
|
||||||
//
|
|
||||||
byte mac[6];
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
|
||||||
//
|
|
||||||
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
|
||||||
// and you can append some floats
|
|
||||||
static int count = 0;
|
|
||||||
count++;
|
|
||||||
hello.h1 = (count % 1000);
|
|
||||||
hello.h2 = 2; //2: analog
|
|
||||||
hello.h3 = val;
|
|
||||||
// hello.h4 = 0;
|
|
||||||
//
|
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
|
||||||
uint8_t frm[frm_size];
|
|
||||||
frm[0] = '{';
|
|
||||||
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.
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every 50 ms
|
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every 50 ms
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
|
|
@ -118,146 +118,146 @@ Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every
|
||||||
#define LED_PIN 2
|
#define LED_PIN 2
|
||||||
extern Task blink_task;
|
extern Task blink_task;
|
||||||
void blink() {
|
void blink() {
|
||||||
//
|
//
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
//
|
//
|
||||||
switch (count % 4) {
|
switch (count % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
digitalWrite(LED_PIN, LOW); // first ON
|
digitalWrite(LED_PIN, LOW); // first ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
digitalWrite(LED_PIN, HIGH); // first OFF
|
||||||
blink_task.delay(LED_GAPTIME);
|
blink_task.delay(LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
digitalWrite(LED_PIN, LOW); // second ON
|
digitalWrite(LED_PIN, LOW); // second ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
digitalWrite(LED_PIN, HIGH); // second OFF
|
||||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
||||||
|
|
||||||
// on 'Note'
|
// on 'Note'
|
||||||
void onNoteHandler(Note & n) {
|
void onNoteHandler(Note & n) {
|
||||||
//is it for me?
|
//is it for me?
|
||||||
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
||||||
//
|
//
|
||||||
if (n.velocity < 0) n.velocity = 0;
|
if (n.velocity < 0) n.velocity = 0;
|
||||||
if (n.pitch < 0) n.pitch = 0;
|
if (n.pitch < 0) n.pitch = 0;
|
||||||
//
|
//
|
||||||
// volume: task control
|
// volume: task control
|
||||||
if (n.velocity == 0) {
|
if (n.velocity == 0) {
|
||||||
//schedule 1 read
|
//schedule 1 read
|
||||||
volume_read_task.disable();
|
volume_read_task.disable();
|
||||||
volume_read_task.setIterations(1);
|
volume_read_task.setIterations(1);
|
||||||
volume_read_task.restart();
|
volume_read_task.restart();
|
||||||
} else {
|
} else {
|
||||||
// limiting max. speed.
|
// limiting max. speed.
|
||||||
if (n.velocity < 20) n.velocity = 20;
|
if (n.velocity < 20) n.velocity = 20;
|
||||||
volume_read_task.setIterations(TASK_FOREVER);
|
volume_read_task.setIterations(TASK_FOREVER);
|
||||||
volume_read_task.setInterval(n.velocity);
|
volume_read_task.setInterval(n.velocity);
|
||||||
volume_read_task.restart();
|
volume_read_task.restart();
|
||||||
|
}
|
||||||
|
//button: pullup on/off
|
||||||
|
if (n.onoff == 1) {
|
||||||
|
pinMode(n.pitch, INPUT_PULLUP);
|
||||||
|
} else {
|
||||||
|
pinMode(n.pitch, INPUT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//button: pullup on/off
|
|
||||||
if (n.onoff == 1) {
|
|
||||||
pinMode(n.pitch, INPUT_PULLUP);
|
|
||||||
} else {
|
|
||||||
pinMode(n.pitch, INPUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'receive'
|
// on 'receive'
|
||||||
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
|
|
||||||
//
|
|
||||||
Serial.write(incomingData, len);
|
|
||||||
|
|
||||||
// open => identify => use.
|
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
|
||||||
Hello hello("");
|
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
|
||||||
//
|
//
|
||||||
Serial.println(hello.to_string());
|
Serial.write(incomingData, len);
|
||||||
}
|
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
||||||
Note note;
|
Hello hello("");
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
||||||
onNoteHandler(note);
|
//
|
||||||
//
|
Serial.println(hello.to_string());
|
||||||
Serial.println(note.to_string());
|
}
|
||||||
}
|
|
||||||
|
// open => identify => use.
|
||||||
|
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||||
|
Note note;
|
||||||
|
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||||
|
onNoteHandler(note);
|
||||||
|
//
|
||||||
|
Serial.println(note.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
||||||
char buff[256] = "";
|
char buff[256] = "";
|
||||||
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (sendStatus != 0) Serial.println(buff);
|
if (sendStatus != 0) Serial.println(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
//led
|
//led
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
//input
|
//input
|
||||||
pinMode(D1, INPUT);
|
pinMode(D1, INPUT);
|
||||||
pinMode(D2, INPUT);
|
pinMode(D2, INPUT);
|
||||||
pinMode(D3, INPUT);
|
pinMode(D3, INPUT);
|
||||||
//
|
//
|
||||||
pinMode(D5, INPUT);
|
pinMode(D5, INPUT);
|
||||||
pinMode(D6, INPUT);
|
pinMode(D6, INPUT);
|
||||||
pinMode(D7, INPUT);
|
pinMode(D7, INPUT);
|
||||||
pinMode(D8, INPUT);
|
pinMode(D8, INPUT);
|
||||||
|
|
||||||
//serial
|
//serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
//info
|
//info
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
Serial.println("\"hi, i m your postman.\"");
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
//wifi - disabled
|
//wifi - disabled
|
||||||
system_phy_set_max_tpw(0);
|
system_phy_set_max_tpw(0);
|
||||||
WiFiMode_t node_type = WIFI_STA;
|
WiFiMode_t node_type = WIFI_STA;
|
||||||
WiFi.mode(node_type);
|
WiFi.mode(node_type);
|
||||||
|
|
||||||
//esp-now
|
//esp-now
|
||||||
if (esp_now_init() != 0) {
|
if (esp_now_init() != 0) {
|
||||||
Serial.println("Error initializing ESP-NOW");
|
Serial.println("Error initializing ESP-NOW");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||||
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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
||||||
|
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//
|
//
|
||||||
runner.execute();
|
runner.execute();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
faa_piano/sketch.yaml
Normal file
2
faa_piano/sketch.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
|
||||||
|
default_port: /dev/tty.SLAB_USBtoUART
|
||||||
2
faa_roller/sketch.yaml
Normal file
2
faa_roller/sketch.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
|
||||||
|
default_port: /dev/tty.SLAB_USBtoUART
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
//============<identities>============
|
//============<identities>============
|
||||||
#define MY_GROUP_ID (1000)
|
#define MY_GROUP_ID (1000)
|
||||||
#define MY_ID (MY_GROUP_ID + 1)
|
#define MY_ID (MY_GROUP_ID + 777)
|
||||||
#define MY_SIGN ("TAAK")
|
#define MY_SIGN ("TAAK")
|
||||||
//============</identities>============
|
//============</identities>============
|
||||||
|
|
||||||
|
|
@ -43,16 +43,16 @@ Scheduler runner;
|
||||||
//-*-*-*-*-*-*-*-*-*-*-*-*-
|
//-*-*-*-*-*-*-*-*-*-*-*-*-
|
||||||
int taak_pin = D6;
|
int taak_pin = D6;
|
||||||
void taak_on() {
|
void taak_on() {
|
||||||
pinMode(taak_pin, OUTPUT);
|
pinMode(taak_pin, OUTPUT);
|
||||||
Serial.println("taak_on!");
|
Serial.println("taak_on!");
|
||||||
digitalWrite(taak_pin, HIGH);
|
digitalWrite(taak_pin, HIGH);
|
||||||
}
|
}
|
||||||
Task taak_on_task(0, TASK_ONCE, &taak_on, &runner, false);
|
Task taak_on_task(0, TASK_ONCE, &taak_on, &runner, false);
|
||||||
|
|
||||||
void taak_off() {
|
void taak_off() {
|
||||||
pinMode(taak_pin, OUTPUT);
|
pinMode(taak_pin, OUTPUT);
|
||||||
Serial.println("taak_off!");
|
Serial.println("taak_off!");
|
||||||
digitalWrite(taak_pin, LOW);
|
digitalWrite(taak_pin, LOW);
|
||||||
}
|
}
|
||||||
Task taak_off_task(0, TASK_ONCE, &taak_off, &runner, false);
|
Task taak_off_task(0, TASK_ONCE, &taak_off, &runner, false);
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
|
|
@ -64,131 +64,131 @@ Task taak_off_task(0, TASK_ONCE, &taak_off, &runner, false);
|
||||||
#define LED_PIN 2
|
#define LED_PIN 2
|
||||||
extern Task blink_task;
|
extern Task blink_task;
|
||||||
void blink() {
|
void blink() {
|
||||||
//
|
//
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
//
|
//
|
||||||
switch (count % 4) {
|
switch (count % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
digitalWrite(LED_PIN, LOW); // first ON
|
digitalWrite(LED_PIN, LOW); // first ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
digitalWrite(LED_PIN, HIGH); // first OFF
|
||||||
blink_task.delay(LED_GAPTIME);
|
blink_task.delay(LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
digitalWrite(LED_PIN, LOW); // second ON
|
digitalWrite(LED_PIN, LOW); // second ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
digitalWrite(LED_PIN, HIGH); // second OFF
|
||||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
||||||
|
|
||||||
// on 'Note'
|
// on 'Note'
|
||||||
void onNoteHandler(Note & n) {
|
void onNoteHandler(Note & n) {
|
||||||
//is it for me?
|
//is it for me?
|
||||||
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
||||||
//
|
//
|
||||||
if (n.velocity < 0) n.velocity = 0;
|
if (n.velocity < 0) n.velocity = 0;
|
||||||
//
|
//
|
||||||
if (n.pitch < 0) n.pitch = 0;
|
if (n.pitch < 0) n.pitch = 0;
|
||||||
taak_pin = n.pitch;
|
taak_pin = n.pitch;
|
||||||
//taak_on && taak_off
|
//taak_on && taak_off
|
||||||
if (n.velocity == 0) {
|
if (n.velocity == 0) {
|
||||||
if (n.onoff == 1) {
|
if (n.onoff == 1) {
|
||||||
taak_on_task.restartDelayed(10);
|
taak_on_task.restartDelayed(10);
|
||||||
} else {
|
} else {
|
||||||
taak_off_task.restartDelayed(10);
|
taak_off_task.restartDelayed(10);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
//taak_hit
|
||||||
|
else {
|
||||||
|
taak_on_task.restartDelayed(10);
|
||||||
|
taak_off_task.restartDelayed(10 + n.velocity * 2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//taak_hit
|
|
||||||
else {
|
|
||||||
taak_on_task.restartDelayed(10);
|
|
||||||
taak_off_task.restartDelayed(10 + n.velocity * 2);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'receive'
|
// on 'receive'
|
||||||
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
|
|
||||||
//
|
|
||||||
Serial.write(incomingData, len);
|
|
||||||
|
|
||||||
// open => identify => use.
|
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
|
||||||
Hello hello("");
|
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
|
||||||
//
|
//
|
||||||
Serial.println(hello.to_string());
|
Serial.write(incomingData, len);
|
||||||
}
|
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
||||||
Note note;
|
Hello hello("");
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
||||||
onNoteHandler(note);
|
//
|
||||||
//
|
Serial.println(hello.to_string());
|
||||||
Serial.println(note.to_string());
|
}
|
||||||
}
|
|
||||||
|
// open => identify => use.
|
||||||
|
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||||
|
Note note;
|
||||||
|
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||||
|
onNoteHandler(note);
|
||||||
|
//
|
||||||
|
Serial.println(note.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
||||||
char buff[256] = "";
|
char buff[256] = "";
|
||||||
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (sendStatus != 0) Serial.println(buff);
|
if (sendStatus != 0) Serial.println(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
//led
|
//led
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
//serial
|
//serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
//info
|
//info
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
Serial.println("\"hi, i m your postman.\"");
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
//wifi - disabled
|
//wifi - disabled
|
||||||
system_phy_set_max_tpw(0);
|
system_phy_set_max_tpw(0);
|
||||||
WiFiMode_t node_type = WIFI_STA;
|
WiFiMode_t node_type = WIFI_STA;
|
||||||
WiFi.mode(node_type);
|
WiFi.mode(node_type);
|
||||||
|
|
||||||
//esp-now
|
//esp-now
|
||||||
if (esp_now_init() != 0) {
|
if (esp_now_init() != 0) {
|
||||||
Serial.println("Error initializing ESP-NOW");
|
Serial.println("Error initializing ESP-NOW");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||||
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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
||||||
|
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//
|
//
|
||||||
runner.execute();
|
runner.execute();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
faa_taak/sketch.yaml
Normal file
2
faa_taak/sketch.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
|
||||||
|
default_port: /dev/tty.SLAB_USBtoUART
|
||||||
|
|
@ -42,19 +42,49 @@ Scheduler runner;
|
||||||
|
|
||||||
//-*-*-*-*-*-*-*-*-*-*-*-*-
|
//-*-*-*-*-*-*-*-*-*-*-*-*-
|
||||||
void port_read() {
|
void port_read() {
|
||||||
//
|
//
|
||||||
byte port = 0;
|
byte port = 0;
|
||||||
static byte port_prev = 0;
|
static byte port_prev = 0;
|
||||||
port = 0x00;
|
port = 0x00;
|
||||||
port |= (digitalRead(D1) ? 0x01 : 0x00);
|
port |= (digitalRead(D1) ? 0x01 : 0x00);
|
||||||
port |= (digitalRead(D2) ? 0x02 : 0x00);
|
port |= (digitalRead(D2) ? 0x02 : 0x00);
|
||||||
port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
|
port |= (digitalRead(D3) ? 0x04 : 0x00); // by design, PULLED-UP, being used for the FLASH button.
|
||||||
port |= (0 ? 0x08 : 0x00); // LED pin, skip
|
port |= (0 ? 0x08 : 0x00); // LED pin, skip
|
||||||
port |= (digitalRead(D5) ? 0x10 : 0x00);
|
port |= (digitalRead(D5) ? 0x10 : 0x00);
|
||||||
port |= (digitalRead(D6) ? 0x20 : 0x00);
|
port |= (digitalRead(D6) ? 0x20 : 0x00);
|
||||||
port |= (digitalRead(D7) ? 0x40 : 0x00);
|
port |= (digitalRead(D7) ? 0x40 : 0x00);
|
||||||
port |= (digitalRead(D8) ? 0x80 : 0x00);
|
port |= (digitalRead(D8) ? 0x80 : 0x00);
|
||||||
if (port_prev != port) {
|
if (port_prev != port) {
|
||||||
|
//
|
||||||
|
byte mac[6];
|
||||||
|
WiFi.macAddress(mac);
|
||||||
|
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
||||||
|
//
|
||||||
|
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
||||||
|
// and you can append some floats
|
||||||
|
static int count = 0;
|
||||||
|
count++;
|
||||||
|
hello.h1 = (count % 1000);
|
||||||
|
hello.h2 = 1; // 1:digital
|
||||||
|
hello.h3 = port;
|
||||||
|
// hello.h4 = 0;
|
||||||
|
//
|
||||||
|
uint8_t frm_size = sizeof(Hello) + 2;
|
||||||
|
uint8_t frm[frm_size];
|
||||||
|
frm[0] = '{';
|
||||||
|
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.
|
||||||
|
//
|
||||||
|
port_prev = port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
|
||||||
|
//
|
||||||
|
void volume_read() {
|
||||||
|
//
|
||||||
|
int val = analogRead(A0);
|
||||||
//
|
//
|
||||||
byte mac[6];
|
byte mac[6];
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
|
|
@ -65,8 +95,8 @@ void port_read() {
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
hello.h1 = (count % 1000);
|
hello.h1 = (count % 1000);
|
||||||
hello.h2 = 1; // 1:digital
|
hello.h2 = 2; //2: analog
|
||||||
hello.h3 = port;
|
hello.h3 = val;
|
||||||
// hello.h4 = 0;
|
// hello.h4 = 0;
|
||||||
//
|
//
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
uint8_t frm_size = sizeof(Hello) + 2;
|
||||||
|
|
@ -77,36 +107,6 @@ void port_read() {
|
||||||
//
|
//
|
||||||
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.
|
||||||
//
|
//
|
||||||
port_prev = port;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Task port_read_task(1, TASK_FOREVER, &port_read, &runner, true); // every 1 ms
|
|
||||||
//
|
|
||||||
void volume_read() {
|
|
||||||
//
|
|
||||||
int val = analogRead(A0);
|
|
||||||
//
|
|
||||||
byte mac[6];
|
|
||||||
WiFi.macAddress(mac);
|
|
||||||
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
|
||||||
//
|
|
||||||
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
|
||||||
// and you can append some floats
|
|
||||||
static int count = 0;
|
|
||||||
count++;
|
|
||||||
hello.h1 = (count % 1000);
|
|
||||||
hello.h2 = 2; //2: analog
|
|
||||||
hello.h3 = val;
|
|
||||||
// hello.h4 = 0;
|
|
||||||
//
|
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
|
||||||
uint8_t frm[frm_size];
|
|
||||||
frm[0] = '{';
|
|
||||||
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.
|
|
||||||
//
|
|
||||||
}
|
}
|
||||||
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every 50 ms
|
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every 50 ms
|
||||||
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
//*-*-*-*-*-*-*-*-*-*-*-*-*
|
||||||
|
|
@ -118,146 +118,146 @@ Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, false); // every
|
||||||
#define LED_PIN 2
|
#define LED_PIN 2
|
||||||
extern Task blink_task;
|
extern Task blink_task;
|
||||||
void blink() {
|
void blink() {
|
||||||
//
|
//
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
//
|
//
|
||||||
switch (count % 4) {
|
switch (count % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
digitalWrite(LED_PIN, LOW); // first ON
|
digitalWrite(LED_PIN, LOW); // first ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
digitalWrite(LED_PIN, HIGH); // first OFF
|
||||||
blink_task.delay(LED_GAPTIME);
|
blink_task.delay(LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
digitalWrite(LED_PIN, LOW); // second ON
|
digitalWrite(LED_PIN, LOW); // second ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
digitalWrite(LED_PIN, HIGH); // second OFF
|
||||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
||||||
|
|
||||||
// on 'Note'
|
// on 'Note'
|
||||||
void onNoteHandler(Note & n) {
|
void onNoteHandler(Note & n) {
|
||||||
//is it for me?
|
//is it for me?
|
||||||
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
||||||
//
|
//
|
||||||
if (n.velocity < 0) n.velocity = 0;
|
if (n.velocity < 0) n.velocity = 0;
|
||||||
if (n.pitch < 0) n.pitch = 0;
|
if (n.pitch < 0) n.pitch = 0;
|
||||||
//
|
//
|
||||||
// volume: task control
|
// volume: task control
|
||||||
if (n.velocity == 0) {
|
if (n.velocity == 0) {
|
||||||
//schedule 1 read
|
//schedule 1 read
|
||||||
volume_read_task.disable();
|
volume_read_task.disable();
|
||||||
volume_read_task.setIterations(1);
|
volume_read_task.setIterations(1);
|
||||||
volume_read_task.restart();
|
volume_read_task.restart();
|
||||||
} else {
|
} else {
|
||||||
// limiting max. speed.
|
// limiting max. speed.
|
||||||
if (n.velocity < 20) n.velocity = 20;
|
if (n.velocity < 20) n.velocity = 20;
|
||||||
volume_read_task.setIterations(TASK_FOREVER);
|
volume_read_task.setIterations(TASK_FOREVER);
|
||||||
volume_read_task.setInterval(n.velocity);
|
volume_read_task.setInterval(n.velocity);
|
||||||
volume_read_task.restart();
|
volume_read_task.restart();
|
||||||
|
}
|
||||||
|
//button: pullup on/off
|
||||||
|
if (n.onoff == 1) {
|
||||||
|
pinMode(n.pitch, INPUT_PULLUP);
|
||||||
|
} else {
|
||||||
|
pinMode(n.pitch, INPUT);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//button: pullup on/off
|
|
||||||
if (n.onoff == 1) {
|
|
||||||
pinMode(n.pitch, INPUT_PULLUP);
|
|
||||||
} else {
|
|
||||||
pinMode(n.pitch, INPUT);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'receive'
|
// on 'receive'
|
||||||
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
|
|
||||||
//
|
|
||||||
Serial.write(incomingData, len);
|
|
||||||
|
|
||||||
// open => identify => use.
|
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
|
||||||
Hello hello("");
|
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
|
||||||
//
|
//
|
||||||
Serial.println(hello.to_string());
|
Serial.write(incomingData, len);
|
||||||
}
|
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
||||||
Note note;
|
Hello hello("");
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
||||||
onNoteHandler(note);
|
//
|
||||||
//
|
Serial.println(hello.to_string());
|
||||||
Serial.println(note.to_string());
|
}
|
||||||
}
|
|
||||||
|
// open => identify => use.
|
||||||
|
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||||
|
Note note;
|
||||||
|
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||||
|
onNoteHandler(note);
|
||||||
|
//
|
||||||
|
Serial.println(note.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
||||||
char buff[256] = "";
|
char buff[256] = "";
|
||||||
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (sendStatus != 0) Serial.println(buff);
|
if (sendStatus != 0) Serial.println(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
//led
|
//led
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
//input
|
//input
|
||||||
pinMode(D1, INPUT);
|
pinMode(D1, INPUT);
|
||||||
pinMode(D2, INPUT);
|
pinMode(D2, INPUT);
|
||||||
pinMode(D3, INPUT);
|
pinMode(D3, INPUT);
|
||||||
//
|
//
|
||||||
pinMode(D5, INPUT);
|
pinMode(D5, INPUT);
|
||||||
pinMode(D6, INPUT);
|
pinMode(D6, INPUT);
|
||||||
pinMode(D7, INPUT);
|
pinMode(D7, INPUT);
|
||||||
pinMode(D8, INPUT);
|
pinMode(D8, INPUT);
|
||||||
|
|
||||||
//serial
|
//serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
//info
|
//info
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
Serial.println("\"hi, i m your postman.\"");
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
//wifi - disabled
|
//wifi - disabled
|
||||||
system_phy_set_max_tpw(0);
|
system_phy_set_max_tpw(0);
|
||||||
WiFiMode_t node_type = WIFI_STA;
|
WiFiMode_t node_type = WIFI_STA;
|
||||||
WiFi.mode(node_type);
|
WiFi.mode(node_type);
|
||||||
|
|
||||||
//esp-now
|
//esp-now
|
||||||
if (esp_now_init() != 0) {
|
if (esp_now_init() != 0) {
|
||||||
Serial.println("Error initializing ESP-NOW");
|
Serial.println("Error initializing ESP-NOW");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||||
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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
||||||
|
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//
|
//
|
||||||
runner.execute();
|
runner.execute();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
faa_tone/sketch.yaml
Normal file
2
faa_tone/sketch.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
|
||||||
|
default_port: /dev/tty.SLAB_USBtoUART
|
||||||
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
//============<identities>============
|
//============<identities>============
|
||||||
#define MY_GROUP_ID (6000)
|
#define MY_GROUP_ID (6000)
|
||||||
#define MY_ID (MY_GROUP_ID + 1)
|
#define MY_ID (MY_GROUP_ID + 3)
|
||||||
#define MY_SIGN ("VOLUME")
|
#define MY_SIGN ("VOLUME")
|
||||||
//============</identities>============
|
//============</identities>============
|
||||||
|
|
||||||
|
|
@ -44,35 +44,35 @@ Scheduler runner;
|
||||||
int volume_pin = A0;
|
int volume_pin = A0;
|
||||||
bool volume_pullup = false;
|
bool volume_pullup = false;
|
||||||
void volume_read() {
|
void volume_read() {
|
||||||
//
|
//
|
||||||
if (volume_pullup) pinMode(volume_pin, INPUT_PULLUP);
|
if (volume_pullup) pinMode(volume_pin, INPUT_PULLUP);
|
||||||
else pinMode(volume_pin, INPUT);
|
else pinMode(volume_pin, INPUT);
|
||||||
//
|
//
|
||||||
int val = analogRead(volume_pin);
|
int val = analogRead(volume_pin);
|
||||||
//
|
//
|
||||||
Serial.println(val);
|
Serial.println(val);
|
||||||
//
|
//
|
||||||
byte mac[6];
|
byte mac[6];
|
||||||
WiFi.macAddress(mac);
|
WiFi.macAddress(mac);
|
||||||
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
uint32_t mac32 = (((((mac[2] << 8) + mac[3]) << 8) + mac[4]) << 8) + mac[5];
|
||||||
//
|
//
|
||||||
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
Hello hello(String(MY_SIGN), MY_ID, mac32); // the most basic 'hello'
|
||||||
// and you can append some floats
|
// and you can append some floats
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
hello.h1 = (count % 1000);
|
hello.h1 = (count % 1000);
|
||||||
hello.h2 = val;
|
hello.h2 = val;
|
||||||
// hello.h3 = 0;
|
// hello.h3 = 0;
|
||||||
// hello.h4 = 0;
|
// hello.h4 = 0;
|
||||||
//
|
//
|
||||||
uint8_t frm_size = sizeof(Hello) + 2;
|
uint8_t frm_size = sizeof(Hello) + 2;
|
||||||
uint8_t frm[frm_size];
|
uint8_t frm[frm_size];
|
||||||
frm[0] = '{';
|
frm[0] = '{';
|
||||||
memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
|
memcpy(frm + 1, (uint8_t *) &hello, sizeof(Hello));
|
||||||
frm[frm_size - 1] = '}';
|
frm[frm_size - 1] = '}';
|
||||||
//
|
//
|
||||||
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.
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, true); // every 1 ms
|
Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, true); // every 1 ms
|
||||||
|
|
||||||
|
|
@ -85,137 +85,137 @@ Task volume_read_task(50, TASK_FOREVER, &volume_read, &runner, true); // every 1
|
||||||
#define LED_PIN 2
|
#define LED_PIN 2
|
||||||
extern Task blink_task;
|
extern Task blink_task;
|
||||||
void blink() {
|
void blink() {
|
||||||
//
|
//
|
||||||
static int count = 0;
|
static int count = 0;
|
||||||
count++;
|
count++;
|
||||||
//
|
//
|
||||||
switch (count % 4) {
|
switch (count % 4) {
|
||||||
case 0:
|
case 0:
|
||||||
digitalWrite(LED_PIN, LOW); // first ON
|
digitalWrite(LED_PIN, LOW); // first ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
digitalWrite(LED_PIN, HIGH); // first OFF
|
digitalWrite(LED_PIN, HIGH); // first OFF
|
||||||
blink_task.delay(LED_GAPTIME);
|
blink_task.delay(LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
digitalWrite(LED_PIN, LOW); // second ON
|
digitalWrite(LED_PIN, LOW); // second ON
|
||||||
blink_task.delay(LED_ONTIME);
|
blink_task.delay(LED_ONTIME);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
digitalWrite(LED_PIN, HIGH); // second OFF
|
digitalWrite(LED_PIN, HIGH); // second OFF
|
||||||
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
blink_task.delay(LED_PERIOD - 2* LED_ONTIME - LED_GAPTIME);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
Task blink_task(0, TASK_FOREVER, &blink, &runner, true); // -> ENABLED, at start-up.
|
||||||
|
|
||||||
// on 'Note'
|
// on 'Note'
|
||||||
void onNoteHandler(Note & n) {
|
void onNoteHandler(Note & n) {
|
||||||
//is it for me?
|
//is it for me?
|
||||||
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
if (n.id == MY_GROUP_ID || n.id == MY_ID) {
|
||||||
//
|
//
|
||||||
if (n.pitch < 0) n.pitch = 0;
|
if (n.pitch < 0) n.pitch = 0;
|
||||||
volume_pin = n.pitch; //useless: for esp8266, A0 is only one adc.
|
volume_pin = n.pitch; //useless: for esp8266, A0 is only one adc.
|
||||||
//
|
//
|
||||||
if (n.velocity < 0) n.velocity = 0;
|
if (n.velocity < 0) n.velocity = 0;
|
||||||
//
|
//
|
||||||
if (n.velocity == 0) {
|
if (n.velocity == 0) {
|
||||||
//schedule 1 read
|
//schedule 1 read
|
||||||
volume_read_task.disable();
|
volume_read_task.disable();
|
||||||
volume_read_task.setIterations(1);
|
volume_read_task.setIterations(1);
|
||||||
volume_read_task.restart();
|
volume_read_task.restart();
|
||||||
} else {
|
} else {
|
||||||
// limiting max. speed.
|
// limiting max. speed.
|
||||||
if (n.velocity < 20) n.velocity = 20;
|
if (n.velocity < 20) n.velocity = 20;
|
||||||
volume_read_task.setIterations(TASK_FOREVER);
|
volume_read_task.setIterations(TASK_FOREVER);
|
||||||
volume_read_task.setInterval(n.velocity);
|
volume_read_task.setInterval(n.velocity);
|
||||||
volume_read_task.restart();
|
volume_read_task.restart();
|
||||||
|
}
|
||||||
|
//pull-up on/off
|
||||||
|
if (n.onoff == 1) {
|
||||||
|
volume_pullup = true; //useless: for esp8266, A0 no support for internal pull-up ?
|
||||||
|
} else {
|
||||||
|
volume_pullup = false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//pull-up on/off
|
|
||||||
if (n.onoff == 1) {
|
|
||||||
volume_pullup = true; //useless: for esp8266, A0 no support for internal pull-up ?
|
|
||||||
} else {
|
|
||||||
volume_pullup = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'receive'
|
// on 'receive'
|
||||||
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
void onDataReceive(uint8_t * mac, uint8_t *incomingData, uint8_t len) {
|
||||||
|
|
||||||
//
|
|
||||||
Serial.write(incomingData, len);
|
|
||||||
|
|
||||||
// open => identify => use.
|
|
||||||
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
|
||||||
Hello hello("");
|
|
||||||
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
|
||||||
//
|
//
|
||||||
Serial.println(hello.to_string());
|
Serial.write(incomingData, len);
|
||||||
}
|
|
||||||
|
|
||||||
// open => identify => use.
|
// open => identify => use.
|
||||||
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
if (incomingData[0] == '{' && incomingData[len - 1] == '}' && len == (sizeof(Hello) + 2)) {
|
||||||
Note note;
|
Hello hello("");
|
||||||
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
memcpy((uint8_t *) &hello, incomingData + 1, sizeof(Hello));
|
||||||
onNoteHandler(note);
|
//
|
||||||
//
|
Serial.println(hello.to_string());
|
||||||
Serial.println(note.to_string());
|
}
|
||||||
}
|
|
||||||
|
// open => identify => use.
|
||||||
|
if (incomingData[0] == '[' && incomingData[len - 1] == ']' && len == (sizeof(Note) + 2)) {
|
||||||
|
Note note;
|
||||||
|
memcpy((uint8_t *) ¬e, incomingData + 1, sizeof(Note));
|
||||||
|
onNoteHandler(note);
|
||||||
|
//
|
||||||
|
Serial.println(note.to_string());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// on 'sent'
|
// on 'sent'
|
||||||
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
void onDataSent(uint8_t *mac, uint8_t sendStatus) {
|
||||||
char buff[256] = "";
|
char buff[256] = "";
|
||||||
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
sprintf(buff, "Delivery failed! -> %02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (sendStatus != 0) Serial.println(buff);
|
if (sendStatus != 0) Serial.println(buff);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
void setup() {
|
void setup() {
|
||||||
|
|
||||||
//led
|
//led
|
||||||
pinMode(LED_PIN, OUTPUT);
|
pinMode(LED_PIN, OUTPUT);
|
||||||
|
|
||||||
//serial
|
//serial
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
delay(100);
|
delay(100);
|
||||||
|
|
||||||
//info
|
//info
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println();
|
Serial.println();
|
||||||
Serial.println("\"hi, i m your postman.\"");
|
Serial.println("\"hi, i m your postman.\"");
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
Serial.println("- my id: " + String(MY_ID) + ", gid: " + String(MY_GROUP_ID) + ", call me ==> \"" + String(MY_SIGN) + "\"");
|
||||||
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
Serial.println("- mac address: " + WiFi.macAddress() + ", channel: " + String(WIFI_CHANNEL));
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
|
|
||||||
//wifi - disabled
|
//wifi - disabled
|
||||||
system_phy_set_max_tpw(0);
|
system_phy_set_max_tpw(0);
|
||||||
WiFiMode_t node_type = WIFI_STA;
|
WiFiMode_t node_type = WIFI_STA;
|
||||||
WiFi.mode(node_type);
|
WiFi.mode(node_type);
|
||||||
|
|
||||||
//esp-now
|
//esp-now
|
||||||
if (esp_now_init() != 0) {
|
if (esp_now_init() != 0) {
|
||||||
Serial.println("Error initializing ESP-NOW");
|
Serial.println("Error initializing ESP-NOW");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
esp_now_set_self_role(ESP_NOW_ROLE_COMBO);
|
||||||
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_add_peer(broadcastmac, ESP_NOW_ROLE_COMBO, 1, NULL, 0);
|
||||||
|
|
||||||
Serial.println("-");
|
Serial.println("-");
|
||||||
Serial.println("\".-.-.-. :)\"");
|
Serial.println("\".-.-.-. :)\"");
|
||||||
Serial.println();
|
Serial.println();
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
//
|
//
|
||||||
runner.execute();
|
runner.execute();
|
||||||
//
|
//
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
faa_volume/sketch.yaml
Normal file
2
faa_volume/sketch.yaml
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
default_fqbn: esp8266:esp8266:nodemcuv2:baud=460800
|
||||||
|
default_port: /dev/tty.SLAB_USBtoUART
|
||||||
Loading…
Reference in a new issue