ESP32 Blynk and ESPNOW issue

Hello,

My ESP8266 Blynk board with ESPNOW works well. However the combination of ESP32 Blynk and ESPNOW together does not work . I searched this forum on this issue but I cannot find any clear-cut solution.

As an replacemet, I added an ESP32 which receives sensor data via ESPNOW and relay the data to ESP32 Blynk gateway via serial communication. I don’t think this is desirable.

Is there any simple way to solve this issue ?

Thanks. Kang

//ESPNOW works when Blynk is disabled but does not work if Blnk is activated.
#define BLYNK_TEMPLATE_ID "TMPLBYXg9XVK"
#define BLYNK_TEMPLATE_NAME "ESP32S3 IoT Controller"
#define BLYNK_AUTH_TOKEN "**********"

// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial


#include <WiFi.h>
#include <esp_now.h> 

#include <WiFi.h>
#include <WiFiClient.h>
#include <BlynkSimpleEsp32.h>

char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "*******";
char pass[] = "********";

unsigned long t = 0;
float outdoorTemp;

BlynkTimer timer;

typedef struct _Mydata1
{ 
  
  float temp1;
  //double temp2;
  _Mydata1()
  {
  }
}Mydata1;
Mydata1 mydata1;

void myTimerEvent1() 
{
  Blynk.virtualWrite(V14, outdoorTemp); 
}

void myTimerEvent2() 
{
  Serial.print("ESPNOW Outdoor Temperature = ");
  Serial.println(outdoorTemp,1);
}


//esp_now_peer_info_t dest;  

void setup(void) {
  Serial.begin(115200);
  
  WiFi.mode(WIFI_STA);  
  esp_now_init(); 
 
  dest.channel = 1;  
  dest.encrypt = false; 
  
  //esp_now_add_peer(&dest);

  esp_now_register_recv_cb(OnDataRecv);

  Blynk.begin(auth, ssid, pass);
  timer.setInterval(2000L, myTimerEvent1);
  timer.setInterval(5000L, myTimerEvent2);
}


void loop() 
{
  Blynk.run();
  timer.run();
   
  /*
 To check ESPNOW data when Blynk is deactivated.
  if( millis() - t > 2000)
    {
       t = millis();
       Serial.print("ESPNOW Outdoor Temp = ");
       Serial.println(outdoorTemp,1);
    }
  */
}

void OnDataRecv(const uint8_t * mac, const uint8_t *data, int len) 
{
  memcpy(&mydata1,data,len);
  outdoorTemp = mydata1.temp1;
}

@gentler Please edit your post, using the pencil icon at the bottom, and add triple backticks at the beginning and end of your code so that it displays correctly.
Triple backticks look like this:
```

Copy and paste these if you can’t find the correct symbol on your keyboard.

Pete.

I dont use EspNOW, so i don’t have anything constructive comments, but I’ struggling to understand why you’d comment-out the Blynk.run() command in your void loop, but still retain the Blynk.begin() command in void setup.

I’m also confused why, when you’re already using BlynkTimer, you’d have this in your void loop…

Pete.

Since ESP-Now is an multi-ESP peer to peer data linked protocol using a Wifi-AP configuration, it’s hard to understand how that’s even compatible with Blynk?

1 Like

The comment-out is to run Blynk only or to run ESPNOW only or to run both Blynk and ESPNOW in my desparate effort to find a solution.

I added the timer in the void() loop because I cannot get serial monitor display of ESPNOW value when Blynk is disabled.

If ESP32 ESPNOW can be used with ESP32 Blynk simultaneously, I think ESPNOW can be a very nice tool in gathering sensor data with very cheap cost and with minimum effort.
So I hope that Blynk team can find a solution.

Thank you for your comment, Pete.

Kang

I doubt very much that it would be something the Blynk team would look at.
Using EspNow is simply being used to eliminate the need for Blynk users to have subscriptions that allow more devices, so it’s not in Blynk’s best interest to do this is it?

In my experience, posting code with flaws like the ones I’ve highlighted isn’t likely to encourage other community members to take the sketch seriously and chip-in with ideas.

Pete.

1 Like

Here’s something interesting to look at - I’m using this approach for a non- Blynk project but I could see adding in Blynk as some point to the Wifi gateway piece….

Interesting approach, but the Receiver and WiFi Transmitter are only written to handle outbound data. That means that if you change the WiFi Transmitter code to create a permanent connection to Blynk - acting as a Device in Blynk - then it would only handle one-way traffic from the ESP-NOW network to Blynk.
You wouldn’t be able to use switch widgets in Blynk for example to control the devices on the ESP-NOW network without a significant re-write of all three parts of the example code in the link.

If you’re happy to use it to send outgoing data only then it would be simpler to use the Blynk HTTP(S) API in the WiFi Transmitter sketch, as that’s how it’s written to work anyway. This would save you a device in Blynk, and simplify the code changes needed.

Pete.