tuya / tuya-connect-kit-for-mqtt-embedded-c

Provide core capabilities like device connection, uplink and downlink communication and OTA across platforms and operating systems.
MIT License
62 stars 54 forks source link

BLE CRC error #106

Closed DamianJeu closed 8 months ago

DamianJeu commented 10 months ago

Hi, Im in the process of porting bluetooth to esp32, my device is detected by the tuya app, currently it stops at crc after receiving the first frame. For example, the frame I received: 0x00.0x31.0x40.0x01.0xA4.0x62.0xD5.0x33.0x09.0x56.0xC4.0xF5.0x1B,0xBB,0x3C,0xF7.0xBB,0xEA, 0x38.0x86.0x32.0xF8.0x94.0x84.0xCF,0xDA,0x1F,0x3C,0x5B,0xF3,0x33.0x16.0xEF,0x9F,0xA5,0xD5, 0x24.0xBE,0x0B,0x8F,0x20.0x9C,0x06.0xA3.0xCD,0x47.0xCB,0xD1.0x1A,0xA7.0x26.0x47 Each time is 52 bytes. I get an error: 00:00:17 ERROR tuya_ble_service.c:467: receive data crc16 check fail 00:00:17 ERROR tuya_ble_service.c:791: ret:-1 Is anyone able to help me?

xmow49 commented 9 months ago

Im in the process of porting bluetooth to esp32

Hi, do you have published your code? I'm also interested in the BLE on the ESP32. Can I have the beginning of your code to test and maybe improve it ? Thanks

shiliu-yang commented 8 months ago

For tuya Wifi provisioning for esp32, you can refer to this: https://github.com/tuya/tuya-connect-kit-for-mqtt-embedded-c/issues/107#issuecomment-1763612500

DamianJeu commented 8 months ago

In my case, the problem was with endianness in the tuya_cloudtypes.h file. Im swapping the bit order in the "UNI" macros.

shiliu-yang commented 8 months ago

In my case, the problem was with endianness in the tuya_cloudtypes.h file. Im swapping the bit order in the "UNI" macros.

You need to configure the -DLITTLE_ENDIAN=1 or -DLITTLE_ENDIAN=0 compile option depending on your chip platform at compile time.

https://github.com/tuya/tuya-connect-kit-for-mqtt-embedded-c/blob/642ead7acef194ab53c6784c8045211394fe6177/CMakeLists.txt#L20C35-L20C35

Or you can define it yourself in the code

DamianJeu commented 8 months ago

In my case, the problem was with endianness in the tuya_cloudtypes.h file. Im swapping the bit order in the "UNI" macros.

You need to configure the -DLITTLE_ENDIAN=1 or -DLITTLE_ENDIAN=0 compile option depending on your chip platform at compile time.

https://github.com/tuya/tuya-connect-kit-for-mqtt-embedded-c/blob/642ead7acef194ab53c6784c8045211394fe6177/CMakeLists.txt#L20C35-L20C35

Or you can define it yourself in the code

I created my own definition in code, but your solution i think is more universal

toyokomi commented 8 months ago

Hello @shiliu-yang thank you for your code. Right now I have problem because after receiving data there is information that CRC16 has failed. I am not sure but I am using UUID different that you have in your implementation. ESP32 is little endian by default so there is no need to change it. How can I get UUID for device? I think there is a problem so CRC16 is failing. From Tuya knowledge base there is difference between device ID and UUID. I am using Tuyalink based solution.

DamianJeu commented 8 months ago

If you use tuyalink it wont work. This solution is for tuyaOS, then in hardware development you need to use linkSDK (tuya website). if u want use tuyaLink -> https://github.com/tuya/tuya-iot-core-sdk