Arduino Wifi connection problem: client.connect(server, 80) command not working

client.connect(server, 80); is not working. Here is the code:

#include <WiFi.h>
#include <WiFiClient.h>
#include <WiFiServer.h>

#undef int
#undef abs
#undef double
#undef float
#undef round

int SensorIn1 = 1;
int led_pin = 13;

char devid = “v90EC98310145483”; // THIS IS THE DEVICE ID FROM PUSHINGBOX

int del=100; // Amount of seconds delay between posting to google docs.

char postmsg[100];
int k=0;
int temp_av = 0;
char server = “api.pushingbox.com”;
char ssid = “****";
char pass[] = "
”;

WiFiClient client;

void setup()
{
Serial.begin(9600);
WiFi.begin(ssid, pass);
delay(1000);
Serial.println(“connecting…”);
}

void loop(){

int val;
val = analogRead(SensorIn1);
Serial.println(val);

// Post to Google Form…
if (client.connect(server, 80))
{
k=0;
Serial.println(“connected”);
sprintf(postmsg,“GET /pushingbox?devid=%c&status=%d HTTP/1.1”,devid,val);
client.println(postmsg);
client.println(“Host: api.pushingbox.com”);
client.println(“Connection: close”);
client.println();

Serial.println(postmsg);
Serial.println(“Host: api.pushingbox.com”);
Serial.println(“Connection: close”);
Serial.println();

delay(1000);
client.stop();
}
delay(1000);

if (!client.connected())
{
Serial.println();
Serial.println(“disconnecting.”);
client.stop();
k==1;
return;
}
}

The output I receive is
connecting…
456
disconnecting.
563
disconnecting.
and so on…

I have tried using different servers and accordingly selected the port numbers (eg 80, 443 etc) but the it never connects to the server. Kindly help.

7 below is a typical starting point:

http://forum.arduino.cc/index.php/topic,148850.0.html

This is a test sketch to determine the firmware version. If the firm version is not 1.1.0, and you are using an IDE version 1.0.4 or newer, you must upgrade the wifi shield firmware.

#include <WiFi.h>
#include <SPI.h>

void setup() {
 Serial.begin(9600); 

  // disable SD SPI
 pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);

 // check for the presence of the shield:
 if (WiFi.status() == WL_NO_SHIELD) {
   Serial.println("WiFi shield not present"); 
   // don't continue:
   while(true);
 } 

 // check firmware version
 Serial.print(F("Firmware version: "));
 Serial.println(WiFi.firmwareVersion());.
}

void loop() {
}
1 Like