Comments (8)
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.
from wifiduck.
+1 I want this feature.
Thanks to @Jorgen-VikingGod I've able to get it working.
But the more simpler solution I did on the second step is just this line
ws = new WebSocket("ws://" + location.host + "/ws");
So no need to saveConfigToJS and other modification to the html.
from wifiduck.
Thanks for opening your first issue here! đ
đ Be sure to:
1. đ Have a look at the Wiki and README for information
2. đ Search for similar issues (open and closed)
3. âī¸ Provide enough information to understand, recreate and help out with your problem
4. âšī¸ Let us know if you find a solution
5. đ Close the issue when your problem has been solved
from wifiduck.
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?
from wifiduck.
Would love this feature.
I also want to controll my KVM switch.
from wifiduck.
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
webserver.cpp.txt
Script.js change
Line 117: ws = new WebSocket("ws://" + location.hostname + "/ws");
After changing the Script.js you will have to run webconverter.py
from wifiduck.
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 config.js
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 index.html
and terminal.html
please load config.js
before loading all other js files
<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 ws_init
use this address
function ws_init() {
status('connecting...');
ws = new WebSocket('ws://' + address + '/ws');
This way the ESP modifies the config.js
file each time it becomes a new address and the website can connect the websocket to the right server.
from wifiduck.
@RayPS awesome - so simple is the world đ
I'll adapt my code as well. I didn't read the doc of location.host - thought it was only the hostname; but it handles the ip address too.
What an easy and smart solution đĨŗ
Thx for sharing your findings!
from wifiduck.
Related Issues (20)
- Keystroke fix HOT 2
- WiFi not visible to mobile device HOT 2
- Hardware HOT 2
- WIFI WHID HOT 2
- FileStorage library invoked from serial_bridge.cpp not working with Arduino Pro Micro HOT 2
- Can you flash the DSTIKE USB32? HOT 2
- will it work on pi pico?? add the option!! HOT 2
- [Feature Request]: HID and STORAGE HOT 1
- i2c loop error HOT 3
- I CAN RUN SCRIPS BUT THEY STOP - CJMCU 3212 - INFO HOT 61
- Unable to save settings to enable Execute on start up. HOT 2
- Probleme while flashing Pro Micro HOT 3
- [Feature Request]: PLEASE PUT A RPI PICO W OPTION!!! HOT 1
- [Locale]: IT HOT 5
- a simple button[Feature Request]: HOT 1
- Question with SD HOT 1
- help me to find file Main connections (D1 -> 3, D2 -> 2) HOT 2
- [Feature Request]: Support ESP32-S2 HOT 3
- [Feature Request]: brother use esp32 and pi pico please HOT 1
- Internet connection problem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
đ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. đđđ
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google â¤ī¸ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wifiduck.