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
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
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
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?
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
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() {
}
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
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();
}
I am just typing the ip address as 192.168.0.137 which was working fine for html.
Hi.
Access like this: 192.168.0.137/sdata.txt
Let me know if this works.
Regards,
Sara
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
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