远程实体按键-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 1523|回复: 10

[已解答] 远程实体按键

[复制链接]
发表于 2022-6-13 08:59 | 显示全部楼层 |阅读模式
本帖最后由 7zxc 于 2022-7-1 20:22 编辑

已经通过点灯科技添加了几个设备,现在能APP控制,想用ESP8266做个远程实体按键控制所添加的设备,有办法吗?
以前用TCP可以实现,现在改过来点灯科技不知道怎么接入,和怎么发送指令!!


2022/7/1:还是用回去TCP,点灯科技MQTT组通信不会用,下面效果

1

1


发表于 2022-6-13 09:10 | 显示全部楼层
用8266控制其他8266?
 楼主| 发表于 2022-6-13 12:44 | 显示全部楼层
奈何col 发表于 2022-6-13 09:10
用8266控制其他8266?

是的,之前用用一个8266建了TCP服务器,另一个连接发送数据可以实现控制,现在想用小爱同学接入了点灯科技,就不知道怎连接了,理论APP发送的数据,用8266也能发送
发表于 2022-6-15 09:09 | 显示全部楼层
如果设备都在同一局域网中,可以通过websocket通信,否则,通过mqtt通信
mqtt通信参考:
https://diandeng.tech/doc/api-mqtt

组件通信指令参考:
https://diandeng.tech/doc/cmd
 楼主| 发表于 2022-6-26 21:18 | 显示全部楼层
coloz 发表于 2022-6-15 09:09
如果设备都在同一局域网中,可以通过websocket通信,否则,通过mqtt通信
mqtt通信参考:
https://diandeng. ...

谢谢,放假试了下mttq,点灯科技的broker.diandeng.tech每次获取连接信息,都将重置iotToken,要设备一直保持通电且不能再获取连接信息,否则又要新写username: iotId,password: iotToken,是不是可以通过每次ESP8266开机先获取这2个信息
发表于 2022-6-27 08:23 | 显示全部楼层
7zxc 发表于 2022-6-26 21:18
谢谢,放假试了下mttq,点灯科技的broker.diandeng.tech每次获取连接信息,都将重置iotToken,要设备一直 ...

参考点灯sdk
发表于 2022-9-6 09:38 | 显示全部楼层
楼主成功了么?实体键连接blinker mqtt?
我试了一下用js的mqtt.js
然后。按钮这儿连上mqtt那物联网8266芯片那边就连接出错了
然后8266重连成功之后,按钮这儿又失败了。

应该是一个设备只能有1个mqtt连接,一旦8266连了,js按钮这儿就断开了。反之亦然。
这个有啥办法解决么?

Arduino这儿的log
09:29:54.502 -> [1103980] reconnect_time: 0
09:29:54.649 -> [1104136] Connection failed
09:29:54.649 -> [1104136] Retrying MQTT connection in 5 seconds...
09:29:59.667 -> [1109136] Connecting to MQTT...
09:29:59.667 -> [1109136] reconnect_time: 1
09:29:59.773 -> [1109252] 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)
发表于 2022-9-6 12:52 | 显示全部楼层
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)
发表于 2022-9-7 00:31 | 显示全部楼层
本帖最后由 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 -> [1032517] Got: {"fromDevice":"js_client_device_name","data":{"btn-light":"on"}}
00:18:55.434 -> [1032518] data: {"btn-light":"on"}
00:18:55.434 -> [1032518] fromDevice: js_client_device_name
00:18:55.434 -> [1032520] _sharerCount: 0
00:18:55.434 -> [1032523] ERROR: No authority&share uuid found, check is from bridge/share device, data: {"btn-light":"on"}
00:18:55.468 -> [1032552] available: 1
00:18:55.468 -> [1032553] checkAvail: 1
00:18:55.468 -> [1032553] parse data: {"fromDevice":"js_client_device_name","data":{"btn-light":"on"}}
00:18:55.468 -> [1032553] defined BLINKER_ARDUINOJSON
00:18:55.468 -> [1032558] autoManager begin: 0 0
00:18:55.468 -> [1032560] get_key: null
00:18:55.468 -> [1032562] checkNum count: 1
00:18:55.504 -> [1032565] checkNum count: 1
00:18:55.504 -> [1032567] Blinker readString: {"fromDevice":"js_client_device_name","data":{"btn-light":"on"}}
00:18:55.504 -> [1032576] autoFormatData key: light-slide, json: "light-slide":{"val":0}
00:18:55.504 -> [1032582] new.
00:18:55.504 -> [1032583] flush
00:18:55.504 -> [1032585] needFreshShare
00:18:55.504 -> [1032587] message: /share/device?deviceName=8266devicename&key=8266devicekey
00:18:55.504 -> [1032595] blinker server begin
00:18:55.504 -> [1032597] Freeheap: 32584
00:18:55.678 -> [1032750] HTTPS begin: http://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=8266devicename&key=8266deviceauthtoken
00:18:55.678 -> [1032750] HTTPS payload: /share/device?deviceName=8266devicename&key=8266deviceauthtoken
00:18:55.678 -> [1032759] [HTTP] status... code: 200
00:18:55.678 -> [1032762] {"detail": {"users": []}, "message": 1000}
00:18:55.678 -> [1032767] _type: 16
00:18:55.678 -> [1032768] payload: {"users":[]}
00:18:55.678 -> [1032773] sharers data: {"users":[]}
00:18:55.713 -> [1032775] print: {"light-slide":{"val":0}}
00:18:55.713 -> [1032778] Proto print...
00:18:55.713 -> [1032781] Freeheap: 32488
发表于 2022-9-7 13:51 | 显示全部楼层
奈何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 -> [713713] Got: {"fromDevice":"BUTTONID","data":{"btn-light":"on"}}
13:46:05.606 -> [713714] data: {"btn-light":"on"}
13:46:05.606 -> [713714] fromDevice: BUTTONID
13:46:05.606 -> [713717] _sharerCount: 0
13:46:05.606 -> [713719] ERROR: No authority&share uuid found, check is from bridge/share device, data: {"btn-light":"on"}
13:46:05.639 -> [713748] available: 1
13:46:05.639 -> [713748] checkAvail: 1
13:46:05.639 -> [713749] parse data: {"fromDevice":"BUTTONID","data":{"btn-light":"on"}}
13:46:05.639 -> [713749] defined BLINKER_ARDUINOJSON
13:46:05.639 -> [713753] autoManager begin: 0 0
13:46:05.639 -> [713755] get_key: null
13:46:05.639 -> [713758] checkNum count: 1
13:46:05.639 -> [713760] checkNum count: 1
13:46:05.639 -> [713762] Blinker readString: {"fromDevice":"BUTTONID","data":{"btn-light":"on"}}
13:46:05.639 -> [713771] autoFormatData key: light-slide, json: "light-slide":{"val":0}
13:46:05.673 -> [713777] new.
13:46:05.673 -> [713778] flush
13:46:05.673 -> [713780] needFreshShare
13:46:05.673 -> [713782] message: /share/device?deviceName=SWICHID&key=SWICHKEY
13:46:05.673 -> [713790] blinker server begin
13:46:05.673 -> [713792] Freeheap: 32664
13:46:05.851 -> [713960] HTTPS begin: http://iot.diandeng.tech/api/v1/user/device/share/device?deviceName=SWICHID&key=SWICHKEY
13:46:05.851 -> [713960] HTTPS payload: /share/device?deviceName=SWICHID&key=SWICHKEY
13:46:05.851 -> [713968] [HTTP] status... code: 200
13:46:05.851 -> [713972] {"detail": {"users": []}, "message": 1000}
13:46:05.851 -> [713977] _type: 16
13:46:05.851 -> [713978] payload: {"users":[]}
13:46:05.851 -> [713982] sharers data: {"users":[]}
13:46:05.885 -> [713984] print: {"light-slide":{"val":0}}
13:46:05.885 -> [713988] Proto print...
13:46:05.885 -> [713990] Freeheap: 32568
13:46:05.885 -> [713992] isJson: {"data":{"light-slide":{"val":0}},"fromDevice":"SWICHID","toDevice":"APPDEVICEID","deviceType":"OwnApp"}
13:46:05.885 -> [714006] MQTT Publish...
13:46:05.885 -> [714008] Freeheap: 32568
13:46:05.885 -> [714010] _print_times: 1
13:46:05.885 -> [714013] {"data":{"light-slide":{"val":0}},"fromDevice":"SWICHID","toDevice":"APPDEVICEID","deviceType":"OwnApp"}
13:46:05.918 -> [714025] ...OK!
13:46:05.918 -> [714026] Freeheap: 31896
13:46:05.918 -> [714028] Freeheap: 32928
13:46:35.922 -> [744043] MQTT Ping!
13:46:35.922 -> [744043] Freeheap: 33968
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2024-11-28 08:47 , Processed in 0.093003 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表