小程序虚拟设备,无法在真机调试中,下发数据

小程序开发相关产品技术讨论,包括面板、智能小程序、React Native、Ray跨端框架、Panel SDK、微信小程序、小程序开发工具(IDE)及其他开发技术相关等话题


Post Reply
silverlight
Posts: 43

使用是官方的例程panel-universal(其他例程也有类似情况),在开发者工具中可以实现虚拟设备数据的正确下发,但真机调试的时候使用手机无法正确下发,但真实设备可以正常上传和下发数据。之前并没有出现过这种问题。
报错如下

Code: Select all

service.js:3 SyntaxError: Uncaught (in promise) [object Object] (at service.js:3:386161)
    at new Be (service.js:3:386161)
    at publishDps2 (publishDps.js:55:10)
    at SmartDeviceModel.js:672:14
    at SmartDeviceModel.__publishDps__ (logger.js:9:22)
    at Object.set (SmartDeviceModel.js:294:29)
    at onChange (index.tsx:43:29)
    at onClick (index.tsx:26:26)
    at onClick (Button.thing.js:29:57)
    at handler (createCallbackProxy.js:66:18)
    at Container.js:164:36

我对onclik和onchangge进行错误捕获,并没有捕获到错误信息。猜测是publishDps2这个函数出了问题。

Code: Select all

import React from 'react';

import { Button, Text, View } from '@ray-js/ray';
import Strings from '@/i18n';
import { getArray } from '@/utils/array';

import styles from './index.module.less';
export const EnumView: React.FC<ItemViewProps> = ({ item, dpValue, onChange }) => {

  function getRange(){
    var Range = [];
    try{
      Range = getArray(item?.property?.range as string[]);
    }catch(error){
      console.log("getRange",error);
    }
    return Range;
  }

  return (
    <View className={styles.container}>
      {getRange().map(rangeItem => (
        <Button
          key={rangeItem}
          className={styles.item}
          onClick={() => onChange(rangeItem)}
          style={
            rangeItem === dpValue
              ? {
                  backgroundColor: '#468AEE',
                  color: '#fff',
                }
              : {
                  backgroundColor: '#4689ee61',
                  color: '#fff',
                }
          }
        >
          <Text>{Strings.getDpLang(item.code, rangeItem)}</Text>
        </Button>
      ))}
    </View>
  );
};
Last edited by silverlight on 2024年 Jun 12日 12:23, edited 1 time in total.
lshinylee
Posts: 158

Re: 小程序虚拟设备,无法在真机调试中,下发数据

会不会是下发的功能点指令为空?

:D :D :D

silverlight
Posts: 43

Re: 小程序虚拟设备,无法在真机调试中,下发数据

lshinylee 2024年 Jun 12日 09:24

会不会是下发的功能点指令为空?

Image
下发的指令是有内容的

lshinylee
Posts: 158

Re: 小程序虚拟设备,无法在真机调试中,下发数据

https://developer.tuya.com/cn/miniapp/d ... publishDps

方便直接调用下 publishDps 看看里面 fail 的回调有吗?

:D :D :D

silverlight
Posts: 43

Re: 小程序虚拟设备,无法在真机调试中,下发数据

lshinylee 2024年 Jun 12日 10:43

https://developer.tuya.com/cn/miniapp/d ... publishDps

方便直接调用下 publishDps 看看里面 fail 的回调有吗?

Code: Select all

import React, { useEffect, useState } from 'react';
import { View, Text, Button,device  } from '@ray-js/ray';
import { useDevInfo } from '@ray-js/panel-sdk';
import { publishDps } from '@ray-js/ray';

const App = () => {
  const devInfo = useDevInfo();
  const [deviceDetails, setDeviceDetails] = useState(null);
  const { getDeviceInfo } = device;

  const fetchDeviceInfo = async () => {
    try {
      const detail = await getDeviceInfo({ deviceId: devInfo.devId });
      setDeviceDetails(detail);
      console.log('Device Info', detail);
    } catch (error) {
      console.error('Error fetching device info:', error);
    }
  };

  const handlePublishDps = async () => {
    try {
      const result = await publishDps({ pir_state:"pir"});
      console.log('Publish DP Result:', result);
    } catch (error) {
      console.error('Error publishing DP:', error);
    }
  };

  useEffect(() => {
    fetchDeviceInfo();
  }, [devInfo.devId]);

  return (
    <View>
      <Text>设备名称: {deviceDetails?.name}</Text>
      <Button onClick={handlePublishDps}>下发 DP</Button>
    </View>
  );
};

export default App;

Image
下发为啥是空啊?报错如下,说是数据类型错误,该功能点数据类型是枚举型,枚举值:为pir和 none。
Image

Code: Select all

Error publishing DP: {
"errorCode": 20028,
 "errorMsg": "Publish Dps error", 
 "innerError": {
 "errorMsg": "Error Domain=com.thing.smart.devicecorekit Code=3005 "dp点数据类型错误"
  UserInfo={NSLocalizedDescription=dp点数据类型错误, 
  ThingErrorDpEventOptCodeKey=102}", "errorCode": "3005"}}
  
lshinylee
Posts: 158

Re: 小程序虚拟设备,无法在真机调试中,下发数据

这个提示挺明显了,下发的数据类型错了,你看看dpId 为1的功能点是什么数据类型的

:D :D :D

silverlight
Posts: 43

Re: 小程序虚拟设备,无法在真机调试中,下发数据

lshinylee 2024年 Jun 12日 11:48

这个提示挺明显了,下发的数据类型错了,你看看dpId 为1的功能点是什么数据类型的

dpid1是开关bool类型,可我这里 const result = await publishDps({ pir_state:"pir"})。指定的功能点是pir_state,而不是dpid1所对应的功能点啊。如果是下发时选的功能点错误,为啥开发者工具里却正确下发了数据?

我重新修改了下发数据的部分代码,明确了选择功能点。现在开发者工具里面返回的结果是publish DP Result: undefined和真机调试的结果一致了。改了之后真机调试不再报错,应该是我上面使用publishDps的格式不对。但真机调试的时候依然无法正确下发数据。是我写的格式哪里有错吗,为啥都是undefined。

而且我发现对bool类型下发数据虽然也是返回publish DP Result: undefined,但是真机调试却能正确下发数据,就很奇怪

Code: Select all

  const handlePublishDps = async () => {
    try {
      const result = await publishDps({
        deviceId: devInfo.devId,
        dps: { 3: 60 }, // 3为value类型      
dps: { 6:'off'}, // 6为enum类型 dps: { 1:true},//1为bool类型 mode: 1, pipelines: [0, 1, 2, 3, 4, 5, 6], options: {}, }); console.log('Publish DP Result:', result); } catch (error) { console.error('Error publishing DP:', error); } };
Post Reply