Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Received only 20 bytes #107

Open
toyokomi opened this issue Oct 11, 2023 · 15 comments
Open

Received only 20 bytes #107

toyokomi opened this issue Oct 11, 2023 · 15 comments

Comments

@toyokomi
Copy link

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
Copy link
Contributor

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
Copy link
Author

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

@toyokomi toyokomi reopened this Oct 18, 2023
@shiliu-yang
Copy link
Contributor

@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
Copy link
Author

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

@toyokomi toyokomi reopened this Oct 23, 2023
@toyokomi
Copy link
Author

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

@shiliu-yang
Copy link
Contributor

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

image
image

@xmow49
Copy link

xmow49 commented Nov 9, 2023

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
Copy link

dzungpv commented Apr 24, 2024

@toyokomi Do you finish implementation Wifi provisioning for Tuyalink?

@dzungpv
Copy link

dzungpv commented Apr 26, 2024

@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
Copy link

xmow49 commented Apr 26, 2024

@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
Copy link

dzungpv commented Apr 30, 2024

@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
Copy link

xmow49 commented May 3, 2024

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
Copy link

dzungpv commented May 3, 2024

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
Copy link
Author

toyokomi commented May 3, 2024

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

@toyokomi toyokomi closed this as completed May 3, 2024
@toyokomi toyokomi reopened this May 3, 2024
@dzungpv
Copy link

dzungpv commented May 4, 2024

@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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants