a771la
1
ora sto usando:
if(L2) bfill.emit_p(PSTR("<a href=\"/R2\"><img src=\"http://www.byte4geek.com/images/arduino/butON.png\" width=33% height=45% vspace=20% hspace=20%>"));
else bfill.emit_p(PSTR("<a href=\"/R2\"><img src=\"http://www.byte4geek.com/images/arduino/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"));
vorrei creare una variabile "sito" in modo da fare una cosa del genere:
String sito="http://www.byte4geek.com/images/arduino"
if(L2) bfill.emit_p(PSTR("<a href=\"/R2\"><img src=\sito+"/butON.png\" width=33% height=45% vspace=20% hspace=20%>"));
else bfill.emit_p(PSTR("<a href=\"/R2\"><img src=\sito+"/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"));
come posso fare?
grazie
Dovresti potere fare ciò:
const char *sito="http://www.byte4geek.com/images/arduino";
if(L2)
bfill.emit_p (PSTR("<a href=\"/R2\"><img src=\"$S/butON.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
else
bfill.emit_p (PSTR("<a href=\"/R2\"><img src=\"$S/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
Ancora meglio:
const char *sito PROGMEM = "http://www.byte4geek.com/images/arduino";
if(L2)
bfill.emit_p (PSTR("<a href=\"/R2\"><img src=\"$F/butON.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
else
bfill.emit_p (PSTR("<a href=\"/R2\"><img src=\"$F/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
Ancora ancora meglio:
const char *sito PROGMEM = "http://www.byte4geek.com/images/arduino";
bfill.emit_p (PSTR("<a href=\"/R2\"><img src=\"$F/but$F.png\" width=33% height=45% vspace=20% hspace=20%>"), sito, L2 ? PSTR ("ON") : PSTR ("OFF"));
Ma non sono sicurissimo che compili :D.
a771la
3
la prima funziona
grazie.....
questo è il mio codice:
#include <EtherCard.h>
static byte mymac[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
byte Ethernet::buffer[700];
boolean L1,L2,L3,L4;
const char *sito="http://www.byte4geek.com/images/arduino";
void setup () {
ether.begin(sizeof Ethernet::buffer, mymac, 10);
ether.hisport = 81;
ether.dhcpSetup();
DDRD = B00111100;
PORTD |= B00111100;
L1=L2=L3=L4 = true;
}
void loop() {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(pos) {
if(strstr((char *)Ethernet::buffer + pos, "GET /R1") != 0) {
L1 = !L1;
digitalWrite(2, L1);
}
if(strstr((char *)Ethernet::buffer + pos, "GET /R2") != 0) {
L2 = !L2;
digitalWrite(3, L2);
}
if(strstr((char *)Ethernet::buffer + pos, "GET /R3") != 0) {
L3 = !L3;
digitalWrite(4, L3);
}
if(strstr((char *)Ethernet::buffer + pos, "GET /R4") != 0) {
L4 = !L4;
digitalWrite(5, L4);
}
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"
"<title>Ardumino 1.0</title>"));
if(L1) bfill.emit_p (PSTR("<a href=\"/R1\"><img src=\"$S/butON.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
else bfill.emit_p (PSTR("<a href=\"/R1\"><img src=\"$S/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
if(L2) bfill.emit_p (PSTR("<a href=\"/R2\"><img src=\"$S/butON.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
else bfill.emit_p (PSTR("<a href=\"/R2\"><img src=\"$S/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
if(L3) bfill.emit_p (PSTR("<a href=\"/R3\"><img src=\"$S/butON.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
else bfill.emit_p (PSTR("<a href=\"/R3\"><img src=\"$S/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
if(L4) bfill.emit_p (PSTR("<a href=\"/R4\"><img src=\"$S/butON.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
else bfill.emit_p (PSTR("<a href=\"/R4\"><img src=\"$S/butOFF.png\" width=33% height=45% vspace=20% hspace=20%>"), sito);
bfill.emit_p(PSTR("
<a href=\"/\">Aggiorna</a></div></div></body></html>"));
ether.httpServerReply(bfill.position());
}
}
cosa posso ottimizzare?
a771la
4
SukkoPera:
Ancora ancora meglio:
const char *sito PROGMEM = "http://www.byte4geek.com/images/arduino";
bfill.emit_p (PSTR("<a href="/R2"><img src="$F/but$F.png" width=33% height=45% vspace=20% hspace=20%>"), sito, L2 ? PSTR ("ON") : PSTR ("OFF"));
Ma non sono sicurissimo che compili :D.
sembra funzionare ma:
devo cambiare da :
const char *sito PROGMEM = "http://www.byte4geek.com/images/arduino";
a
const char *sito = "http://www.byte4geek.com/images/arduino";
e cmq non visualizza nessuna immagine ma i relè vengono correttamente comandati
Se togli PROGMEM $F deve diventare $S, credo.
a771la
6
vi chiedo di nuovo aiuto.
questo funziona benissimo :
#include <EtherCard.h>
static byte mymac[] = {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA};
byte Ethernet::buffer[600];
boolean L1,L2,L3,L4;
const char *sito = "http://miosito";
void setup () {
ether.begin(sizeof Ethernet::buffer, mymac, 10);
ether.hisport = 81;
ether.dhcpSetup();
DDRD = B00111100;
PORTD |= B00000000;
L1=L2=L3=L4 = false;
}
void loop() {
word len = ether.packetReceive();
word pos = ether.packetLoop(len);
if(pos) {
if(strstr((char *)Ethernet::buffer + pos, "GET /R1") != 0) {
L1 = !L1;
digitalWrite(2, L1);
}
if(strstr((char *)Ethernet::buffer + pos, "GET /R2") != 0) {
L2 = !L2;
digitalWrite(3, L2);
}
if(strstr((char *)Ethernet::buffer + pos, "GET /R3") != 0) {
L3 = !L3;
digitalWrite(4, L3);
}
if(strstr((char *)Ethernet::buffer + pos, "GET /R4") != 0) {
L4 = !L4;
digitalWrite(5, L4);
}
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"
"Ardumino 1.0"));
bfill.emit_p (PSTR("<a href="/R1"><img src="$S/lam-$F.jpg" width=50% height=40%>"), sito, L1 ? PSTR ("on") : PSTR ("off"));
bfill.emit_p (PSTR("<a href="/R2"><img src="$S/cor-$F.jpg" width=50% height=40%>"), sito, L2 ? PSTR ("on") : PSTR ("off"));
bfill.emit_p (PSTR("<a href="/R3"><img src="$S/wd-$F.jpg" width=50% height=40%>"), sito, L3 ? PSTR ("on") : PSTR ("off"));
bfill.emit_p (PSTR("<a href="/R4"><img src="$S/hdd-$F.jpg" width=50% height=40%>"), sito, L4 ? PSTR ("on") : PSTR ("off"));
bfill.emit_p(PSTR("
<a href="/"><img src="$S/agg.png" width=15% height=15%>"), sito);
ether.httpServerReply(bfill.position());
}
}
usando la scheda di rete enc28j60
la mia domanda è: come modifico il codice per usare la Ethernet Shield W5100 ?
a771la
7
sto riscrivendo tutto il codice.....
e ora ho di nuovo il problema di prima
come faccio a trasformare :
if(L1){client.println ("<a href=\"./10\"> <img src = \"http://miosito.altervista.org/arduino/lam-off.jpg\" width=40% height=40% ></a>");}
else
{client.println ("<a href=\"./11\"> <img src = \"http://miosito.altervista.org/arduino/lam-on.jpg\" width=40% height=40% ></a>");}
in :
if(L1){client.println ("<a href=\"./10\"> <img src = \ VAR "/lam-off.jpg\" width=40% height=40% ></a>");}
else
{client.println ("<a href=\"./11\"> <img src = \ VAR "/lam-on.jpg\" width=40% height=40% ></a>");}
???????
grazie