chipKIT® Development Platform

Inspired by Arduino™

WiFiTCP

Created Fri, 03 May 2013 13:10:41 +0000 by jferreira


jferreira

Fri, 03 May 2013 13:10:41 +0000

Hello,

Has anyone been able to use de WiFiTCPEchoServer? I am trying to connect it with the WiFiTCPEchoClient but on another computer.

I made the followings changes to the code (WiFiTCPEchoServer):

#include <WiFiShieldOrPmodWiFi.h>              // I uncommented this
                                                                           because I am using MRF24WBxx 
IPv4 ipServer = {192,168,1,101};     //IP that I reserved in the router
const char * szSsid = "lies2";            //name of my network

I made the followings changes to the code (WiFiTCPEchoClient):

#include <WiFiShieldOrPmodWiFi.h>              // I uncommented this
                                                                   because I am using MRF24WBxx
char * szIPServer = "192.168.1.101";    // server to connect to
const char * szSsid = "lies2";                 //name of my network

When I run the code, ther server's final print is "Listening on port: 44300" but the connection is never made. In the router I can see the client but not the server.

I'm guessing that I should change some things, maybe in the router or in the server code... Any thoughts?


KeithV

Fri, 03 May 2013 17:23:32 +0000

Do a simple ping of 192.168.1.101 and see if you get a response. If you get a response, then you probably have mis-match ports; make sure your ports are the same in the 2 programs. If you get no response, they you probably have assigned an IP that is not on your subnet. Also, use the PC code first to verify your server as it is just easier to prove to yourself that the server is up and running. Maybe it is your client code ??

Also, check that your subnet address 192.168.1.xxx or 192.168.0.xxx; some routers defualt to 1 others to 0, an easy error to make. In the TCP Server example, a subnet mask is not obtained, so the server code doesn't verify that it actually is listening on a valid IP for your subnet. The ping will fail if the TCP server has a bogus IP for the subnet.

At this point look at the WiFiRemoteWOL example. In that code DHCP is used to get all of the network parameters such as the subnet mask, DNS servers, gateway, and then an appropriate static IP is constructed to work on your subnet.

The good news is, you got to the point of listening; so the plumbing should all be hooked up; but I would go to the RemoteWOL example to validate each step of startup. Really, now you are playing network admin, the hardware is there.


KeithV

Fri, 03 May 2013 17:42:10 +0000

Oh, and there is another problem you need to be very aware of when using 2 chipKIT boards at once on the same computer. When you program 1 board, ALL of the connected chipKIT boards are going to get a reset. That means they all start concurrently and you can get into a race condition where the client is connecting before the server is up and you can miss the connection attempt... although in most case the client will continue to retry until a connection is made, but this can take sever minutes... How long are you waiting? And, as you know, it can take 40 seconds to connect to the WiFi router, so you do need to wait awhile (say 2 min) before saying the test failed.

You can get around this mass reset problem by putting the boards on different computers; or by powering the server with external power and disconnecting the USB cable from your computer.

Again, this is why it is best to start with one side running on the PC.


jferreira

Mon, 06 May 2013 13:44:38 +0000

I tried out what you said and I got no results...

  1. I checked my subnet address and it really is 192.168.1.xxx;

  2. The code in the client is correct because it works with a server in JAVA (code of my own making). I also used the TCPEchoClient in the folder DNETck/examples/TCPEchoServer/PCCODE but I always get the same error: unable to connect.

  3. I tried to make the ping, but when I run the code of the server I get: Destination host unreachable. With the client code the ping works.

  4. I ran the WiFiRemoteWOL but each time the program gets stuck in the listening mode. It finds and sets itself the same IP that I put in the server code, but nothing connects to it.

  5. I have two chipkit WiFi Shield, so i am using one for each computer.


jferreira

Mon, 06 May 2013 15:49:20 +0000

I'm guessing that I have a problem with the function tcpServer.availableClients(), because this is always zero...


KeithV

Tue, 07 May 2013 04:43:53 +0000

the ping should work if you are connected. Go ahead and change the begin() to not include the IP address and print out the IP addres so you know what DHCP gave you. Then see if you can ping the dynamically assigned server. If the client is working, you have it, it must be something stupid with the IPs.

Here is one real possibility, you have another machine on the network with that IP, or the default submask is totally out of whack.

The difference between the client and server is that the client uses DHCP and gets all of the network parameters from the gateway. The server application just assumes the IP you give it with no other information. It is real easy to double book IPs if you don't get them from the DHCP server.

Since your client work, you are indeed playing system admin now.


jferreira

Tue, 07 May 2013 10:56:00 +0000

I did what you said and this is what I get in the serial monitor:

" WiFiTCPEchoServer 1.0 Digilent, Copyright 2012

Connection Created, ConID = 1 IP Stack Initialized Started Listening My IP: 192.168.1.101 Gateway IP: 192.168.1.1 Subnet mask: 255.255.255.0 Dns1 IP: 192.168.1.1 Dns2 IP: 0.0.0.0

Listening on port: 44300 "

I still can't connect it with the client, because the client never finds the server... This time, however, the data from the server apperead on the router.


KeithV

Mon, 13 May 2013 16:20:34 +0000

this is very odd, it must be a network configuration problem. The fact that the router issued an IP means you have connectivity to the chipKIT and it is working. But you say you still can not ping the server with the dynamically assigned IP?

Is it possible that your client and server chipKITs are on different subnets? Are they both using the same WiFi router or different ones? Did you hang a NAT WiFi router off of your NAT gateway? (this causes 2 different networks). That is, did you not make your WiFi router an AP? Are you using a phone hot spot as your WiFi router? What happens when you switct the location of the clent and server? (again, testing for NAT WiFi router instead of AP; because you can see up, but not down).

If you can not ping, but the router can assign an IP means then router can see the server; but where-ever you are pinging from can not. Can you ping the router that assigned the server the IP? Did you change the IP in your client to access the dynamically assiend IP in your server?

Can you get a windows map of your network via windows "Open Network and Sharing" and see the topology of your network. Also, show me the dynamically assigned IPs and Masks of both the client and server and the IP port the client is attempting to connect too; and the server port it is listenting on.