arduino_uip icon indicating copy to clipboard operation
arduino_uip copied to clipboard

Library won't work when gateway sets up

Open airween opened this issue 8 years ago • 11 comments

Hi there,

I'ld like to build a simple remote switch through HTTP. The examples are good points to start. But there is a problem: when I set up the gateway, the program doesn't work. Without it, the code works as well.

IPAddress ip(192, 168, 72, 3);
IPAddress gateway(192,168,72,254);
IPAddress subnet(255,255,255,0);
EthernetServer server(80);

void setup() {
  Serial.begin(9600);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);

This dosen't work. If I left the last 3 arguments, then HTTP server works as well.

Could anybody helps me?

Regards, a.

airween avatar Dec 01 '16 21:12 airween

Well, I've removed all Serial function call (no Serial.begin(), any .print()...), and the problem solved. Is there any explanation for this?

airween avatar Dec 01 '16 22:12 airween

Which hardware/board are you using? Which software?

stevstrong avatar Dec 02 '16 09:12 stevstrong

Hi stevstrong,

I'm using arduino nano with ENC28J60. Library is uipethernet.

Thanks, a.

airween avatar Dec 02 '16 12:12 airween

@airween The Print class for AVR may have a problem with the "F()" macro, as also did the STM32duino, where I am involved in. For the Ethernet.begin it would be normal to use only the MAC address, since the IP number is normally automatically allocated by the router (DHCP).

stevstrong avatar Dec 02 '16 12:12 stevstrong

Hi @stevstrong, thanks for your reply. That's a bad news for me - now I don't know, what can I do. Anyway, meantime I've ran into a (several) new problems. Eg., I've removed all Serial.*() call from code, but the explicit IP settings doesn't work again... I'll check the DHCP settings, but... it would be better to use it as explicit. Another example: when I change the TCP port (from 80 to another one, eg. 81), then sometimes it doesn't work again... but sometimes it start to work... It drives me crazy....

airween avatar Dec 02 '16 17:12 airween

Another issue - that's not linked to this original issue. Here is a small "syslog" routine:

void syslog(char *msg) {
    udp.beginPacket(IPAddress(192,168,72,254),514);
    udp.write("IPBridge ");
    udp.write(msg);
    udp.endPacket();
    udp.flush();
    udp.stop();
}

and here is why do I use:

  if (client)
  { 
    //Serial.println("-> New Connection");
    syslog("New connection");

There is a cron script, which checks this board that responds or not in every 10 minutes. On syslog server, I see the results:

Dec  2 18:17:53 IPBridge New connection
Dec  2 18:20:01 IPBridge New connection
Dec  2 18:20:02 IPBridge New connection
...nothing...
Dec  3 08:50:01 IPBridge New connection
Dec  3 08:50:01 IPBridge New connection
Dec  3 09:00:01 IPBridge New connection
Dec  3 09:00:01 IPBridge New connection

While the elapsed time there isn't any syslog message from board - but the board has worked as well, I'm logging the result of cron script, and there seems that board is working. But the sending of UDP packets doesn't work randomly.

Do you have any idea, why does it happen?

Thanks, a.

airween avatar Dec 03 '16 08:12 airween

Ervin, sorry I am not that deeply involved in UIP, but I remember I also had several issue with my ENC28J60 module and all associated software (Ethercard as well), that's why I moved to a W5500 module. It may cost a bit more (around $5 on Aliexpress), but is working RELIABLE and much faster and you can save a lot of time avoiding these kind of issues :).

stevstrong avatar Dec 03 '16 11:12 stevstrong

He @stevstrong - thanks again your feedback. Yep, you're right - the board has run about 30 hours ago, now it answers all requests, but the syslog doesn't work much. It sometimes sends the message, sometimes not... That's absolutely unpredictable. I'll see your suggestion - thanks.

Regards, a.

airween avatar Dec 03 '16 12:12 airween

No problem (szivesen :)) As alternative, you could save some cents by buying a W5100 module. Advantage of WIZ modules vs. ENC28: lower flash and RAM usage, full Arduino compatibility, reliability.

stevstrong avatar Dec 03 '16 15:12 stevstrong

Wow! :) Thank you (köszönöm :)) again. I've found some other modules in .hu, in a chinese webshop (but the delivery time is only few days).

airween avatar Dec 03 '16 15:12 airween

airwenn,

I hope you found a solution. I am having the same issue you had. If I leave out DNS, gateway and netmask on the Ethernet.begin call, the problem disappears. With all parameters included, a client connection will seldomly succeed. UDP traffic works, but with some errors.

jp-001 avatar May 10 '18 16:05 jp-001