3 years, 4 months ago.

Does TcpClient_ENC28J60 work?

Has anyone successfully used Zoltan Hudak's / Norbert Truchsess' excellent work with UIPEthernet.h to connect to a remote server. I have tried Zoltan's TcpClient_ENC28J60 on two different platforms, including the STM32F334R8 which I also tested millis was OK on. I just repeatedly get:

Connecting to TCP/IP server ..<\r><\n> Failed to connect to server<\r><\n>

So it's not connecting. I also get no success trying to use DHCP to provide the IP address, so I am using a static IP address. I can't connect to servers on the same network either.

I enabled serial output during tick and see ARP and IP packets.

Connected to the same router, I can successfully use F7_Ethernet on a DISCO-F746NG to created a TCPSocket, connect and retrieve data from remote servers. This shows it shouldn't be an issue with my network.

I have had success with Zoltan's WebSwitch_ENC28J60 which establishes a server (I used the same fixed IP address as above). I can browse to it and turn the LED on / off, so no problem acting as a server.

I should have said that I changed to const IPAddress SERVER_IP(184, 106, 153, 149); and const uint16_t SERVER_PORT = 80; which are the thingspeak IP and port. I have tried others as well.

posted by Chris P 10 Jul 2016
Comment on this question

1 Answer

3 years, 4 months ago.

Hello Chris,
I'm sorry for the inconvenience. That must be frustrating. Since the WebSwitch_ENC28J60 works I would recommend to try the following:

  • Create a TcpServer_ENC28J60. Use the same IP and MAC number which worked for the WebSwitch_ENC28J60. (Make sure the WebSwitch_ENC28J60 is not connected to the network at the same time.)
  • Try to send it a ping command from your PC to check whether it's alive.
  • If it's responding then increment or decrement the last byte in IP, recompile and send it a ping again. If it works then you have a pair of working IP's.
  • Keep the TcpServer_ENC28J60 running with the last working IP.
  • Create a TcpClient_ENC28J60 with static IP that worked for theTcpServer_ENC28J60 first time. Do not forget to change the MAC number. It must be unique within the connected network!

Let me know how it worked.

Zoltan

Hello Zoltan, thank you for your response! Unfortunately I only have one ENC28J60 module so can't have a separate server and client running at the same time. I can ping WebSwitch_ENC28J60 successfully, but not TcpClient_ENC28J60 unless I use the same MAC as I have previously used for WebSwitch_ENC28J60.

One thing I noticed is that if I replace the main.cpp of WebSwitch_ENC28J60 with the main.cpp of TcpClient_ENC28J60 it falls through the client.connect rather than endlessly blocking (on HRM1017). [as an aside the mbed compiler kept compiling the previous main.cpp until I made a minor change to main.cpp :-) ]

I will try TcpServer_ENC28J60.

posted by Chris P 10 Jul 2016

Actually if I use TcpClient_ENC28J60 keeping the same MAC as used with WebSwitch_ENC28J60 and just change the IP address I can ping the new IP address.

posted by Chris P 10 Jul 2016

Hello Chris, Which server are you trying to connect to with the TcpClient_ENC28J60? Make sure that the server is listening at the same port as the client is trying to connect to (10001). If you are familiar with Qt then try to build this TCP/IP server on you PC (I used it for testing). Do not forget to change the IP address. Once built, run the server and try to connect to it with the TcpClient_ENC28J60.

posted by Zoltan Hudak 10 Jul 2016

Hello Zoltan, I am using the thingspeak.com server (port 80) and I have successfully connected to it using the F7_Ethernet library.

I have used an ESP8266 wirelessly connected to the same network as a possible target, but that doesn't work with the original TcpClient_ENC28J60 program. I see nothing on the ESP8266. However ( :-) ) I do see connection events on the ESP8266 UART output with an adapted Webswitch_ENC28J60:

mbed: Connecting to TCP/IP server ..<\r><\n> Server connected.<\r><\n> Sending some data to server:<\r><\n> 0x56 0xe 0x49 0x40 <\r><\n> Awaiting message from server:<\r><\n> Message received from server:<\r><\n> 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x41 <\r><\n> Disconnected from server.<\r><\n> Waiting..........<\r><\n> Connecting to TCP/IP server ..<\r><\n> Failed to connect to server<\r><\n>

ESP8266: 0,CONNECT<\r><\n><\r><\n>+IPD,0,4:V<14>I@AT+CIPSEND=0,10<\r><\r><\n><\r><\n> OK<\r><\n> <\r><\r><\n>busy s...<\r><\n><\r><\n>Recv 10 bytes<\r><\n><\r><\n>SEND OK<\r><\n>0,CLOSED<\r><\n>

It's intermittent.

posted by Chris P 10 Jul 2016

So where I have got to now is that using the TcpClient_ENC28J60 main.cpp with the WebSwitch_ENC28J60 UIPEthernet library I can connect to a local server (intermittently). It won't however connect out to an external server (by IP: 184.106.153.149).

Could it be a Gateway issue? Or could it be a timeout issue which is sometimes OK on a local server but never for an external?

posted by Chris P 10 Jul 2016

I was investigating the state of _uip_conn and _uip_conn->tcpstateflags with printf and it started to work intermittently with the external server. Presuming it was the delay, I have added a wait_ms(2) just before (or after) UIPEthernet.tick(); in int UIPClient::connect(IPAddress ip, uint16_t port) and without the printf it works intermittently with the external server. This suggests it is something to do with timings.

posted by Chris P 10 Jul 2016

I set a loop running where it tries to connect to thingspeak every 10 seconds ten times before an NVIC_SystemReset() and restarting. Of the 89 times through the set of ten attempts (so 890 in total), there were 90 instances of server connected, but only 50 messages on thingspeak. Each attempt of the ten was labelled with a number so I can tell which was successful and it breaks done as follows: 3x first attempt, 30x second attempt and 17x third attempt Never was it between 4 and 10 and never did it successfully connect and have a message received by the server more than once per set of ten attempts.

So in conclusion, an NVIC_SystemReset() is currently required to have a successful attempt.

posted by Chris P 11 Jul 2016

You need to log in to post a question