No connection to the blynk server

Hi,

i’m a long time user of the blynk platform and it always worked fine for me.
After the update to blynk 2.0 i’m not able to connect to the blynk server anymore.

I use an Arduino MEGA 2560 in combination with the ethernet shield W5500.
Blynk library v1.1.0 It is connected to the homenetwork and works fine.

I use following code to connect to the blynk server (i left out all the other code);

#define BLYNK_TEMPLATE_ID "xxxxxxx"
#define BLYNK_DEVICE_NAME "xxxxxxx"
#define BLYNK_AUTH_TOKEN "xxxxxxxx"                             

#define BLYNK_PRINT Serial

#include <SPI.h>                                                                    
#include <Ethernet2.h>                                                                
#include <BlynkSimpleEthernet2.h>                                                   
char auth[] = BLYNK_AUTH_TOKEN;

void setup() {
Serial.begin(115200);
ethernetSetup();    
MQTTSetup();   
                                               
Blynk.begin(auth);
// Blynk.begin(auth, "blynk.cloud", 80);
}


#ifndef EthernetMQTT_h
#define EthernetMQTT_h

#include <PubSubClient.h>

const byte mac[] = {..x,.x..,.x..,.x..,.x..,.x..};                             
const IPAddress ip(192, 168, x, x);
const IPAddress server(192, 168, x, x); 

EthernetClient ethClient;                        
PubSubClient client(ethClient);              
void receivedCallback(char* topic, byte* payload, unsigned int length);   

long lastReconnectAttempt = 0;

boolean reconnect() {
  if (client.connect("arduinoClient")) {  
    client.subscribe("xxx/xxx/xxx");
  }
  return client.connected();
}

void ethernetSetup() {
  Ethernet.begin(mac, ip);   
  delay(3000);                     
  lastReconnectAttempt = 0;
}

void MQTTSetup(){
  client.setServer(server, 1883);
  client.setCallback(receivedCallback); 
}

void MQTTLoop(){    if (!client.connected()) {
    long now = millis();
    if (now - lastReconnectAttempt > 5000) {
      lastReconnectAttempt = now;      
      if (reconnect()) {
        lastReconnectAttempt = 0;
      }
    }
  } else {
    client.loop();             
  }
}
#endif


void loop() {
MQTTLoop();
Blynk.run();
}

hope anyone has the solution for me.
Thanks.

Posting the serial output might help.

That’s a bad idea, as what’s in your ethernetSetup function will have a big influence on connectivity.
Post your full sketch please.

Pete.

serial monitor

Hello,

maybe need use

Blynk.begin(auth, ssid, pass, "blynk.cloud"); in void setup()

I tried that but without SSID and pass becource i’m connected with a ethernet cable instead of a wireless network. With the previous version of Blynk this was not a problem.

Pete.

see previous lines.

Have you tried the example

Without the ethernetSetup() function?

When you update a previous post with updated code it’s useful if you make a post saying that you’ve done that, because we aren’t notified when. you make an edit.

Normally, the Ethernet.begin command would specify the DNS server, gateway and subnet mask, like this…

Ethernet.begin(mac, ip, dns, gateway, subnet);

Gateway would normally be the IP address of your router, the DNS server could be the same, or something like 8.8.8.8
Subnet mask for a 192.168.1.x would be 255.255.255.0 but it’s not clear whether that is the IP address range you’re using.

I suspect that your device is connecting to your MQTT server, as its internal to your network, but that it doesn’t know how to get packets to the outside world, and if it does how to resolve the Blynk cloud server.

On a side note, there might be a better way to use Blynk. My home automation system uses MQTT only code on my devices, and Node-Red with the Blynk plug-in as the gateway to communicate with Blynk.
More info here if you’re interested in this approach…

Pete.

Without ethernet function no succes, even no connection with my MQTT server anymore.

I replaced the code with the entire Ethernet.begin(mac, ip, dns, gateway, subnet) and declared the correct data for each statement but still the same result. No connection to the Blynk server but still good connection with my MQTT server. Next thing i’m gonna try is use the node-red as i’m allready use this for the visualisation and control of my home automatisation.

Maybe i’m seeing it wrong but you are calling Ethernet ( Ethernet.begin(mac, ip); )
in your ethernetSetup void but you’ve only included Ethernet2.h earlier…

Without seeing your actual code and the actual IP addresses you’ve used it’s difficult to comment further.

But if you’re already using Node-Red then it’s a no-brainier to go down that route.

Pete.

A post was split to a new topic: Ethernet2 Problem with Blynk IoT

I’m now running blynk using node-red and it’s working fine. Strange that it’s not running in the Arduino code but atleast i found a way around it. Thanks for helping me and suggesting this other sollution.

1 Like

I love the simplicity of using Node-Red to amalgamate the data coming from multiple ‘devices’ into one Blynk device dashboard.
I also like the fact that, if you write your device code sensibly, Node-Red can be your rules engine and you can make the vast majority of your functionality changes in Node-Red rather than having to update the sketches running on your devices.

As far as the original issue is concerned, I still think it’s an issue of getting the device to ‘see’ the outside world via your router, then being able to resolve the Blynk server via a DNS server.

Pete.