problema arduino + ajax

Salve ragazzi,
dovrei mandare dei valori da arduino ad una pagina html e poi utilizzarli da Html.
Sto guardando questo link per rpenderci spunto:

e siccome non avevo mai lavorato con ajax, avevo chiesto aiuto anche per fare il contrario, cioè mandare dati da html a arduino, questo è l'esempio

sketch:

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

//****************VALUES YOU CHANGE*************/
//byte ip[] = { 192, 168, 0, 12 };// Don't forget to modify the IP to an available one on your home network
byte ip[] = { 192, 168, 2, 177 };// Don't forget to modify the IP to an available one on your home network
//*********************************************/

static uint8_t mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

 TinyWebServer::PathHandler handlers[] = {
  {"/", TinyWebServer::GET, &index_handler},
  {"/RICEVI", TinyWebServer::POST, &riceve_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;

//_________________________________________________________________________________________________________________________________________________________________________
boolean riceve_handler(TinyWebServer& web_server) 
{  
      web_server.send_error_code(200);
      web_server.send_content_type("text/plain");
      web_server.end_headers();
      Client& client = web_server.get_client();
                 
    if (client.available()) 
    { 
      String readString;
      int16_t c;  
      
       while ((c = client.read())>0)
       {
         readString += (char)c;
         if(c=='#'){           
         Serial.println (readString);  //debug
         
         //------------------------------------
         //qui elabori la stringa in arrivo
         //-----------------------------------
            
         //svuoto la stringa dopo aver incontrato # ... in questo modo la massima lunghezza di  readString
         //sara di 255.255.255.255# quindi 16 char, si evita di crashare arduino a causa di un eventuale 
         //saturazione della ram
         readString="";
         }             
       }
      
        readString=""; //svuota la stringa del client.read  
    } 
   
      client.stop();   
}

//_________________________________________________________________________________________________________________________________________________________________________
void send_file_name(TinyWebServer& web_server, const char* filename) {
//Serial.print ("1");
  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) {
//Serial.print ("2");
  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) {
//Serial.print ("3");
  send_file_name(web_server, "SETUP.HTM");
  return true;
}
//_________________________________________________________________________________________________________________________________________________________________________

void setup() {
 
  Serial.begin(9600);
  //Serial << F("Free RAM: ") << FreeRam() << "\n";
 
  pinMode(SS_PIN, OUTPUT);   // set the SS pin as an output
  digitalWrite(SS_PIN, HIGH);   // and ensure SS is high
  pinMode(10, OUTPUT);   // Set the CS pin as an output
  digitalWrite(10, HIGH);   // Turn off the W5100 chip! (wait for configuration)
  pinMode(4, OUTPUT);   // Set the SDcard CS pin as an output
  digitalWrite(4, HIGH);   // Turn off the SD card! (wait for configuration)
  // initialize the SD card.
  Serial.println("Setting up SD card...");
  // pass over the speed and Chip select for the SD card
  if (!card.init(SPI_FULL_SPEED, 4)) {
    Serial.println("card failed");
    has_filesystem = false;
  }
  // initialize a FAT volume.
  if (!volume.init(&card)) {
    Serial.println("vol.init failed!");
    has_filesystem = false;
  }
  if (!root.openRoot(&volume)) {
    Serial.println("openRoot failed");
    has_filesystem = false;
  }

  // Initialize the Ethernet.
  Serial.println("Setting up the Ethernet card...");
  Ethernet.begin(mac, ip);

  // Start the web server.
  Serial.println("Web server starting...");
  web.begin();

  Serial.println("Ready to accept HTTP requests.");
}
 
//_________________________________________________________________________________________________________________________________________________________________________
void loop() {
  if (has_filesystem) {
    web.process();
  }
}

in allegato trovato il file html.
Qualcuno mi dà una mano con questo esempio a mandare dati di ip,sub,gateway ecc. alla pagina html??
Dovrei aggiornarla con i valori che leggo nella eeprom di arduino

Grazie mille

setup.htm (6.37 KB)

Guarda cosa mi hai risposto nel tuo treadh qui quando ti offrivo una soluzione bidirezionale http://arduino.cc/forum/index.php/topic,154993.15.html reply 16/17/18

sausim:
il file .js dovrebbe servire per fare appunto la comunicazione tra arduino e html....io non devo comunicare con l'html, cioè non devo aggiornare la pagine o i valori dell' html...io ho già tutto dentro l'SD e nel browser...con arduino devo fare solo la get per prendere l'url, ma non ho esempi con tinywebserver.

Succede ha chi non ha molto chiaro quello che deve andare a fare, ma lo vuole fare!!!
Hai ragione pablos!!!!

Però aiutami dai!!!!
Sono nuovo, mi serve il tuo aiuto!!!

Ho guardato questo link pablos

ho provato ad adattarlo al mio progetto....ma non va!!!

Hai qualche consiglio??

posto il codice non funzionante di quello che ho fatto....
spero in un anima buona che mi spiega dove sto sbagliando.

sketch:

TinyWebServer::PathHandler handlers[] = {
  {"/", TinyWebServer::GET, &index_handler },
  {"/" "*", TinyWebServer::GET, &file_handler },
  {"/RICEVI", TinyWebServer::POST, &riceve_handler},
  {"/MANDA", TinyWebServer::POST, &send_handler},
{NULL},
};


boolean send_handler(TinyWebServer& web_server) 
{  
    web_server.send_error_code(200);
    web_server.send_content_type("text/plain");
    web_server.end_headers();
    Client& client = web_server.get_client();
    
    Serial.println("entro nella funzione send");
    
    if (client.available()) { 
      String readString; 
      int16_t c;  
      while ((c = client.read())>0) {  //leggo la scritta ricevuta dall'html
         readString += (char)c;        //aggiungo i caratteri ad una variabile 
      }
      if (c == 'snd') {
        Serial.print ("preso dato dalla funzione");
      }
    }
}

html:

ho dichiarato una funzione javascript:

function GetDataTcpIp() {
var dato = "snd";
var url = "/MANDA"; $.ajax({type: "POST", data: dato, dataType: "text", cache: false, url: url, success: function (r);    
	   });

}

e la richiamo nel body:

<body onload = "GetDataTcp()">

ma il tutto non funzia.....
per prima cosa ho provato a mandare un messaggio alert al posto della funzione nel body, ma nemmeno quello funzia...penso che sbaglio qualcosa nell'html.

Ringrazio anticipatamente chi mi volesse aiutare, visto che chi può, non vuole!!!
Grazie sausim

Mi spiace ma non conosco il funzionamento di Ajax e JavaScript. :frowning:

Neppure io...

usa wireshark per analizzare la comunicazione e capire che succede.

Nemmeno io conosco ajax