Ciao a tutti,
ho realizzato una semplice applicazione per la termostatazione delle tubazioni dell'acqua fredda della mia caldaia quando sono in vacanza d'inverno, in modo tale da non far congelare il circuito dell'acqua (sanitaria+riscaldamento) avendo la caldaia nel sotto tetto.
ho già sviluppato l'applicazione che prevede:
n°4 sensori di temperatura LM35
- temperatura acqua fredda ingresso caldaia
- temperatura acqua fredda uscita caldaia
- temperatura valvola acqua/gas
- temperatura ambiente
n°3 uscite digitali per comando relè (complete di circuito di pilotaggio)
- comando cavo scaldante ingresso acqua fredda
- comando cavo scaldante uscita acqua fredda
- comando cavo scaldante valvola acqua/gas
ho effettuato tutte le prove per l'accensione/spegnimento/esclusione dei cavi scaldanti con relativo debug su serialmonitor (come si fa di solito), fi qui non ho avuto grossi problemi....
ho sviluppato il sito web con dreamweaver cs3 e l'ho caricato su scheda sd (ethernet shield v2 con micro SD), ho implementato l'esempio tinywebserver.fileupload con relative modifiche per MAC address ed indirizzo IP, ho testato l'upload tramite il comando curl e tutto funziona correttamente, arduino mi risponde con la pagina web presente in SD di cui allego il link: boscomortara.dynalias.net/index.htm ed una immagine statica della stessa:
Uploaded with ImageShack.us
ora viene il bello:
come faccio ad effettuare un link in lettura/scrittura sulle variabili presenti in arduino, quelle con cui ho effettuato il debug da serial monitor?
ho effettuato alcune ricerche per utilizzare i metodi GET e POST dei form (ogni pulsante invia dati è parte di un form contenente due variabili: setpoint start e setpoint stop)
sarebbe possibile che all'apertura della pagina web arduino si comportasse in questo modo:
-
recupero variabili da arduino -> aggiornamento contenuto statico pagina web -> visualizzazione pagina web "modificata" con i valori attuali (non m'importa se è statica, riaggiornando la pagina si avranno i nuovi valori istantanei presenti in arduino)
-
ad ogni click sul corrispondente pulsante "invia dati" -> arduino prenda in carico i nuovi dati provenienti dal form corrispondente ed aggiorni le variabili di start e stop memorizzate in precedenza.
allego il codice di esempio che ho utilizzato per la visualizzazione delle pagine web caricando le stesse da/verso uSD:
// -*- c++ -*-
//
// Copyright 2010 Ovidiu Predescu <ovidiu@gmail.com>
// Date: June 2010
//
#include <SPI.h>
#include <Ethernet.h>
#include <Flash.h>
#include <SdFat.h>
#include <SdFatUtil.h>
#include <TinyWebServer.h>
boolean file_handler(TinyWebServer& web_server);
boolean index_handler(TinyWebServer& web_server);
TinyWebServer::PathHandler handlers[] = {
// Work around Arduino's IDE preprocessor bug in handling /* inside
// strings.
//
// `put_handler' is defined in TinyWebServer
{"/", TinyWebServer::GET, &index_handler },
{"/upload/" "*", TinyWebServer::PUT, &TinyWebPutHandler::put_handler },
{"/" "*", TinyWebServer::GET, &file_handler },
{NULL},
};
const char* headers[] = {
"Content-Length",
NULL
};
TinyWebServer web = TinyWebServer(handlers, headers);
boolean has_filesystem = true;
Sd2Card card;
SdVolume volume;
SdFile root;
SdFile file;
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// Don't forget to modify the IP to an available one on your home network
byte ip[] = { 192, 168, 1, 112 };
void send_file_name(TinyWebServer& web_server, const char* filename) {
if (!filename) {
web_server.send_error_code(404);
web_server << F("Could not parse URL");
} else {
TinyWebServer::MimeType mime_type
= TinyWebServer::get_mime_type_from_filename(filename);
web_server.send_error_code(200);
web_server.send_content_type(mime_type);
web_server.end_headers();
if (file.open(&root, filename, O_READ)) {
Serial << F("Read file "); Serial.println(filename);
web_server.send_file(file);
file.close();
} else {
web_server << F("Could not find file: ") << filename << "\n";
}
}
}
boolean file_handler(TinyWebServer& web_server) {
char* filename = TinyWebServer::get_file_from_path(web_server.get_path());
send_file_name(web_server, filename);
free(filename);
return true;
}
boolean index_handler(TinyWebServer& web_server) {
send_file_name(web_server, "INDEX.HTM");
return true;
}
void file_uploader_handler(TinyWebServer& web_server,
TinyWebPutHandler::PutAction action,
char* buffer, int size) {
static uint32_t start_time;
static uint32_t total_size;
switch (action) {
case TinyWebPutHandler::START:
start_time = millis();
total_size = 0;
if (!file.isOpen()) {
// File is not opened, create it. First obtain the desired name
// from the request path.
char* fname = web_server.get_file_from_path(web_server.get_path());
if (fname) {
Serial << F("Creating ") << fname << "\n";
file.open(&root, fname, O_CREAT | O_WRITE | O_TRUNC);
free(fname);
}
}
break;
case TinyWebPutHandler::WRITE:
if (file.isOpen()) {
file.write(buffer, size);
total_size += size;
}
break;
case TinyWebPutHandler::END:
file.sync();
Serial << F("Wrote ") << file.fileSize() << F(" bytes in ")
<< millis() - start_time << F(" millis (received ")
<< total_size << F(" bytes)\n");
file.close();
}
}
void setup() {
Serial.begin(115200);
Serial << F("Free RAM: ") << FreeRam() << "\n";
// initialize the SD card
Serial << F("Setting up SD card...\n");
pinMode(10, OUTPUT); // set the SS pin as an output (necessary!)
digitalWrite(10, HIGH); // but turn off the W5100 chip!
if (!card.init(SPI_FULL_SPEED, 4)) {
Serial << F("card failed\n");
has_filesystem = false;
}
// initialize a FAT volume
if (!volume.init(&card)) {
Serial << F("vol.init failed!\n");
has_filesystem = false;
}
if (!root.openRoot(&volume)) {
Serial << F("openRoot failed");
has_filesystem = false;
}
if (has_filesystem) {
// Assign our function to `upload_handler_fn'.
TinyWebPutHandler::put_handler_fn = file_uploader_handler;
}
Serial << F("Setting up the Ethernet card...\n");
Ethernet.begin(mac, ip);
// Start the web server.
Serial << F("Web server starting...\n");
web.begin();
Serial << F("Ready to accept HTTP requests.\n");
}
void loop() {
if (has_filesystem) {
web.process();
}
}
aiuto!!!!
sono ad un passo dalla fine
grazie a tutti
saluti
Kattivik76