SOLVED: ESP32 esp-now data transfer is pausing

newtwoarduino
Posts: 2
Joined: Thu Apr 02, 2020 3:24 pm

SOLVED: ESP32 esp-now data transfer is pausing

Postby newtwoarduino » Thu Apr 02, 2020 3:30 pm

I am working with esp-now. I simply want a nonstop continuous stream of bytes being transferred from one esp32 to another. For my test, I am trying to send a 1 and then a 0, and repeating.

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);

}
Last edited by newtwoarduino on Fri Apr 03, 2020 5:59 pm, edited 1 time in total.

mattlogue
Posts: 4
Joined: Sat Mar 02, 2019 1:54 am

Re: ESP32 esp-now data transfer is pausing

Postby mattlogue » Fri Apr 03, 2020 3:17 pm

Sorry not answering. I am plagued by same symptoms, not impressed with esp now, won't reach me from garage, yet I see tons of other APs. May just chain together in WiFi and use UDP.

newtwoarduino
Posts: 2
Joined: Thu Apr 02, 2020 3:24 pm

Re: ESP32 esp-now data transfer is pausing

Postby newtwoarduino » Fri Apr 03, 2020 5:57 pm

No worries.
I have been doing more experimentation today... It appears the pause only happens when sending to the serial monitor.
When I remove that from the equation, the data stream is indeed constant from one esp32 to the other.

Who is online

Users browsing this forum: No registered users and 43 guests