arc*_*ace 2 wifi mqtt iot esp8266 adafruit
我正在开发自己的物联网技术,并使用带有 C/C++ 的 ESP8266。我已经设置了一个程序,允许我通过 gbridge.io 使用 Google Assistant 切换继电器。我使用 MQTT 将它订阅到 gbridge,它告诉它何时切换开关。不幸的是,我对处理网络相关的事情很陌生,所以我这可能是措辞不正确。它侦听(我认为是正确的词)端口 1883。我正在使用这种方法,因为我不想在我的家用路由器上打开一个端口。通过监听 1883 端口,我的路由器是否会暴露或网络易受攻击?此代码来自Adafruit MQTT 库示例。
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"
/************************* WiFi Access Point *********************************/
const char* WLAN_SSID = "SSID";
const char* WLAN_PASS = "password";
/************************* Adafruit.io Setup *********************************/
#define AIO_SERVER "mqtt.gbridge.io"
#define AIO_SERVERPORT 1883 // use 8883 for SSL
#define AIO_USERNAME "gbridge-username"
#define AIO_KEY "mqqt password"
/************ Global State (you don't need to change this!) ******************/
// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;
// or... use WiFiFlientSecure for SSL
//WiFiClientSecure client;
// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, AIO_SERVER, AIO_SERVERPORT, AIO_USERNAME, AIO_KEY);
/****************************** Feeds ***************************************/
// Setup a feed called 'photocell' for publishing.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
Adafruit_MQTT_Publish onoffset = Adafruit_MQTT_Publish(&mqtt,"on off set link");
// Setup a feed called 'onoff' for subscribing to changes.
Adafruit_MQTT_Subscribe onoffbutton = Adafruit_MQTT_Subscribe(&mqtt,"on off link");
Run Code Online (Sandbox Code Playgroud)
2020 年 8 月更新:gbridge 已关闭其服务器
端口 1883 通常用于不安全的 MQTT。这与您的路由器或网络易受攻击无关。它的意思是:
当您通过 SSL 运行 MQTT 时,SSL 将验证连接是否使用属于您尝试连接的域名的证书进行加密。两端也会对所有流量进行加密,使观察方无法窃听。
基于 SSL 的 MQTT 通常在端口 8883 上运行。
这些都不会损害您的网络或危及您的路由器。它只影响 MQTT 客户端和代理之间的通信。
您的 MQTT 客户端未侦听端口 1883 - 它连接到代理上的端口 1883。代理是侦听端口 1883 的代理 - 这就是您不必在路由器上打开端口的原因。
在您上面引用的代码中,您需要使用WiFIClientSecure而不是WiFiClient. 您还需要为要连接的服务器提供证书或指纹。但这与您提出的问题不同;如果您需要帮助,则属于单独的帖子。
| 归档时间: |
|
| 查看次数: |
585 次 |
| 最近记录: |