Hola a todos!
Estoy trabajando en un PFG con un Arduino Uno y el siguiente Shield WIFI de SeeedStudio: Wifi Shield V1.1 | Seeed Studio Wiki para conectarme a un servidor Apache 2.4 que tengo montado y enviarle datos.
El código que utilizo es el siguiente:
/*
* WiFlyHQ Example httpclient.ino
*
* This sketch implements a simple Web client that connects to a
* web server, sends a GET, and then sends the result to the
* Serial monitor.
*
* This sketch is released to the public domain.
*
*/
#include <WiFlyHQ.h>
#include <SoftwareSerial.h>
SoftwareSerial wifiSerial(2,3);
WiFly wifly;
/* Change these to match your WiFi network */
const char mySSID[] = "RedWifi";
const char myPassword[] = "ClaveWifi";
const char site[] = "servertemp.sytes.net";
void terminal();
void setup()
{
char buf[32];
Serial.begin(115200);
Serial.println("Starting");
Serial.print("Free memory: ");
Serial.println(wifly.getFreeMemory(),DEC);
wifiSerial.begin(9600);
if (!wifly.begin(&wifiSerial, &Serial)) {
Serial.println("Failed to start wifly");
terminal();
}
/* Join wifi network if not already associated */
if (!wifly.isAssociated()) {
/* Setup the WiFly to connect to a wifi network */
Serial.println("Joining network");
wifly.setSSID(mySSID);
wifly.setPassphrase(myPassword);
wifly.enableDHCP();
if (wifly.join()) {
Serial.println("Joined wifi network");
} else {
Serial.println("Failed to join wifi network");
terminal();
}
} else {
Serial.println("Already joined network");
}
Serial.print("MAC: ");
Serial.println(wifly.getMAC(buf, sizeof(buf)));
Serial.print("IP: ");
Serial.println(wifly.getIP(buf, sizeof(buf)));
Serial.print("Netmask: ");
Serial.println(wifly.getNetmask(buf, sizeof(buf)));
Serial.print("Gateway: ");
Serial.println(wifly.getGateway(buf, sizeof(buf)));
wifly.setDeviceID("Wifly-WebClient");
Serial.print("DeviceID: ");
Serial.println(wifly.getDeviceID(buf, sizeof(buf)));
if (wifly.isConnected()) {
Serial.println("Old connection active. Closing");
wifly.close();
}
if (wifly.open(site, 80, true)) {
Serial.print("Connected to ");
Serial.println(site);
/* Send the request */
wifly.println("GET /index.html HTTP/1.1");
wifly.println();
} else {
Serial.println("Failed to connect");
}
}
void loop()
{
terminal();
}
/* Connect the WiFly serial to the serial monitor. */
void terminal()
{
if (wifly.available() > 0) {
char ch = wifly.read();
Serial.write(ch);
if (ch == '\n') {
/* add a carriage return */
Serial.write('\r');
}
}
if (Serial.available() > 0) {
wifly.write(Serial.read());
}
}
Con el cual consigo conectarme a la red WIFI, al servidor y enviarle la petición GET.
El resultado que obtengo en el monitor serie es el siguiente:
Starting
Free memory: 1067
Joining network
Joined wifi network
MAC: 00:06:66:51:13:a4
IP: 192.168.1.11
Netmask: 255.255.255.0
Gateway: 192.168.1.1
DeviceID: Wifly-WebClient
open servertemp.sytes.net 80
Connected to servertemp.sytes.net
HTTP/1.1 200 OK
Date: Sun, 26 Apr 2015 20:12:27 GMT
Content-Type: text/html
CACHE-CONTROL: no-cache
Content-Length: 498
<html>
<head>
<META http-equiv="Content-Type" content="text/html; charset=windows-1254">
<title>replace</title>
<body>
<script language="JavaScript" type="text/javascript">
var pageName = '/';
if ( ('/' == pageName) || (pageName.indexOf('content.asp') != -1) || (pageName.indexOf('Content.asp') != -1) || (pageName.indexOf('mirror.asp') != -1) || (pageName.indexOf('wan.asp') != -1))
{
top.location.replace(pageName);
}
else
{
top.contentfrm.location.replace(pageName);
}
</script>
</body>
</html>
Aparentemente bien, pero tengo dos problemas que no he conseguido resolver:
1.- El código html que me envía el servidor no es el correspondiente a la página index.html que se encuentra en el directorio: C:\Apache24\htdocs, es más, no se corresponde a ningún otro archivo de los que están alojados en ese directorio.
2.- En el log del servidor, situado en C:\Apache24\logs, no encuentro rastro de esa petición, pero sí aparecen reflejadas las peticiones que hago desde el navegador (introduciendo la dirección del servidor en la barra de direcciones del navegador y pulsando intro).
Llevo varios días intentando buscar información acerca de qué me puede estar pasando y no he sabido encontrar solución.
Agradecería enormemente cualquier tipo de ayuda.
Un saludo.