Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nothing ever received #330

Open
rwb196884 opened this issue Aug 28, 2024 · 3 comments
Open

Nothing ever received #330

rwb196884 opened this issue Aug 28, 2024 · 3 comments

Comments

@rwb196884
Copy link

I'm using an Arduino nano with an ESP8266 for wifi which I have working for other WiFi projects and I'm trying to subscribe to my mqtt broker on Debian 12 and receive messages.

I never receive anything.

#include <SoftwareSerial.h>
#include <WiFiEsp.h>
#include <MQTT.h> // MQTT by Joel Gaehwiler

// ESP8266 wifi board things.
#define RX 6 // blue
#define TX 7 // black
SoftwareSerial Esp8266(RX, TX);
const char AP[] = "ap";
const char PASS[] = "secret";
WiFiEspClient wifi_client;

// mqtt things.
MQTTClient  mqtt_client;

void setup() {
   pinMode(LED_BUILTIN, OUTPUT);
  Serial.begin(9600);
  Esp8266.begin(9600);
  WiFi.init(&Esp8266);
  
  // Check for the presence of the shield.
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    while (true);
  }

  mqtt_client.begin("192.168.0.113", wifi_client);
  mqtt_client.onMessage(messageReceived);
  reconnect();
}

void loop() {
  if( !mqtt_client.connected()) { reconnect(); }
  mqtt_client.loop();
}

void reconnect() {
  while ( WiFi.status() != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(AP);
    WiFi.begin(AP, PASS);
  }
  Serial.println("WIFI connected.");
  
  while (!mqtt_client.connect("arduino")) {
    Serial.print(".");
    delay(1000);
  }
  Serial.println("MQTT connected.");

  mqtt_client.subscribe("zigbee2mqtt/Home/BoilerFlow");
}

void messageReceived(String &topic, String &payload) {
  Serial.println("mqtt_client.messageReceived: " + topic + " - " + payload);
}

Any ideas?

(PubSubClient doesn't work either and is dead and ArduinoMqttClient won't even connect to the broker; this is my third attempt.)

@256dpi
Copy link
Owner

256dpi commented Aug 30, 2024

From a quick glance I can only imagine that the data is published to "/zigbe2mqtt..." and the subscription is on "zigbee2mqtt..." (note the missing slash at the beginning)? In MQTT the slash at the beginning matters on most brokers.

@rwb196884
Copy link
Author

Leading slash makes no difference.
Same problem on ESP32: nothing ever received.

@ForrestErickson
Copy link

When experimenting with MQTT I like to have a Processing program also working with MQTT.
Here is a link to something I wrote to do so for a bunch of ESP32 assemblies.

https://github.com/nk25719/PMD___aka-KiCad-esp32-6leds-2switches-1pj-circuit-/tree/main/FactoryTest/FT_MQTT/FT_processingPMD_MQTT

You will have to code in your topic to publish and subscribe.

You look in the console window of the IDE for messsages.
image
Make the Processing draw window selected and then press digits to send a simple MQTT message.
image

Hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants