Salve ragazzi non riesco a capire perché ho un comportamento ciclico all'interno della funzione Setup() nelle reference Arduino leggo che viene eseguita solo una volta all'avvio o al reset di una piattaforma arduino.
#include "SPI.h"
#include "Ethernet.h"
#include "SD.h"
#include "WebServer.h"
#define TRUE 1
#define FALSE 0
#define MAX_POST_PARAM_SIZE 16
#define MAX_TAG_SIZE 16
#define MAX_LINE_HTML_FILE 200
char name[MAX_POST_PARAM_SIZE], value[MAX_POST_PARAM_SIZE];
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192, 168, 0, 101);
WebServer webserver("",80);
File webPage;
void loadPageStructure(File webPage,char **Tag){
/*char c;
int i=0,j=0;
while((c=webPage.read())!=-1){
if(c=='<'){
Tag[i][j++]=c;
}else if(c!='>'&&j>0){
Tag[i][j++]=c;
}else if(c=='>'){
Tag[i][j]='>';
i++;
j=0;
}
}*/
}
/*void updateState(boolean s){
if(s==TRUE){
}else if(s==FALSE){
}
}*/
void Start(WebServer &server, WebServer::ConnectionType type, char *, bool){
server.httpSuccess();
if (type != WebServer::HEAD) {
webPage=SD.open("INDEX~1.HTM");
char msg[1000];
char c;
while((c=webPage.read())!=-1){
server.print(c);
}
server.readPOSTparam(name,MAX_POST_PARAM_SIZE,value,MAX_POST_PARAM_SIZE);
webPage.close();
/*if(strcmp(value,"18051991"))
updateState(TRUE);
else
updateState(FALSE);*/
}
}
void setup(){
pinMode(10, OUTPUT);
Serial.begin(9600);
if(!SD.begin(4)){
Serial.print("SD inizialization failed!");
return;
}
Serial.print("SD inizialization done!");
if (!SD.exists("INDEX~1.HTM")){
Serial.print("The file not exist");
return;
}
char **Tag;
Tag=(char**)malloc(MAX_LINE_HTML_FILE*sizeof(char*));
for(int i=0;i<MAX_LINE_HTML_FILE;i++){
Tag[i]=(char*)malloc(MAX_TAG_SIZE*sizeof(char));
}
webPage=SD.open("INDEX~1.HTM");
loadPageStructure(webPage,Tag);
webPage.close();
Serial.print("fine e chiusa");
/*Assegno ip all'interfaccia e configuro webduino*/
Ethernet.begin(mac,ip);
webserver.setDefaultCommand(&Start);
webserver.addCommand("index.html", &Start);
webserver.begin();
}
void loop(){
webserver.processConnection();
}
L'output nel monitor seriale è il seguente: