Giter Club home page Giter Club logo

Comments (8)

justusiv avatar justusiv commented on May 27, 2024 2

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.

RayPS avatar RayPS commented on May 27, 2024 1

+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.

welcome avatar welcome commented on May 27, 2024

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.

aroslanov avatar aroslanov commented on May 27, 2024

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.

 avatar commented on May 27, 2024

Would love this feature.

I also want to controll my KVM switch.

from wifiduck.

unarat avatar unarat commented on May 27, 2024

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.

Jorgen-VikingGod avatar Jorgen-VikingGod commented on May 27, 2024

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.

Jorgen-VikingGod avatar Jorgen-VikingGod commented on May 27, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤ī¸ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.