0
votes

I have a Arduino Uno and a WiFi shield ; the project goal is to aquire data from a sensor and to send it to a Processing sketch running on a PC over WiFi.

Taking most of my code from the various official exemples, I managed to have the WiFi shield to successfully connect to a WiFi (WPA) network (according to the board and the smartphone hosting the network).

However, when I try to send/receive data from the board, I always get an error, and I do not know where it is from.

I doubt the error comes from my code, as it's almost only copy and pastes, but here are the relevant parts just in case :

Initilization :

char ssid[] = "MiniStepper"; // Network name
char pass[] = "Test1234"; // Network code
int keyIndex = 0; // Network key
int statut = WL_IDLE_STATUS;
WiFiServer server(80);

Setup :

void beginWiFi(){ // called in setup()
  // Connection to the network (working, so omitted)
  //...

  server.begin();
}

Answering to requests :

void connexionRead(){ // called in loop()

  WiFiClient client = server.available();
  if(!client) return;

  Serial.println("New connexion !"); // This never prints, so I'm sure the problem is earlier

  // ...code sending back a HTML file with the HTTP protocol
}

I'm doing access using Chrome (I tried Firefox with no results as well), using the IP Address given by WiFi.localIP() (the smartphone hosting the network gives the same) :

http://192.168.43.200/

which gives back "ERR_CONNECTION_REFUSED".

I'm really new to IoT, and I'm guessing it's probably a config problem (firewall, ...) ; my computer is running Ubuntu 15.10 (Willy Werewolf) (I tried with the same results with a Windows 7 PC), the network is encrypted by WPA, hosted by a XPeria U (I tried with other smartphone-hosted WPA networks with the same results), the arduino WiFi shield with Uno board (bought less than 3 months ago so I'm guessing it's the latest version).

My researches on the Arduino Forum or here only let results like "doesn't work in Arduino 1.0.5, go back to Arduino 1.0.3", but the current version is 1.8.2, so I'm not really sure if going back this much would help.

Is there anything I missed ?

EDIT. Here is the ping :

/home/ubuntu>ping 192.168.43.200
PING 192.168.43.200 (192.168.43.200) 56(84) bytes of data.
64 bytes from 192.168.43.200: icmp_seq=1 ttl=255 time=9.54 ms
64 bytes from 192.168.43.200: icmp_seq=2 ttl=255 time=6.01 ms
64 bytes from 192.168.43.200: icmp_seq=3 ttl=255 time=6.15 ms
64 bytes from 192.168.43.200: icmp_seq=4 ttl=255 time=7.23 ms
64 bytes from 192.168.43.200: icmp_seq=5 ttl=255 time=7.03 ms
 <and more>
--- 192.168.43.200 ping statistics ---
31 packets transmitted, 31 received, 0% packet loss, time 30048ms
rtt min/avg/max/mdev = 4.112/6.415/11.377/1.706 ms
2
I assume you run the browser in you PC and 192.168.43.200 is the IP address of your Arduino. You should begin analyzing the problem by parts. 3 questions: 1-Does ping to 192.168.43.200 work? 2-If you log into the AP, can you see the Arduino connected? 3-Is the Arduino receiving the IP address from the AP's DHCP or is it statically configured?rodolk
Your assumptions are correct ; 2 : yes, 3 : testing with different networks gave different IPs, so it's not statically configured.CLOVIS
I do not know for question 1 though...CLOVIS
Can you run command 'ping 192.168.43.200' from command line in your PC? (assuming the Arduino IP is still 192.168.43.200) And copy the results hererodolk
Just edited the post to add the ping command, it seems to work. Any idea of what could cause it ?CLOVIS

2 Answers

0
votes

If the error is ERR_CONNECTION_REFUSED it is most probably because you don't have the port open in the Arduino. So you should check the application is actually listening to that port or also if the Arduino is running any firewall preventing connection (I doubt this is the case).

Again, this is assuming the Arduino is the one with address 192.168.43.200. To debug this problem you can use Wireshark, run it in your PC to sniff traffic to 192.168.43.200. You should see an outgoing TCP message to 192.168.43.200:80 and then a TCP RST message back.

0
votes

After some more reasearches, I learned that apparently the constructor builds the WiFi Shields with outdated firmware. This problem is solved with the new upgrade (released before 2012, that's why I never thought it could be the case).

// Use this line in the Arduino code :
Serial.println(WiFi.firmwareVersion());
// If it doesn't print 1.1.0, you're outdated.

For instance, here are the steps to upgrade the WiFi shield under linux (in case somebody needs it, this is mostly the same as the official page) :

First, install the package dfu-programmer :

sudo apt-get install dfu-programmer

(there is a typo in the official page linked above) or

sudo aptitude install dfu-programmer

Now disconnect your WiFi shield from the Arduino board (a Uno in my case), and connect the J3 jumper : picture of the J3 jumper, called 'DFU programming jumper' here.

Connect the WiFi shield to your computer directly using a mini-USB cable (still without the main board), press the 'reset' button.

Assuming your Arduino IDE download is earlier than 2012 (otherwise follow the steps on the official page to download the file), go where you installed it, then harware/arduino/avr/firmwares/wifishield/scripts, you should see a script called ArduinoWifiShield_upgrade.sh. Just open a terminal in this folder :

sudo ./ArduinoWifiShield_upgrade.sh -a <the path where you installed Arduino, that contains the harware folder> -f all

Retry a few times if it doesn't work, it worked after the 4th or 5th time for me.

When it worked, unplug the mini-USB cable, unplug the J3 jumper. Next time when you'll try to upload some code to the WiFi shield, you might have an error in the IDE, if you do, press the 'reset' button on the Shield.

These steps solved the problem to me.