Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By ridge
#25869 Not much thought really, when I read that article 16 years ago it was pure fantasy guesses by a college professor.
Today, the hardware and price point (inflation adjusted of course) is real with the esp8266.

Free tools available for everyone he did not even imagine! :)
User avatar
By danbicks
#25915 Guys,

@Ridge & @Martin do you have a simple example of downloading a text file from a web server and making a copy of this file locally in SPIFFS?

How is this done? using a stream object of some type?. My idea is to be able to pull down a config file from a web server in the cloud and then use this for ESP local config.

Would be really cool to interrogate this file prior to download for later versions etc. Any ideas on how to go about this.

Cheers Guru's

Dans
User avatar
By martinayotte
#25921 I don't have a tested example in my hand, but here is a untested snippet of how it can be done :

Code: Select allvoid DownloadFromServer()
{
  WiFiClient client;
  if (!client.connect("myserver", 80)) {
    Serial.println("Failed to connect with 'myserver' !");
  }
  else {
    client.print("GET /download.php HTTP/1.1\r\nHost: myserver\r\n\r\n");
    delay(10); 
    if (!SPIFFS.begin()) {
      Serial.println("SPIFFS failed to mount !\r\n");                   
    }
    else {
      File f = SPIFFS.open("/Config.cfg", "w");
      if (!f) {
        Serial.println("Can't open Config.cfg !\r\n");         
      }
      else {
        while(client.available()){
          String line = client.readStringUntil('\r');
          f.write((uint8_t *)line.c_str(), line.length());
        }
        f.close();
      }
    }         
  } 
}
User avatar
By danbicks
#25973 Martin,

Big thanks for this snip, I will have a play with it and let you know the outcome, cheers mate.

Dans