You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
esp-geiger/main/utils.c

71 lines
1.6 KiB

#include <soc/timer_group_struct.h>
#include <soc/timer_group_reg.h>
#include "esp_log.h"
#include "esp_wifi.h"
#include "utils.h"
#include "application.h"
static const char * TAG = "utils.c";
static void recon_internal(void);
/**
* Attempt to reconnect to AP if we have SSID stored
*/
void try_reconn_if_have_wifi_creds(void)
{
recon_internal();
}
static volatile bool recurse = false;
static void recon_internal(void)
{
if (recurse) {
ESP_LOGE(TAG, "Stopping recursion!");
}
recurse = true;
wifi_config_t wificonf;
// try to connect if we have a saved config
ESP_ERROR_CHECK(esp_wifi_get_config(WIFI_IF_STA, &wificonf));
if (wificonf.sta.ssid[0]) {
ESP_LOGI(TAG, "(Re)connecting using saved STA creds");
ESP_ERROR_CHECK(esp_wifi_connect());
} else {
ESP_LOGI(TAG, "No WiFi creds, no (re)conn");
}
recurse = false;
}
esp_err_t nvs_get_bool(nvs_handle handle, const char* key, bool* out_value)
{
uint8_t x = (uint8_t) *out_value;
esp_err_t rv = nvs_get_u8(handle, key, &x);
if (rv == ESP_OK) {
*out_value = (bool)x;
}
return rv;
}
esp_err_t nvs_set_bool(nvs_handle handle, const char* key, bool value)
{
return nvs_set_u8(handle, key, (uint8_t) value);
}
void feed_all_dogs(void)
{
TIMERG0.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG0.wdt_feed=1;
TIMERG0.wdt_wprotect=0;
TIMERG1.wdt_wprotect=TIMG_WDT_WKEY_VALUE;
TIMERG1.wdt_config2=CONFIG_INT_WDT_TIMEOUT_MS*2; //Set timeout before interrupt
TIMERG1.wdt_config3=CONFIG_INT_WDT_TIMEOUT_MS*4; //Set timeout before reset
TIMERG1.wdt_feed=1;
TIMERG1.wdt_wprotect=0;
}