Ciao a tutti ragazzi! Sto facendo un progetto con Arduino per cui riesca a controllare una macchientta del caffè da remoto utilizzando una ethernet shield. Funziona tutto perfettamente usando la funzione "Client.print(.... codice html) con dei bottoni che richiamano un http//indirizzoIP/Accensione (Ad esempio <button onclick=location.href='http://192.168.1.5/Accensione'> ACCENDI COFFEEDUINO ) ma ora volevo implementare il tutto con una grafica migliorata che ho già preparato siccome l'Esame di maturità è alle porte. Per fare ciò avrei bisogno di utilizzare la scheda SD e guardando con un mio professore l'unica libreria funzionante era la "SDFatLib", difatti, come da codice postato, riesco a leggere il tutto e a stampare su browser la pagina html con css integrato. Il mio problema è che non riesco a passare valori da quella pagina web ad arduino.. qualcuno potrebbe aiutarmi? Sono disperato :-[ , grazie mille in anticipo!
Arduino code
/*********************************************************************************************************************************************************************************************
COFFEEDUINO 1.2 Shield Ethernet con SD CARD senza funduino
BACKUP 19/06/2016 h 17:39
******************************************************************************************************************************************************************************************/
/*********************************************************************************Includo le librerie**************************************************************************************/
#include <SPI.h>
#include <SdFat.h>
#include <Ethernet.h>
// Indirizzo fisico MAC
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; /*Mac in esadecimale delle shield*/
// Indirizzo IP
byte ip[] = { 192, 168, 1, 5 };
// Gateway
byte gateway[] = { 192, 168, 1, 1 };
// Subnet Mask
byte subnet[] = { 255, 255, 255, 0 };
int chipSelect = 4;
SdFat sd;
SdFile htmlFile;
// Creo un server che rimane in ascolto sulla porta 80
EthernetServer server(80);
String readString;
/*********************************************************************************Definisco i pin**************************************************************************************/
#define ONbutton 2
#define COFFEEbutton 3
#define VAPbutton 5
#define LEDCOFFEEbutton A0
#define WATERpin 6
/*************************************************************************Dichiarazione delle variabili Globali************************************************************************/
boolean acqua = false; //Inizializza la variabile "acqua" come false
int luce = 0; //Inizializza come intero la variabile "luce"
boolean macchinetta = true;//Inizializza la variabile "acqua" come false
String acquahtml; //Inizializza la variabile "acquahtml"
String lucehtml; //Inizializza la variabile "lucehtml"
String accensionehtml; //Inizializza la variabile "accensionehtml"
/*********************************************************************************Funzione Setup**************************************************************************************/
void setup()
{
//Inizializzo lo shield con mac, ip, gateway e subnet
Ethernet.begin(mac, ip, gateway, subnet);
server.begin();
if (!sd.begin(chipSelect, SPI_HALF_SPEED)) {
sd.initErrorHalt();
}
else
{
Serial.println(" lettura SD OK!");
}
}
void loop()
{
EthernetClient client = server.available();
if (client)
{
boolean currentLineIsBlank = true;
while (client.connected())
{
if (client.available())
{
char c = client.read();
if (c == '\n' && currentLineIsBlank)
{
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println();
if (!htmlFile.open("comandi.html", O_READ))
{
client.println("<!doctype html>");
client.println("<html>");
client.println("<head>");
client.println("<meta charset='utf-8'>");
client.println("<title>TEST HTML</title>");
client.println("</head>");
client.println("<body> ");
client.print("<h1>ERRORE</h1>");
client.println(" <h2>FILE NON TROVATO 2</h2>");
client.println("</body>");
client.println("</html>");
delay(1); //aspetto 1 ms affinche la risposta giunga al browser del client
client.stop(); //chiudo la connessione
}
else
{
char data;
while ((data = htmlFile.read()) >= 0)
{
client.print(data);
Serial.write(data);
}
// close the file:
htmlFile.close();
}
break;
}
if (c == '\n') {
currentLineIsBlank = true;
}
else if (c != '\r') {
currentLineIsBlank = false;
}
}
}
delay(1);
client.stop();
}
}
void printDirectory(File dir, int numTabs) {
while (true) {
File entry = dir.openNextFile();
if (! entry) {
// no more files
break;
}
for (uint8_t i = 0; i < numTabs; i++) {
Serial.print('\t');
}
Serial.print(entry.name());
if (entry.isDirectory()) {
Serial.println("/");
printDirectory(entry, numTabs + 1);
} else {
// files have sizes, directories do not
Serial.print("\t\t");
Serial.println(entry.size(), DEC);
}
entry.close();
}
//Controllo se è stato premuto il link
if (readString.indexOf("/Accensione") > 0)
{
Serial.println("Switch COFFEMACHINE ON");
digitalWrite(ONbutton, LOW);
}
if (readString.indexOf("Spegnimento") > 0)
{
Serial.println("Switch COFFEEMACHINE OFF");
digitalWrite(ONbutton, HIGH);
}
macchinetta = digitalRead(ONbutton);
Serial.print("lo stato di accensione della macchinetta e': ");
Serial.println(macchinetta);
if ((luce <= 21) && (acqua == 1) && (macchinetta == false)) {
if (readString.indexOf("CortoCoffee") > 0)
{
Serial.println("Do a Corto coffee");
digitalWrite(COFFEEbutton, LOW);
delay(17000); //tempo ipotetico per caffè corto
digitalWrite(COFFEEbutton, HIGH);
}
if (readString.indexOf("MedioCoffee") > 0)
{
Serial.println("Do a Medio coffee");
digitalWrite(COFFEEbutton, LOW);
delay(35000); //tempo ipotetico per caffè medio
digitalWrite(COFFEEbutton, HIGH);
}
if (readString.indexOf("LungoCoffee") > 0)
{
Serial.println("Do a Lungo coffee");
digitalWrite(COFFEEbutton, LOW);
delay(45000); //tempo ipotetico per caffè lungo
digitalWrite(COFFEEbutton, HIGH);
}
}
if (macchinetta == true) {
accensionehtml = ("## Coffemachine is OFF");
}
else if (macchinetta == false) {
accensionehtml = ("## Coffemachine is ON");
}
if ((acqua == true) && (macchinetta == false)) {
acquahtml = ("## C'è acqua");
}
else if ((acqua == false) && (macchinetta == false)) {
acquahtml = ("## Non c'è acqua");
}
else if (macchinetta == true) {
acquahtml = ("##");
}
if ((luce <= 21) && (macchinetta == false)) {
lucehtml = ("##CoffeeMachine is ready to do coffee");
}
else if ((luce > 21) && (macchinetta == false)) {
lucehtml = ("## Coffeemachine is not ready to do coffee");
}
else if (macchinetta == true) {
lucehtml = ("##");
}
}
Ringrazio ancora anticipatamente per l'aiuto che riuscirete a darmi ;D
htmlxprogettotxt.txt (3.57 KB)
htmlxprogettotxt.txt (3.57 KB)