So far, the only parameters saved from the WiFiManager page were the SSID and password for your network. Let's add other parameters such as the MQTT server, port, user, password and topic and save them to a configuration file located in the SPIFFS:
#include <FS.h> #include <ESP8266WiFi.h> #include <PubSubClient.h> #include <DNSServer.h> #include <ESP8266WebServer.h> #include <WiFiManager.h> #include <ArduinoJson.h>
Define the CLIENT_ID that will be used to connect to the MQTT broker later:
#define CLIENT_ID "ESP_%06X"
Define your default values here; if there are different values in config.json, they are overwritten:
char mqtt_server[40]; char mqtt_port[6] = "1883"; ...