-->
Page 1 of 1

ESP8266 Server File up and download over UART to an ST32

PostPosted: Thu Nov 29, 2018 9:21 am
by MGM
I have a problem with an ESP8266.
I'm new to the world of the ESP8266 so please just ask if there are not enough informations.

A Blockschematic is attached.
A Website has 3 Buttons.

1. Download (Download the csv from the external Memory. The STM send the csv over UARt to the ESP8266.
The ESP8266 send it to the Computer)

2.Update (Send a file to the STM32 over UART an the Chip stores it in the Memory)

3.Change Password (Open a window where I can change the Passwort of the Server)

Everything should send over the own Wifi-network of the ESP8266.

I programm the EPS8266 with the Arduino IDE.

How do I implement something like this?

I want to implement 3 functions, that do this three point.
-HandelDownload
-HandleUpdate
-HandleChange_Password


Here is the code that I have written till now.
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <WiFiClient.h>
#include <ESP8266WiFiMulti.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <ESP8266mDNS.h>
#include <FS.h>

#include "mainpage.h" //Our HTML webpage contents

//On board LED Connected to GPIO2
#define LED 2

const char *ssid = "MYESP8266";
const char *password = "123456789";

ESP8266WebServer server(80);

void handleRoot() {
 Serial.println("You called root page");
 String s = MAIN_page; //Read HTML contents
 server.send(200, "text/html", s); //Send web page
}

void handleDownload(){   // Download a CSV to the Website
  if (!SPIFFS.begin()) {
   Serial.println("SPIFFS failed to mount !\r\n");                   
  }
  else {
    String str = "";
    File f = SPIFFS.open(server.arg(0), "r");
    if (!f) {
     Serial.println("Can't open SPIFFS file !\r\n");         
    }
    else {
     char buf[1024];
     int siz = f.size();
     while(siz > 0) {
      size_t len = std::min((int)(sizeof(buf) - 1), siz);
      f.read((uint8_t *)buf, len);
      buf[len] = 0;
      str += buf;
      siz -= sizeof(buf) - 1;
      }
    f.close();
    server.send(200, "text/plain", str);
    }
  }
}

void handleUpdate() { //Upload a file to the ESP8266 that send it to the
//STM32
 Serial.println("Update page");
 digitalWrite(LED,HIGH); //LED off
 server.send(200, "text/html", "Update"); //Shows Update
}

void handleChange_Password() { //Change password of the ESP8266
 Serial.println("Change_Password page");
 digitalWrite(LED,HIGH); //LED off
 server.send(200, "text/html", "Change"); //Shows Change
}

void setup(void){

  Serial.begin(115200);
  SPIFFS.begin();
  Serial.println("");

  //Onboard LED port Direction output
  pinMode(LED,OUTPUT);
  //Power on LED state off
  digitalWrite(LED,HIGH);

  WiFi.mode(WIFI_AP);           //Only Access point
  WiFi.softAP(ssid, password);  //Start HOTspot removing password will         
  disable security

  IPAddress myIP = WiFi.softAPIP(); //Get IP address
  Serial.print("HotSpt IP:");
  Serial.println(myIP);

  server.on("/", handleRoot);      //Which routine to handle at root         
  //location. This is display page

  server.on("/Download", handleDownload);
  server.on("/Update", handleUpdate);
  server.on("/Change_Password", handleChange_Password);


  server.begin();                  //Start server

  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
}


I hope some one can help me. Thanks