回答
要在多台设备上使用同一个Hamibot脚本,你需要完成以下步骤:
-
在每台设备上安装Hamibot应用
- 确保所有设备都安装了最新版Hamibot应用
- 使用同一个Hamibot账号登录所有设备
-
获取设备ID
- 在Hamibot应用中,进入「我的设备」页面
- 每台设备会显示唯一的设备ID(如示例中的"a51d237e9af41ecc021c9ff6")
- 记录下每台设备的ID和名称
-
调用API运行脚本到多台设备
使用以下代码示例,将脚本部署到多个设备:
// 文档地址 https://docs.hamibot.com/
http.request('https://api.hamibot.com/v1/scripts/你的脚本_id/run', {
method: 'POST',
contentType: 'application/json',
headers: {
authorization: 'hmp_你的令牌',
},
body: JSON.stringify({
devices: [
{ _id: '设备1的ID', name: '设备1名称' },
{ _id: '设备2的ID', name: '设备2名称' },
{ _id: '设备3的ID', name: '设备3名称' }
],
}),
});
- 使用开发脚本的多设备部署
如果你使用的是开发脚本,API端点略有不同:
// 文档地址 https://docs.hamibot.com/
http.request('https://api.hamibot.com/v1/devscripts/你的开发脚本_id/run', {
method: 'POST',
contentType: 'application/json',
headers: {
authorization: 'hmp_你的令牌',
},
body: JSON.stringify({
devices: [
{ _id: '设备1的ID', name: '设备1名称' },
{ _id: '设备2的ID', name: '设备2名称' }
],
}),
});
注意:
- 所有设备必须使用同一个Hamibot账号登录
- 设备ID可以在Hamibot应用的"我的设备"页面查看
- 一次API调用最多可以指定50台设备同时运行脚本
- 脚本会自动同步到所有指定的设备上执行
如果你需要停止脚本在某些设备上运行,可以使用DELETE方法:
http.request('https://api.hamibot.com/v1/scripts/你的脚本_id/run', {
method: 'DELETE',
contentType: 'application/json',
headers: {
authorization: 'hmp_你的令牌',
},
body: JSON.stringify({
devices: [
{ _id: '需要停止的设备ID', name: '设备名称' }
],
}),
});
ℹ️ 本回答由 AI 生成,内容仅供参考