File download from SD card hangs up my ESP
Posted: Sun Dec 04, 2016 2:58 pm
Hi. I'm using ESP8266 Arduino for compiling and uploading my code to NodeMCU 1.0 (ESP-12E Module).
Flash Size: 4M (3M SPIFFS)
CPU frequency: 80 MHz
Upload Speed: 115200
I'm using portable arduino extracted in my D: drive.
I've written this basic code to download 'datalog.txt' file (stored in the root of my SD card).
But, when I press the 'Download' button, the ESP hangs and then restarts as displayed below (from my Serial Monitor):
I don't understand the verbatim error dump. What am I doing wrong?
Please help!
Flash Size: 4M (3M SPIFFS)
CPU frequency: 80 MHz
Upload Speed: 115200
I'm using portable arduino extracted in my D: drive.
I've written this basic code to download 'datalog.txt' file (stored in the root of my SD card).
Code: Select all
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <SPI.h>
#include <SD.h>
const int chipSelect = 4;
const char *ssid = "tiny-esp";
const char *password = "password";
ESP8266WebServer server(80);
String home = "<h1>Hello! from ESP8266!</h1>"
"<p><a href=\"down\"><button>Download</button></a>";
void handleRoot() {
server.send(200, "text/html", home);
}
void handleDownload() {
File dataFile = SD.open("datalog.txt");
int fsizeDisk = dataFile.size();
Serial.print("fsizeDisk: ");
Serial.println(fsizeDisk);
size_t fsizeSent = server.streamFile(dataFile,"text/plain");
Serial.print("fsizeSent: ");
Serial.println(fsizeSent);
dataFile.close();
}
void setup() {
delay(500);
Serial.begin(115200);
Serial.println();
WiFi.softAP(ssid, password);
IPAddress apip = WiFi.softAPIP();
Serial.print("Please visit: \n");
Serial.println(apip);
// see if the card is present and can be initialized:
if (!SD.begin(chipSelect)) {
Serial.println("\nCard failed, or not present");
// don't do anything more:
return;
}
Serial.println("\nCard Initialized.");
server.on("/", handleRoot);
server.on("/down", handleDownload);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
But, when I press the 'Download' button, the ESP hangs and then restarts as displayed below (from my Serial Monitor):
Code: Select all
Please visit:
192.168.4.1
Card Initialized.
HTTP server started
fsizeDisk: 28600
Panic D:\arduino-1.6.9-windows\arduino-1.6.9\hardware\esp8266com\esp8266\cores\esp8266\core_esp8266_main.cpp:98 __yield
ctx: sys
sp: 3ffffc80 end: 3fffffb0 offset: 01b0
>>>stack>>>
3ffffe30: 3ffefdf4 000003b9 000003b9 4010020c
3ffffe40: 00000000 3ffe9645 00000001 4020815d
3ffffe50: 3ffefdf4 00000481 3fff0d50 402077e5
3ffffe60: 3fff337c 00000b68 00000000 40207823
3ffffe70: 3fff3a74 3fff1480 3fff3a74 3fff1474
3ffffe80: 3fff337c 00000b68 3fff307c 40202a57
3ffffe90: 3fff3a74 00000b68 3fff2cfc 40202c07
3ffffea0: 00000000 3ffe9704 3fff337c 3fff1474
3ffffeb0: 3fff337c 3fff147c 3fff2cfc 40202d34
3ffffec0: 3ffeead0 0883f900 3fff1478 40202d54
3ffffed0: 3fff337c 3fff147c 3fff1478 4022670d
3ffffee0: 00000000 0104a8c0 00000010 00000000
3ffffef0: 00000000 00000010 3ffefe40 40221001
3fffff00: 40210000 00000000 0000007d 3fff151c
3fffff10: 3ffebae4 3fff1520 3fff3434 40224b39
3fffff20: 3fff1370 3fff1fac 3fff1fac 4021547e
3fffff30: 40215972 3ffed310 3ffebabc 3fff1fac
3fffff40: 3ffebad6 00000000 3fff3434 40223f35
3fffff50: 0204a8c0 3ffee318 02a93dee 00000000
3fffff60: 40104b62 02a93dee 3ffeead0 60000600
3fffff70: 4022d230 3ffeeaa8 3ffeead0 0884220c
3fffff80: 4022d256 3fffdab0 00000000 3fff2004
3fffff90: 3fffdc90 00000000 3fff3434 4022ce8b
3fffffa0: 40000f49 3fffdab0 3fffdab0 40000f49
<<<stack<<<
ets Jan 8 2013,rst cause:2, boot mode:(3,7)
load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v00000000
~ld
Please visit:
192.168.4.1
Card Initialized.
HTTP server started
I don't understand the verbatim error dump. What am I doing wrong?
Please help!