Blynk and ESP NOW. "Connecting to blynk cloud.com:80" problem

Hello, my project consists of the following:
I have two ESP8266 (master and slave) communicating with each other through ESP NOW. The master obtains values from an MPU6050 accelerometer / gyroscope and the slave is in charge of controlling a WS2812 led strip with the readings obtained from the master.
Up to this point, it works correctly. I want to use Blynk for the slave ESP8266 in order to control color, LED intensity, etc. through the app (I have not programmed that part yet) BUT the problem begins after I attach the ESPNOW part to the Blynk code. The serial monitor only shows me “Connecting to blynk-cloud.com:80”.
I have searched the forums and on the Internet and I have not found a solution, please if someone can help me out, I would greatly appreciate it!

#include <ArduinoJson.h> 
#if defined(ESP8266)
#include <ESP8266WiFi.h
#include <BlynkSimpleEsp8266.h>
#include <Adafruit_NeoPixel.h>
#ifdef __AVR__
 #include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif

static uint8_t PEER[] {0x3E, 0x71, 0xBF, 0x38, 0xE2, 0x1A}; //MAC SLAVE

#define PIN        D2
#define PIN2       D5 
#define NUMPIXELS 22 

int periodo = 2000; //delay
unsigned long tiempoahora = 0; //delay

Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_BRG + NEO_KHZ800);  //configuraciĂłn tira led tipo BRG
Adafruit_NeoPixel pixels2(NUMPIXELS, PIN2, NEO_BRG + NEO_KHZ800);  //configuraciĂłn tira led tipo BRG

char auth[] = "xxxxx";
BlynkTimer timer; 
char ssid[] = "INFINITUM3EF9_2.4";
char pass[] = "kYX95bL3L9";
 
//*******************************************************************
BLYNK_WRITE(V2) {
  switch (param.asInt())
  {
    case 1: // Item 1
    pixels2.clear();
      Serial.println("TIRA DERECHA");
       for( int e = 0; e <= NUMPIXELS; e++){
         pixels.setPixelColor(e, pixels.Color(0, 0, 255)); //
     } 
     pixels.show();
      break;
    case 2: // Item 2
    pixels.clear();
      Serial.println("TIRA IZQUIERDA");
        for( int e = 0; e <= NUMPIXELS; e++){
         pixels2.setPixelColor(e, pixels2.Color(0, 0, 255)); //
     } 
     pixels2.show();
      break;
    default:
      Serial.println("default blynk");
  }
}//*******************************************************************

//***RECEPCION DEL MENSAJE***//
void printReceivedMessage(const uint8_t mac[6], const uint8_t* buf, size_t count, void* cbarg) {
String sJson;
String cJson;
StaticJsonDocument<1000> doc; //JSON********
if(millis() > tiempoahora + periodo){
    tiempoahora = millis();
for(int i = 0; i < count; ++i)
{  
 
  sJson = String(static_cast<char>(buf[i]));   //convierte a string
 
  cJson += sJson; //concatenar Json
  } //fin for  
  
  //***DESERIALIZACION***//
 DeserializationError error = deserializeJson(doc, cJson);
  // Test. 
  if (error) {
    Serial.print(F("deserializeJson() failed: "));
    Serial.println(error.c_str());
    return;
  } 

 String valX = doc["valX"];
 String valY = doc["valY"];

Serial.print(valX);
Serial.println(valY);
  }//millis
} //final void 

void setup()
{
  // Debug console
  Serial.begin(115200);
  Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80)

  //***INICIALIZACIĂ“N DE LA TIRA LED***//
  #if defined(__AVR_ATtiny85__) && (F_CPU == 16000000)
  clock_prescale_set(clock_div_1);
#endif
  // END of Trinket-specific code.

   pixels.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
  pixels2.begin();

  pixels.clear();
  pixels2.clear();

   WiFi.persistent(false);
  WiFi.mode(WIFI_AP);
  WiFi.softAP("ESPNOW", nullptr, 3);
  WiFi.softAPdisconnect(false);

  Serial.print("MAC address of this node is "); 
  Serial.println(WiFi.softAPmacAddress());

//*INICIALIZACIĂ“N DEL PROTOCOLO ESP-NOW*//   
  bool ok = WifiEspNow.begin();
  if (!ok) {
    Serial.println("WifiEspNow.begin() failed");
    ESP.restart();
  }

//***EMPAREJAMIENTO CON EL ESCLAVO***//   
  WifiEspNow.onReceive(printReceivedMessage, nullptr);

  ok = WifiEspNow.addPeer(PEER);
  if (!ok) {
    Serial.println("WifiEspNow.addPeer() failed");
    ESP.restart();
  }
}//fin setup

void loop()
{
  Blynk.run();
  timer.run();

}

First of all, try a simple sketch to ensure that your ESP8266 can connect to Blynk without any issues. If it can’t connect then try changing g the port used in your Blynk.begin to 8090 8080
After that, I think your code will fail when it tries to use the ESP’s WiFi modem as an Access Point after connecting to Blynk, as I think that this will cause a Blynk disconnection.

Pete.

Thanks for answering. Yes, I already proved that my ESP8266 can connect well with a simple sketch, even control the led strip through a menu.
Everything connects with blynk effectively except when I add the following in the setup (the ESP NOW part). Does that mean there is no way to use Blynk and ESP NOW at the same time?

WiFi.mode(WIFI_AP);
WiFi.softAP("ESPNOW", nullptr, 3);
WiFi.softAPdisconnect(false);

Serial.print("MAC address of this node is "); 
Serial.println(WiFi.softAPmacAddress());

//*INICIALIZACIĂ“N DEL PROTOCOLO ESP-NOW*//   
bool ok = WifiEspNow.begin();
if (!ok) {
  Serial.println("WifiEspNow.begin() failed");
  ESP.restart();
}

//***EMPAREJAMIENTO CON EL ESCLAVO***//   
WifiEspNow.onReceive(printReceivedMessage, nullptr);

ok = WifiEspNow.addPeer(PEER);
if (!ok) {
  Serial.println("WifiEspNow.addPeer() failed");
  ESP.restart();
}

Typo :stuck_out_tongue: the proper port is 8080

However, since ESP NOW still uses the same 2.4GHz radio on the ESP device, as it would if using WiFi, I suspect the answer to using both is no… But perhaps more Googling and searching this forum may be necessary to confirm and/or set up the devices?

But after a (little)bit of my own searching, I still think it not possible.

Doh! Fat fingers on the phone keyboard - again!

Pete.

1 Like

Oh wow, that complicates everything haha :cry:
Any ideas or suggestions about what I should to use instead ESP NOW for communication between the two ESP8266 to also use them with Blynk?
Please, I’m completely new to programming and networking.

Firstly, is it possible to use one device to both the master/slave tasks?

If not then the normal process is to run Blynk code on both devices, and use the Blynk server to handle the communications between the two devices. To achieve this, each device needs its own Auth code and Blynk Bridge code will need to be run on at least one of the devices.

Pete.

1 Like

Blynk has a feature called Bridge that might do what you are looking for. However, as it is part of Blynk, and Blynk is IoT based, all devices will require their own direct links to the server (cloud or local), unlike how ESP NOW functions (internet/network independent).

1 Like

Hi, I’m already using BLYNK BRIDGE but it’s too slow when I control it from the Blynk app. Is there any way to solve this by code?

Im having much the same sort of problem. The workaround that Im currently working on is to use WiFi and eep-now in rotation; turning WiFi off allows eep-now to resume control. Then WiFi back on… and that’s the current problem, getting WiFi to come back on is proving difficult. I’ll let you know how this develops. In the meantime, grateful for any input.

esp.now not eep

The only way that Ive found to get over this problem, is to have two modules side by side, one handling WiFi and Blynk, the other handling the wireless asp-now protocols. The second module then can pass data over UART (three wires) or (four if you want to include power) back to your Blynk module. I use it on esp32’s but it should work ok on 8266’s.

What I found at Andreas Spiess is to do a restart of the ESP8266 / ESP32
After a restart you can choose new to use ESP-NOW or WiFi.
Though this requieres saving all data to a non-volatile memory that does NOT wear out.
The flash has 100.000 writecycles which is sufficient for code-developing / updating but not sufficient for writing every few minutes. So you would need an external FRAM-Chip. The ESP32 has some RAM in its “RTC”-section which stays alive through a restart or a reset of the chip

best regards Stefan

Peace, mercy and blessings of ALLAH
I have successfully used Blynk with ESPNow by making the ESP32 work as a station, not as access point.

void setup() {
  // Init Serial Monitor
  Serial.begin(115200);

  Blynk.begin(auth, ssid, pass);

  // Set device as a Wi-Fi Station
  WiFi.mode(WIFI_STA);

  // Init ESP-NOW
  if (esp_now_init() != ESP_OK) {
    Serial.println("Error initializing ESP-NOW");
    return;
  }

Can you share the rest of your objects for listening and sending over espnow while connected to blynk?

It does not work at all