Problem with navigator.serial of SPP bluetooth using Windows 11

I developed a web app that connects to my ESP32 bluetooth as it was a serial port, this is called SPP (Serial Port Profile).

It was working on my PC with Windows 10, but as I was testing it in different computers I realise this isn't working anymore in Windows 11.

The console just gives an output "Cannot connect with the serial port", no further information.... It is really weird, because nothing has changed more than the OS, from W10 to W11.

As I said before, in the W10 it just got connected perfectly, once I try it on a W11 computer it always gives the error.

Do you know why it is happening? I have tried to get more information about the connection but I couldn't get anything else than unable to connect...

This is the code of the connection:

const connectToESP32 = async () => {
let newPort = null
let readers = null
let writers = null
try {
  // @ts-ignore
  newPort = await navigator.serial.requestPort({
    filters: [{ bluetoothServiceClassId: btClass }],
  })
  if ("serial" in navigator) {
    toast.loading("Connected", {
      id: "1",
    })
  } else {
    toast.error("Not compatible", {
      id: "1",
    })
  }
  await newPort.open({ baudRate: 115200 })
  setPort(newPort)
  console.debug("Port info: ", newPort.getInfo())

  const textDecoder = new TextDecoder()
  readerRef.current = newPort.readable?.getReader()
  writerRef.current = newPort.writable?.getWriter()

  readers = readerRef.current
  writers = writerRef.current

}} catch (error) {
  console.error("Error connecting:", error)
  setStopProg(true)
  toast.error("Error connecting", {
    id: "1",
  })
  if (newPort) {
    try {
      // @ts-ignore
      readers.releaseLock()
      // @ts-ignore
      writers.releaseLock()
      await newPort.close()
    } catch (error) {
      console.error("Error al cerrar puerto:", error)
    }
    setPort(null)
  }
}
}

The application was working perfectly in Windows 10, so I am worried it might be something related with a layer behind....

Upvotes: 0

Views: 49

Answers (0)

Related Questions