I'm new to arduino. Running the Arduino Uno + WiFi Shield.
I've snagged a sample from the examples to demonstrate my problem. (and to attempt to make sure I wasn't missing anything with my actual code.)
I'm able to connect to my wifi network. I'm able to ping the arduino from other network nodes.
However, from the arduino I'm unable to connect to a port on a server to send a packet.
Am I missing something?
No issues telneting to the port from other machines, I'm able to type a string in and it shows up in my debug screen on the server.
Tried a tcpdump on the server, no hits; the only results from the arduino's IP were arp requests (when it was obtaining DHCP address).
Thanks for any help you can provide.
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "myssid"; // your network SSID (name)
char pass[] = "key"; // your network password
int status = WL_IDLE_STATUS;
//char servername[]="google.com"; // remote server we will connect to
IPAddress servername(192,168,1,79);
WiFiClient client;
void setup() {
Serial.begin(9600);
Serial.println("Attempting to connect to WPA network...");
Serial.print("SSID: ");
Serial.println(ssid);
status = WiFi.begin(ssid, pass);
if ( status != WL_CONNECTED) {
Serial.println("Couldn't get a wifi connection");
// don't do anything else:
while(true);
}
else {
Serial.println("Connected to wifi");
Serial.println("\nStarting connection...");
// if you get a connection, report back via serial:
if (client.connect(servername, 8889)) {
Serial.println("connected");
client.println("25");
}else{
Serial.println("not connected");
}
}
}
void loop() {
}
results in:
Attempting to connect to WPA network...
SSID: myssid
Connected to wifi
Starting connection...
not connected
Resolved by reverting to Arduino IDE 1.0.3 and recompiling.
#include <SPI.h>
#include <WiFi.h>
char ssid[] = "yourNetwork"; // your network SSID (name)
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0; // your network key Index number (needed only for WEP)
int status = WL_IDLE_STATUS;
// if you don't want to use DNS (and reduce your sketch size)
// use the numeric IP instead of the name for the server:
//IPAddress server(74,125,232,128); // numeric IP for Google (no DNS)
char server[] = "www.google.com"; // name address for Google (using DNS)
// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
WiFiClient client;
void setup() {
//Initialize serial and wait for port to open:
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect. Needed for Leonardo only
}
// check for the presence of the shield:
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// don't continue:
while(true);
}
// attempt to connect to Wifi network:
while (status != WL_CONNECTED) {
Serial.print("Attempting to connect to SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
status = WiFi.begin(ssid, pass);
// wait 10 seconds for connection:
delay(10000);
}
Serial.println("Connected to wifi");
printWifiStatus();
Serial.println("\nStarting connection to server...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected to server");
// Make a HTTP request:
client.println("GET /search?q=arduino HTTP/1.1");
client.println("Host: www.google.com");
client.println("Connection: close");
client.println();
}
}
void loop() {
// if there are incoming bytes available
// from the server, read them and print them:
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting from server.");
client.stop();
// do nothing forevermore:
while(true);
}
}
void printWifiStatus() {
// print the SSID of the network you're attached to:
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address:
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength:
long rssi = WiFi.RSSI();
Serial.print("signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
Ok it all look legit, let's see do you know the Ip of you wifi shield? Can you Ping it?
And most important is the network mask set right? Maybe you wifi box give out 192.168.0.*** address with a network mask of 255.255.255.0 then the shield wont see the computer?
Haha, I have a spare arduino if I break the flash.
I'm not having trouble with any other devices, Oh well. No firewalling between devices, just standard nat router out to the internet (seem to be no issue there). Switched from 802.11ngb to only 802.11gb I will try it on another wireless network to see if I have the same issue.
Thank you for your help.
I did add in another check and it's getting the correct IP's set by DHCP:
Attempting to connect to SSID: myssid
Connected to wifi
SSID: myssid
IP Address: 192.168.1.101
Subnet Mask: 255.255.255.0
Gateway: 192.168.1.254
signal strength (RSSI):-70 dBm
I don't know why, but it kinda piss me off to know the the official WiFi board does not work with the official démo program. lol
These WiFi board cost a fortune and they say that it's suppose to be a breeze to make them work. That why I prefer to work with modules. At least if I get trouble I can just blame my self for not paying the extra and just beat my brain until it finally work.
My friend broth his at home, I saw it work, It work super well, I got one comming by the mail. I'll start developing for it as soon as i get it. He make every thing with those, so will I.
Attempting to connect to SSID: myssid
Connected to wifi
SSID: myssid
IP Address: 192.168.1.101
Subnet Mask: 255.255.255.0
Gateway: 192.168.1.254
signal strength (RSSI):-68 dBm
Starting connection to server...
connected to server
HTTP/1.1 200 OK
Date: Sun, 18 Aug 2013 01:37:36 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=a25fdfc02c43a338:FF=0:TM=1376789856:LM=1376789856:S=CXF_aBQn_T0LUFe4; expires=Tue, 18-Aug-2015 01:37:36 GMT; path=/; domain=.google.com
Set-Cookie: NID=67=FUt547y1K8UYJ2-WsYbz3g6nuxhknrUDS0F8wNmxETeAD5Qg0JWEggy-20CCghBxKYDvJg2mga4MVwPu3m4Iow4CVxt6rsbjaCZQq2VSaxmBNAPdW9p04kpZKktqz5AH; expires=Mon, 17-Feb-2014 01:37:36 GMT; path=/; domain=.google.com; HttpOnly
P3P: CP="This is not a P3P policy! See P3P and Google's cookies - Google Account Help for more info."
Server: gws
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alternate-Protocol: 80:quic
Connection: close