theelims / ESP32-sveltekit

A simple and extensible framework for ESP32 based IoT projects with a feature-rich, beautiful, and responsive front-end build with Sveltekit, Tailwind CSS and DaisyUI. This is a project template to get you started in no time with a fully integrated build chain.
https://theelims.github.io/ESP32-sveltekit/
Other
118 stars 22 forks source link

Getting Started: WebSocket Not Working #54

Closed IanSC closed 6 months ago

IanSC commented 7 months ago

I had some trouble but got it to run, so I am just verifying if the solution is correct, and it might help others too.

When this repo is run, I get message on the browser "Connection to device lost". Toggling the light using REST is working. Socket is not working.

I tried this solution and it solves the web socket issue: https://stackoverflow.com/questions/69350342/svelte-sveltekit-and-socket-io-client-not-working-in-dev-works-in-preview

It says to add to svelte.config.js

const config = {
  kit: {
    vite: {
      resolve: {
        alias: {
          "xmlhttprequest-ssl": "./node_modules/engine.io-client/lib/xmlhttprequest.js",
        },
      },
    },
  },
};

Is this the recommended solution?

Thank you for the great lib.

theelims commented 7 months ago

Can you please elaborate your setup a little bit? Which browser, are you using the vite proxy, which versions, ...

There are known issues with opera and edge #52

IanSC commented 7 months ago

My bad. I retested and it works without adding anything, but not consistently.

For the test, I connect directly to Wifi of esp32. I disabled FT_SECURITY in features.ini to save time.

Windows: Chrome and Edge, rest/socket working, both browser used same time Mac: Chrome and Safari, rest/socket working, both browser used same time Android Phone: Chrome, rest/socket working Mac: Brave Browser v1.65.126, rest working, websocket NOT working

It usually works, but if disconnected and reconnected, I encoountered:

Example:

Scenario 2

The actual result keeps changing, but these are some of the results I've encountered.

For straight use, it is working fine.