【发布时间】:2016-02-20 09:29:51
【问题描述】:
我知道,我的问题可能很简单,但我已经三天无法弄清楚这些东西了。
我需要通过 ESP8266 模块从我的 Arduino nano 向 MQTT 服务器发送一些请求。我找到了这个任务的好库 - PubSubClient.h。这是一个如何做到这一点的例子:
#include <Ethernet.h>
#include <PubSubClient.h>
// Update these with values suitable for your network.
byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED };
IPAddress ip(172, 16, 0, 100);
IPAddress server(172, 16, 0, 2);
void callback(char* topic, byte* payload, unsigned int length) {
// handle message arrived
}
EthernetClient ethClient;
PubSubClient client(server, 1883, callback, ethClient);
但我不使用以太网屏蔽。我使用连接到数字端口的 ESP8266 并创建 SoftwareSerial 端口以使用 wifi 传输数据:
SoftwareSerial espSerial(8,7);
而且我不能同时使用 SoftwareSerial 端口和 PubSubClient。 当我尝试这种方式时: PubSubClient 客户端(服务器,1883,0,espSerial); 我得到了错误:
no matching function for call to 'PubSubClient::PubSubClient(byte [4], int, int, SoftwareSerial&)'
我一直试图在整个互联网上找到解决方案,但没有成功。请帮我解决这个问题。我应该做些什么? 我为我糟糕的英语道歉
【问题讨论】:
-
您是在 8266 上运行 C/C++ 还是 Lua? Lua 可能会做more sense here...其实这个程序有多大?你需要使用arduino吗? nodemcu 模块(不到 7 美元)有很多 I/O 引脚、1 个模拟输入、pwm 等...