Reputation: 65
When I call WiFi.begin(ssid, pass)
, it saves your credentials. So next time your sketch runs, it will connect automatically.
But if I call WiFi.config(IP, Gate, Subnet)
before that, it connects without using the DHCP server.
But after restart it's using DHCP again.
It seems to me that the WiFi.config
parameters are not stored anywhere for further usage. Am I right? What should I do to store them?
Upvotes: 2
Views: 1309
Reputation: 1644
To store WiFi credentials and IP settings, you would use SPIFFS. I suggest you also to store SSID and pass in a file despite WiFi core stores it.
Here is basic file operation on SPIFFS to store some data on it :
#include "FS.h"
SPIFFS.begin();
File configFile = SPIFFS.open("config.txt", "w+");
if (configFile)
{
configFile.println(IP);
configFile.println(WiFi.SSID());
// and so on ..
}
configFile.close();
Please consider the file r/w operation options declared in the SPIFFS doc.
Here is also a good config file example with JSON.
Upvotes: 1