Go Down

Topic: web server su sd con tiny e senza (Read 1 time) previous topic - next topic

mauroz

quando carichi gli esempi riesci a pingare l'arduino?

roc3d

ciao mauroz, con l'esempio caricato il ping va bene, nessun pacchetto perso

roc3d

per la precisione sto usando l'esempio blinkled5
http://arduino.cc/forum/index.php/topic,56928.0.html
da cui ho scaricato il codice e sto usando l'ide 0022

pablos

prova a mettere questo e carica qualsiasi pagina html rinominata index.htm che deve essere nella sd ovviamente
IDE 1.0 e cambia l'indirizzo ip

Code: [Select]

Code:

#include <SPI.h>
#include <Ethernet.h>
#include <Flash.h>
#include <SD.h>
#include <TinyWebServer.h>

const int SD_CS = 4;
const int ETHER_CS = 10;
byte ip[] = { 192, 168, 2, 177 };
static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
boolean file_handler(TinyWebServer& web_server);
boolean index_handler(TinyWebServer& web_server);

TinyWebServer::PathHandler handlers[] = {
 {"/", TinyWebServer::GET, &index_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;

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 setup() {
 Serial.begin(9600);
 pinMode(SS_PIN, OUTPUT); // set the SS pin as an output                                
 digitalWrite(SS_PIN, HIGH); // and ensure SS is high
 pinMode(ETHER_CS, OUTPUT); // Set the CS pin as an output
 digitalWrite(ETHER_CS, HIGH); // Turn off the W5100 chip! (wait for                              
 pinMode(SD_CS, OUTPUT);       // Set the SDcard CS pin as an output
 digitalWrite(SD_CS, HIGH); // Turn off the SD card! (wait for
                             
 card.init(SPI_FULL_SPEED, SD_CS);
 volume.init(&card);  
 root.openRoot(&volume);
 Ethernet.begin(mac, ip);
 web.begin();
 Serial << F("Ready to accept HTTP requests.\n");
}

void loop()
{  
   web.process();
}

no comment

pablos

se non ti va anche questo hai problemi con lib flash
no comment

Go Up