GET function not working as expected. PHP setting issue.

Hi
I am working on internet base datalogger. I am following this tutorial Tweaking4All.com - Arduino Ethernet - Pushing data to a (PHP) server

Before I list my problems, following is some additional data.

  1. Sparkfun's data stream works perfectly fine. (with GSM, WiFi, Ethernet)
  2. Arduino examples of Ethernet Shield, GSM shield, Wifi shield works perfectly fine.

Coming to my problem

//server=http://yourphpserver.com/add_data.php?arr=value
if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET /add_data.php?");
    client.print("serial=");
  1. Considering this above code, I am not able to send any data. If i do following changes my program works and i am able to send data to my website.
if (client.connect(server, 80)) {
    Serial.println("-> Connected");
    // Make a HTTP request:
    client.print( "GET http://yourphpserver.com/add_data.php?");
    client.print("serial=");
  1. When closing internet connection using following code. HTTP/1.1 is getting appended to my value?
    e.g 25.6HTTP/1.1, 25.8HTTP/1.1, 28.9, etc.....
    If i skip client.println("HTTP/1.1"); then Host is getting appended and so on.
client.println("HTTP/1.1");
      client.print("Host: ");
      client.println("www.yourphpserver.com");
      client.println("Connection:close");
      client.println();
      client.stop();
  1. If i use only client.stop(); then also i am not able to send any data. I don't know php so my friend is setting up for website. And he is not taking interest in troubleshooting this. Any guidance will be appreciated!

Thanks and regards

Any guidance will be appreciated!

Post ALL of your code.

In addition to PaulS, what ethernet shield are you using? That example in the link you posted is for a ENC28J60 ethernet controller, not a W5100 IC like the official Arduino models.

SurferTim:
In addition to PaulS, what ethernet shield are you using? That example in the link you posted is for a ENC28J60 ethernet controller, not a W5100 IC like the official Arduino models.

I have used W5100, simcom900 shield, Seeedstudio WiFi shield, M10 and M95 GSM modules. All stock examples and data.sparkfun.com examples are working perfectly fine. I suspect there is problem with my php settings.
In my next post you will get my full code.
Thaks

Following is my code

#include <GSM.h>
// APN data
#define GPRS_APN       "airtelgprs.com" // replace your GPRS APN
#define GPRS_LOGIN     ""    // replace with your GPRS login
#define GPRS_PASSWORD  "" // replace with your GPRS password
#define PINNUMBER ""
GSMClient client;
GPRS gprs;
GSM gsmAccess;
char server[] = "suyogtechnologies.com";
unsigned long currentMillis;
unsigned long previousMillis = 0;
const long interval = 60000; 
void setup()
{
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  Serial.println("Starting Arduino web client.");
  // connection state
  boolean notConnected = true;

  // After starting the modem with GSM.begin()
  // attach the shield to the GPRS network with the APN, login and password
  while (notConnected)
  {
    if ((gsmAccess.begin(PINNUMBER) == GSM_READY) &
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY))
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("connecting...");
  
}

void loop()
{ currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
  previousMillis = currentMillis;
  if (client.connect("suyogtechnologies.com", 80))
  {   Serial.println("connected");
      client.print("GET http://suyogtechnologies.com/testing.php?arr=");
      client.print(currentMillis);  
      client.print("&arr1=1234"); //just a testing variable   
      client.println("HTTP/1.1");   
      client.print("Host: ");
      client.println("www.suyogtechnologies.com");
      client.println("Connection:close");
      client.println();
      client.stop();
    }
    Serial.println(currentMillis);
  }
}

currently my website is down.

Following is php code. All things related to php are done by my friend not me.

<?php

$ip= $_SERVER['REMOTE_ADDR'];

$arr=$_GET['arr'];
$arr1=$_GET['arr1'];

if(!empty($arr))
{
mysql_connect("localhost","anandiwh_data","anandiwh_");
$db_found = mysql_select_db("anandiwh_data");

mysql_query("INSERT INTO `testing` VALUES ('','$arr1','$arr')") or die("query failed:" . mysql_error());

$array_data=array();
$array_ip=array();


$abc=mysql_query("SELECT * FROM `testing`")or die("query failed:" . mysql_error());
while($rw=mysql_fetch_assoc($abc))
{
array_push($array_data,$rw['data']);
array_push($array_ip,$rw['ip']);
}
echo"<pre>"; print_r($array_data);
echo"<pre>"; print_r($array_ip);
}


/*
foreach($arr_check as $key => $val)
{
 echo $key
}*/

?>

output i get is

arr=891011 //currentMillis
arr1=1234HTTP/1.1

      client.print("GET http://suyogtechnologies.com/testing.php?arr=");
      client.print(currentMillis);  
      client.print("arr1=1234"); //just a testing variable   
      client.println("HTTP/1.1");

The script to execute is NOT http://suyogtechnologies.com/testing.php. http is the protocol to use to talk to the server. The server has already been defined.

The GET request as you send it is "GET http://suyogtechnologies.com/testing.php?arr=XXXXarr1=1234HTTP/1.1" which is utter nonsense. Get rid of the http://suyogtechnologies.com./ bit. Put an & between arr=XXXX and arr1=1234. Put a space before the HTTP/1.1 part.

PaulS:
The script to execute is NOT http://suyogtechnologies.com/testing.php. http is the protocol to use to talk to the server. The server has already been defined.

The GET request as you send it is "GET http://suyogtechnologies.com/testing.php?arr=XXXXarr1=1234HTTP/1.1" which is utter nonsense. Get rid of the http://suyogtechnologies.com./ bit.

This is exactly my problem. GET /testing.php is not working with my my server!
But if i use "GET http://suyogtechnologies.com/testing.php?arr=" data is getting logged to my server.
but HTTP/1.1 (with and without space before H) is getting appended

PaulS:
Put a space before the HTTP/1.1 part.

missing "&" and space before http are typo errors, I have rectified them.

Are you using a web proxy server?

NO,

but HTTP/1.1 (with and without space before H) is getting appended

It isn't rocket science to have the php script strip that off. I don't believe that your GET request, with the http: part in it is working.

PaulS:
It isn't rocket science to have the php script strip that off. I don't believe that your GET request, with the http: part in it is working.

Finally thats what I have decided to do. And believe me GET request is working with full link! :slight_smile:
So can we conclude that there is no problem with arduino but some problem with php setting on server side?

Suyog:
Finally thats what I have decided to do. And believe me GET request is working with full link! :slight_smile:
So can we conclude that there is no problem with arduino but some problem with php setting on server side?

If that is your domain (suyogtechnologies.com), it is not working. Your site is down.

SurferTim:
If that is your domain (suyogtechnologies.com), it is not working. Your site is down.

yes website is down godaddy is website builder is too costly to renew :frowning: =(
so php is also down.

Then how do you expect that to work?

Does your ISP allow you to host a website with your current plan? If so, set up your own LAMP server. Do you have an old computer you can set up with some flavor of Linux? Your friend that does your php programming should be able to help you with that.

SurferTim:
Then how do you expect that to work?

Does your ISP allow you to host a website with your current plan? If so, set up your own LAMP server. Do you have an old computer you can set up with some flavor of Linux? Your friend that does your php programming should be able to help you with that.

Plan just got over day before yesterday. MY ISP does allows to host server, currently i am trying to set you that. By that time i will try experimenting with my friend's website.