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.
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
// 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 .
<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"){
?>
| DKTB1: |
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"'; ?>/> |
Nhi?t ??: |
|
|
| DKTB2: |
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"'; ?>/> |
Ánh sáng: |
|
<?php } } ?> ```