SD-kaart werkt met Cardinfo wel maar niet met een Script.
6 berichten
• Pagina 1 van 1
SD-kaart werkt met Cardinfo wel maar niet met een Script.
Ik ben bezig met het voorbeeld programma van SDwebserver met de ESP8266 (NodeMCU) als ik het Script Cardinfo gebruik krijg ik netjes te zien hoe groot de kaart enz. en wat er op de kaart staat.
Maar als ik de SDwebserver script gebruik dan krijg ik te lezen dat er geen Card aanwezig is.
Dus snap ik nu niet wat er aan de hand is, ik heb het ook met const int chipSelect = 15; omdat de CS op 15 moest staan.
Heeft iemand een idee wat er mis is.
- Code: Alles selecteren
Initializing SD card...Wiring is correct and a card is present.
Card type: SD2
Volume type is FAT16
Volume size (bytes): 2002419712
Volume size (Kbytes): 1955488
Volume size (Mbytes): 1909
Files found on the card (name, date and size in bytes):
INDEX.TXT 2016-01-31 14:50:56 4488
KUNDE.PHP 2016-02-27 07:39:28 3319
KUNDEI~1.TXT 2016-04-26 17:03:22 64
LOGBUCH.PHP 2016-02-29 09:20:02 3314
LOGBUCH.TXT 2016-04-27 08:17:02 6771
LOGIN.PHP 2016-02-24 12:20:06 921
LOGMOVE.PHP 2016-02-29 13:05:36 427
LOGOLD.TXT 2016-02-29 13:05:40 6470
MASTER~1.PHP 2016-04-27 08:50:22 368
MASTER~1.ZIP 2016-04-27 08:38:46 0
NEWDATE.PHP 2016-02-27 07:39:28 176
NEWDATE.TXT 2016-02-29 14:52:28 10
SERVICE.PHP 2016-02-26 19:34:38 6271
SETTINGS.PHP 2016-03-01 13:02:08 7284
STYLE.CSS 2016-02-04 19:13:18 1012
WARTUNG.PHP 2016-02-29 12:30:32 3285
WARTUN~1.TXT 2016-02-29 14:52:42 22
ZIPPER.PHP 2016-04-27 08:36:04 571
ZIPPER~1.PHP 2016-02-26 09:42:10 646
CONFIG~1.CON 2016-03-01 11:29:20 371
CONFIG.TXT 2016-02-26 10:22:08 466
CONFIG~1.PHP 2016-02-08 09:31:00 763
EINSTE~1.PHP 2016-02-28 11:23:10 7082
FIRMA.PHP 2016-02-26 19:05:24 3453
FIRMA.TXT 2016-02-24 19:03:36 71
HILFE.PHP 2016-02-26 19:05:52 2346
HILFE.TXT 2016-02-25 06:41:20 42
INDEX.PHP 2016-03-01 10:33:26 2203
Maar als ik de SDwebserver script gebruik dan krijg ik te lezen dat er geen Card aanwezig is.
- Code: Alles selecteren
scandone
f 0, Connecting to FRITZ!Box 7330
scandone
state: 0 -> 2 (b0)
state: 2 -> 3 (0)
state: 3 -> 5 (10)
add 0
aid 5
cnt
connected with FRITZ!Box 7330, channel 9
dhcp client start...
ip:192.168.178.30,mask:255.255.255.0,gw:192.168.178.10
Connected! IP address: 192.168.178.30
MDNS responder started
You can now connect to http://esp8266sd.local
HTTP server started
pm open,type:2 0
SDCARD Not Detected
URI: /
Method: GET
Arguments: 0
Dus snap ik nu niet wat er aan de hand is, ik heb het ook met const int chipSelect = 15; omdat de CS op 15 moest staan.
Heeft iemand een idee wat er mis is.
- Code: Alles selecteren
/*
SDWebServer - Example WebServer with SD Card backend for esp8266
Copyright (c) 2015 Hristo Gochkov. All rights reserved.
This file is part of the ESP8266WebServer library for Arduino environment.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Have a FAT Formatted SD Card connected to the SPI port of the ESP8266
The web root is the SD Card root folder
File extensions with more than 3 charecters are not supported by the SD Library
File Names longer than 8 charecters will be truncated by the SD library, so keep filenames shorter
index.htm is the default index (works on subfolders as well)
upload the contents of SdRoot to the root of the SDcard and access the editor by going to http://esp8266sd.local/edit
*/
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266mDNS.h>
#include <SPI.h>
#include <SD.h>
#define DBG_OUTPUT_PORT Serial
const char* ssid = "*************"; // naam weggehaald
const char* password = "*************"; // code weggehaald
const char* host = "esp8266sd";
//const int chipSelect = 15;
ESP8266WebServer server(80);
static bool hasSD = false;
File uploadFile;
void returnOK() {
server.send(200, "text/plain", "");
}
void returnFail(String msg) {
server.send(500, "text/plain", msg + "\r\n");
}
bool loadFromSdCard(String path){
String dataType = "text/plain";
if(path.endsWith("/")) path += "index.htm";
if(path.endsWith(".src")) path = path.substring(0, path.lastIndexOf("."));
else if(path.endsWith(".htm")) dataType = "text/html";
else if(path.endsWith(".css")) dataType = "text/css";
else if(path.endsWith(".js")) dataType = "application/javascript";
else if(path.endsWith(".png")) dataType = "image/png";
else if(path.endsWith(".gif")) dataType = "image/gif";
else if(path.endsWith(".jpg")) dataType = "image/jpeg";
else if(path.endsWith(".ico")) dataType = "image/x-icon";
else if(path.endsWith(".xml")) dataType = "text/xml";
else if(path.endsWith(".pdf")) dataType = "application/pdf";
else if(path.endsWith(".zip")) dataType = "application/zip";
File dataFile = SD.open(path.c_str());
if(dataFile.isDirectory()){
path += "/index.htm";
dataType = "text/html";
dataFile = SD.open(path.c_str());
}
if (!dataFile)
return false;
if (server.hasArg("download")) dataType = "application/octet-stream";
if (server.streamFile(dataFile, dataType) != dataFile.size()) {
DBG_OUTPUT_PORT.println("Sent less data than expected!");
}
dataFile.close();
return true;
}
void handleFileUpload(){
if(server.uri() != "/edit") return;
HTTPUpload& upload = server.upload();
if(upload.status == UPLOAD_FILE_START){
if(SD.exists((char *)upload.filename.c_str())) SD.remove((char *)upload.filename.c_str());
uploadFile = SD.open(upload.filename.c_str(), FILE_WRITE);
DBG_OUTPUT_PORT.print("Upload: START, filename: "); DBG_OUTPUT_PORT.println(upload.filename);
} else if(upload.status == UPLOAD_FILE_WRITE){
if(uploadFile) uploadFile.write(upload.buf, upload.currentSize);
DBG_OUTPUT_PORT.print("Upload: WRITE, Bytes: "); DBG_OUTPUT_PORT.println(upload.currentSize);
} else if(upload.status == UPLOAD_FILE_END){
if(uploadFile) uploadFile.close();
DBG_OUTPUT_PORT.print("Upload: END, Size: "); DBG_OUTPUT_PORT.println(upload.totalSize);
}
}
void deleteRecursive(String path){
File file = SD.open((char *)path.c_str());
if(!file.isDirectory()){
file.close();
SD.remove((char *)path.c_str());
return;
}
file.rewindDirectory();
while(true) {
File entry = file.openNextFile();
if (!entry) break;
String entryPath = path + "/" +entry.name();
if(entry.isDirectory()){
entry.close();
deleteRecursive(entryPath);
} else {
entry.close();
SD.remove((char *)entryPath.c_str());
}
yield();
}
SD.rmdir((char *)path.c_str());
file.close();
}
void handleDelete(){
if(server.args() == 0) return returnFail("BAD ARGS");
String path = server.arg(0);
if(path == "/" || !SD.exists((char *)path.c_str())) {
returnFail("BAD PATH");
return;
}
deleteRecursive(path);
returnOK();
}
void handleCreate(){
if(server.args() == 0) return returnFail("BAD ARGS");
String path = server.arg(0);
if(path == "/" || SD.exists((char *)path.c_str())) {
returnFail("BAD PATH");
return;
}
if(path.indexOf('.') > 0){
File file = SD.open((char *)path.c_str(), FILE_WRITE);
if(file){
file.write((const char *)0);
file.close();
}
} else {
SD.mkdir((char *)path.c_str());
}
returnOK();
}
void printDirectory() {
if(!server.hasArg("dir")) return returnFail("BAD ARGS");
String path = server.arg("dir");
if(path != "/" && !SD.exists((char *)path.c_str())) return returnFail("BAD PATH");
File dir = SD.open((char *)path.c_str());
path = String();
if(!dir.isDirectory()){
dir.close();
return returnFail("NOT DIR");
}
dir.rewindDirectory();
server.setContentLength(CONTENT_LENGTH_UNKNOWN);
server.send(200, "text/json", "");
WiFiClient client = server.client();
server.sendContent("[");
for (int cnt = 0; true; ++cnt) {
File entry = dir.openNextFile();
if (!entry)
break;
String output;
if (cnt > 0)
output = ',';
output += "{\"type\":\"";
output += (entry.isDirectory()) ? "dir" : "file";
output += "\",\"name\":\"";
output += entry.name();
output += "\"";
output += "}";
server.sendContent(output);
entry.close();
}
server.sendContent("]");
dir.close();
}
void handleNotFound(){
if(hasSD && loadFromSdCard(server.uri())) return;
String message = "SDCARD Not Detected\n\n";
message += "URI: ";
message += server.uri();
message += "\nMethod: ";
message += (server.method() == HTTP_GET)?"GET":"POST";
message += "\nArguments: ";
message += server.args();
message += "\n";
for (uint8_t i=0; i<server.args(); i++){
message += " NAME:"+server.argName(i) + "\n VALUE:" + server.arg(i) + "\n";
}
server.send(404, "text/plain", message);
DBG_OUTPUT_PORT.print(message);
}
void setup(void){
DBG_OUTPUT_PORT.begin(115200);
DBG_OUTPUT_PORT.setDebugOutput(true);
DBG_OUTPUT_PORT.print("\n");
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
DBG_OUTPUT_PORT.print("Connecting to ");
DBG_OUTPUT_PORT.println(ssid);
// Wait for connection
uint8_t i = 0;
while (WiFi.status() != WL_CONNECTED && i++ < 20) {//wait 10 seconds
delay(500);
}
if(i == 21){
DBG_OUTPUT_PORT.print("Could not connect to");
DBG_OUTPUT_PORT.println(ssid);
while(1) delay(500);
}
DBG_OUTPUT_PORT.print("Connected! IP address: ");
DBG_OUTPUT_PORT.println(WiFi.localIP());
if (MDNS.begin(host)) {
MDNS.addService("http", "tcp", 80);
DBG_OUTPUT_PORT.println("MDNS responder started");
DBG_OUTPUT_PORT.print("You can now connect to http://");
DBG_OUTPUT_PORT.print(host);
DBG_OUTPUT_PORT.println(".local");
}
server.on("/list", HTTP_GET, printDirectory);
server.on("/edit", HTTP_DELETE, handleDelete);
server.on("/edit", HTTP_PUT, handleCreate);
server.on("/edit", HTTP_POST, [](){ returnOK(); }, handleFileUpload);
server.onNotFound(handleNotFound);
server.begin();
DBG_OUTPUT_PORT.println("HTTP server started");
if (SD.begin(SS)){
DBG_OUTPUT_PORT.println("SD Card initialized.");
hasSD = true;
}
}
void loop(void){
server.handleClient();
}
Ik ben niet de slimste maar doe wel mijn best.
Andreas
Andreas
Advertisement
Re: SD-kaart werkt met Cardinfo wel maar niet met een Script
Ha ik heb wat gevonden en het werkt ook nog.
een pullup weerstand van 10K tussen 3.3V en GPIO12 (MOSI).
Hier gevonden http://doityourselfchristmas.com/forums/showthread.php?43345-Using-SD-cards-with-ESP8266-s
Een ik kan dus nu op de card kommen, maar volgens mij heb ik nu een ander probleem en dat is PHP.
Heb een website geschreven in PHP een hele tijd geleden en die wilde ik op de SDwebserver laten draaien maar dat werkt niet.
Kan dit überhaupt niet en moet ik nu alles in HTML maken???????????
een pullup weerstand van 10K tussen 3.3V en GPIO12 (MOSI).
Hier gevonden http://doityourselfchristmas.com/forums/showthread.php?43345-Using-SD-cards-with-ESP8266-s
Een ik kan dus nu op de card kommen, maar volgens mij heb ik nu een ander probleem en dat is PHP.
Heb een website geschreven in PHP een hele tijd geleden en die wilde ik op de SDwebserver laten draaien maar dat werkt niet.
Kan dit überhaupt niet en moet ik nu alles in HTML maken???????????
Ik ben niet de slimste maar doe wel mijn best.
Andreas
Andreas
- nicoverduin
- Berichten: 5043
- Geregistreerd: 13 Mei 2013, 20:57
- Woonplaats: Heemskerk
Re: SD-kaart werkt met Cardinfo wel maar niet met een Script
Php op de esp zal vermoedelijk niet werken..... het is geen echte server heb....
Re: SD-kaart werkt met Cardinfo wel maar niet met een Script
Oke Nico dat is dan duidelijk, dan ga ik maar eens de boel omzetten naar HTML.
Ik ben niet de slimste maar doe wel mijn best.
Andreas
Andreas
- nicoverduin
- Berichten: 5043
- Geregistreerd: 13 Mei 2013, 20:57
- Woonplaats: Heemskerk
Re: SD-kaart werkt met Cardinfo wel maar niet met een Script
Als je slimme dingen wil toevoegen moet je de HTML ombouwen met bijvoorbeeld $(variabele naam) zoals in JSP. Als je dan de HTML leest kun je in een regel de variabele naam vervangen voor werkelijke waarden waardoor je wel de juiste html naar de browser stuurt.
Re: SD-kaart werkt met Cardinfo wel maar niet met een Script
Dank voor de tip Nico, dit heb ik zelf nog nooit gedaan, ga mij daar eens in verdiepen.
Ik ben niet de slimste maar doe wel mijn best.
Andreas
Andreas
6 berichten
• Pagina 1 van 1
Wie is er online?
Gebruikers in dit forum: Geen geregistreerde gebruikers en 22 gasten