Merci de l'aide,
la varibale reste vide...
Voici le code complet (j'ai recup un code et modifié)
#include <EtherCard.h>
#include "DHT.h"
static byte mymac[] = {0xDD,0xDD,0xDD,0x00,0x00,0x01};
static byte myip[] = {192,168,0,40};
byte Ethernet::buffer[700];
const int ledPin = 2;
boolean ledStatus;
char* on = "ON";
char* off = "OFF";
char* statusLabel;
char* buttonLabel;
char* temp1;
// DHT
#define DHTPIN 30
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup () {
Serial.begin(57600);
Serial.println("WebLed Demo");
if (!ether.begin(sizeof Ethernet::buffer, mymac, 53))
Serial.println( "Failed to access Ethernet controller");
else
Serial.println("Ethernet controller initialized");
if (!ether.staticSetup(myip))
Serial.println("Failed to set IP address");
Serial.println();
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, LOW);
ledStatus = false;
dht.begin();
}
void loop() {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(pos) {
if(strstr((char *)Ethernet::buffer + pos, "GET /?status=ON") != 0) {
Serial.println("Received ON command");
ledStatus = true;
}
if(strstr((char *)Ethernet::buffer + pos, "GET /?status=OFF") != 0) {
Serial.println("Received OFF command");
ledStatus = false;
}
if(ledStatus) {
digitalWrite(ledPin, HIGH);
statusLabel = on;
buttonLabel = off;
} else {
digitalWrite(ledPin, LOW);
statusLabel = off;
buttonLabel = on;
}
float temp = dht.readTemperature();
Serial.print("float :");
Serial.println(temp);
Serial.println("------");
char buffer[10];
sprintf(temp1,"%f",temp);
Serial.println(temp1);
BufferFiller bfill = ether.tcpOffset();
bfill.emit_p(PSTR("HTTP/1.0 200 OK\r\n"
"Content-Type: text/html\r\nPragma: no-cache\r\n\r\n"
"<html><head><title>WebLed</title></head>"
"<body>LED Status: $S "
"<a href=\"/?status=$S\"><input type=\"button\" value=\"$S\"></a>"
"
temp1 : $S"
"</body></html>"
), statusLabel, buttonLabel, buttonLabel, temp1);
ether.httpServerReply(bfill.position());
}
}
sur le moniteur, j'obtiens ça :
Received ON command
float :20.30
Received OFF command
Je devrais avoir ma variable temp1 sous les "--------"
Au niveau de sprintf, je l'utilisais mal, je faisais
char temp1[10];
sprintf(temp1,"%f",temp);
A quoi sert le char buffer[10] ?
Que ce soit sur l'I-Web ou sur le moniteur serie, la variable temp1 reste vide :