Go Down

Topic: Ethernet shield not connecting to the Webserver - new to Arduino (Read 6790 times) previous topic - next topic

SurferTim

That is what I got!  8)

No magic here. I am not the Wizard of Oz. I just used what I know about the internet and tcp/ip protocols.

You may want to change that to a dns type server. You can use a domain name for a server now, instead of an ip address. I have not tried it yet, but that would eliminate the possibility of your web host changing the ip of the server. They do that occasionally to do maintenance on the servers.

Pelletta


I used this server:
Code: [Select]
byte server[] = {31, 170, 161, 36}; // My webserver IP

with this request
Code: [Select]
client.println("GET /test.php HTTP/1.0");
client.println("Host: venard.hostzi.com\r\n");

...and it returned, among other things, "A sample string as test message". Is that what it is supposed to say? My web browser says that is correct.




Thanks for sharing this trick, you've saved me a headache ;)

tiendientu343

I want control device over internet.
I have server host at 000webhost.com . server name: http://tiendt343.comli.com
Ardui connect sheid ethenet is client.
i want ask? i problemed as:
i connected to server.
But when i get request , Server reply as is Form html.
Code: [Select]
connecting...
connected
HTTP/1.1 200 OK
Date: Fri, 03 May 2013 00:51:01 GMT
Server: Apache
X-Powered-By: PHP/5.2.17
Content-Length: 279
Connection: close
Content-Type: text/html

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

@01$</html>
<!-- Hosting24 Analytics Code -->
<script type="text/javascript" src="http://stats.hosting24.com/count.php"></script>
<!-- End Of Analytics Code -->

disconnecting.

Data then i receive is " Form web html" as top.
But i want send 1 request to server and receive 1 value when i request from server. How do ?
this is code arduino
Code: [Select]

// Chuong trinh Client ket noi webserver
// Ngay bat dau: 23/4/2013
// Arthor : Bui Duy Tien
#include <SPI.h>
#include <Ethernet.h>
// Khai bao dia chi MAC cua Ethernet Shield.
byte mac[] = {  0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
// Khai bao server name k?t n?i
char serverName[] = "http://tiendt343.comli.com";
// 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):
EthernetClient client;

void setup() {
// Open serial communications and wait for port to open:
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }


  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
    while(true);
  }
  // give the Ethernet shield a second to initialize:
  delay(100);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
 
  if (client.connect(serverName, 80)) {
    Serial.println("connected");
    // Make a HTTP request:
    client.println("GET /vlir/index.php?device=hardware&temp=30&as=200 HTTP/1.0");
    client.println("Host: tiendt343.comli.com");
    client.println("Connection: close\r\n");
    client.println();
  }
  else {
    // kf you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    while(true);
  }
}


and this code php .
Code: [Select]

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<?php

/**
 * @author tiendientu343
 * @copyright 2013
 */

mysql_connect('localhost''root''');//K?t n?i CSDL
mysql_select_db('tien');//Ch?n CSDL

/**
 * ?i?u khi?n thi?t b?, t? web l?u vào CSDL
 */ 
if (isset($_GET['sub'])){//?ã submit d? li?u trong form
    
mysql_query("UPDATE thietbi SET dieukhien='".$_GET['rd1']."' WHERE id='1'");
    
mysql_query("UPDATE thietbi SET dieukhien='".$_GET['rd2']."' WHERE id='2'");
    
//header("location:?device=webservice");
}
/**
 * L?y d? li?u t? CSDL
 */
$tttb1 "";
$tttb2 "";
$txttemp "";
$txtas "";
$sql mysql_query("SELECT * FROM thietbi"); //??c t? CSDL
if ($row mysql_fetch_object($sql)){
    
$tttb1 $row->dieukhien;
    
$txttemp $row->giatri;
}
if (
$row mysql_fetch_object($sql)){
    
$tttb2 $row->dieukhien;
    
$txtas $row->giatri;
}

/**
 * 
 */  
if (isset($_GET['device'])){//Ki?m tra thi?t b? truy c?p
    
if ($_GET['device']=="hardware"){
        
/**
         * Ph?n c?ng truy c?p
         * http://localhost/tien/?device=hardware&temp=30&as=400
         */
        
if (isset($_GET['temp'])){
            
mysql_query("UPDATE thietbi SET giatri='".$_GET['temp']."' WHERE id='1'");    
        }
        if (isset(
$_GET['as'])){
            
mysql_query("UPDATE thietbi SET giatri='".$_GET['as']."' WHERE id='2'");    
        }
        echo 
'@'.$tttb1.'&tttb2='.$tttb2.'$';//response
        
        /**
         * Xem trên web
         * http://localhost/tien/?device=webservice
         */  
    
}elseif ($_GET['device']=="webservice"){
        
?>

        <form action="" method="GET">
        <table>
            <tr>
                <td>DKTB1: </td>
                <td>
                    B?t<input type="radio"  name="rd1" value="1" <?php if ($tttb1==1) echo 'checked="checked"'?> />
                    T?t<input type="radio" name="rd1" value="0" <?php if ($tttb1==0) echo 'checked="checked"'?>/>
                </td>
               
                <td>Nhi?t ??: </td>
                <td>
                    <input type="text" name="txttemp" disabled="disabled" value="<?php echo $txttemp?>"/>
                </td>
                <td rowspan="2">
                    <input type="submit" value="Ok" name="sub"/>
                </td>
            </tr>
            <tr>
                <td>DKTB2: </td>
                <td>
                    B?t<input type="radio"  name="rd2" value="1" <?php if ($tttb2==1) echo 'checked="checked"'?>/>
                    T?t<input type="radio" name="rd2" value="0" <?php if ($tttb2==0) echo 'checked="checked"'?>/>
                </td>
                <td>Ánh sáng: </td>
                <td>
                    <input type="text" name="txtas" disabled="disabled" value="<?php echo $txtas?>"/>
                </td>
               
            </tr>
        </table>
        </form>
        <?php
    
}
}
?>

</html>


SurferTim

Your shield is connecting and getting this as a return from the php server:
Code: [Select]
        echo '@'.$tttb1.'&tttb2='.$tttb2.'$';//response
It apparently is printing the "@" and the two values ("01") with the "$", but I don't know why it is not printing the "&ttb2=" part in the middle though.

You should start another topic in networking.

tiendientu343

response is  " @01$" because i want split form html from server same is uart form. but i want  get value? how?

Go Up