Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESP-NOW strategy support for esp8266 #361

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Adding debug outputs, ACK is back
  • Loading branch information
Strix-CZ committed Aug 8, 2020
commit f2375ed3852c86d7c28baecb7d06a415269f6236
3 changes: 1 addition & 2 deletions src/PJON.h
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,7 @@ class PJON {
!(payload[1] & PJON_ACK_REQ_BIT) ||
_mode == PJON_SIMPLEX
) return PJON_ACK;
//return (strategy.receive_response() == PJON_ACK) ? PJON_ACK : PJON_FAIL;
return PJON_ACK;
return (strategy.receive_response() == PJON_ACK) ? PJON_ACK : PJON_FAIL;
};

/* Compose and transmit a packet passing its info as parameters: */
Expand Down
16 changes: 15 additions & 1 deletion src/interfaces/ARDUINO/ESPNOWHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,20 @@ enum {
static uint8_t last_mac[ESP_NOW_ETH_ALEN];
static PacketQueue packetQueue;
volatile bool sendingDone = true;
volatile uint32_t sendCount = 0;
volatile uint32_t recCalled = 0;
volatile uint32_t failCount = 0;

static void espnow_send_cb(const uint8_t *mac_addr, uint8_t status) {
sendCount++;
if (status != 0)
failCount++;
// The only thing we do in the send callback is unblock the other thread which blocks after posting data to the MAC
sendingDone = true;
};

static void espnow_recv_cb(const uint8_t *mac_addr, const uint8_t *data, int len) {
recCalled++;
espnow_packet_t* packet = new espnow_packet_t();

memcpy(packet->mac_addr, mac_addr, ESP_NOW_ETH_ALEN);
Expand All @@ -68,6 +75,7 @@ static void espnow_recv_cb(const uint8_t *mac_addr, const uint8_t *data, int len
packet->data_len = len;

if (!packetQueue.push(packet)) { // queue is full - drop the packet
failCount++;
free(packet->data);
delete packet;
}
Expand Down Expand Up @@ -188,11 +196,14 @@ class ENHelper {
};

void send_frame(uint8_t *data, uint16_t length, uint8_t dest_mac[ESP_NOW_ETH_ALEN]) {
if (!sendingDone)
if (!sendingDone) {
failCount++;
return; // we are still sending the previous frame - discard this one
}

uint8_t packet[ESPNOW_MAX_PACKET];
if (length + 4 > ESPNOW_MAX_PACKET) {
failCount++;
return;
}

Expand All @@ -213,6 +224,9 @@ class ENHelper {
yield();
} while(!sendingDone);
}
else {
failCount++;
}
};

void send_response(uint8_t response) {
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/ARDUINO/PacketQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#define ESP_NOW_ETH_ALEN 6
#endif

#define ESPNOW_QUEUE_SIZE 200
#define ESPNOW_QUEUE_SIZE 6

typedef struct
{
Expand Down