Skip to content
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

Question - Reading SSID list from Raspberry Device #1255

Open
4 tasks done
pzajas opened this issue Dec 10, 2024 · 0 comments
Open
4 tasks done

Question - Reading SSID list from Raspberry Device #1255

pzajas opened this issue Dec 10, 2024 · 0 comments
Labels

Comments

@pzajas
Copy link

pzajas commented Dec 10, 2024

Prerequisites

  • I checked the documentation and FAQ without finding a solution
  • I checked to make sure that this issue has not already been filed
  • I'm sure that question is related to the library itself and not Bluetooth Low Energy or Classic in general. If that so, please post your question on StackOverflow.
  • I'm running the latest version

Question

Hello!

I'm building an app that connects to raspberry device via ble to pass wifi credentials to that app. It's working now but the SSID json? I recive seems fairly malformed. I'm able to get one clean ssid only from it but I should get like 10+. It looks like this after some parsing:

(NOBRIDGE) LOG [DEBUG] Extracted 41 SSIDs before cleaning: ["CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",",
"CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2.", ",", "CGA2121_QV5rJnx", "2."]

This is raw:

WyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0EyMTIxX1FWNXJKbngiLCIyLlsiQ0dBMjEyMV9RVjVySm54IiwiMi5bIkNHQTIxMjFfUVY1ckpueCIsIjIuWyJDR0Ey

Also, I have React.js app that does the same thing and everything works correctly there:

['CGA2121_QV5rJnx', '2.4G-Vectra-WiFi-B591DC', '2.4G-Vectra-WiFi-9DC6A4', '5G-Vectra-WiFi-B591DC', 'UPC1717935', '5G-Vectra-WiFi-9DC6A4', 'CGA2121_5b3dqhu', 'DCF979', 'TP-LINK_87D7C6', 'UPCB8BA3BF', 'UPC7650130', 'KODPRIVa171']

Any ideas about what is wrong in my case? Would be grateful for each hint guys.

Tanks in advance! :D

Question related code

const getSSIDList = async (device: Device, serviceUUID: string, characteristicUUID: string) => {
    try {
      const characteristic = await device.readCharacteristicForService(serviceUUID, characteristicUUID)
      const decodedBase64Value = base64.decode(characteristic.value)
      const buffer = stringToArrayBuffer(decodedBase64Value)
      const decodedWithAB2Str = ab2str(buffer)
      const ssidList = decodedWithAB2Str.match(/"([^"]+)"/g).map((ssid) => ssid.replace(/["\[\]]/g, '').trim())
      const cleanedSSIDs = ssidList.filter((ssid) => ssid && ssid.length > 4 && !ssid.includes('2.['))
      const uniqueSSIDs = Array.from(new Set(cleanedSSIDs))
      await AsyncStorage.setItem('ssids', JSON.stringify(uniqueSSIDs))

      return uniqueSSIDs
    } catch (error) {
      console.error('Error retrieving SSID list from device:', error)
      return []
    }
  }

  const stringToArrayBuffer = (str: string): ArrayBuffer => {
    const encoder = new TextEncoder()
    return encoder.encode(str).buffer
  }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant