Hello everybody. I have a problem regarding SPIFFS. I'm making a code that takes a value from Firebase, and adds it to SPIFFS, but when I start ESP32 without internet to read the recorded value, SPIFFS does not start in setup () and hangs right there, not advancing. Does anyone know what I may have done wrong?
After making 14 other posts, you did not post your well formatted code in code tags and you want to know what's wrong with your thingy?
See, if I or Shelly or Joe or Ganglon-7 from Rigel 4 is to help you solve a possible coding issue, does it make sense that I or Shelly or Joe or Ganglon-7 from Rigel 4 would benefit more if they were to see your code so they could evaluate the code for possible issues?
Perhaps you'll want to read the ESP32 SPIFF API to learn the what about and what nots.
Think about it this way.
Help, my solar cells are not putting out any power. Of course you cannot see that my solar cells are covered with snow. It would have been of great help and saved you a 4 hour drive to my place to know right off the bat that my solar cells are covered with snow. If only I had showed you a picture first, right?
Sorry about that. I'm a beginner and I'm still getting used to it, sorry.
So, the code:
void setup() {
Serial.begin(115200);
//SPIFFS start
if (SPIFFS.begin())
{
Serial.println("SPIFFS ok");
}
else
{
Serial.println("SPIFFS error");
while (true);
}
if (!SPIFFS.exists("/lockers.json")) {
Serial.println("the file does not exist");
}
else
{
Serial.println("the file was successfully read");
file = SPIFFS.open("/lockers.json", "a");
if (file)
{
Serial.printf("Name: %s - %u bytes\n", file.name(), file.size());
while (file.available()) {
}
file.close();
}
}
//Deserialize JSON
file = dir.openNextFile();
file = SPIFFS.open("/lockers.json", "r");
if (deserializeJson(doc, file)) {
Serial.println("Deserialize ok");
} else {
Serial.println("Deserialize ERRROR");
}
file.close();
//FIREBASE
connectWifi();
Firebase.begin("https://testfi.firebaseio.com/", "UX61Cz2L9ctDr1EziojXtMnQLoXBZKmdfgFw9L0d");
Serial.println("Firebase init");
Firebase.reconnectWiFi(true);
//Set database read timeout to 1 minute (max 15 minutes)
Firebase.setReadTimeout(firebaseData, 1000 * 60);
//tiny, small, medium, large and unlimited.
//Size and its write timeout e.g. tiny (1s), small (10s), medium (30s) and large (60s).
Firebase.setwriteSizeLimit(firebaseData, "tiny");
//In setup(), set the streaming path to "lockers" and begin stream connection
Firebase.setStreamCallback(firebaseData, streamCallback, streamTimeoutCallback);
if (!Firebase.beginStream(firebaseData, "lockers/-MHF8iOfCNOJBUPHajB0/locker"))
{
//Could not begin stream connection, then print out the error detail
Serial.println("Could not begin stream");
Serial.println(firebaseData.errorReason());
Serial.println();
}
}
void connectWifi() {
Serial.println("\nStarting ConfigOnSwitch on " + String(ARDUINO_BOARD));
unsigned long startedAt = millis();
//Local intialization. Once its business is done, there is no need to keep it around
// Use this to default DHCP hostname to ESP8266-XXXXXX or ESP32-XXXXXX
//ESP_WiFiManager ESP_wifiManager;
// Use this to personalize DHCP hostname (RFC952 conformed)
ESP_WiFiManager ESP_wifiManager("ConfigOnSwitch");
ESP_wifiManager.setDebugOutput(true);
// Use only to erase stored WiFi Credentials
//resetSettings();
//ESP_wifiManager.resetSettings();
//set custom ip for portal
//ESP_wifiManager.setAPStaticIPConfig(IPAddress(192, 168, 100, 1), IPAddress(192, 168, 100, 1), IPAddress(255, 255, 255, 0));
ESP_wifiManager.setMinimumSignalQuality(-1);
// We can't use WiFi.SSID() in ESP32as it's only valid after connected.
// SSID and Password stored in ESP32 wifi_ap_record_t and wifi_config_t are also cleared in reboot
// Have to create a new function to store in EEPROM/SPIFFS for this purpose
Router_SSID = ESP_wifiManager.WiFi_SSID();
Router_Pass = ESP_wifiManager.WiFi_Pass();
//Remove this line if you do not want to see WiFi password printed
Serial.println("Stored: SSID = " + Router_SSID + ", Pass = " + Router_Pass);
// SSID to uppercase
ssid.toUpperCase();
if (Router_SSID == "")
{
Serial.println("Open Config Portal without Timeout: No stored Credentials.");
digitalWrite(PIN_LED, HIGH); // Turn led on as we are in configuration mode.
//it starts an access point
//and goes into a blocking loop awaiting configuration
if (!ESP_wifiManager.startConfigPortal((const char *) ssid.c_str(), password))
Serial.println("Not connected to WiFi but continuing anyway.");
else
Serial.println("WiFi connected...yeey :)");
}
digitalWrite(PIN_LED, LOW); // Turn led off as we are not in configuration mode.
#define WIFI_CONNECT_TIMEOUT 30000L
#define WHILE_LOOP_DELAY 200L
#define WHILE_LOOP_STEPS (WIFI_CONNECT_TIMEOUT / ( 3 * WHILE_LOOP_DELAY ))
startedAt = millis();
while ( (WiFi.status() != WL_CONNECTED) && (millis() - startedAt < WIFI_CONNECT_TIMEOUT ) )
{
WiFi.mode(WIFI_STA);
WiFi.persistent (true);
// We start by connecting to a WiFi network
Serial.print("Connecting to ");
Serial.println(Router_SSID);
WiFi.config(stationIP, gatewayIP, netMask);
//WiFi.config(stationIP, gatewayIP, netMask, dns1IP, dns2IP);
WiFi.begin(Router_SSID.c_str(), Router_Pass.c_str());
int i = 0;
while ((!WiFi.status() || WiFi.status() >= WL_DISCONNECTED) && i++ < WHILE_LOOP_STEPS)
{
delay(WHILE_LOOP_DELAY);
}
}
Serial.print("After waiting ");
Serial.print((millis() - startedAt) / 1000);
Serial.print(" secs more in setup(), connection result is ");
if (WiFi.status() == WL_CONNECTED)
{
Serial.print("connected. Local IP: ");
Serial.println(WiFi.localIP());
}
else
Serial.println(ESP_wifiManager.getStatus(WiFi.status()));
}
When I start without internet, programming stops if (!Firebase.beginStream(firebaseData...) I thought about checking for internet before, but it didn't work either.
if (WiFi.status() == == WL_CONNECTED)
{
Firebase.begin("https://testfi.firebaseio.com/", "UX61Cz2L9ctDr1EziojXtMnQLoXBZKmdfgFw9L0d");
Serial.println("Firebase init");
Firebase.reconnectWiFi(true);
//Set database read timeout to 1 minute (max 15 minutes)
Firebase.setReadTimeout(firebaseData, 1000 * 60);
//tiny, small, medium, large and unlimited.
//Size and its write timeout e.g. tiny (1s), small (10s), medium (30s) and large (60s).
Firebase.setwriteSizeLimit(firebaseData, "tiny");
//In setup(), set the streaming path to "/locker" and begin stream connection
Firebase.setStreamCallback(firebaseData, streamCallback, streamTimeoutCallback);
if (!Firebase.beginStream(firebaseData, "lockers/-MHF8iOfCNOJBUPHajB0/locker"))
{
//Could not begin stream connection, then print out the error detail
Serial.println("Could not begin stream");
Serial.println(firebaseData.errorReason());
Serial.println();
}
}
}
It would need that, when starting without internet, he skips the part of Firebase and follow with the code.
void setup()
{
Serial.begin(115200);
SPIFFS.begin()
connectWifi();
}
Does that work?
Meaning does SPIFF's and WiFi begin? Nothing else, eliminating the added fluff.
This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.