3

I've recently achieved connecting my board, an ESP8266 to my local WiFi, but I've had to hardcode the credentials to the code, just like in 99% of the tutorials online. My code looks somewhat like this:

#include <Arduino.h>
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#include <ESP8266HTTPClient.h>

#define USE_SERIAL Serial

ESP8266WiFiMulti WiFiMulti;

void setup() {

    USE_SERIAL.begin(115200);

    WiFi.mode(WIFI_STA);
    WiFiMulti.addAP("SSID", "Password");

}

void loop() {
    // Some more code
}

The thing is, I would like to know if there is some way to parametrize the credentials so I don't have to recompile and upload the code to the board everytime my WiFi password changes.

One of my ideas was to connect all the boards to a local router without actual connection to the internet and have a server in that same LAN manage the sensitive information, not the boards. That would allow me to manage credentials properly. Does this even make sense?

2
  • Have a read about SmartConfig here. I stumbled across this recently after getting some ESP32s to play with, and it's available for the ESP8266 too. However, I'm not implementing it myself and haven't read enough about it to answer formally. Like you, though, I am creating a WiFi network that isn't connected directly to the Internet. This allows you to create 'bridge' in future, perhaps with Ethernet or WiFi dev boards, to be a smart link to the outside world. Jul 17, 2018 at 21:16
  • save them to a text file with SPIFFS, then open an API to update the config file. should be a just a few lines of code in total.
    – dandavis
    Jul 17, 2018 at 21:29

1 Answer 1

1

The common way to do this is to put the ESP8266 into AP (Access Point) mode and then serve a web page with the configuration interface.

To make it even easier, you can create a captive portal so that the user doesn't need to open a specific IP address in their browser. The captive portal will cause the configuration page to be loaded no matter what address they open.

A popular Arduino library that makes this all very easy is WiFiManager:

https://github.com/tzapu/WiFiManager

1
  • It looks pretty solid. Does it consume much resources from the chip? Jul 18, 2018 at 12:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.