So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By RiK1995
#73690 Hello.

For first i have to say I am from Poland and my english is not good enough.

I am figthing with my problem for five days and if i dive in my problem i know less than i was starting.
I have got ESP8266 it is probably Nodemcu 0.9 or 1.0 i dont know because it is not mine and Mega2560(Arduino).

I done flash firmware on my ESP with success(AT command works).
I have got install ESP software in Arduino IDE.
I have got install driver on my Windows.

I have got server who is connect to internet.On this server i have html site with upload files.
___________

I want to do something like this:
- Go to website, upload compiled file for Arduino.
- ESP send GET to my website and "download" compiled file.
- ESP programing arduino with stk500 protocol (I read it on the internet).

I know about SPIFFS on ESP, but i dont know how to use it.

I create sorce code to send GET and recive file what i want:
Code: Select all#include <SPIFFSReadServer.h>
#include <ESP8266WiFi.h>

const char* ssid = "*****";
const char* pass = "*****";

const char* host = "www.pd36868.zut.edu.pl";


bool isFile(File f){
    if(!f){
    Serial.println("file open failed");
   }
}

void setup(){
  Serial.begin(115200);
  SPIFFS.format();
  SPIFFS.begin();
 
  WiFi.begin(ssid, pass);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.print("Connected to ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

int value = 0;

void loop(){
  delay(5000);
  ++value;
 
  Serial.print("connecting to ");
  Serial.println(host);
 
  // Use WiFiClient class to create TCP connections
  WiFiClient client;
  const int httpPort = 80;
  if (!client.connect(host, httpPort)) {
    Serial.println("connection failed");
    return;
  }
 
  // We now create a URI for the request
  String url = "/upload.hex";
  Serial.print("Requesting URL: ");
  Serial.println(url);
 
  // This will send the request to the server
  client.print(String("GET ") + url + " HTTP/1.1\r\n" +
               "Host: " + host + "\r\n" +
               "Connection: close\r\n\r\n");
  delay(500);

 
      File upload = SPIFFS.open("/upload.txt","w+");
      isFile(upload);
      File request = SPIFFS.open("/request.txt","w+");
      isFile(request);
     
  // Read all the lines of the reply from server and print them to Serial
   int i = 0;
    while(client.available()){
      String line = client.readStringUntil('\n');
      Serial.println(line);

      if(i >= 9){
        upload.println(line);
     }
     else{
        request.println(line);
     }
     
     i++;
    }
  upload.close();
 
  Serial.println();
  Serial.println("closing connection");

  File uploadReading = SPIFFS.open("/request.txt","r");
  isFile(uploadReading);
 
  while (uploadReading.available()){
      Serial.println(uploadReading.readStringUntil('\n'));
    }
    uploadReading.close();

    SPIFFS.end();
}


In this code i`m trying to use SPIFFS, but dont work.
It is test code, i know *.txt it`s not compiled file, it is only a test.

_______

For first, i want create file who will be "download" from my website(upload.txt in this code).
For secound, i want to send this file to SPIFFS.
For third, send from SPIFFS by TX,RX (ESP8266 -> ARDUINO) and programing Arduino, but i want to focus on the first two things :).

Thank you for help and sorry for my bad english.