远程实体按键
本帖最后由 7zxc 于 2022-7-1 20:22 编辑已经通过点灯科技添加了几个设备,现在能APP控制,想用ESP8266做个远程实体按键控制所添加的设备,有办法吗?
以前用TCP可以实现,现在改过来点灯科技不知道怎么接入,和怎么发送指令!!
2022/7/1:还是用回去TCP,点灯科技MQTT组通信不会用,下面效果
https://www.bilibili.com/video/BV13S4y1n7t1?pop_share=1
用8266控制其他8266? 奈何col 发表于 2022-6-13 09:10
用8266控制其他8266?
是的,之前用用一个8266建了TCP服务器,另一个连接发送数据可以实现控制,现在想用小爱同学接入了点灯科技,就不知道怎连接了,理论APP发送的数据,用8266也能发送 如果设备都在同一局域网中,可以通过websocket通信,否则,通过mqtt通信
mqtt通信参考:
https://diandeng.tech/doc/api-mqtt
组件通信指令参考:
https://diandeng.tech/doc/cmd
coloz 发表于 2022-6-15 09:09
如果设备都在同一局域网中,可以通过websocket通信,否则,通过mqtt通信
mqtt通信参考:
https://diandeng. ...
谢谢,放假试了下mttq,点灯科技的broker.diandeng.tech每次获取连接信息,都将重置iotToken,要设备一直保持通电且不能再获取连接信息,否则又要新写username: iotId,password: iotToken,是不是可以通过每次ESP8266开机先获取这2个信息 7zxc 发表于 2022-6-26 21:18
谢谢,放假试了下mttq,点灯科技的broker.diandeng.tech每次获取连接信息,都将重置iotToken,要设备一直 ...
参考点灯sdk 楼主成功了么?实体键连接blinker mqtt?
我试了一下用js的mqtt.js
然后。按钮这儿连上mqtt那物联网8266芯片那边就连接出错了
然后8266重连成功之后,按钮这儿又失败了。
应该是一个设备只能有1个mqtt连接,一旦8266连了,js按钮这儿就断开了。反之亦然。
这个有啥办法解决么?
Arduino这儿的log
09:29:54.502 -> reconnect_time: 0
09:29:54.649 -> Connection failed
09:29:54.649 -> Retrying MQTT connection in 5 seconds...
09:29:59.667 -> Connecting to MQTT...
09:29:59.667 -> reconnect_time: 1
09:29:59.773 -> Connection failed
js的log
连接成功
mqtt.html:33 发布成功
mqtt.html:28 订阅成功
mqtt.html:46 收到消息: /device/xxxxxxxxx/r {"fromDevice":"xxxxxxx","data":{"btn-light":"on"}}
8266连上之后 js这儿的log
连接失败: Error: Connection refused: Bad username or password
at MqttClient._handleConnack (mqtt.js:1390:17)
at MqttClient._handlePacket (mqtt.js:551:12)
at work (mqtt.js:440:12)
at writable._write (mqtt.js:454:5)
at doWrite (mqtt.js:15942:139)
at writeOrBuffer (mqtt.js:15931:5)
at Writable.write (mqtt.js:15840:11)
at Duplexify.ondata (mqtt.js:14885:20)
at emitOne (mqtt.js:6481:13)
at Duplexify.emit (mqtt.js:6559:7) onwebbe 发表于 2022-9-6 09:38
楼主成功了么?实体键连接blinker mqtt?
我试了一下用js的mqtt.js
然后。按钮这儿连上mqtt那物联网8266芯片 ...
1.一个authkey只能一个设备使用,每次获取连接信息,都将重置iotToken
2.按键也做为一个单独的设备,然后:
let device = new BlinkerDevice('authkey',{
sourceCheck: false, // 关闭sourceCheck
});
3.再向指定设备发送数据
let message = {"abc" : 123}
let toDevice = 'ABCDEFGHIJ' // 目标设备的识别码
device.sendMessage(message, toDevice) 本帖最后由 onwebbe 于 2022-9-7 00:47 编辑
谢谢 奈何col
试着blinker里面新建了一个独立设备。。用这个设备去拿auth
然后用这个设备去登录mqtt然后toDevice里面用8266开关的device id
但是从8266的log里面发现一点奇怪的东西。。我送的数据是{"btn-light": "on"}
不知道咋回事。。到了8266设备里面就被auto format成了{light-slide: {"val":0}}。我的8266的设备没有ligh-slide, 只有一个按钮btn-light
8266的log如下
00:18:55.434 -> Got: {"fromDevice":"js_client_device_name","data":{"btn-light":"on"}}
00:18:55.434 -> data: {"btn-light":"on"}
00:18:55.434 -> fromDevice: js_client_device_name
00:18:55.434 -> _sharerCount: 0
00:18:55.434 -> ERROR: No authority&share uuid found, check is from bridge/share device, data: {"btn-light":"on"}
00:18:55.468 -> available: 1
00:18:55.468 -> checkAvail: 1
00:18:55.468 -> parse data: {"fromDevice":"js_client_device_name","data":{"btn-light":"on"}}
00:18:55.468 -> defined BLINKER_ARDUINOJSON
00:18:55.468 -> autoManager begin: 0 0
00:18:55.468 -> get_key: null
00:18:55.468 -> checkNum count: 1
00:18:55.504 -> checkNum count: 1
00:18:55.504 -> Blinker readString: {"fromDevice":"js_client_device_name","data":{"btn-light":"on"}}
00:18:55.504 -> autoFormatData key: light-slide, json: "light-slide":{"val":0}
00:18:55.504 -> new.
00:18:55.504 -> flush
00:18:55.504 -> needFreshShare
00:18:55.504 -> message: /share/device?deviceName=8266devicename&key=8266devicekey
00:18:55.504 -> blinker server begin
00:18:55.504 -> Freeheap: 32584
00:18:55.678 -> HTTPS begin: http://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=8266devicename&key=8266deviceauthtoken
00:18:55.678 -> HTTPS payload: /share/device?deviceName=8266devicename&key=8266deviceauthtoken
00:18:55.678 -> status... code: 200
00:18:55.678 -> {"detail": {"users": []}, "message": 1000}
00:18:55.678 -> _type: 16
00:18:55.678 -> payload: {"users":[]}
00:18:55.678 -> sharers data: {"users":[]}
00:18:55.713 -> print: {"light-slide":{"val":0}}
00:18:55.713 -> Proto print...
00:18:55.713 -> Freeheap: 32488
奈何col 发表于 2022-9-6 12:52
1.一个authkey只能一个设备使用,每次获取连接信息,都将重置iotToken
2.按键也做为一个单独的设备,然后 ...
试了一下。下载了blinker-js,然后改了一下example
会把{"btn-light":"on"}改成"light-slide":{"val":0}
JS Code:
import { BlinkerDevice } from '../lib/blinker';
import { ButtonWidget, NumberWidget } from '../lib/widget';
let device = new BlinkerDevice("BUTTON-DEVICE-NAME", {
sourceCheck: false
});
device.ready().then(() => {
let message = {"btn-light" : "on"}
let toDevice = 'SWITCH-DEVICE-NAME' // 目标设备的识别码
device.sendMessage(message, toDevice)
});
have strange issue as below log in 8266 SWITCH Device side:
13:46:05.573 -> Got: {"fromDevice":"BUTTONID","data":{"btn-light":"on"}}
13:46:05.606 -> data: {"btn-light":"on"}
13:46:05.606 -> fromDevice: BUTTONID
13:46:05.606 -> _sharerCount: 0
13:46:05.606 -> ERROR: No authority&share uuid found, check is from bridge/share device, data: {"btn-light":"on"}
13:46:05.639 -> available: 1
13:46:05.639 -> checkAvail: 1
13:46:05.639 -> parse data: {"fromDevice":"BUTTONID","data":{"btn-light":"on"}}
13:46:05.639 -> defined BLINKER_ARDUINOJSON
13:46:05.639 -> autoManager begin: 0 0
13:46:05.639 -> get_key: null
13:46:05.639 -> checkNum count: 1
13:46:05.639 -> checkNum count: 1
13:46:05.639 -> Blinker readString: {"fromDevice":"BUTTONID","data":{"btn-light":"on"}}
13:46:05.639 -> autoFormatData key: light-slide, json: "light-slide":{"val":0}
13:46:05.673 -> new.
13:46:05.673 -> flush
13:46:05.673 -> needFreshShare
13:46:05.673 -> message: /share/device?deviceName=SWICHID&key=SWICHKEY
13:46:05.673 -> blinker server begin
13:46:05.673 -> Freeheap: 32664
13:46:05.851 -> HTTPS begin: http://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=SWICHID&key=SWICHKEY
13:46:05.851 -> HTTPS payload: /share/device?deviceName=SWICHID&key=SWICHKEY
13:46:05.851 -> status... code: 200
13:46:05.851 -> {"detail": {"users": []}, "message": 1000}
13:46:05.851 -> _type: 16
13:46:05.851 -> payload: {"users":[]}
13:46:05.851 -> sharers data: {"users":[]}
13:46:05.885 -> print: {"light-slide":{"val":0}}
13:46:05.885 -> Proto print...
13:46:05.885 -> Freeheap: 32568
13:46:05.885 -> isJson: {"data":{"light-slide":{"val":0}},"fromDevice":"SWICHID","toDevice":"APPDEVICEID","deviceType":"OwnApp"}
13:46:05.885 -> MQTT Publish...
13:46:05.885 -> Freeheap: 32568
13:46:05.885 -> _print_times: 1
13:46:05.885 -> {"data":{"light-slide":{"val":0}},"fromDevice":"SWICHID","toDevice":"APPDEVICEID","deviceType":"OwnApp"}
13:46:05.918 -> ...OK!
13:46:05.918 -> Freeheap: 31896
13:46:05.918 -> Freeheap: 32928
13:46:35.922 -> MQTT Ping!
13:46:35.922 -> Freeheap: 33968
页:
[1]