微信小程序与thingsboard通过HTTP协议通信 | 您所在的位置:网站首页 › 仿豆瓣源码 › 微信小程序与thingsboard通过HTTP协议通信 |
参考资料:http://www.ithingsboard.com/docs/reference/http-api/#protocol-customization 1、 登录thingsboard租户,新建设备 访问令牌很重要,是设备的身份验证,将设备连接到服务器客户端必须在请求URL中指定访问令牌 2、 创建仪表板
JS: Page({ onLoad(){ this.get() this.send() }, send(){ let v1=Math.floor(Math.random()*100) let v2=Math.floor(Math.random()*100) this.setData({ v1:v1, v2:v2 }) wx.request({//发起网络请求 url: 'http://47.107.64.37:8080/api/v1/wx/telemetry',//此处wx为设备的访问令牌,47.107.64.37为服务器IP data:{ value1:v1, value2:v2 }, method:'POST', dataType:'json', success(res){ //console.log(res) }, fail(){ console.log('fail') }, }) setTimeout(this.send,3000) }, get(){ let that=this wx.request({//发起网络请求, url: 'http://47.107.64.37:8080/api/v1/wx/rpc', //此处wx为设备的访问令牌,47.107.64.37为服务器IP method:'GET', success(res){ console.log(res) if(res.data.method=="setSwitch")//Round Switch控件的数据 { that.setData({ switch:res.data.params }) } if(res.data.method=="setTem")//Knob Control控件的数据 { that.setData({ Tem:res.data.params }) } that.get() }, fail(){ that.get() } }) } })4、 调试 编译小程序,小程序向thingsboard发送数据 |
CopyRight 2018-2019 实验室设备网 版权所有 |