kdjun97 / blog-comments

For blog comments
0 stars 0 forks source link

iot/esp-ble-with-flutter3/ #14

Open utterances-bot opened 1 year ago

utterances-bot commented 1 year ago

[IoT] 앱과 연동하는 IoT (BLE 통신 예제) - 3편 | Jumy

Flutter App과 ESP32 BLE 통신 예제

https://kdjun97.github.io/iot/esp-ble-with-flutter3/

oliginur commented 1 year ago

안녕하세요 포스팅 내용 정독하고 많은걸 배웠습니다.( ) 몇가지 궁금한 사항이 있는데

  1. mtu를 협상하는 부분이 어디서 이루어져야 하나요? 현재 flutter_blue_plus를 사용하고있는데
  2. discoverServices() 호출시에 인자를 넣을수 없는데 별도로 구현하신걸까요?
  3. 본문에서 사용되어지고 있는 espController 객채의 출처가 궁금합니다. 연결된 디바이스 정보내에도 targetDevice라는 객채가 없는데 별도 클래스로 선언해놓으신건지.. 깃에서 해당 프로젝트를 찾아보았지만 찾질 못해서요 ..

감사합니다.

kdjun97 commented 1 year ago

1 -> 협상은 이 부분입니다 // MTU 50으로 설정 await espController.targetDevice.requestMtu(50); int mtu = await espController.targetDevice.mtu.first; 2 -> 오래돼서 기억은 나지 않지만, 인자를 넣을 수 없다고 하신걸로 보아 따로 구현을 한 것 같습니다. 3 -> 제가 따로 esp에 대한 정보를 가진 컨트롤러를 만들었습니다. (별도 클래스 맞습니다!)

추가로 궁금하신 부분 있으시면 댓글 달아주세요!

kdjun97 commented 1 year ago

1번 질문에 대해 첨언하자면, 공식 패키지 문서를 참고하면 (https://pub.dev/packages/flutter_blue_plus)

Read the MTU and request larger size 에 관해

final mtu = await device.mtu.first; await device.requestMtu(512);

위 코드에서 현재 mtu를 얻어오고, 2번째 줄에서 mtu 협상 요청에 대해 진행함을 알 수 있습니다.

제 본래 코드를 오래전에 짜서, 비동기 처리를 어떻게 한 지는 모르겠으나, 다시 읽어보니 저도 예전에 제 코드가 이해가 되지는 않네요...

예전 코드를 약간 수정하자면 mtu를 얻어오고, mtu request를 해준 뒤, while로 mtu가 맞는지를 체크하여 break를 하는게 맞아보입니다. 물론 timeout같은 exception handling도 필요해보입니다!

추가로 궁금하신 부분 있으시면 댓글 달아주세요!

oghmmm commented 8 months ago

// MTU 협상 (connectToDevice 함수 안) await espController.targetDevice.connect(autoConnect: false); espController.isConnected = true; // MTU 50으로 설정 await espController.targetDevice.requestMtu(50); int mtu = await espController.targetDevice.mtu.first; // 협상 결렬? 그럼 다시 협상 ㄱㄱ while (mtu != 50) { print("Waiting for requested MTU"); await Future.delayed(Duration(seconds: 1)); mtu = await espController.targetDevice.mtu.first; } print('DEVICE CONNECTED'); await DiscoverServices().discoverServices(espController);

잘 보았습니다 이부분은 아두이노 코드가 아닌가요? connectToDevice 함수는 어디서 찾을수 있고 호출은 어떻게하는지 알려주시면 감사하겠습니다

kdjun97 commented 8 months ago

위 부분은 아두이노 코드가 아닌 dart 코드입니다. flutter에서 작성이 되었고, connectToDevice는 따로 제가 만든 class에 정의되어있습니다. 언급해주신 함수는 2편의 함수 구현부를 참고하시면 될 것 같습니다.

감사합니다.