I have tried using a barebones example to try incorporate the two as a proof of concept. This is the code Iām using, based on the latest ESP32 Edgent example
/*************************************************************
Blynk is a platform with iOS and Android apps to control
ESP32, Arduino, Raspberry Pi and the likes over the Internet.
You can easily build mobile and web interfaces for any
projects by simply dragging and dropping widgets.
Downloads, docs, tutorials: https://www.blynk.io
Sketch generator: https://examples.blynk.cc
Blynk community: https://community.blynk.cc
Follow us: https://www.fb.com/blynkapp
https://twitter.com/blynk_app
Blynk library is licensed under MIT license
*************************************************************
Blynk.Edgent implements:
- Blynk.Inject - Dynamic WiFi credentials provisioning
- Blynk.Air - Over The Air firmware updates
- Device state indication using a physical LED
- Credentials reset using a physical Button
*************************************************************/
/* Fill in information from your Blynk Template here */
/* Read more: https://bit.ly/BlynkInject */
#define BLYNK_TEMPLATE_ID "TMPLXKNDXvcy"
#define BLYNK_TEMPLATE_NAME "OTA Test"
#define BLYNK_FIRMWARE_VERSION "0.2.1"
#define BLYNK_PRINT Serial
//#define BLYNK_DEBUG
#define APP_DEBUG
#include "BlynkEdgent.h"
#include <WiFi.h>
#include <esp_now.h>
// Define the ESP-NOW peer address of the other ESP32
uint8_t peerAddress[] = {0x34, 0x94, 0x54, 0xE5, 0xC0, 0xF8};
// Define the data structure for sending and receiving data over ESP-NOW
struct espNowData {
int data1;
float data2;
};
// Define the ESP-NOW send callback function
void OnDataSent(const uint8_t *mac_addr, esp_now_send_status_t status) {
if (status != ESP_NOW_SEND_SUCCESS) {
Serial.println("Data send failed");
}
}
// Define the ESP-NOW receive callback function
void OnDataRecv(const uint8_t *mac_addr, const uint8_t *data, int len) {
// Cast the data buffer to the espNowData structure
espNowData receivedData;
memcpy(&receivedData, data, sizeof(receivedData));
// Process the received data
Serial.print("Received data: ");
Serial.print(receivedData.data1);
Serial.print(", ");
Serial.println(receivedData.data2);
}
BLYNK_CONNECTED()
{
Blynk.virtualWrite(V0, BLYNK_FIRMWARE_VERSION);
}
void setup()
{
Serial.begin(115200);
delay(100);
// Print Mac Address.
Serial.println();
Serial.print("ESP Board MAC Address: ");
Serial.println(WiFi.macAddress());
// Connect to WiFi and Blynk
BlynkEdgent.begin();
// Initialize ESP-NOW
WiFi.mode(WIFI_STA);
if (esp_now_init() != ESP_OK) {
Serial.println("ESP-NOW initialization failed");
return;
}
// Register the ESP-NOW send callback function
esp_now_register_send_cb(OnDataSent);
// Register the ESP-NOW receive callback function
esp_now_register_recv_cb(OnDataRecv);
// Register the peer address
esp_now_peer_info_t peerInfo;
memset(&peerInfo, 0, sizeof(peerInfo));
memcpy(peerInfo.peer_addr, peerAddress, sizeof(peerAddress));
peerInfo.channel = 1;
peerInfo.encrypt = false;
if (esp_now_add_peer(&peerInfo) != ESP_OK) {
Serial.println("Error adding ESP-NOW peer");
return;
}
}
void loop() {
// Send data over ESP-NOW
espNowData sendData = {123, 3.14};
esp_err_t result = esp_now_send(peerAddress, (uint8_t *) &sendData, sizeof(sendData));
if (result != ESP_OK) {
Serial.println("Data send failed");
}
else {
Serial.print("Sent data: ");
Serial.print(sendData.data1);
Serial.print(", ");
Serial.println(sendData.data2);
}
delay(1000);
// Process Blynk events
BlynkEdgent.run();
}
If I comment out BlynkEdgent.run(), ESP-NOW works flawlessly. However, as soon as BlynkEdgent.run() is called, it seems to break ESP-NOW, resulting in :
ESPNOW: esp now not init!
Can anyone point me in the right direction to getting them to run simultaneously?