orbital-systems / react-native-esp-idf-provisioning

ESP IDF provisioning and custom data library for react-native
MIT License
26 stars 6 forks source link

Issue with connect(pop) Method Not Showing Expected Logs for Security2 Connection #54

Closed KristampsWong closed 7 months ago

KristampsWong commented 7 months ago

Hello react-native-esp-idf-provisioning team,

I would like to extend my deepest gratitude for developing such a niche yet incredibly useful toolkit for React Native developers interested in working with ESP32 devices.

I have successfully used the connect(pop, null, username) method to establish a connection to an ESP32 device, which worked flawlessly. The logs displayed on the ESP32 terminal were as expected, including security2 connection initiation and public key creation, among others.

However, when attempting to provide an alternative connection method in my app through the use of connect(pop) (without the second and third parameters), I noticed that the ESP32 terminal did not display the same logs as when connecting with the connect(pop, null, username) method. Specifically, I didn't observe the logs related to security2 connection initiation or public key creation.

This led me to wonder if this behavior is related to the security settings configured within the connect() API. Could it be possible that the connect(pop) method currently only supports secure1 connections? Or is there another explanation for the difference in log output when using connect(pop) compared to connect(pop, null, username)?

This is my react native code

const search = async () => {
    let prefix = 'PROV_'
    let transport = ESPTransport.ble
    let security = ESPSecurity.secure2
    try {
      const devices = await ESPProvisionManager.searchESPDevices(
        prefix,
        transport,
        security,
      )
      setDevice(devices[0])
      console.log(devices[0])
    } catch (e) {
      console.log(e)
    }
  }
  const handlePressConnection = async () => {
    console.log('Pressed')
    setIsLoading(true)
    try {
      const newDevice = new ESPDevice({
        name: device.name,
        transport: ESPTransport.ble,
        security: ESPSecurity.secure2,
      })
      await newDevice.connect(pop)
      console.log('connected')
      await newDevice.scanWifiList().then((res) => {
        dispatch(setWifiList(res))
      })
      setIsLoading(false)
      navigation.navigate('WifiListScreen')
    } catch (e) {
      setIsLoading(false)
      console.log(e)
    }
  }

I could not see console.log('connected') on handlepressConnection method.

Thanks

mateogianolio commented 7 months ago

Hi and thank you for your kind words!

Yes, this is a bit confusing and is why I created #27. The required parameters are different based on security setting:

mateogianolio commented 7 months ago

Closing in favour of #27.