Bueno, os cuento lo que estoy investigando, me he comprado un shield
ethernet w5100. y estoy experimentando para mandar parámetros a una
web y obtener datos de la web para utilizarlo en arduino.
he conseguido realizar un código que se conecta a una web que tengo y
que al principio de cada dato que quiero pasar le a arduino le pongo
un código, ejemplo <variable1>
lo he conseguido, pero estoy intentando que esto suceda solo cuando
pulse un botón y cada vez haga una consulta nueva, ya que la web dará
información distinta cada vez que se actualize.
os pongo el código para que me ayudéis...
/*
Web client
This sketch connects to a website (
http://www.google.com)
using an Arduino Wiznet Ethernet shield.
Circuit:
* Ethernet shield attached to pins 10, 11, 12, 13
created 18 Dec 2009
by David A. Mellis
*/
#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[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(82, 165, 139, 80);
// 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;
String codigo;
void setup() {
// start the serial library:
Serial.begin(9600);
// 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:
for(;;)
;
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
// if you get a connection, report back via serial:
if (client.connect(server, 80)) {
Serial.println("connected");
// Make a HTTP request:
client.println("GET
http://www.pandorasoft.com/arduino/index.php
HTTP/1.0");
client.println();
}
else {
// kf you didn't get a connection to the server:
Serial.println("connection failed");
}
}
void loop()
{
int boton = analogRead(0)/4; //entrada moneda
if (boton == 0){
Serial.println("muestro codigo ");
Serial.print(codigo);
}
// if there are incoming bytes available
// from the server, read them and print them:
if (client.available()) {
char c = client.read();
codigo = codigo + c;
Serial.print(c);
}
// if the server's disconnected, stop the client:
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
client.stop();
// do nothing forevermore:
for(;;)
;
}
}
en la variable código meto todo lo que he obtenido de la web.
y con string manipulo la cadena y extraigo las variables (esta ultima
parte no esta en este código para no liar a la gente)
¿cual es el problema, es que cuando pulso el boton no hace nada? creo
que es el for(;;); final, pero si lo quito ser repite el
disconnecting
una ayudita...