I am trying to use the nodeMCU to log data to the SPIFFS with a SD card backup from a sensor once a minute and use a FTP server to transfer the file to my pc. The example I found to setup the server works fine and I can transfer files to and from the server. When I use the Node as just a microcontroller unit it logs to the SD card fine. After adding the write to SPIFFS and FTP server code it is not logging to the SPIFFS (as far as I can tell) and I get an error from Filezilla of
Status: Connecting to 192.168.0.100:21...
Status: Connection established, waiting for welcome message...
Error: Connection timed out after 20 seconds of inactivity
Error: Could not connect to server
The code compiles without a problem
I am still fairly new to coding so maybe it is something I missed.
#define FS_NO_GLOBALS
#include <SD.h>
#include <Wire.h>
#include "Adafruit_HTU21DF.h"
#include "FS.h"
#ifdef ESP8266
#include <ESP8266WiFi.h>
#elif defined ESP32
#include <WiFi.h>
#include "SPIFFS.h"
#endif
#include <ESP8266FtpServer.h>
const char* ssid = "******";
const char* password = "******";
FtpServer ftpSrv; //set #define FTP_DEBUG in ESP8266FtpServer.h to see ftp verbose on serial
// Connect Vin to 3-5VDC
// Connect GND to ground
// Connect SCL to I2C clock pin (A5 on UNO)
// Connect SDA to I2C data pin (A4 on UNO)
File myFile;
Adafruit_HTU21DF htu = Adafruit_HTU21DF();
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.println("HTU21D-F");
if (!htu.begin()) {
Serial.println("Couldn't find sensor!");
while (1);
}
Serial.print("Initializing SD card...");
// On the Ethernet Shield, CS is pin 4. It's set as an output by default.
// Note that even if it's not used as the CS pin, the hardware SS pin
// (10 on most Arduino boards, 53 on the Mega) must be left as an output
// or the SD library functions will not work.
pinMode(10, OUTPUT);
if (!SD.begin(2)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
/////FTP Setup, ensure SPIFFS is started before ftp; /////////
#ifdef ESP32 //esp32 we send true to format spiffs if cannot mount
if (SPIFFS.begin(true)) {
#elif defined ESP8266
if (SPIFFS.begin()) {
#endif
Serial.println("SPIFFS opened!");
ftpSrv.begin("esp8266","esp8266"); //username, password for ftp. set ports in ESP8266FtpServer.h (default 21, 50009 for PASV)
}
}
void loop() {
myFile = SD.open("Temp_Hum.txt", FILE_WRITE);
Serial.print("Temp: "); Serial.print(htu.readTemperature());
Serial.print("\t\tHum: "); Serial.println(htu.readHumidity());
myFile.print("Temp: "); myFile.print(htu.readTemperature());
myFile.print("\t\tHum: "); myFile.println(htu.readHumidity());
myFile.close();
fs::File f = SPIFFS.open("Temp_Hum.txt", "w");
f.print("Temp: "); f.print(htu.readTemperature());
f.print("\t\tHum: "); f.println(htu.readHumidity());
f.close();
delay(60000);
ftpSrv.handleFTP(); //make sure in loop you call handleFTP()!!
}
Arduino IDE 1.8.5
NodeMCU 1.0 ESP-12E
Adafruit HTU21D-F Temperature and Humidity Sensor
Adafruit MicroSD Breakout Board
Any help would be appreciated