Using ESP-Now and Blynk

I have set up my project to have a main esp32 that controls water valves and some other stuff. I have sensor esp32 that I want to send sensor data to main esp32 which in return sends to a virtual pin in blynk. I can get the main esp32 to receive sensor data through esp-now when I have not added the device to blynk. Once I add it to blynk It says esp-now is active and added a peer but I receive no data from sensor. I believe it has to do with changing of wifi during setup of device in blynk but I am not positive. Here is snippets of my code where i handle esp-now. Any help on where I am going wrong would be awesome.

    // Initialize ESP-NOW if it hasn't been initialized yet
    if (esp_now_init() != ESP_OK) {
        Serial.println("ESP-NOW already initialized or failed to initialize.");
        return; // If initialization failed or is already initialized, exit the function

    // Register ESP-NOW receive callback

    // Define the peer's broadcast address
    uint8_t broadcastAddress[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};

    // Set up the peer information
    esp_now_peer_info_t peerInfo = {};
    memcpy(peerInfo.peer_addr, broadcastAddress, 6); = 0;  // Use the current Wi-Fi channel
    peerInfo.encrypt = false;

    // Attempt to add the peer
    if (esp_now_add_peer(&peerInfo) == ESP_OK) {
        Serial.println("ESP-NOW peer added successfully.");
    } else {
        // If adding the peer fails, it might already exist or there's another issue.
        // You can decide how to handle this in your application.
        Serial.println("Failed to add ESP-NOW peer, it might already exist.");

void setup() {
    blinkLEDTask,      /* Task function */
    "BlinkLEDTask",    /* Name of the task */
    1000,              /* Stack size in words */
    NULL,              /* Task input parameter */
    1,                 /* Priority of the task */
    NULL);             /* Task handle (not used) */

    buttonTask,        /* Task function */
    "ButtonTask",      /* Name of the task */
    1000,              /* Stack size in words */
    NULL,              /* Task input parameter */
    2,                 /* Priority of the task */
    NULL);             /* Task handle (not used) */
  pinMode(buttonPin, INPUT_PULLUP);

  // Initialize ESP-NOW after Blynk
  if (esp_now_init() == ESP_OK) {
    Serial.println("ESP-NOW Initialized");
  } else {
    Serial.println("Error initializing ESP-NOW");

// ESP-NOW callback function
void onDataReceive(const uint8_t * mac, const uint8_t *incomingData, int len) {
  // Print the MAC address of the sender
  char macStr[18];
  snprintf(macStr, sizeof(macStr), "%02x:%02x:%02x:%02x:%02x:%02x",
           mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
  Serial.print("Received message from: ");

  if (len == sizeof(SensorData)) {
    SensorData receivedData;
    memcpy(&receivedData, incomingData, sizeof(SensorData));
    // Print the received message details
    Serial.print("Temperature: ");
    Serial.print("°C, Humidity: ");
    Serial.print("%, Soil Moisture: ");

    // Now update the Blynk virtual pins with the received values
    Blynk.virtualWrite(V24, receivedData.temperature);
    Blynk.virtualWrite(V19, receivedData.humidity);
    Blynk.virtualWrite(V18, receivedData.soilMoisture);
  } else {
    Serial.println("Received data does not match expected structure size.");

@maxwellsmonson Please edit your post, using the pencil icon at the bottom, and add triple backticks on a seperate line 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.


@PeteKnight Sorry about that all fixed!