ntruchsess / arduino_uip

UIPEthernet: A plugin-replacement of the stock Arduino Ethernet library for ENC28J60 shields and breakout boards. Full support for persistent (streaming) TCP-connections and UDP (Client and Server each), ARP, ICMP, DHCP and DNS. Build around Adam Dunkels uIP Stack. Further developed version can be found on https://github.com/UIPEthernet/UIPEthernet
489 stars 212 forks source link

Library won't work when gateway sets up #169

Open airween opened 7 years ago

airween commented 7 years ago

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 commented 7 years ago

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

stevstrong commented 7 years ago

Which hardware/board are you using? Which software?

airween commented 7 years ago

Hi stevstrong,

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

Thanks, a.

stevstrong commented 7 years ago

@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).

airween commented 7 years ago

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 commented 7 years ago

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.

stevstrong commented 7 years ago

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 :).

airween commented 7 years ago

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.

stevstrong commented 7 years ago

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.

airween commented 7 years ago

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).

jp-001 commented 6 years ago

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.