<dd>Save the specified SSID's credential entry to station_config pointed to by the parameter as **config**. -1 is returned if the SSID is not saved. </dd>
<dd>Save the specified SSID's credential entry to station_config_t pointed to by the parameter as **config**. -1 is returned if the SSID is not saved. </dd>
<dd>Save the specified credential entry to station_config pointed to by the parameter as **config**. -1 is returned if specified number is not saved. </dd>
<dd>Save the specified credential entry to station_config_t pointed to by the parameter as **config**. -1 is returned if specified number is not saved. </dd>
</dl>
#### <iclass="fa fa-caret-right"></i> save
```cpp
bool save(const struct station_config* config)
bool save(const station_config_t* config)
```
Save a credential entry.
<dlclass="apidl">
<dt>**Parameter**</dt>
<dd><spanclass="apidef">config</span><spanclass="apidesc">station_config to be saved.</span></dd>
<dd><spanclass="apidef">config</span><spanclass="apidesc">station_config_t to be saved.</span></dd>
<dd><spanclass="apidef">false</span><spanclass="apidesc">Failed to save.</span></dd>
@ -142,7 +142,7 @@ Delete a credential the specified SSID.
```cpp
void deleteAllCredentials(void) {
AutoConnectCredential credential;
struct station_config config;
station_config_t config;
uint8_t ent = credential.entries();
while (ent--) {
@ -154,24 +154,31 @@ Delete a credential the specified SSID.
## The data structures
### <iclass="fa fa-code"></i> station_config
### <iclass="fa fa-code"></i> station_config_t
A structure is included in the ESP8266 SDK. You can use it in the sketch like as follows:
The saved credential structure is defined as stato_config_t in the AcutoConnectCredential header file.
```cpp
extern "C" {
#include<user_interface.h>
}
typedef struct {
uint8_t ssid[32];
uint8_t password[64];
uint8_t bssid[6];
uint8_t dhcp; /**<0:DHCP,1:StaticIP*/
union _config {
uint32_t addr[5];
struct _sta {
uint32_t ip;
uint32_t gateway;
uint32_t netmask;
uint32_t dns1;
uint32_t dns2;
} sta;
} config;
} station_config_t;
```
```cpp
struct station_config {
uint8 ssid[32];
uint8 password[64];
uint8 bssid_set;
uint8 bssid[6];
};
```
!!! note "The byte size of station_config_t in program memory and stored credentials is different"
There is a gap byte for boundary alignment between the `dhcp` member and the static IP members of the above station_config_t. Its gap byte will be removed with saved credentials on the flash.
### <iclass="fa fa-code"></i> The credential entry
@ -180,13 +187,26 @@ A data structure of the credential saving area in EEPROM as the below. [^4]
[^4]:
There may be 0xff as an invalid data in the credential saving area. The 0xff area would be reused.
| 9 | 2 | Container size, excluding size of AC_CREDT and size of the number of entries(width for uint16_t type). |
| 11 | variable | SSID terminated by 0x00. Max length is 32 bytes. |
| variable | variable | Password plain text terminated by 0x00. Max length is 64 bytes. |
| variable | 6 | BSSID |
| variable | | Contained the next entries. (Continuation SSID+Password+BSSID) |
| variable | 1 | 0x00. End of container. |
| byte offset | Length | Value |
|------------- |--------|-------|
| 0 | 8 | AC_CREDT |
| 8 | 1 | Number of contained entries (uint8_t) |
| 9 | 2 | Container size, excluding size of AC_CREDT and size of the number of entries(width for uint16_t type). |
| 11 | variable | SSID terminated by 0x00. Max length is 32 bytes. |
| variable | variable | Password plain text terminated by 0x00. Max length is 64 bytes. |
| variable | 6 | BSSID |
| variable | 1 | Flag for DHCP or Static IP (0:DHCP, 1:Static IP) |
| <tdcolspan=3>The following IP address entries are stored only for static IPs.
| variable(1) | 4 | Station IP address (uint32_t) |
| variable(5) | 4 | Gateway address (uint32_t) |
| variable(9) | 4 | Netmask (uint32_t) |
| variable(13) | 4 | Primary DNS address (uint32_t) |
| variable(17) | 4 | Secondary IP address (uint32_t) |
| variable | variable | Contained the next entries. (Continuation SSID+Password+BSSID+DHCP flag+Static IPs(if exists)) |
| variable | 1 | 0x00. End of container. |
!!! note "AutoConnectCredential has changed"
It was lost AutoConnectCredential backward compatibility. Credentials saved by AutoConnect v1.0.3 (or earlier) will not work properly with AutoConnect v1.1.0. You need to erase the flash of the ESP module using the esptool before the sketch uploading.
```
esptool -c esp8266 (or esp32) - p [COM_PORT] erase_flash
@ -180,6 +180,13 @@ Because AutoConnect does not send a login success response to the captive portal
If the sketch is correct, a JSON syntax error may have occurred. In this case, activate the [AC_DEBUG](faq.md#3-turn-on-the-debug-log-options) and rerun. If you take the message of JSON syntax error, the [Json Assistant](https://arduinojson.org/v5/assistant/) helps syntax checking. This online tool is provided by the author of ArduinoJson and is most consistent for the AutoConnect.
## <iclass="fa fa-question-circle"></i> Saved credentials are wrong or lost.
A structure of AutoConnect saved credentials have changed in two times throughout enhancement with v1.0.3 and v1.1.0. Especially in v1.1.0 enhancements, there is no backward compatibility of AutoConnectCredential structures to the earlier versions. To save the credentials correctly in v110, you must erase the flash of the ESP module using the esptool completely.
## <iclass="fa fa-question-circle"></i> Submit element in a custom Web page does not react.
Is there the AutoConnectElements element named **SUBMIT** in the custom Web page? (case sensitive ignored) AutoConnect does not rely on the `input type=submit` element for the form submission and uses [HTML form element submit](https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement/submit) function instead. So, the submit function will fail if there is an element named 'submit' in the form. You can not use **SUBMIT** as the element name of AutoConnectElements in a custom Web page that declares the AutoConnectSubmit element.
After connection established, the current status screen will appear. It is already connected to WLAN with WiFi mode as WIFI\_AP\_STA and the IP connection status is displayed there including the SSID. Then at this screen, you have two options for the next step.
style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:3.17499995px;line-height:1.25;font-family:'Times New Roman';-inkscape-font-specification:'Times New Roman, Normal';font-variant-ligatures:normal;font-variant-caps:normal;font-variant-numeric:normal;font-feature-settings:normal;text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:0.26458332"
x="79.585876"
y="-32.471371"
id="text9138-7-3-9-9-90-9"><tspan
sodipodi:role="line"
id="tspan1283"
x="79.585876"
y="-32.471371">Loads saved credentials from the flash</tspan><tspan
sodipodi:role="line"
id="tspan1285"
x="79.585876"
y="-28.502621">that matches the last SSID stored in</tspan><tspan
If you want to configure with static IP, uncheck "**Enable DHCP**". Once the WiFi connection is established, the entered static IP configuration is saved in the credentials and restored to the station configuration via the [Open SSIDs](#open-ssids) menu.
If you want to configure with static IP, uncheck "**Enable DHCP**". Once the WiFi connection is established, the entered static IP[^1] configuration is saved in the credentials and restored to the station configuration via the [Open SSIDs](#open-ssids) menu.
[^1]: AutoConnect will not check the syntax and validity of the entered IP address. If the entered static IPs are incorrect, it cannot connect to the access point.
!!! note "Saved credentials data structure has changed"
A structure of AutoConnect saved credentials have changed in v1.1.0 and was lost backward compatibility. Credentials saved by AutoConnect v1.0.3 (or earlier) will not display properly with AutoConnect v1.1.0. You need to erase the flash of the ESP module using the esptool before the sketch uploading.
```
esptool -c esp8266 (or esp32) - p [COM_PORT] erase_flash
```
## <iclass="fa fa-bars"></i> Disconnect
Disconnect ESP8266/ESP32 from the current connection. It can also reset the ESP8266/ESP32 automatically after disconnection by instructing with using [API](api.md#autoreset) in the sketch.