AutoConnectWithFSParameters示例中的简单修改 说明

问题描述

说明

在一个很好的示例AutoConnectWithFSParameters中,它尝试通过在Web上提供这些数据的方式来保存ESP8266的WI-FI网络的SSID,密码,localIP,gatewayIP和subnetMask,而ESP则充当热点。 没关系,但是我需要帮助,我需要做的是将这些数据提供给ESP,以通过代码而不是通过链接进行保存, 这是我想做的一个例子:

#include <FS.h>          // this needs to be first,or it all crashes and burns...
#include <WiFiManager.h> // https://github.com/tzapu/WiFiManager
#include <ArduinoJson.h> // https://github.com/bblanchon/ArduinoJson

#ifdef ESP32
  #include <SPIFFS.h>
#endif

void(* resetFunc) (void) = 0; //declare reset function @ address 0

void setup() {
  String SSIDName="test";
  String Password="test";
  String localIPs="192.168.1.10";
  String gatewayIPs="192.168.1.1";
  String subnetMasks="255.255.255.0";
}

void loop() {
  if(true) {
    WiFiManager wifiManager;    
    wifiManager.resetSettings();

    #ifdef ARDUINOJSON_VERSION_MAJOR >= 6
      DynamicJsonDocument json(1024);
    #else
      DynamicJsonBuffer jsonBuffer;
      JsonObject& json = jsonBuffer.createObject();
    #endif

    json["ip"] ="192.168.43.99";
    json["gateway"] = "192.168.43.1";
    json["subnet"] = "255.255.255.0";

    File configFile = SPIFFS.open("/config.json","w");
    
    if (!configFile) {
      Serial.println("failed to open config file for writing");
    }

    #ifdef ARDUINOJSON_VERSION_MAJOR >= 6
      serializeJson(json,Serial);
      serializeJson(json,configFile);
    #else
      json.printTo(Serial);
      json.printTo(configFile);
    #endif

    configFile.close();
    // wifiManager.wifiConnectNew("testSSID","testPassword");  
    // this is a private function that i found but i can't use it as It's Private
    resetFunc();
  }
}

什么,我要手动将新的SSID名称和密码保存到ESP8266文件中,而无需通过ESP访问点输入数据。 如果可以的话,请帮我提供可以用来保存这两个参数的函数名。

编辑 当我使用WiFi.begin时,如以下代码所示:

configFile.close();
WiFi.begin("testSSID","testPass");
Serial.print("Connecting");

while (WiFi.status() != WL_CONNECTED) {
  delay(500);
  Serial.print(".");
}

Serial.println();

Serial.print("Connected,IP address: ");
Serial.println(WiFi.localIP());
resetFunc();

它打印出连接成功,这很好,但是不好的地方是它没有保存这两个参数,因为它没有保存SSID和PASS,但是它保存了所有新的设置,因此进入了AP模式。 IP地址。 我需要的是一种将SSID和密码保存到ESP的方法,就像我们保存IP地址一样,即:使用代码。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...