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

Received only 20 bytes #107

Open toyokomi opened 8 months ago

toyokomi commented 8 months ago

Right now I am porting code to ESP32 but there is one problem with Wifi provisioning that device is receiving data which is 20 bytes only. From code it looks like we should receive more.

shiliu-yang commented 8 months ago

This is a demo I adapted based on the examples\bluetooth\nimble\bleprph example on esp32. You can refer to this example to improve ble_wrapper.c and adapt it to esp32. ble_netcfg.zip

You can also try running this demo first before improving ble_wrapper.c. Wifi provisioning needs to work in conjunction with the Tuya Smart App to obtain the WiFi SSID and password. The screenshot below shows the log when running normally.

111

toyokomi commented 8 months ago

@shiliu-yang how you get UUID for your device? I am using Tuyalink base solution.

shiliu-yang commented 8 months ago

@shiliu-yang how you get UUID for your device? I am using Tuyalink base solution.

You need to get the license list, the following 2 documents will help you

https://support.tuya.com/en/help/_detail/Kc4tu4synxpw2

https://support.tuya.com/en/help/_detail/Kavu6b1dr9nw1

toyokomi commented 8 months ago

Okay, I have raised ticket for getting UUID. It can be obtained from Device Details generated file.

toyokomi commented 8 months ago

@shiliu-yang How you get the AUTH KEY? We have only device secret which is 16bits length instead of 32bits.

shiliu-yang commented 8 months ago

@shiliu-yang How you get the AUTH KEY? We have only device secret which is 16bits length instead of 32bits.

image image

xmow49 commented 7 months ago

Hi, @shiliu-yang I tested your example, it work like you, but when I enable CONFIG_EXAMPLE_EXTENDED_ADV, I have some error: image

Also, I see the device as pixel_oem in the app, can we change that ? where in the code ? were can I put my tuya product ID Edit: I find it

Thanks

dzungpv commented 2 months ago

@toyokomi Do you finish implementation Wifi provisioning for Tuyalink?

dzungpv commented 2 months ago

@xmow49 I see you coding TICMeter project. Do you success pairing the ESP32 with Tuya app over Bluetooth and connected to the cloud? I ask here because I check your git seem not include pairing from the beginning but after wifi information set.

xmow49 commented 2 months ago

@xmow49 I see you coding TICMeter project. Do you success pairing the ESP32 with Tuya app over Bluetooth and connected to the cloud? I ask here because I check your git seem not include pairing from the beginning but after wifi information set.

Hi, Yes, I successfully do the paring with the tuya app using BLE, the device is automatically detected by the app. I can receive the WiFi SSID and password to start the connection on my ESP32 and then I start the tuya SDK stack, all work like a charm. You can look my repo, I edited some files to solve some problems.

dzungpv commented 2 months ago

@xmow49 I see you coding TICMeter project. Do you success pairing the ESP32 with Tuya app over Bluetooth and connected to the cloud? I ask here because I check your git seem not include pairing from the beginning but after wifi information set.

Hi, Yes, I successfully do the paring with the tuya app using BLE, the device is automatically detected by the app. I can receive the WiFi SSID and password to start the connection on my ESP32 and then I start the tuya SDK stack, all work like a charm. You can look my repo, I edited some files to solve some problems.

I try your code with ESP32, but after wifi information set, the ESP connected to internet it could not show online in the Smartlife/Tuya app. It show error:

00:01:45 ERROR tuya_ble_service.c:1164: ret:-1
00:01:45 INFO  tuya_iot.c:657: token: 1RQG1WAz
00:01:45 INFO  tuya_iot.c:658: region: AZ
00:01:45 INFO  tuya_iot.c:659: regist_key: hujs
00:01:45 ERROR tuya_ble_service.c:205: sg_ble_service_params null
00:01:47 INFO  http_client_wrapper.c:65: Sending HTTP POST request to h2.iot-dns.com/v2/url_config
00:01:49 INFO  http_client_wrapper.c:65: Sending HTTP POST request to a2.tuyaus.com/d.json?a=tuya.device.active&et=1&t=108&uuid=uuidxxx&v=4.4&sign=e3ddxxx
00:01:50 INFO  app_main.c:319: Sync timestamp:1714450587
00:01:50 ERROR tuya_iot.c:148: activate data save error:4361
00:01:50 ERROR tuya_iot.c:223: activate_response_parse error:-17

Your project a bit complicate, I try your project with ESP32-C6 too but it boot loop, so I just extract the wifi provisioning code from your tuya.c class, the fork component and adapt it to the wifi_provisioning_demo example https://github.com/tuya/tuya-connect-kit-for-mqtt-embedded-c/blob/without-submodules/examples/wifi_provisioning_demo/wifi_provisioning_demo.c

Can you test with the https://github.com/tuya/tuya-connect-kit-for-mqtt-embedded-c/tree/without-submodules/examples/wifi_provisioning_demo ? I spent many hour but still failed.

xmow49 commented 2 months ago

so I just extract the wifi provisioning code from your tuya.c class, the fork component and adapt it to the wifi_provisioning_demo

The demo works with the tuya lib on my project because I use also the tuya_wifi_provisioning(...)

try on your side to create a new esp idf project, in the "components" folder clone my tuya lib So you will have components/tuya-iot-link-sdk folder

Next in the main.c you can use the provisioning example as an example to test the lib and the provisioning. (copy the content of the main file into your main.c and rename the main() from example to app_main() in the main.c

dzungpv commented 2 months ago

so I just extract the wifi provisioning code from your tuya.c class, the fork component and adapt it to the wifi_provisioning_demo

The demo works with the tuya lib on my project because I use also the tuya_wifi_provisioning(...)

try on your side to create a new esp idf project, in the "components" folder clone my tuya lib So you will have components/tuya-iot-link-sdk folder

Next in the main.c you can use the provisioning example as an example to test the lib and the provisioning. (copy the content of the main file into your main.c and rename the main() from example to app_main() in the main.c

Thank you, it is OK now, but I merged original lib with change from https://github.com/accabog/esp32_tuya and using your ble_wrapper.c and it work. Your original component show error when connect to the server with my ESP32.

toyokomi commented 2 months ago

@dzungpv I have succeed in developing pairing process. I am able to pair device with Tuya app and send data to Tuya service.

dzungpv commented 2 months ago

@dzungpv I have succeed in developing pairing process. I am able to pair device with Tuya app and send data to Tuya service.

I have it working too. But take much effort. Better Tuya must release a dedicate SDK base on the ESP IDF or public all the api so we can build on top of it. For example in the ESP IDF they have stable wifi_provisioning lib: https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/provisioning/wifi_provisioning.html. @shiliu-yang @flyingcys you should look at this.