Pessoal, boa tarde.
Gostaria de ajuda com o Arduino + PHP.
Tenho um UNO-R3 com Shield Ethernet W5100 (cópia chinesa). Está funcionando beleza.
Minha dúvida é na passagem de valores para um site. Tenho um domínio www.site.com.br, onde em www.site.com.br/arduino tenho um método já programado para inserção de dados em MySQL.
Se fizer direto no browser www.site.com.br/arduino/index.php?variavel=valor, o metodo grava direitinho no MySQL. Entretanto, ao usar o arduino para realizar a tarefa, não tenho muito sucesso. Segue abaixo o sketch (usei um exemplo do arduino.cc - no exemplo passo um valor fixo para testar):
#include <SPI.h>
#include <Ethernet.h>
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
byte mac[] = { 0x00, 0xAA, 0xBB, 0xCC, 0xDE, 0x02 };
char serverName[] = "www.site.com.br";
// 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(1000);
Serial.println(Ethernet.localIP());
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 /arduino/index.php?t=13");
Serial.println("Tentativa de Passar Valor");
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()) {
client.println("GET /arduino/index.php?variavel=13");
Serial.println("Tentativa de Passar Valor");
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
while(true);
}
}
Resposta no Monitor
192.168.1.102
connecting...
connected
Tentativa de Passar Valor
HTTP/1.1 503 Service Unavailable
Server: Varnish
Retry-After: 0
Content-Type: text/html; charset=utf-8
Content-Length: 419
Date: Sat, 17 Nov 2012 16:21:39 GMT
X-Varnish: 1134533171
Age: 0
Via: 1.1 varnish
Connection: close
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>503 Service Unavailable</title>
</head>
<body>
<h1>Error 503 Service Unavailable</h1>
<p>Service Unavailable</p>
<h3>Guru Meditation:</h3>
<p>XID: 1134533171</p>
<hr>
<p>Varnish cache server</p>
</body>
</html>
Tentativa de Passar Valor
disconnecting.
Imagino que seja uma coisa "tosta", mas toda a ajuda é bem vida.
Abraço Pessoal.