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.
AutoConnect/src/AutoConnectCredential.h

61 lines
1.8 KiB

7 years ago
/**
* Declaration of AutoConnectCredential class.
* @file AutoConnectCredential.h
* @author hieromon@gmail.com
6 years ago
* @version 0.9.6
* @date 2018-09-27
7 years ago
* @copyright MIT license.
*/
#ifndef _AUTOCONNECTCREDENTIAL_H_
#define _AUTOCONNECTCREDENTIAL_H_
7 years ago
#include <Arduino.h>
6 years ago
#if defined(ARDUINO_ARCH_ESP8266)
7 years ago
extern "C" {
#include <user_interface.h>
}
6 years ago
#elif defined(ARDUINO_ARCH_ESP32)
#include <esp_wifi.h>
struct station_config {
uint8_t ssid[32];
uint8_t password[64];
uint8_t bssid_set;
uint8_t bssid[6];
wifi_fast_scan_threshold_t threshold;
};
#endif
7 years ago
/** Credential storage area offset specifier in EEPROM.
* By defining AC_IDENTIFIER_OFFSET macro in the user sketch, the credential
* storage area can be shifted in EEPROM.
*/
#ifndef AC_IDENTIFIER_OFFSET
#define AC_IDENTIFIER_OFFSET 0
#endif
/** AutoConnectCredential class. */
class AutoConnectCredential {
public:
AutoConnectCredential();
6 years ago
explicit AutoConnectCredential(uint16_t offset);
7 years ago
~AutoConnectCredential();
uint8_t entries() { return _entries; }
bool del(const char* ssid);
int8_t load(const char* ssid, struct station_config* config);
bool load(int8_t entry, struct station_config* config);
bool save(const struct station_config* config);
private:
void _allocateEntry(); /**< Initialize storage for credentials. */
7 years ago
void _retrieveEntry(char* ssid, char* password, uint8_t* bssid); /**< Read an available entry. */
7 years ago
uint8_t _entries; /**< Count of the available entry */
uint16_t _containSize; /**< Container size */
int _dp; /**< The current address in EEPROM */
int _ep; /**< The current entry address in EEPROM */
uint16_t _offset; /**< The offset for the saved area of credentials in EEPROM. */
7 years ago
};
#endif // _AUTOCONNECTCREDENTIAL_H_