Skip to content

Commit

Permalink
Replace SIPPFS with LittleFS (#10)
Browse files Browse the repository at this point in the history
Tested on the real hardware and it works
  • Loading branch information
garyservin committed Nov 16, 2021
1 parent 5023fee commit 7956d3f
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions linka-firmware.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/**
Particulate matter sensor firmware for D1 Mini (ESP8266) and PMS5003
Read from a Plantower PMS5003 particulate matter sensor using a Wemos D1
Mini (or other ESP8266-based board) and report the values to an HTTP
server
Read from a Plantower PMS5003/PMS7003 particulate matter sensor using
a Wemos D1 Mini (or other ESP8266-based board) and report the values
to an HTTP server
Written by Linka Gonzalez
https://github.com/garyservin/linka-firmware
Expand All @@ -13,6 +13,7 @@
Copyright 2020 Linka Gonzalez
*/
#define VERSION "0.2"
#define USE_LittleFS
#include <FS.h> // This needs to be first, or it all crashes and burns...
#include <SPI.h> // Explicit #include of built-in SPI needed for platformio
/*--------------------------- Configuration ------------------------------*/
Expand All @@ -29,6 +30,7 @@
#include <time.h> // To get current time
#include "PMS.h" // Particulate Matter Sensor driver (embedded)
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson
#include <LittleFS.h>

/*--------------------------- Global Variables ---------------------------*/
// Particulate matter sensor
Expand Down Expand Up @@ -82,7 +84,7 @@ bool force_captive_portal = false;

/*--------------------------- Function Signatures ------------------------*/
void initOta();
bool initWifi();
void initWifi();
void initFS();
void updatePmsReadings();

Expand Down Expand Up @@ -449,7 +451,7 @@ void initOta()
/*
Connect to Wifi. Returns false if it can't connect.
*/
bool initWifi()
void initWifi()
{
// Disable debug for WiFi connect
wc.setDebug(false);
Expand Down Expand Up @@ -506,7 +508,7 @@ bool initWifi()
json["description"] = description_param.getValue();
json["api_url"] = api_url_param.getValue();

File configFile = SPIFFS.open("/config.json", "w");
File configFile = LittleFS.open("/config.json", "w");
if (!configFile) {
Serial.println("failed to open config file for writing");
}
Expand All @@ -531,17 +533,17 @@ bool initWifi()
void initFS(void)
{
//clean FS, for testing
//SPIFFS.format();
//LittleFS.format();

//read configuration from FS json
Serial.println("mounting FS...");

if (SPIFFS.begin()) {
if (LittleFS.begin()) {
Serial.println("mounted file system");
if (SPIFFS.exists("/config.json")) {
if (LittleFS.exists("/config.json")) {
//file exists, reading and loading
Serial.println("reading config file");
File configFile = SPIFFS.open("/config.json", "r");
File configFile = LittleFS.open("/config.json", "r");
if (configFile) {
Serial.println("opened config file");
size_t size = configFile.size();
Expand Down

0 comments on commit 7956d3f

Please sign in to comment.