Skip to content
Snippets Groups Projects
Commit eeebeaf7 authored by thiebolt's avatar thiebolt
Browse files

update

parent a9351cee
No related branches found
Tags 221225
No related merge requests found
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Example OpenOCD configuration file for ESP32-WROVER-KIT board.
#
# For example, OpenOCD can be started for ESP32 debugging on
#
# openocd -f board/esp32-wrover-kit-3.3v.cfg
#
# Source the JTAG interface configuration file
source [find interface/ftdi/esp32_devkitj_v1.cfg]
set ESP32_FLASH_VOLTAGE 3.3
# Source the ESP32 configuration file
source [find target/esp32.cfg]
{
"name":"Arduino on ESP32",
"toolchainPrefix":"xtensa-esp32-elf",
"svdFile":"esp32.svd",
"request":"attach",
"postAttachCommands":[
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"overrideRestartCommands":[
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
]
}
\ No newline at end of file
This diff is collapsed.
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
*/ */
#define BOARD_NAME "neOSensor" #define BOARD_NAME "neOSensor"
#define BOARD_REVISION 1.2 #define BOARD_REVISION 1.2
#define BOARD_FWREV 220815 // Firmware revision <year><month><day> in 2 digits each #define BOARD_FWREV 221225 // Firmware revision <year><month><day> in 2 digits each
/* ############################################################################# /* #############################################################################
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* User's high-level parameters management class. * User's high-level parameters management class.
* Most of those parameters come from WiFiManager parameters * Most of those parameters come from WiFiManager parameters
* *
* F.Thiebolt may.23 NVS @ ESP32 to store WiFi credentials in namespace
* Thiebolt F. Jun.18 initial release * Thiebolt F. Jun.18 initial release
* *
*/ */
...@@ -29,6 +30,13 @@ ...@@ -29,6 +30,13 @@
#include <WiFi.h> #include <WiFi.h>
#endif /* ESP8266 */ #endif /* ESP8266 */
/* NVS namespace @ EPS32 */
#ifdef ESP32
#include "Preferences.h" // NVS storage (instead of the DEPRECATED eeprom)
#elif defined (ESP8266)
#warning "[esp8266] no NVS namespace available ... grab WiFi ssid/psk from last connection"
#endif
#include "neocampus.h" #include "neocampus.h"
#include "neocampus_debug.h" #include "neocampus_debug.h"
...@@ -53,6 +61,11 @@ extern bool _need2reboot; ...@@ -53,6 +61,11 @@ extern bool _need2reboot;
#define CONFIG_JSON_SIZE (JSON_OBJECT_SIZE(20)) #define CONFIG_JSON_SIZE (JSON_OBJECT_SIZE(20))
// NVS namespace for WiFi credentials
#define WIFI_NVS_NAMESPACE "wifiCredentials" // 15 chars max.
#define WIFI_NVS_SSID_KEY "ssid"
#define WIFI_NVS_PASS_KEY "pass"
// constructor // constructor
wifiParametersMgt::wifiParametersMgt( void ) { wifiParametersMgt::wifiParametersMgt( void ) {
...@@ -317,6 +330,8 @@ bool wifiParametersMgt::_setopt_eraseALL( bool value ) { ...@@ -317,6 +330,8 @@ bool wifiParametersMgt::_setopt_eraseALL( bool value ) {
/* /*
* apply DEFAULTS values * apply DEFAULTS values
* Note: options ought to get false as defaults * Note: options ought to get false as defaults
* [may.23] trying to read WiFi credentials from ESP32 NVS
* specific namesace ... or from WiFi global vars @ ESP8266
*/ */
void wifiParametersMgt::_applyDefaults( void ) { void wifiParametersMgt::_applyDefaults( void ) {
...@@ -342,6 +357,38 @@ void wifiParametersMgt::_applyDefaults( void ) { ...@@ -342,6 +357,38 @@ void wifiParametersMgt::_applyDefaults( void ) {
// Whole destruction option // Whole destruction option
_opt_eraseALL = false; _opt_eraseALL = false;
/*
* [may.23] now trying to access wifi credentials from NVS namespace
*/
#ifdef ESP32
Preferences nvs_wifi;
if( nvs_wifi.begin(WIFI_NVS_NAMESPACE,true) ) { // readonly mode
log_debug(F("\n[wifiParams] opened NVS WiFi credentials namespace ..."));log_flush();
if( nvs_wifi.isKey(WIFI_NVS_SSID_KEY) ) {
nvs_wifi.getBytes(WIFI_NVS_SSID_KEY, _ssid, sizeof(_ssid));
log_debug(F("\n\t[NVS] SSID :"));log_debug(_ssid);log_flush();
}
if( nvs_wifi.isKey(WIFI_NVS_PASS_KEY) ) {
nvs_wifi.getBytes(WIFI_NVS_PASS_KEY, _pass, sizeof(_pass));
log_debug(F("\n\t[NVS] PASS :"));log_debug(_pass);log_flush();
}
// close NVS namespace
nvs_wifi.end();
}
#elif defined (ESP8266)
#warning "[ESP8266] retrieving WiFi credentials from WiFi library is experimental"
if( WiFi.SSID().length() ) {
strncpy(_ssid,WiFi.SSID().c_str(),sizeof(_ssid));
_ssid[sizeof(_ssid)-1]='\0';
log_debug(F("\n\t[NVS-like] SSID :"));log_debug(_ssid);log_flush();
}
if( WiFi.psk().length() ) {
strncpy(_pass,WiFi.psk().c_str(),sizeof(_pass));
_pass[sizeof(_pass)-1]='\0';
log_debug(F("\n\t[NVS-like] PASS :"));log_debug(_pass);log_flush();
}
#endif
/* /*
* finally structure is initialized * finally structure is initialized
*/ */
...@@ -359,6 +406,25 @@ bool wifiParametersMgt::_saveConfig( JsonObject root ) { ...@@ -359,6 +406,25 @@ bool wifiParametersMgt::_saveConfig( JsonObject root ) {
if( strlen(_ssid) ) { if( strlen(_ssid) ) {
root["ssid"] = _ssid; root["ssid"] = _ssid;
root["pass"] = _pass; root["pass"] = _pass;
#ifdef ESP32
// save WiFi credentials to NVS
Preferences nvs_wifi;
if( nvs_wifi.begin(WIFI_NVS_NAMESPACE,false) ) { // R/W mode
log_debug(F("\n[wifiParams] save WiFi credentials to NVS namespace '"));log_debug(WIFI_NVS_NAMESPACE);log_debug(F("' ... "));log_flush();
if( nvs_wifi.putBytes(WIFI_NVS_SSID_KEY,_ssid,strlen(_ssid)+1) != strlen(_ssid)+1 ) {
log_error(F("\n[wifiParams] ERROR while saving SSID to NVS ?!?!"));log_flush();
}
if( nvs_wifi.putBytes(WIFI_NVS_PASS_KEY,_pass,strlen(_pass)+1) != strlen(_pass)+1 ) {
log_error(F("\n[[wifiParams] ERROR while saving PASS to NVS ?!?!"));log_flush();
}
// close NVS namespace
nvs_wifi.end();
}
else {
log_error(F("\n[wifiParams] unable to create WiFi credentials namespace in NVS ?!?!"));log_flush();
}
#endif /* ESP32 */
} }
else { else {
log_debug(F("\n[wifiParams] no WIFI credentials to save ..."));log_flush(); log_debug(F("\n[wifiParams] no WIFI credentials to save ..."));log_flush();
...@@ -487,8 +553,32 @@ for (JsonObject::iterator it=root.begin(); it!=root.end(); ++it) { ...@@ -487,8 +553,32 @@ for (JsonObject::iterator it=root.begin(); it!=root.end(); ++it) {
/* /*
* check if wifi connexion parameters have been read ... * check if wifi connexion parameters have been read ...
* ... otherwise we'll extract them from struct station * ... otherwise we'll extract them from struct station
* [may.23] special NVS backport ==> force WiFi credentials
* to get saved in the NVS area
*/ */
if( _wifiSet ) return true; if( _wifiSet ) {
#ifdef ESP32
// save WiFi credentials to NVS
Preferences nvs_wifi;
if( nvs_wifi.begin(WIFI_NVS_NAMESPACE,false) ) { // R/W mode
log_debug(F("\n[wifiParams] save WiFi credentials to NVS namespace '"));log_debug(WIFI_NVS_NAMESPACE);log_debug(F("' ... "));log_flush();
if( nvs_wifi.putBytes(WIFI_NVS_SSID_KEY,_ssid,strlen(_ssid)+1) != strlen(_ssid)+1 ) {
log_error(F("\n[wifiParams] ERROR while saving SSID to NVS ?!?!"));log_flush();
}
if( nvs_wifi.putBytes(WIFI_NVS_PASS_KEY,_pass,strlen(_pass)+1) != strlen(_pass)+1 ) {
log_error(F("\n[[wifiParams] ERROR while saving PASS to NVS ?!?!"));log_flush();
}
// close NVS namespace
nvs_wifi.end();
}
else {
log_error(F("\n[wifiParams] unable to create WiFi credentials namespace in NVS ?!?!"));log_flush();
}
#endif /* ESP32 */
return true;
}
// grab WiFi from previous settings (Wifi global var) // grab WiFi from previous settings (Wifi global var)
setWIFIsettings(); setWIFIsettings();
......
# SPDX-License-Identifier: GPL-2.0-or-later
#
# Example OpenOCD configuration file for ESP32-WROVER-KIT board.
#
# For example, OpenOCD can be started for ESP32 debugging on
#
# openocd -f board/esp32-wrover-kit-3.3v.cfg
#
# Source the JTAG interface configuration file
source [find interface/ftdi/esp32_devkitj_v1.cfg]
set ESP32_FLASH_VOLTAGE 3.3
# Source the ESP32 configuration file
source [find target/esp32.cfg]
{
"name":"Arduino on ESP32",
"toolchainPrefix":"xtensa-esp32-elf",
"svdFile":"esp32.svd",
"request":"attach",
"postAttachCommands":[
"set remote hardware-watchpoint-limit 2",
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
],
"overrideRestartCommands":[
"monitor reset halt",
"monitor gdb_sync",
"thb setup",
"c"
]
}
\ No newline at end of file
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment