Issue with connecting using ethernet shield

Blynk library version: 0.3.3-1.0.0-beta
IDE: Arduino
IDE version: 1.6.13-1.8.13(did not tried older)
Board type: Arduino mega 2560(1x chinese, 1x original italian)
Additional modules: Ethernet shield w5100 (1x original italian, 2x chinese)

Hi guys! First of all, thank you for great product! Using it at home for aproximmate year for now…
I can’t make work my new arduino mega and ethernet shield w5100(
The issue is simple, blynk sketch just not connecting to blynk server in local network, and in blynk-cloud.
The bug is strange, year ago or something like that, it all was working. I actually have one mega with w5100 that i program approximate in that time, and it still working. Bug reproduces with all versions of ethernet library that i found, and all blynk-lib versions. Bug behavior is version dependent. It can be just stuck on connecting, or connection timeout. I actualy tried all possible variations and combinations of libraries versions(blynk-lib and ethernet-lib), different arduinos, shields, different switches, cables, ide versions, and so on. Seem’s like i only one who use that hardware) And that is ethernet library, or blynk compability with it, totaly broken(

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG
#define W5100_CS  10
#define SDCARD_CS 4

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

const char auth[] = "fg8hpyqvnJbPAYbwd1hWUna2KuzkvRNB";
byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // as i remember blynk lib generates mac from token, but i tried to mannualy set it up.
IPAddress arduino_ip (10,10,158,180);
IPAddress server_ip (10,10,158,254); //well yep, server on a router, but if move local server to another subent - still nothing
IPAddress dns_ip     (10,10,158,254);
IPAddress gateway_ip (10,10,158,254);
IPAddress subnet_mask(255,255,255,0);
uint16_t port = 8080;

void setup()
{
  // Debug console
  Serial.begin(115200);

  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH); 

 // Ethernet.begin(mac, arduino_ip, dns_ip, gateway_ip, subnet_mask);

 // Blynk.config(auth,server_ip, 8080);
  // Blynk.connect(10000);
//  Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, mac);
    Blynk.begin(auth, IPAddress(10,10,158,254), 8080);
 // tried using blynk config, and blynk begin in different combinations too
}

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

Does your server actually listen to port 8080? What does your serial monitor show?

Uninstall this library and install 0.6.1 instead.

If you’re running two Arduinos with Ethernet shields on the same network at the same time then the MAC addresses and IP addresses need to be unique, and not clashing with any other devices that are already on the network.
I’d suggest downloading Advanced IP Scanner to ensure that you don’t have any conflicts with existing devices…

Pete.

Yes. I have 2 rpi with linux library, and they connected to the same server. And they working

Hi! Of course mac and ip is unique) I’ve thought it’s may be not unique, and tried to set it manually, but it not helped. And i temporarily disable old one mega 2560 that is working.

By 0.3.3-1.0.0-beta i mean that i tried to use all downloadable versions of library(

Unlike most devices, Arduino Ethernet shields don’t have an embedded MAC address so you have to specify it manually. When you do, they need to be unique on your network.

But 0.6.1 is the one you should be using.

These Ethernet shields extremely unreliable, and in my opinion they aren’t fit for purpose. Even the genuine Arduino ones aren’t good.
If you’re lucky, you’ll get one that works well - until it stops working altogether. I’ve spent more time and money on these things than I care to remember, until eventually saw the light and became a convert to the ESP8266/ESP32.

One thing to try is a different Ethernet switch, or connecting your shields directly into the router. These shields refuse to work at all with some Ethernet switches.

Pete.

Thank you for your answers. Well, i tested all these shields, and they all working. They get address be dhcp, they answer by this address… Also, i tried all these shields with my old arduino mega that have working firmware - and they all workind and connecting to server. So i think that is something or with library versions, or may be with ide version, gcc, or something.
This is what i see in port monitor. If i compile it with latest ethernet library 2.0.0 (now version 1.1.2)- it will spam very quickly messages like this
изображение

This is a proof that mac and ip unique if i defined it
Screenshot_20210416_141143

The interesting thing is that, with old Ethernet library i don’t even see that it trying to send something on router, where blynk server is. (filetrash.ivaninc.me is old name of 10.10.158.254, need to change it)

(cannot attach more than one media in message)
But with ethernet 2.0.0 lib, i see tcp spam) So it at least trying to connect…

What happens if you add Blynk debug to your sketch, what do you see in your serial monitor monitor?

Pete.

As i mentioned before, nothing special. With latest version of blynk-library 0.6.1, and ethernet lib 2.0.0
just a LOT of messages like this, that appear very quickly, and nothing else. It with

#define BLYNK_PRINT Serial
#define BLYNK_DEBUG

Can you post what you get from boot-up to the first of these messages (and copy/paste the results rather than posting a screenshot)?

Pete.

I’m really sorry, i thought that screenshot will better)

[0] Using static IP
[1560] IP:10.10.158.0
[1561] 
    ___  __          __
   / _ )/ /_ _____  / /__
  / _  / / // / _ \/  '_/
 /____/_/\_, /_//_/_/\_\
        /___/ v0.6.1 on Arduino Mega

[1569] Connecting to 10.10.158.254
[1575] Connecting to 10.10.158.254
[1580] Connecting to 10.10.158.254
[1584] Connecting to 10.10.158.254
[1587] Connecting to 10.10.158.254
[1591] Connecting to 10.10.158.254
[1595] Connecting to 10.10.158.254
[1599] Connecting to 10.10.158.254
[1602] Connecting to 10.10.158.254
[1606] Connecting to 10.10.158.254
[1610] Connecting to 10.10.158.254

Yes, there is an interesting thing, that it showing not correct ip address, it looks like subnet. But it seems like little bug in ethernet library, becouse blynk lib calling Ethernet.localip() function. But, ping works on defined address in sketch.
Again,

#define W5100_CS  10
#define SDCARD_CS 4
#define BLYNK_PRINT Serial
#define BLYNK_DEBUG

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>

const char auth[] = "fg8hpyqvnJbPAYbwd1hWUna2KuzkvRNB";
byte mac[] = { 0x00, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress arduino_ip (10,10,158,180);
IPAddress server_ip (10,10,158,254);
IPAddress dns_ip     (10,10,158,254);
IPAddress gateway_ip (10,10,158,254);
IPAddress subnet_mask(255,255,255,0);
uint16_t port = 8080;


void setup() {
  Serial.begin(115200);
  pinMode(SDCARD_CS, OUTPUT);
  digitalWrite(SDCARD_CS, HIGH);
  Blynk.begin(auth, server_ip, 8080, arduino_ip, dns_ip, gateway_ip, subnet_mask, mac);
}

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

Hi! Any ideas?

You could try turning on verbose compiler messages and study what it says about the library version candidates that have been found, and which one is being used for the compilation. This might steer you towards finding an issue.

Of course, the real solution is to stop banging your head against the wall and consign the Megas and their Ethernet shields to the bin and go for an IoT compatible board such as a NodeMCU or ESP32.

Pete.

So your sketch works if you use DHCP?!

[Normally] IP’s ending with .0 is the Network ID, .255 the broadcast address, and (even though it’s perfectly doable today) neither should be assigned to a host. It’s like asking for trouble! :slight_smile:

I would look into that first… Then everything else - again! :stuck_out_tongue_winking_eye:

No strange routing or firewall rules on your router? Any useful information in the log files (both Blynks own and the servers)? Tried to disconnect everything from your network except the server and Arduino (and rebooted)?

Just some ideas, could be anything :frowning:

EDIT: Did some Google Fu and a common problem seems to be that the Mega needs its Hardware SS pin set as an output, otherwise it can interfere with the SPI:

pinMode(53, OUTPUT);

Worth a try!

Hey! Don’t you dare talk like that about my baby W5100! :kissing_heart: :stuck_out_tongue_closed_eyes:

:rofl: :rofl: :rofl: