Skip to content

Commit

Permalink
stimawifi version 20241227; format sdcard on reset
Browse files Browse the repository at this point in the history
  • Loading branch information
pat1 committed Dec 27, 2024
1 parent 07c5f07 commit 27cdecf
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 14 deletions.
Binary file modified platformio/stima_v3/stimawifi/bin/lolin_c3_mini_v3/firmware.bin
Binary file not shown.
4 changes: 2 additions & 2 deletions platformio/stima_v3/stimawifi/include/stimawifi_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define STIMAWIFI_CONFIG_H_

// increment on change
#define SOFTWARE_VERSION "2024-10-31T00:00" // date and time
#define MAJOR_VERSION "20241031" // date YYYYMMDD
#define SOFTWARE_VERSION "2024-12-27T00:00" // date and time
#define MAJOR_VERSION "20241227" // date YYYYMMDD
#define MINOR_VERSION "0" // time HHMM without leading 0

// SSID and password of WiFi for setup
Expand Down
2 changes: 2 additions & 0 deletions platformio/stima_v3/stimawifi/src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
#include "critical.hpp"
#include "semaphore.hpp"
#include "SD.h"
#include <SdFat.h>
//#include <ArduinoLog.h>
#include <StreamUtils.h>
#include <DS1307RTC.h>
#include <esp_task_wdt.h>
72 changes: 60 additions & 12 deletions platformio/stima_v3/stimawifi/src/stimawifi.ino
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@ lo stato di funzionamento. Il thread loop di arduino effettua una
sintesi degli stati di tutti i thread e li visualizza tramite i
colori del LED e tramite il display opzionale.
Per archiviare i dati è necessario avere un corretto timestamp.
Data e ora possono essere impostati tramite:
* NTP
* GPS
* UDP
Se presente un RTC locale (DS1307) data e ora sono impostate sull'RTC
automaticamente con uno dei metodi precedenti e poi se tutti i metodi
precedenti non sono più disponibili riletti dall'RTC.
Threads:
thread loop arduino
Expand Down Expand Up @@ -942,35 +952,74 @@ void setup() {
#include "soc/rtc_cntl_reg.h"
WRITE_PERI_REG(RTC_CNTL_BROWN_OUT_REG, 0); //disable Brownout detector
*/

// Initialize GPIO, library and sensors
pinMode(RESET_PIN, INPUT_PULLUP);

pixels.begin(); //INITIALIZE NeoPixel strip object (REQUIRED)
pixels.clear(); // Turn OFF all pixels ASAP
pixels.setBrightness(125); // Set BRIGHTNESS (max = 255)

/*
pinMode(PMS_RESET, OUTPUT);
//reset pin for sensor
digitalWrite(PMS_RESET,LOW); // reset low
delay(500);
digitalWrite(PMS_RESET,HIGH);
*/

Wire.begin();
//Wire.begin(SDA_PIN,SCL_PIN);
Wire.setClock(I2C_BUS_CLOCK);

//Serial.setTxTimeoutMs(0); // https://github.com/espressif/arduino-esp32/issues/6983
Serial.begin(115200);
//Serial.setDebugOutput(true);

// manage reset button in hardware (RESET_PIN) or in software (I2C)
bool reset=digitalRead(RESET_PIN) == LOW;
if (button.get() == 0)
{
if (button.BUTTON_A)
{
//String keyString[] = {"None", "Press", "Long Press", "Double Press", "Hold"};
//frtosLog.notice(F("BUTTON A: %s"),keyString[button.BUTTON_A].c_str());
//Serial.print(F("BUTTON A: "));
//Serial.println(keyString[button.BUTTON_A]);
if (button.BUTTON_A == KEY_VALUE_HOLD) reset=true;
}
}

//Serial.setTxTimeoutMs(0); // https://github.com/espressif/arduino-esp32/issues/6983
Serial.begin(115200);
//Serial.setDebugOutput(true);
if (reset) {

Serial.println(F("Try to reformat SD card."));
SPI.begin(C3SCK, C3MISO, C3MOSI, C3SS); //SCK, MISO, MOSI, SS

// SdCardFactory constructs and initializes the appropriate card.
SdCardFactory cardFactory;
ExFatFormatter exFatFormatter;
FatFormatter fatFormatter;
#define SD_CONFIG SdSpiConfig(C3SS, DEDICATED_SPI)
uint8_t sectorBuffer[512];
SdCard* m_card = cardFactory.newCard(SD_CONFIG);
if (!m_card || m_card->errorCode()){
Serial.println(F("Error: card init failed."));
}else{
uint32_t cardSectorCount = m_card->sectorCount();
if (!cardSectorCount){
Serial.println(F("Error: get sector count failed."));
}else{
// Format exFAT if larger than 32GB.
bool rtn = cardSectorCount > 67108864
? exFatFormatter.format(m_card, sectorBuffer, &Serial)
: fatFormatter.format(m_card, sectorBuffer, &Serial);

if (rtn){
Serial.println(F("OK SD card formatted."));
}
}
}
}


// if loggin on SDcard is enabled initialize SDcard
// initialize logging
Expand All @@ -994,8 +1043,10 @@ void setup() {
if (logFile) {
//logFile.seekEnd(0);
frtosLog.begin(LOG_LEVEL, &loggingStream,loggingmutex);
} else {
//Log.begin(LOG_LEVEL_VERBOSE, &loggingStream);
} else {
frtosLog.begin(LOG_LEVEL, &Serial,loggingmutex);
//Log.begin(LOG_LEVEL_VERBOSE, &Serial);
frtosLog.error(F("logging begin with sdcard\n"));
}
}
Expand All @@ -1008,6 +1059,7 @@ void setup() {

// set runtime log level to the same of compile time
frtosLog.begin(LOG_LEVEL, &Serial,loggingmutex);
//Log.begin(LOG_LEVEL_VERBOSE, &Serial);
#endif

frtosLog.setPrefix(logPrefix); // Uncomment to get timestamps as prefix
Expand All @@ -1017,10 +1069,6 @@ void setup() {

httpClient.setTimeout(5000); // esp32 issue https://github.com/espressif/arduino-esp32/issues/3732

Wire.begin();
//Wire.begin(SDA_PIN,SCL_PIN);
Wire.setClock(I2C_BUS_CLOCK);

// check return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Expand Down Expand Up @@ -1063,7 +1111,7 @@ void setup() {
u8g2.setCursor(0, 2*CH);
u8g2.print(F("Reset wifi"));
u8g2.setCursor(0, 3*CH);
u8g2.print(F("configuration"));
u8g2.print(F("Reset conf"));
u8g2.sendBuffer();
delay(3000);
}
Expand Down Expand Up @@ -1373,7 +1421,7 @@ void setup() {
}else{
reboottime=3600*24*7; // we reset everythings one time a week
}
frtosLog.notice(F("reboot every: %d"),reboottime);
frtosLog.notice(F("reboot every: %l"),reboottime);
Alarm.timerRepeat(reboottime,reboot); // timer for reboot

// upgrade firmware
Expand Down

0 comments on commit 27cdecf

Please sign in to comment.