update confg + ota
This commit is contained in:
@@ -10,5 +10,15 @@
|
|||||||
{
|
{
|
||||||
"TagUID" : "23 0E 2C 19",
|
"TagUID" : "23 0E 2C 19",
|
||||||
"audiofile" : "/ringoffire.mp3"
|
"audiofile" : "/ringoffire.mp3"
|
||||||
}]
|
}],
|
||||||
|
"WiFi": [
|
||||||
|
{
|
||||||
|
"ssid": "poes",
|
||||||
|
"psk": "Rijnstraat214"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"ssid": "wifi2",
|
||||||
|
"psk": "pass2"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
||||||
Submodule FW/leo_muziekdoos_esp32/lib/BatterySense updated: bc76604d68...b03ad5dbb5
@@ -21,4 +21,6 @@ extra_scripts = ./littlefsbuilder.py
|
|||||||
build_flags =
|
build_flags =
|
||||||
-DHARDWARE=2
|
-DHARDWARE=2
|
||||||
-DCORE_DEBUG_LEVEL=4
|
-DCORE_DEBUG_LEVEL=4
|
||||||
-DNDEF_DEBUG=1
|
-DNDEF_DEBUG=1
|
||||||
|
#upload_protocol = espota
|
||||||
|
#upload_port = muziekdoos.local
|
||||||
@@ -4,8 +4,8 @@
|
|||||||
#include "LITTLEFS.h"
|
#include "LITTLEFS.h"
|
||||||
#include "ArduinoJson.h"
|
#include "ArduinoJson.h"
|
||||||
|
|
||||||
const char *tagConfigfile = "/tagconfig.json";
|
const char *tagConfigfile = "/settings.json";
|
||||||
DynamicJsonDocument tagDoc(512);
|
DynamicJsonDocument settingsDoc(512);
|
||||||
|
|
||||||
bool configInitOK = false;
|
bool configInitOK = false;
|
||||||
struct tagConfig
|
struct tagConfig
|
||||||
@@ -16,21 +16,53 @@ struct tagConfig
|
|||||||
|
|
||||||
std::vector<tagConfig> tags;
|
std::vector<tagConfig> tags;
|
||||||
|
|
||||||
|
bool checkTagConfig(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
JsonArray array = settingsDoc["tags"].as<JsonArray>();
|
||||||
|
log_i("JsonArray size = %d", array.size());
|
||||||
|
bool hasError = checkTagConfig();
|
||||||
|
return hasError;
|
||||||
|
}
|
||||||
|
|
||||||
|
String GetWifiPassword(String ssid)
|
||||||
|
{
|
||||||
|
|
||||||
|
log_i("Get wifi password for ssid=%s", ssid);
|
||||||
|
if(ssid == "") return "";
|
||||||
|
JsonArray array = settingsDoc["WiFi"].as<JsonArray>();
|
||||||
|
for (JsonVariant v : array)
|
||||||
|
{
|
||||||
|
String netname((const char*)v["ssid"]);
|
||||||
|
uint16_t result = ssid.compareTo(netname);
|
||||||
|
|
||||||
|
log_v("compare %s(config) with %s(read) = %d",netname.c_str(), ssid.c_str(), result);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
String password((const char*)v["psk"]);
|
||||||
|
log_i("ssid found in config", password.c_str());
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log_e("password for %s not found",ssid.c_str() );
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
void loadConfig(const char *fname)
|
void loadConfig(const char *fname)
|
||||||
{
|
{
|
||||||
log_i("config: load");
|
log_i("config: load");
|
||||||
File file = LITTLEFS.open(fname);
|
File file = LITTLEFS.open(fname);
|
||||||
|
|
||||||
DeserializationError error = deserializeJson(tagDoc, file);
|
DeserializationError error = deserializeJson(settingsDoc, file);
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
log_e("Failed to deserialize err=%s", error.c_str());
|
log_e("Failed to deserialize err=%s", error.c_str());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
serializeJsonPretty(tagDoc, Serial);
|
serializeJsonPretty(settingsDoc, Serial);
|
||||||
|
|
||||||
JsonArray array = tagDoc["tags"].as<JsonArray>();
|
JsonArray array = settingsDoc["tags"].as<JsonArray>();
|
||||||
log_i("JsonArray size = %d", array.size());
|
log_i("JsonArray size = %d", array.size());
|
||||||
bool hasError = false;
|
bool hasError = false;
|
||||||
for (JsonVariant v : array)
|
for (JsonVariant v : array)
|
||||||
@@ -65,7 +97,7 @@ void handleConfig(void)
|
|||||||
|
|
||||||
String getConfigSong(String uid)
|
String getConfigSong(String uid)
|
||||||
{
|
{
|
||||||
JsonArray array = tagDoc["tags"].as<JsonArray>();
|
JsonArray array = settingsDoc["tags"].as<JsonArray>();
|
||||||
for (JsonVariant v : array)
|
for (JsonVariant v : array)
|
||||||
{
|
{
|
||||||
String taguid((const char*)v["TagUID"]);
|
String taguid((const char*)v["TagUID"]);
|
||||||
|
|||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
String getConfigSong(String uid);
|
String getConfigSong(String uid);
|
||||||
|
String GetWifiPassword(String ssid);
|
||||||
|
|
||||||
|
|
||||||
void initConfig(void);
|
void initConfig(void);
|
||||||
void handleConfig(void);
|
void handleConfig(void);
|
||||||
@@ -28,7 +28,7 @@ void SetLedColor(CRGB color, bool blink)
|
|||||||
void initLed(void)
|
void initLed(void)
|
||||||
{
|
{
|
||||||
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
|
FastLED.addLeds<SK6812, LED_PIN, GRB>(leds, NUM_LEDS); // GRB ordering is typical
|
||||||
FastLED.setBrightness(80);
|
FastLED.setBrightness(40);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleLed(void)
|
void handleLed(void)
|
||||||
|
|||||||
@@ -2,37 +2,84 @@
|
|||||||
|
|
||||||
OtaProcess_class ota(100);
|
OtaProcess_class ota(100);
|
||||||
|
|
||||||
|
|
||||||
bool OtaProcess_class::initialize(void)
|
bool OtaProcess_class::initialize(void)
|
||||||
{
|
{
|
||||||
if (m_newState)
|
if (m_newState)
|
||||||
{
|
{
|
||||||
log_i("Otastate = initialize");
|
log_i("Otastate = initialize");
|
||||||
m_newState = false;
|
m_newState = false;
|
||||||
m_otaState = otaInit;
|
m_otaState = otaScan;
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (m_otaState)
|
switch (m_otaState)
|
||||||
{
|
{
|
||||||
case otaInit:
|
|
||||||
log_i("Otastate = initialize(init)");
|
|
||||||
WiFi.mode(WIFI_STA);
|
|
||||||
WiFi.begin(SECRET_SSID, SECRET_PASS);
|
|
||||||
m_otaState = otaConnect;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case otaConnect:
|
case otaScan:
|
||||||
log_i("Otastate = initialize(connect)");
|
{
|
||||||
|
log_i("Otastate = initialize(scan)");
|
||||||
|
|
||||||
if (WiFi.waitForConnectResult() != WL_CONNECTED)
|
int n = WiFi.scanNetworks();
|
||||||
|
if (n == 0)
|
||||||
{
|
{
|
||||||
log_e("Connection Failed! Retry...");
|
log_e("no networks found");
|
||||||
|
m_otaState = otaError;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
m_otaState = otaSetup;
|
log_i(" %d wifi networks found", n);
|
||||||
|
String tmppsk = "";
|
||||||
|
for (int i = 0; i < n; ++i)
|
||||||
|
{
|
||||||
|
tmppsk = GetWifiPassword(WiFi.SSID(i));
|
||||||
|
if(tmppsk != "" && m_ssid == "")
|
||||||
|
{
|
||||||
|
m_ssid = WiFi.SSID(i);
|
||||||
|
m_psk = tmppsk;
|
||||||
|
}
|
||||||
|
log_i("[%d] %s %s (%d) [%s]", i, WiFi.SSID(i), (WiFi.encryptionType(i) == WIFI_AUTH_OPEN) ? " " : "*", WiFi.RSSI(i), (tmppsk != "")? "OK": "Not congigured");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
if(m_ssid != "")
|
||||||
|
{
|
||||||
|
m_otaState = otaInit;
|
||||||
|
log_i("Otastate = initialize(scan): done");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_otaState = otaError;
|
||||||
|
log_e("Otastate = initialize(scan): NOT CONFIGURED");
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case otaInit:
|
||||||
|
{
|
||||||
|
log_i("Otastate = initialize(init)");
|
||||||
|
WiFi.begin(m_ssid.c_str(), m_psk.c_str());
|
||||||
|
m_otaState = otaConnect;
|
||||||
|
log_i("Otastate = initialize(init):done");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case otaConnect:
|
||||||
|
{
|
||||||
|
log_i("Otastate = initialize(connect)");
|
||||||
|
uint32_t timeTemp = millis();
|
||||||
|
if (m_lastconnectTime - timeTemp > WIFICONNECTINTERVAL)
|
||||||
|
{
|
||||||
|
if (WiFi.status() != WL_CONNECTED)
|
||||||
|
{
|
||||||
|
log_e("Connection Failed! Retry...");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_otaState = otaSetup;
|
||||||
|
}
|
||||||
|
m_lastconnectTime = timeTemp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case otaSetup:
|
case otaSetup:
|
||||||
{
|
{
|
||||||
@@ -111,7 +158,6 @@ void OtaProcess_class::idle(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OtaProcess_class::active(void)
|
void OtaProcess_class::active(void)
|
||||||
{
|
{
|
||||||
if (m_newState)
|
if (m_newState)
|
||||||
@@ -122,7 +168,6 @@ void OtaProcess_class::active(void)
|
|||||||
idle();
|
idle();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void OtaProcess_class::disabled(void)
|
void OtaProcess_class::disabled(void)
|
||||||
{
|
{
|
||||||
if (m_newState)
|
if (m_newState)
|
||||||
@@ -168,7 +213,7 @@ void otaDisable(void)
|
|||||||
|
|
||||||
void initOta(void)
|
void initOta(void)
|
||||||
{
|
{
|
||||||
/* noting */
|
/* noting */
|
||||||
}
|
}
|
||||||
|
|
||||||
OTASTATES getOtaState(void)
|
OTASTATES getOtaState(void)
|
||||||
|
|||||||
@@ -3,11 +3,15 @@
|
|||||||
#include "secrets.h"
|
#include "secrets.h"
|
||||||
#include "defines.h"
|
#include "defines.h"
|
||||||
#include "process.h"
|
#include "process.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
#include "LITTLEFS.h"
|
#include "LITTLEFS.h"
|
||||||
|
|
||||||
|
#define WIFICONNECTINTERVAL 1000
|
||||||
|
|
||||||
typedef enum{
|
typedef enum{
|
||||||
otaInit,
|
otaInit,
|
||||||
|
otaScan,
|
||||||
otaConnect,
|
otaConnect,
|
||||||
otaSetup,
|
otaSetup,
|
||||||
otaInitDone,
|
otaInitDone,
|
||||||
@@ -18,8 +22,9 @@
|
|||||||
}OTASTATES;
|
}OTASTATES;
|
||||||
class OtaProcess_class : public processClass
|
class OtaProcess_class : public processClass
|
||||||
{
|
{
|
||||||
|
uint32_t m_lastconnectTime;
|
||||||
|
String m_psk = "";
|
||||||
|
String m_ssid = "";
|
||||||
|
|
||||||
void active(void);
|
void active(void);
|
||||||
bool initialize(void);
|
bool initialize(void);
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ uint32_t PowerOtaLongPressTime = 0;
|
|||||||
uint64_t measure_timer = 0;
|
uint64_t measure_timer = 0;
|
||||||
|
|
||||||
POWERSTATES powerstate = off;
|
POWERSTATES powerstate = off;
|
||||||
|
POWERSTATES lastState = off;
|
||||||
|
|
||||||
Button buttonPower(PWR_BTN, 250UL, 1U, 0);
|
Button buttonPower(PWR_BTN, 250UL, 1U, 0);
|
||||||
extern OtaProcess_class ota;
|
extern OtaProcess_class ota;
|
||||||
@@ -116,14 +117,14 @@ void handlePowerState(void)
|
|||||||
break;
|
break;
|
||||||
case poweringOn2:
|
case poweringOn2:
|
||||||
{
|
{
|
||||||
if (!buttonread)
|
if (buttonPower.releasedFor(200))
|
||||||
{
|
{
|
||||||
powerstate = powerinit;
|
powerstate = powerinit;
|
||||||
powerOn();
|
powerOn();
|
||||||
// if (measureBattery())
|
// if (measureBattery())
|
||||||
// {
|
// {
|
||||||
// log_w("poweringOn: Lowbat");
|
// log_w("poweringOn: Lowbat");
|
||||||
// powerstate = lowBatt;
|
// //powerstate = lowBatt;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -148,13 +149,14 @@ void handlePowerState(void)
|
|||||||
{
|
{
|
||||||
if (buttonPower.pressedFor(100))
|
if (buttonPower.pressedFor(100))
|
||||||
{
|
{
|
||||||
|
lastState = on;
|
||||||
powerstate = poweringOff;
|
powerstate = poweringOff;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// if (handleBattery())
|
// if (handleBattery())
|
||||||
// {
|
// {
|
||||||
// log_w("on: Lowbat");
|
// log_w("on: Lowbat");
|
||||||
// powerstate = lowBatt;
|
// //powerstate = lowBatt;
|
||||||
// break;
|
// break;
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
@@ -181,13 +183,13 @@ void handlePowerState(void)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
powerstate = on;
|
powerstate = lastState;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case poweringOff2:
|
case poweringOff2:
|
||||||
{
|
{
|
||||||
if (!buttonread)
|
if (!buttonPower.releasedFor(200))
|
||||||
{
|
{
|
||||||
powerstate = off;
|
powerstate = off;
|
||||||
SetLedColor(CRGB::Red, true);
|
SetLedColor(CRGB::Red, true);
|
||||||
@@ -211,19 +213,32 @@ void handlePowerState(void)
|
|||||||
log_w("lowbatt");
|
log_w("lowbatt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case overTheAir:
|
case overTheAir:
|
||||||
{
|
{
|
||||||
if (!buttonread)
|
if (buttonPower.releasedFor(200))
|
||||||
{
|
{
|
||||||
powerstate = overTheAir2;
|
powerstate = overTheAir2;
|
||||||
otaEnable();
|
otaEnable();
|
||||||
SetLedColor(CRGB::Blue);
|
SetLedColor(CRGB::Blue, true);
|
||||||
powerOn();
|
powerOn();
|
||||||
}
|
}
|
||||||
log_i("ota state active, release powerbutton");
|
else
|
||||||
|
{
|
||||||
|
SetLedColor(CRGB::Blue, false);
|
||||||
|
log_i("ota state active, release powerbutton");
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
case overTheAir2:
|
case overTheAir2:
|
||||||
{
|
{
|
||||||
|
if(buttonPower.pressedFor(200))
|
||||||
|
{
|
||||||
|
log_i("ota poweroff");
|
||||||
|
lastState = overTheAir2;
|
||||||
|
powerstate = poweringOff;
|
||||||
|
}
|
||||||
if (getOtaState() == OTASTATES::otaBusy)
|
if (getOtaState() == OTASTATES::otaBusy)
|
||||||
{
|
{
|
||||||
SetLedColor(CRGB::Blue, true);
|
SetLedColor(CRGB::Blue, true);
|
||||||
@@ -234,9 +249,14 @@ void handlePowerState(void)
|
|||||||
{
|
{
|
||||||
log_i("ota state active, ota Done ==> On");
|
log_i("ota state active, ota Done ==> On");
|
||||||
|
|
||||||
powerstate = POWERSTATES::on;
|
powerstate = POWERSTATES::off;
|
||||||
SetLedColor(CRGB::Green, true);
|
SetLedColor(CRGB::Green, true);
|
||||||
}
|
}
|
||||||
|
if (getOtaState() == OTASTATES::otaError)
|
||||||
|
{
|
||||||
|
powerstate = POWERSTATES::off;
|
||||||
|
SetLedColor(CRGB::Red, true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
#define TIMEOUT_POWER (5 * 1000 * 60) //5minutes timeout
|
#define TIMEOUT_POWER (5 * 1000 * 60) //5minutes timeout
|
||||||
#define POWERBUTTONDELAY 1000
|
#define POWERBUTTONDELAY 1000
|
||||||
#define BATTERYMEASUREDELAY 60000
|
#define BATTERYMEASUREDELAY 60000
|
||||||
#define POWERBUTTONOTADELAY 10000
|
#define POWERBUTTONOTADELAY 7000
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -40,16 +40,17 @@ void handleSensor(void)
|
|||||||
{
|
{
|
||||||
uint32_t timeNow = millis();
|
uint32_t timeNow = millis();
|
||||||
|
|
||||||
if (lastVbatt - timeNow > VBATTINTERVALL - VBATTMEASPRECHARGE)
|
if (timeNow - lastVbatt > (VBATTINTERVALL - VBATTMEASPRECHARGE))
|
||||||
{
|
{
|
||||||
digitalWrite(MEAS_EN, HIGH);
|
digitalWrite(MEAS_EN, LOW);
|
||||||
log_v("precharge vbatt measurement");
|
log_v("precharge vbatt measurement");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastVbatt - timeNow > VBATTINTERVALL)
|
if (timeNow - lastVbatt > VBATTINTERVALL)
|
||||||
{
|
{
|
||||||
BatterySensor = ADS.readADC(MEAS_ADC);
|
BatterySensor = ADS.readADC(MEAS_ADC);
|
||||||
digitalWrite(MEAS_EN, LOW);
|
digitalWrite(MEAS_EN, HIGH);
|
||||||
|
log_i("read vbatt %4.2f",ADS.toVoltage(BatterySensor));
|
||||||
lastVbatt = timeNow;
|
lastVbatt = timeNow;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,6 +89,11 @@ void handleHallSensor(void)
|
|||||||
last_hall_Delta = hall_delta;
|
last_hall_Delta = hall_delta;
|
||||||
if(skipfirstSample)
|
if(skipfirstSample)
|
||||||
{
|
{
|
||||||
|
log_v("First sample skipped");
|
||||||
|
if(hall_idle_count)
|
||||||
|
{
|
||||||
|
hall_idle_count --;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (hall_delta > HALLIDLETHRESHOLD)
|
if (hall_delta > HALLIDLETHRESHOLD)
|
||||||
|
|||||||
@@ -4,13 +4,13 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
|
|
||||||
#define ADSINTERVAL 100
|
#define ADSINTERVAL 100
|
||||||
#define VBATTINTERVALL 1000
|
#define VBATTINTERVALL 6000
|
||||||
#define VBATTMEASPRECHARGE 250
|
#define VBATTMEASPRECHARGE 240
|
||||||
|
|
||||||
#define HALLINTERVAL 100
|
#define HALLINTERVAL 100
|
||||||
#define HALLIDLETHRESHOLD 5
|
#define HALLIDLETHRESHOLD 20
|
||||||
#define HALLIDLESAMPLES 4
|
#define HALLIDLESAMPLES 8
|
||||||
#define HALLPLAYSAMPLES 8
|
#define HALLPLAYSAMPLES 16
|
||||||
|
|
||||||
|
|
||||||
void initSensor(void);
|
void initSensor(void);
|
||||||
|
|||||||
Reference in New Issue
Block a user