-
-
Notifications
You must be signed in to change notification settings - Fork 371
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
Connect to existing WiFi #47
Comments
Thanks for opening your first issue here! 🎉 |
Same question. I bought WIFI Duck to control my KVM switch using local WIFI. Is there a workaround exists or we'll have to rewrite part of the code? |
Would love this feature. I also want to controll my KVM switch. |
I made some changes that work. Instead of creating an AP, it will now connect to an existing AP using the SSID and PWD in the config.h file. It will not be difficult to add some settings that will allow a creation or connection of an AP. I think one solution would be to check if the channel is set to Zero, if it is, connect to the SSID instead of create it. Changes at lines 82 & 181 Script.js change After changing the Script.js you will have to run webconverter.py |
I managed to do it this way (in case your network could not resolve hostnames) Connecting WiFi and save the current IP into a file called WiFi.begin(STA_SSID, STA_PASSWORD);
if (WiFi.waitForConnectResult() != WL_CONNECTED) {
Serial.printf("STA: Failed!\n");
WiFi.disconnect(false);
delay(1000);
WiFi.begin(STA_SSID, STA_PASSWORD);
}
saveConfigToJS(); void saveConfigToJS() {
// Delete existing file, otherwise the configuration is appended to the file
SPIFFS.remove("/config.js");
// Open file for writing
File file = SPIFFS.open("/config.js", FILE_WRITE);
if (!file) {
Serial.println(F("Failed to create file"));
return;
}
file.print("var ip = '" + WiFi.localIP().toString() + "';");
debugln("var ip = '" + WiFi.localIP().toString() + "';");
// Close the file
file.close();
} in all html files using script.js, like <script src="config.js"></script>
<script src="script.js"></script>
<script src="index.js"></script> On top of script.js add these lines: var address = ip; in method function ws_init() {
status('connecting...');
ws = new WebSocket('ws://' + address + '/ws'); This way the ESP modifies the |
+1 I want this feature. Thanks to @Jorgen-VikingGod I've able to get it working. ws = new WebSocket("ws://" + location.host + "/ws"); So no need to saveConfigToJS and other modification to the html. |
@RayPS awesome - so simple is the world 👍 Thx for sharing your findings! |
I have yet to try this but since i just got my duck working thanks to the other threads i will be giving this a go. I will say that i love the way wled https://github.com/Aircoookie/WLED handles this scenario. if it finds the wifi you setup it will connect to that if not it will spin up an AP. sort of the best of both worlds and would not force to to provide connection details at the time of flashing. I am not smart enough to figure out how they have done it but maybe someone here would be be able to. |
In my use case i would prefer the WiFi duck connect to my home WiFi instead of creating a WiFi that devices connect to. I have setup the ESP8266 to connect to my WiFi to host a web page, but would not have the skill set to get the WiFi duck to do it.
Thoughts.
The text was updated successfully, but these errors were encountered: