Mqtt Ошибка программного обеспечения: соединение прервано - PullRequest
0 голосов
/ 19 июня 2019

Я пытаюсь отправить данные из nodemcu (esp32) в raspberry pi с помощью mqtt. После подключения к сети Wi-Fi эта ошибка возникает. Ошибка: Попытка подключения MQTT ... [E] [WiFiClient.cpp: 365] write (): сбой на fd 55, номер ошибки: 113, «Прерывание соединения из-за программного обеспечения» ошибка, rc = -4 повторить попытку через 5 секунд

Nodemcu не может подключиться к брокеру mosquitto mqtt, работающему на Raspberry Pi. Я попытался проверить, открыт ли порт 1883 или есть какие-либо проблемы на брокере rpi mqtt. Там не найдено никаких проблем. Перепробовал несколько библиотек. Но результат остается таким же. Это код, который я использую:

#include "EspMQTTClient.h"

EspMQTTClient client(
  "XXXXX",
  "XXXXX",
  "XXXXXX",  // MQTT Broker server ip
     // Can be omitted if not needed
     // Can be omitted if not needed
  "TestClient",     // Client name that uniquely identify your device
  1883              // The MQTT port, default to 1883. this line can be omitted
);

void setup()
{
  Serial.begin(9600);

  // Optionnal functionnalities of EspMQTTClient : 
  client.enableDebuggingMessages(); // Enable debugging messages sent to serial output
  client.enableHTTPWebUpdater(); // Enable the web updater. User and password default to values of MQTTUsername and MQTTPassword. These can be overrited with enableHTTPWebUpdater("user", "password").
  client.enableLastWillMessage("TestClient/lastwill", "I am going offline");  // You can activate the retain flag by setting the third parameter to true
}

// This function is called once everything is connected (Wifi and MQTT)
// WARNING : YOU MUST IMPLEMENT IT IF YOU USE EspMQTTClient
void onConnectionEstablished()
{
  // Subscribe to "mytopic/test" and display received message to Serial
  client.subscribe("refrigerator/temp", [](const String & payload) {
    Serial.println(payload);
  });

  // Publish a message to "mytopic/test"
  client.publish("refrigerator/temp", "Temp=34"); // You can activate the retain flag by setting the third parameter to true

  // Execute delayed instructions
  client.executeDelayed(5 * 1000, []() {
    client.publish("refrigerator/temp", "Temp=23");
  });
}

void loop()
{
  client.loop();
}
...