-
Notifications
You must be signed in to change notification settings - Fork 13.3k
parametric WiFi.softAP function (staging ver 2.1.0-rc2 ) still have problem #1589
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
can you provide a example for your problem? |
this is the captive portal example of the library , which is only assign the new AP ssid when strictly put the string in WiFi.softAP("with any string ","with any string "); // working #include <ESP8266WiFi.h>
#include <DNSServer.h>
#include <ESP8266WebServer.h>
const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 4, 1);
DNSServer dnsServer;
ESP8266WebServer webServer(80);
const char* AP_SSID="My Smart IOT";
const char* AP_Password="12345678";
String responseHTML = ""
"<!DOCTYPE html><html><head><title>CaptivePortal</title></head><body>"
"<h1>Hello World!</h1><p>This is a captive portal example. All requests will "
"be redirected here.</p></body></html>";
void setup() {
Serial.begin(115200);
Serial.println("\n\n\n\t\t Booting Sketech...");
WiFi.disconnect(true); delay(1000);
//Serial.setDebugOutput(true);
WiFi.mode(WIFI_AP);
// local_ip, gateway, subnet
WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
WiFi.softAP(AP_SSID,AP_Password); // not working
WiFi.softAP("with any string ","with any string "); // working
// if DNSServer is started with "*" for domain name, it will reply with provided IP to all DNS request
// (port, domain Name, resolved IP)
dnsServer.start(DNS_PORT, "*", apIP);
// replay to all requests with same HTMLb ([](){});
webServer.onNotFound([]() {
webServer.send(200, "text/html", responseHTML);
});
webServer.begin();
}
void loop() {
dnsServer.processNextRequest();
webServer.handleClient();
} |
Well, it works fine for me, so that's probably an edge case. |
hi @marvinroger , you mean this parametric code |
@igrr @Links2004 #include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <FS.h>
#include <ArduinoOTA.h>
const char* ap_default_ssid = "My AP"; ///< Default SSID.
const char* ap_default_psk = "12345678"; ///< Default PSK.
String station_ssid = "keyno";
String station_psk = "----";
bool loadConfig(String *ssid, String *pass)
{
*ssid = station_ssid;
*pass = station_psk ;
return true;
}
void setup()
{
Serial.begin(115200);
delay(100);
Serial.println("\r\n");
Serial.print("Chip ID: 0x");
Serial.println(ESP.getChipId(), HEX);
loadConfig(&station_ssid, &station_psk);
WiFi.mode(WIFI_STA);
delay(10);
WiFi.begin(station_ssid.c_str(), station_psk.c_str());
Serial.print("WiFi.SSID()=");Serial.println(WiFi.SSID());
unsigned long startTime = millis();
while (WiFi.status() != WL_CONNECTED && millis() - startTime < 10000) {
Serial.write('.');
Serial.print(WiFi.status());
delay(500);
}
Serial.println();
if(WiFi.status() == WL_CONNECTED)
{
// ... print IP Address
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
}
void loop()
{
// put your main code here, to run repeatedly:
} |
My plan is to update my wifi setting through request from client and store it in EEPROM , I created utill.h header file along with main.ino file as per following , but I cant set WiFi.begin(a,b) & WiFi.softAP(a, b); parametric #ifndef utill_h
#define utill_h
String Restor(byte);
//void Up_AP(void);
//void Up_Station(void);
void Add_count_reset(void);
//////////////////////////global parameters////////////////////
static char WIFImode=0;
String AP_SSID="";
String AP_Password="";
static String SSID="";
static String Password="";
static String MyHost="";
static char error_code='N';
static byte reset_num=0;
IPAddress apIP(192, 168, 4, 1);
IPAddress netMsk(255, 255, 255, 0);
///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
//void Restor_All(void);
void Restor_All(void)
{
WIFImode=(char)EEPROM.read(0); Serial.print(" WIFImode =" );Serial.println(WIFImode);
AP_SSID=Restor(1); Serial.println(" AP_SSID =" + AP_SSID);//Serial.println(AP_SSID);
AP_Password=Restor(21); Serial.print(" AP_Password =");Serial.println(AP_Password);
SSID=Restor(31); Serial.print(" SSID =");Serial.println(SSID);
Password=Restor(41); Serial.print(" Password =");Serial.println(Password);
MyHost=Restor(51); Serial.print(" MyHost =");Serial.println(MyHost);
reset_num=(byte)EEPROM.read(70); Serial.print(" reset_num =");Serial.println(reset_num);
}
//////////////////////////////////////////////////////////////////////////////////////////////
String Restor(byte location)
{
char str[20]={0};
byte i=0;
byte lenght=byte(EEPROM.read(location));
if(lenght >0 && lenght< 21) for( i=0;i<lenght;i++) {
str[i]=(char)EEPROM.read(location + 1 + i); str[i+1]='\0';
// Serial.println(c[i]);
// str[i]=(char)EEPROM.read(location + 1 + i);Serial.println(str[i]);
}
//Serial.print(" str :");Serial.print(str);
return String(str);
// Serial.print("lenght=");Serial.print(lenght); Serial.print(" String=");Serial.println(str);
}
//////////////////////////////////////////////////////////////////////////////////////////////
bool Store(int location, String str)
{
char*p =&str[0];
byte lenght=0;
while(*p){
EEPROM.write(location+1, p[0]);
location++; p++; lenght++;
//Serial.print("lenght=");Serial.print(lenght); Serial.print(" location=");Serial.print(location);Serial.print(" char=");Serial.println(p);
}
EEPROM.write(location-lenght, lenght);
EEPROM.commit();
// Serial.print("lenght stored=");Serial.println(EEPROM.read(location-lenght));
return true;
}
//////////////////////////////////////////////////////////////////////////////////////////////
void Up_AP()
{
Serial.println("configure the node as Access Point");
WiFi.mode(WIFI_AP);
WiFi.softAPConfig(apIP, apIP, netMsk);
delay(100);
Serial.print("Access Point ssid=");Serial.println(AP_SSID);
Serial.print("Access Point pass=");Serial.println(AP_Password);
WiFi.softAP(AP_SSID.c_str(), AP_Password.c_str());
Serial.print("WiFi.SSID()=");Serial.println(WiFi.SSID());
Serial.print("IP address: ");Serial.println(WiFi.softAPIP());
EEPROM.write(70, 0); EEPROM.commit(); // reset the reset number
}
//////////////////////////////////////////////////////////////////////////////////////////////
void Up_Station()
{
Serial.println("Configure the node as Station");
String(ESP.getChipId(), HEX);
WiFi.mode(WIFI_STA);
// WiFi.begin("keyno", "----");
WiFi.begin(SSID.c_str(), Password.c_str());
Serial.print("WiFi.SSID()=");Serial.println(WiFi.SSID());
if(WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.println("WiFi Connect Failed! Rebooting...");
delay(1000);
Add_count_reset();
ESP.restart();
}
EEPROM.write(70, 0); EEPROM.commit(); // reset the reset number
if (!MDNS.begin(MyHost.c_str())) {
Serial.println("Error setting up MDNS responder!");
while(1) delay(1000);}
MDNS.addService("http", "tcp", 80);
Serial.print("Open http://"); Serial.print(WiFi.localIP());
}
//////////////////////////////////////////////////////////////////////////////////////////////
void Add_count_reset(void)
{
reset_num++;
EEPROM.write(70, reset_num); //Serial.print(" new reset_num =");Serial.println(reset_num);
EEPROM.commit();
}
#endif
`
main.ino file
`
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>
#include "EEPROM.h"
#include <FS.h>
#include <ESP8266mDNS.h>
#include "utill.h"
ESP8266WebServer server(80);
const byte DNS_PORT = 53;
DNSServer dnsServer;
void setup(void)
{
Serial.begin(115200);
Serial.println("\n\n\n\t\t Booting Sketech...");
EEPROM.begin(128);
if (!SPIFFS.begin()) { Serial.println("Failed to mount file system"); return; }
EEPROM.write(0, 'A');
Store( 1, "Keyno_IOT+"); AP_SSID=Restor(1);
Store(31, "keyno"); SSID=Restor(31);
Store(41, "09127163464"); Password=Restor(41);
Restor_All();
if(WIFImode=='S'&& SSID.length()>2 && reset_num<5 ) Up_Station();
else Up_AP();
server.onNotFound([]() {
server.send(200, "text/html", "fffffffffffffffffffff");
});
server.begin();
}
void loop(void)
{
server.handleClient();
}
|
Yes, using latest staging version it works for me. Also, you might want to take a look at how I store config to EEPROM: https://github.com/marvinroger/homie-esp8266/tree/90a33f48e4993bd90ece969d3382b511d0ba8b0d In particular, |
hi @marvinroger , are you sure about compatibility with last staging version , because I have had the following error _ D:\arduino-1.6.4-windows\arduino-1.6.4\libraries\homie_ESP8266\src/Homie/Boot/Boot.hpp:4:25: fatal error: ESP8266WiFi.h: No such file or directory |
Yes I am. Have you selected the correct board in the Arduino IDE?
|
which broad should I select ? such as nodemcu 1.0? |
Yes, for example. |
I have a library I use that does just that. It might help you to compare the code with yours |
Guys, the line |
WPA passwords have to be at least 8 characters long, so if you are using "allowme" literally, it won't work. |
@igrr thanks for the tip, works better now with more char as PSK !! |
I've check other issue and run debugging test and find, send the String or const char* parameter to the WiFi.softAP() function still not working , I find in
Arduino/libraries/ESP8266WiFi/src/ESP8266WiFiAP.cpp
Line 124 in 5f80ad5
The text was updated successfully, but these errors were encountered: