When I monitor the receiver, it appears to receive these bytes as intended, but then pauses for a moment, then continues to receive as intended, then pauses again... repeating.
I put together the code below from snippets of online tutorials.
What can I change in the code to make the stream non-stop? Or should I use a different method than esp-now?
Thank you for your assistance.
SENDER
Code: Select all
#include <esp_now.h>
#include <WiFi.h>
uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
uint8_t data = 0;
void setup() {
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
return;
}
// Register peer
esp_now_peer_info_t peerInfo;
memcpy(peerInfo.peer_addr, broadcastAddress, 6);
peerInfo.channel = 0;
peerInfo.encrypt = false;
// Add peer
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("Failed to add peer");
return;
}
}
void loop() {
data++;
esp_now_send(broadcastAddress, &data, 1);
data--;
esp_now_send(broadcastAddress, &data, 1);
}
RECEIVER
Code: Select all
#include <esp_now.h>
#include <WiFi.h>
uint8_t data;
void OnDataRecv(const uint8_t * mac, const uint8_t *incomingData, int len) {
memcpy(&data, incomingData, 1);
}
void setup() {
Serial.begin(115200);
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
return;
}
esp_now_register_recv_cb(OnDataRecv);
}
void loop() {
Serial.println(data);
}