HarmonyOS智慧设备开发-onehop device Ability学习体验 原创

鸿蒙时代
发布于 2021-8-18 11:10
浏览
1收藏

一、技术相关

项目名称: onehop_device
项目语言: JAVA
体验模板: onehop device Ability
工具:deveco studio

二、效果如下
HarmonyOS智慧设备开发-onehop device Ability学习体验-鸿蒙开发者社区
HarmonyOS智慧设备开发-onehop device Ability学习体验-鸿蒙开发者社区
注:由于没有实际设备连接所以模板无法显示控制页面。

三、开发步骤

建立项目
新建一个java的应用项目
然后构建完成项目后在jltf_template下new->module
HarmonyOS智慧设备开发-onehop device Ability学习体验-鸿蒙开发者社区
HarmonyOS智慧设备开发-onehop device Ability学习体验-鸿蒙开发者社区

选择phone下的onehop device Ability模板

登录你的账号然后启动模拟器即可实现效果

四、项目介绍

该模板用于碰一碰FA低代码开发,只需要修改少量的参数就可以实现碰一碰的配网、控制以及页面布局开发。
缺点:设备端无法主动传输数据到FA。
项目结构如下:
控制设备部分:
HarmonyOS智慧设备开发-onehop device Ability学习体验-鸿蒙开发者社区

配网部分:
HarmonyOS智慧设备开发-onehop device Ability学习体验-鸿蒙开发者社区

部分代码(部分接口)
var FANetConfig = {
// 是否支持WifiAware
isSupportWifiAware: function () {
return callAbility(CONSTANT.IS_SUPPORT_WIFI_AWARE, {});
},
discoveryByNAN: function (scanInfo, callbackFunc) {
if (!(typeof scanInfo.duration === ‘number’ && scanInfo.duration % 1 === 0)) {
console.error(“NetConfig# call discoveryByNAN failed, parameter ‘duration’ type should be integer.”);
return;
}
if (!(typeof scanInfo.lockTime === ‘number’ && scanInfo.lockTime % 1 === 0)) {
console.error(“NetConfig# call discoveryByNAN failed, parameter ‘lockTime’ type should be integer.”);
return;
}

    if (typeof callbackFunc !== 'function') {
        console.error("NetConfig# call discoveryByNAN failed, parameter 'callbackFunc' type should be function.");
        return;
    }
    return callAbility(CONSTANT.DISCOVERY_BY_NAN_CODE, {
        scanNanInfo: scanInfo
    }, callbackFunc);
},
discoveryBySoftAp: function (callbackFunc) {
    if (typeof callbackFunc !== 'function') {
        console.error("NetConfig# call discoveryBySoftAp failed, parameter 'callbackFunc' type should be function.");
        return;
    }
    return callAbility(CONSTANT.DISCOVERY_BY_SOFT_AP_CODE, {}, callbackFunc);
},
connectDevice: function (connectInfo, callbackFunc) {
    let isConnectInfoNull = connectInfo == null || connectInfo == undefined;
    if (isConnectInfoNull) {
        console.error("NetConfig# call connectDevice failed, parameter 'connectInfo' should not be undefined.");
        return;
    }

    if (typeof connectInfo.targetDeviceId !== 'string') {
        console.error("NetConfig# call connectDevice failed, parameter 'connectInfo.targetDeviceId' type should be string.");
        return;
    }

    if (!(typeof connectInfo.type === 'number' && connectInfo.type % 1 === 0)) {
        console.error("NetConfig# call connectDevice failed, parameter 'connectInfo.type' type should be integer.");
        return;
    }

    if (typeof connectInfo.pin !== 'string') {
        console.error("NetConfig# call connectDevice failed, parameter 'connectInfo.pin' type should be string.");
        return;
    }

    if (typeof connectInfo.password !== 'string') {
        console.error("NetConfig# call connectDevice failed, parameter 'connectInfo.password' type should be string.");
        return;
    }

    if (typeof connectInfo.sessionId !== 'string') {
        console.error("NetConfig# call connectDevice failed, parameter 'connectInfo.sessionId' type should be string.");
        return;
    }

    if (typeof callbackFunc !== 'function') {
        console.error("NetConfig# call connectDevice failed, parameter 'callbackFunc' type should be function.");
        return;
    }

    return callAbility(CONSTANT.CONNECT_DEVICE_CODE, {
        connectInfo: connectInfo
    }, callbackFunc);
},

// 获取wifi列表
getWifiList: function (callbackFunc) {
if (typeof callbackFunc !== ‘function’) {
console.error(“NetConfig# call getWifiList failed, parameter ‘callbackFunc’ type should be function.”);
return;
}
return callAbility(CONSTANT.GET_WIFI_LIST_CODE, {}, callbackFunc);
},
sendMessage: function (commonInfo, message, callbackFunc) {
if (commonInfo == null || commonInfo == undefined) {
console.error(“NetConfig# call sendMessage failed, parameter ‘commonInfo’ type should be string.”);
return;
}
if (typeof commonInfo.sessionId !== ‘string’) {
console.error(“NetConfig# call sendMessage failed, parameter ‘sessionId’ type should be string.”);
return;
}

    if (typeof message !== 'string') {
        console.error("NetConfig# call sendMessage failed, parameter 'message' type should be string.");
        return;
    }

    if (typeof callbackFunc !== 'function') {
        console.error("NetConfig# call sendMessage failed, parameter 'callbackFunc' type should be function.");
        return;
    }
    return callAbility(CONSTANT.SEND_MESSAGE_CODE, {
        commonInfo: commonInfo,
        message: message
    }, callbackFunc);
}

}

完整代码地址:
https://gitee.com/jltfcloudcn/smart-devices/tree/master/OneHop_device

©著作权归作者所有,如需转载,请注明出处,否则将追究法律责任
分类
标签
HarmonyOS智慧设备开发-onehop device Abil.docx 402.57K 87次下载
3
收藏 1
回复
举报
回复
    相关推荐