Arduino ethernet webclient php script and mysql( GET command not respoding)

Hi,

Can somebody please help me out.

I’m running an galelio board with a temperature sensor and wish to add the values to a mysql database.But through arduino sketch I am not able to pass sensor values.For checking I created a simple Php file and arduino sketch just to pass a value.when I am passing through url http://192.168.0.5/bl/nc.php?s=6 its echoing but when I am using Arduino sketch its not working. Corresponding sketch is attached.MY php file is just

<?php echo 'print'; $s = $_GET['s']; echo $s; ?>

bl.ino (1.1 KB)

I suspect it's not connecting to the server. Most dns servers will fail if requested to resolve a private ip address. It doesn't return zero, but a -5 which evaluates to true, making it appear the connect function succeeded when it actually failed. The only success return value is 1.

// change this
char server[] = "192.168.0.5"; // my laptops ip
// to this
IPAddress server(192,168,0,5);

// and change this
    if (client.connect(server, 80))
// to this
    if (client.connect(server, 80) == 1)

edit: If it still fails, you might also want to read the response from the server and send it to the serial monitor.

Hi, I tried this.. Its showing connected in serial monitor.. but value is not passed..
Then what would be the error??

Also in the example code Webclient is also getting connected but no data is displayed from google on serial monitor

The GET request. Try this change.

    if (client.connect(server, 80) == 1) 
    {
      Serial.println("connected");
      // Make a HTTP request:
      client.print("GET /bl/nc.php?s=");
      client.print(s);
      client.println(" HTTP/1.1"); 
      client.println(); 

      while(client.connected()) {
        while(client.available()) {
          Serial.write(client.read());
        }
      }

      client.stop(); 
    }

edit: I forgot to change the connect response evaluation. It is changed now.

Hi , Still In serial monitor I am getting like this…
connected
HTTP/1.1 400 Bad Request
Date: Wed, 20 Apr 2016 03:42:40 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.33
Vary: accept-language,accept-charset
Accept-Ranges: bytes
Connection: close
Content-Type: text/html; charset=utf-8
Content-Language: en

<?xml version="1.0" encoding="UTF-8"?> Bad request!

Bad request!

Your browser (or proxy) sent a request that
this server could not understand.

If you think this is a server error, please contact the webmaster.

Error 400

localhost

Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.33

Try this. There is probably something wrong with the format of your request.

    if (client.connect(server, 80) == 1)
    {
      Serial.println("connected");
      // Make a HTTP request:
      client.println("GET /bl/nc.php?s=12.00  HTTP/1.0");
      client.println();

      while(client.connected()) {
        while(client.available()) {
          Serial.write(client.read());
        }
      }

      client.stop();
    }

Hi,
If I am using client.print(“GET /bl\nc.php?s=”);
then at serial monitor its showing like this

connected

301 Moved Permanently

Moved Permanently

The document has moved here.


Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.33 Server at localhost Port 80

It appears this is available only to your server. Is this page available to any other computer (not the server) on that localnet?

edit: It may be a setting on the server. Here is the line that causes my suspicions.

The document has moved here.

yes its available in my phone also
http://192.168.0.5/bl/nc.php
print

showing both in lap and mobile

Change the slash after bl. That is all I can suggest at this point.

// change this
client.print("GET /bl\nc.php?s=");
// to this
client.print("GET /bl/nc.php?s=");[/cdoe]

Hi Sir , Thanks for your replies ..but still I am not able to figure it out.

Now I tried to use my actual php file.I think connection with server is ok ..but some isues
change done --
In path I gave my data.php
client.println("GET /arduino/data.php?temperature=12 HTTP/1.0");

In serial monitor
connected
HTTP/1.1 200 OK
Date: Wed, 20 Apr 2016 04:56:40 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.33
X-Powered-By: PHP/5.5.33
Set-Cookie: PHPSESSID=2j21muf8e0gtbpc04v1nq7l6f1; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 0
Connection: close
Content-Type: text/html

Can you now figure out something??

What do you mean your actual php file?

It looks like it is working. The page isn't sending anything except the header, but that is the PHP challenge, not the Arduino.

Actual php file in the sense php file related to my project…its name is data.php and i edited it in code as client.println(“GET /arduino/data.php?temperature=12 HTTP/1.0”);

that php file is given below

<?php ini_set('display_errors',0); error_reporting(E_ERROR | E_WARNING | E_PARSE); include_once 'functions.php'; //include(profile.php); $obj = new User(); $check= $obj->Check_login(); if ($check) { if($_SESSION['flag']) { $id = $_SESSION['id']; //echo "yes.....Connnn...."; $temperature= $_GET['temperature']; //$status = $_GET['status']; //$temperature= 38; if($temperature > 35) {$status = 'ALERT';} else if ($temperature < 30) {$status = 'TOO COLD';} else {$status = 'FINE';} echo $temperature; echo $status; $sqlz= "INSERT INTO info(id,temperature,status) VALUES ('$id','$temperature','$status')"; $resultz = mysqli_query($obj->__construct(), $sqlz); if($resultz) { echo "Updating......"; } } } ?>

when I am using last discussed arduino code in serial monitor its showing like this
connected
HTTP/1.1 200 OK
Date: Wed, 20 Apr 2016 05:51:03 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.33
X-Powered-By: PHP/5.5.33
Set-Cookie: PHPSESSID=o8da3jfqbk5ln8r5eg03r8fma0; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Content-Length: 0
Connection: close
Content-Type: text/html

when I using a dummy php file just for testing with editing in arduino code
client.println(“GET /arduino/bl/nc.php?s=12 HTTP/1.0”);

<?php echo 'print'; $s = $_GET['s']; echo $s; ?>

In serial monitor I am getting

connected
HTTP/1.1 200 OK
Date: Wed, 20 Apr 2016 05:57:49 GMT
Server: Apache/2.4.17 (Win32) OpenSSL/1.0.2d PHP/5.5.33
X-Powered-By: PHP/5.5.33
Content-Length: 10
Connection: close
Content-Type: text/html

print12.00

hope you got that?

That is a PHP problem. It appears you PHP code has an error and is aborting somewhere in your code. You should use some more detailed error checking in your PHP page. This might help you.