网关sdk开发问题

网关设备, 语音中控设备等
15905600423
Posts: 16

参考文档增加子设备心跳功能,直接报错:tuya_iot_fresh_dev_hb op_ret:-1

Attachments
fde10c9d7a0c814498a04cadb3ed4db.png
c6d795c47783d13ea67aa58bb819c05.png
Kyson
Posts: 230

Re: 网关sdk开发问题

请提供一下SDK的日志,这个报错一般是网关还没初始化,请确保在 tuya_iot_sdk_start 之后调用。

15905600423
Posts: 16

Re: 网关sdk开发问题


< TUYA IOT SDK V:2.2.0 BS:40.00_PT:2.2_LAN:3.3_CAD:1.0.2_CD:1.0.0 >
< BUILD AT:2020_07_14_19_54_21 BY wallice FOR ty_iot_gw_wr_sdk AT arm-linux-gnueabihf-gcc-7.4.1 >
IOT DEFS < WIFI_GW:0 DEBUG:1 KV_FILE:1 SHUTDOWN_MODE:1 LITTLE_END:1 TLS_MODE:4 ENABLE_LOCAL_LINKAGE:1 ENABLE_CLOUD_OPERATION:1 ENABLE_SUBDEVICE:1 ENABLE_ENGINEER_TO_NORMAL:1 OPERATING_SYSTEM:100 ENABLE_SYS_RPC:0 TY_SECURITY_CHIP:0 RELIABLE_TRANSFER:1 ENABLE_LAN_ENCRYPTION:1 ENABLE_LAN_LINKAGE:1 ENABLE_LAN_LINKAGE_MASTER:1 ENABLE_LAN_DEV:1 ENABLE_LAN_DEV_MASTER:1 >


这是我们目前使用的sdk 没看到有这个函数啊

Kyson
Posts: 230

Re: 网关sdk开发问题

这不是 TuyaOS 的 SDK,有 tuya_user_svc_start 这个接口吧?或者代码提供下,你在哪里调用刷新心跳的

15905600423
Posts: 16

Re: 网关sdk开发问题

我们用的应该是联网sdk

Attachments
tuya_gw_link_sdk-master.zip
(11.84 MiB) Downloaded 195 times
15905600423
Posts: 16

Re: 网关sdk开发问题

这个sdk用的可能有两三年了?跟版本是否有关系?

Kyson
Posts: 230

Re: 网关sdk开发问题

SDK 是很老了,但这功能应该是没问题的,你可以把你调用涂鸦接口的大致示例代码提供下。

15905600423
Posts: 16

Re: 网关sdk开发问题

接口调用代码如下

Attachments
647428c1e42b5f54adde4dfa12481c4.png
ed1a66a9d27873e70859ac603ded9aa.png
Kyson
Posts: 230

Re: 网关sdk开发问题

主要是前面,SDK 初始化的逻辑。在调用刷新心跳之前,调用了哪些接口。

15905600423
Posts: 16

Re: 网关sdk开发问题

// Init 初始化
func Init(cfg *TuyaConfig) error {
if cfg != nil {
TuyaConfigData = *cfg
}
os.MkdirAll(TuyaConfigData.StoragePath, os.ModePerm)

Code: Select all

err := FormTuyaStructure()
if err != nil {
	return fmt.Errorf("Failed to form Tuya structure: %w", err)
}
common.Log.Info("Form Tuya Structure success")

// 从文件中读取uuid和authkey
content, err := ioutil.ReadFile("/app/zap/eroom-core/tuyaid")
if err != nil {
	return fmt.Errorf("Read tuyaid file failed: %w", err)
}
uuid_authkey := strings.TrimSpace(string(content))
sepIdx := strings.LastIndex(uuid_authkey, ".")
if sepIdx == -1 || sepIdx == 0 {
	return fmt.Errorf("Invalid tuyaid file")
}
uuid := uuid_authkey[:sepIdx]
authkey := uuid_authkey[sepIdx+1:]
common.Log.Infof("uuid \"%s\" %d, authkey \"%s\" %d", uuid, len(uuid), authkey, len(authkey))

//tuya_iot_init
opRet := C.tuya_iot_init_params(C.CString(TuyaConfigData.StoragePath), (*C.TY_INIT_PARAMS_S)(unsafe.Pointer(nil)))
if opRet != 0 {
	return fmt.Errorf("tuya_iot_init failed: %d", opRet)
}
common.Log.Debug("tuya_iot_init OK")

opRet = C.SetLogManageAttr(C.LOG_LEVEL(TuyaConfigData.LogLevel))
if opRet != 0 {
	return fmt.Errorf("set tuya log level failed: %d", opRet)
}

//sdk版本
sdkinfo := C.GoString(C.tuya_iot_get_sdk_info())
common.Log.Infof("Tuya SDK info:\n********************\n%s********************", sdkinfo)

//设置网关的UUID和AUTHKEY
prodInfo := C.GW_PROD_INFO_S{C.CString(uuid), C.CString(authkey)}
opRet = C.tuya_iot_set_gw_prod_info(&prodInfo)
if opRet != 0 {
	return fmt.Errorf("tuya_iot_set_gw_prod_info failed: %d", opRet)
}
common.Log.Debug("tuya_iot_set_gw_prod_info OK")

iotCbs := C.TY_IOT_CBS_S{}
iotCbs.gw_status_cb = C.GW_STATUS_CHANGED_CB(C.gw_status_cb_c)
iotCbs.gw_ug_cb = C.GW_UG_INFORM_CB(C.gw_ug_cb_c)
iotCbs.gw_reset_cb = C.GW_RESET_IFM_CB(C.gw_reset_cb_c)
iotCbs.dev_obj_dp_cb = C.DEV_OBJ_DP_CMD_CB(C.dev_obj_dp_cb_c)
iotCbs.dev_raw_dp_cb = C.DEV_RAW_DP_CMD_CB(C.dev_raw_dp_cb_c)
iotCbs.dev_dp_query_cb = C.DEV_DP_QUERY_CB(C.dev_dp_query_cb_c)
iotCbs.dev_ug_cb = C.DEV_UG_INFORM_CB(C.dev_ug_cb_c)
iotCbs.dev_reset_cb = C.DEV_RESET_IFM_CB(C.dev_reset_cb_c)

gwCbs := C.TY_IOT_GW_CBS_S{}
gwCbs.gw_dev_grp_cb = C.GW_DEV_GRP_INFM_CB(C.gw_dev_grp_cb_c)
gwCbs.gw_dev_scene_cb = C.GW_DEV_SCENE_INFM_CB(C.gw_dev_scene_cb_c)

opRet = C.tuya_iot_gw_dev_init(&iotCbs, &gwCbs, C.CString(TuyaConfigData.PkOfGateway), C.CString(TuyaConfigData.SwVerOfGateway), (*C.GW_ATTACH_ATTR_T)(unsafe.Pointer(nil)), 0)
if opRet != 0 {
	return fmt.Errorf("tuya_iot_gw_dev_init failed: %d", opRet)
}
common.Log.Info("tuya_iot_gw_dev_init OK")

opRet = C.tuya_iot_reg_get_nw_stat_cb_params(C.GET_NW_STAT_CB(C.status_cb), 1)
if opRet != 0 {
	return fmt.Errorf("tuya_iot_reg_get_nw_stat_cb failed: %d", opRet)
}
common.Log.Info("tuya_iot_reg_get_nw_stat_cb OK")

return nil

}

Post Reply