• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

Access to text file saved in SPIFFS

Q&A Forum › Category: ESP32 › Access to text file saved in SPIFFS
0 Vote Up Vote Down
Shah Rafique asked 1 year ago

Greetings to you
I have a text file stored in ESP-32 at SPIFFS with local IP address. Is there anyway to access to this text file from PC connected in same network? Or Can I save this test file in my PC instead of SPIFFS from ESP-32? I have some sensor data need to be read from out side the ESP-32. Please suggest. Thank you 

14 Answers
0 Vote Up Vote Down
William Lucid answered 1 year ago

Good Morning,
Is your text file a Comma Seperated Value (csv)?  You could use Google Sheets to log you csv text file.

I am logging BME280 data to Google Sheet.  I have documentation posted to this forum.

Log to Google Sheet monthly
 
Regards,
William

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
You can build a web server that serves that particular file.
Are you familiar with building an ESP32 Web Server to serve files?
 
Regards,
Sara

0 Vote Up Vote Down
Shah Rafique answered 1 year ago

Thanks William and Sara for the quick responses. I prefer to have communication locally so, build a web server as suggested by Sara would be more suitable. 
Sara, any specific project with web server I can study?

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
 
Check the following project (you just need the Arduino sketch): https://randomnerdtutorials.com/esp32-web-server-spiffs-spi-flash-file-system/
 
Instead of an HTML file, you’ll want to serve your txt file. 
 
Ignore the Processor() function.
Then, you just need one server.on() function to serve your file.
 (replace your_file with the name of your fike). Then, to access that file, you just need to open your board ip address followed by /your_file.txt

  server.on("/your_file.txt, HTTP_GET, [](AsyncWebServerRequest *request){
    request->send(SPIFFS, "/your_file.txt", "text/txt");
  });

Let me know if you need further help.
Regards,
Sara

0 Vote Up Vote Down
Shah Rafique answered 1 year ago

Thank you Sara for your help

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Then let me know if you made it work.
Regards,
Sara

0 Vote Up Vote Down
Shah Rafique answered 1 year ago

Sara:
Not sure but I am certain did something wrong.  Getting Error 500 . please see and advise.

Start your code here

#include <Arduino.h>
#include <WiFi.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include “SPIFFS.h”
// Replace with your network credentials
const char* ssid = “xxxxxxxxxxxxx”;
const char* password = “xxxxxxxxxxxxxxxxxxxxx”;
// Create AsyncWebServer object on port 80
AsyncWebServer server(80);
void initSPIFFS() {
if (!SPIFFS.begin(true)) {
Serial.println(“An error has occurred while mounting SPIFFS”);
}
else {
Serial.println(“SPIFFS mounted successfully”);
}
}
void initWiFi() {
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.print(“Connecting to WiFi ..”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(‘.’);
delay(1000);
}
Serial.println(WiFi.localIP());
}
void setup() {
Serial.begin(115200);
initWiFi();
initSPIFFS();
server.on(“/sdata.txt”, HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, “/sdata.txt”, “text/txt”);
});

server.serveStatic(“/”, SPIFFS, “/”);
server.begin();
}
void loop() {

}
 

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
I’m sorry, my mistake.
It should be “text/plain” and not text/txt 
See here: https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types
 
Let me know if this solves the issue.
Regards,
Sara

0 Vote Up Vote Down
Shah Rafique answered 1 year ago

Sara:
Thanks for your time. Still no luck. Still getting HTTP ERROR 500

Start your code here

void setup() {
Serial.begin(115200);
initWiFi();
initSPIFFS();
server.on(“/sdata.txt”, HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, “/sdata.txt”, “text/plain”);
});

server.serveStatic(“/”, SPIFFS, “/”);
server.begin();
}
 

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

How are you accessing your web server?
In which URL?
Regards,
Sara

0 Vote Up Vote Down
Shah Rafique answered 1 year ago

I am just typing the ip address as 192.168.0.137 which was working fine for html. 

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
 
Access like this: 192.168.0.137/sdata.txt
 
Let me know if this works.
 
Regards,
Sara

0 Vote Up Vote Down
Shah Rafique answered 1 year ago

Sara: Still now getting HTTP ERROR 404. I have a project with sensor data and record time stored in text file. Now, I would like to get this text file to be read from my PC in the same network. Any idea or alternate option is appreciated. Thank you

0 Vote Up Vote Down
Sara Santos Staff answered 1 year ago

Hi.
Do you actually have the file called sdata.txt in SPIFFS?
The error 404 means it can’t find the file.
 
You can try with a different URL( without the “.txt”):
server.on(“/sdata”, HTTP_GET, [](AsyncWebServerRequest *request){
request->send(SPIFFS, “/sdata.txt”, “text/plain”);
});
 
Then, access at 192.168.0.137/sdata
 
Regards,
Sara
 

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025
  • [eBook Updated] Learn ESP32 with Arduino IDE eBook – Version 3.2 April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.