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

Subscribe not captured messages from other source. #228

Closed
jieweiyang opened this Issue Dec 31, 2016 · 5 comments

Comments

Projects
None yet
2 participants
@jieweiyang

jieweiyang commented Dec 31, 2016

Hello, I am working with below environmeng.

While running the code, both MOSCA and MQTTLens captured the published message.
And the console also received message: Message arrived [keepalive] hello world

But it never capture the the message submit from MQTTLens on same topic, while MOSCA/MQTTLens/HomeBridge captured.

I also tried MQTT client on Android, published message to topic, MOSCA/MQTTLens/HomeBridge captured, but not the PubSubClient.

I monitored the UART of ESP8266 module, it also proved there are data came in.
.+IPD,0,24,192.168.1.50,1883:0...keepalivehello world
.+IPD,0,21,192.168.1.50,1883:0...keepalive{asdfaf}


Code below:

Added a button to publish as below:
client.publish("keepalive", "hello world");

Modified the "reconnect" as below:

void mqttReconn() {
// Loop until we're reconnected
while (!client.connected()) {
Serial.println("Attempting MQTT connection...");
// Attempt to connect, just a name to identify the client
if (client.connect("arduinoClient_1")) {
// Once connected, publish an announcement...
client.publish("keepalive", "hello world");
// ... and resubscribe
client.subscribe("keepalive");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
// Wait 5 seconds before retrying
delay(5000);
}
}
}

void loop() {

if (!client.connected()) {
Serial.println("Disconnected");
mqttReconn();
}

buttonState = digitalRead(Pin_Connect);

if (buttonState == HIGH && buttonState_pre == 0) {
buttonState_pre = 1;
client.publish("keepalive", "hello world");
delay(100);
}
else if (buttonState == LOW) {
buttonState_pre = 0;
}

client.loop();

}

@jieweiyang jieweiyang changed the title from Subscribe not received by PubSubClient from other to Subscribe not received other source. Dec 31, 2016

@jieweiyang jieweiyang changed the title from Subscribe not received other source. to Subscribe not captured messages from other source. Dec 31, 2016

@knolleary

This comment has been minimized.

Show comment
Hide comment
@knolleary

knolleary Dec 31, 2016

Owner

Hi, can you clarify exactly what isn't receiving which message? You say:

While running the code, both MOSCA and MQTTLens captured the published message.
And the console also received message: Message arrived [keepalive] hello world

But it never capture the the message submit from MQTTLens on same topic, while MOSCA/MQTTLens/HomeBridge captured.

Am I reading that right? You say a message being published by mqttlens isn't being received. How is that related to the PubSubClient code?

Owner

knolleary commented Dec 31, 2016

Hi, can you clarify exactly what isn't receiving which message? You say:

While running the code, both MOSCA and MQTTLens captured the published message.
And the console also received message: Message arrived [keepalive] hello world

But it never capture the the message submit from MQTTLens on same topic, while MOSCA/MQTTLens/HomeBridge captured.

Am I reading that right? You say a message being published by mqttlens isn't being received. How is that related to the PubSubClient code?

@jieweiyang

This comment has been minimized.

Show comment
Hide comment
@jieweiyang

jieweiyang Dec 31, 2016

I tested as below:

  1. Message published from PubSubClient:
    Captured - MOSCA - PubSubClient/MQTTLens/HomeBridge/MyMQTT(Android)
    NotCaptured - None

  2. Message published from MQTTLens, and MyMQTT(Android)
    Captured - MOSCA - MQTTLens/HomeBridge/MyMQTT(Android)
    NotCaptured - PubSubClient

Also UART reading showing MOSCA has also send the data to ESP8266 same test 1.

I tried dig into the codes, put console output under PubSubClient::readByte.
Only shows messages publish from PubSubClient and feedback from MOSCA.
But no message which MOSCA received from other source.

Spent hours on this part and can't find a clue...

jieweiyang commented Dec 31, 2016

I tested as below:

  1. Message published from PubSubClient:
    Captured - MOSCA - PubSubClient/MQTTLens/HomeBridge/MyMQTT(Android)
    NotCaptured - None

  2. Message published from MQTTLens, and MyMQTT(Android)
    Captured - MOSCA - MQTTLens/HomeBridge/MyMQTT(Android)
    NotCaptured - PubSubClient

Also UART reading showing MOSCA has also send the data to ESP8266 same test 1.

I tried dig into the codes, put console output under PubSubClient::readByte.
Only shows messages publish from PubSubClient and feedback from MOSCA.
But no message which MOSCA received from other source.

Spent hours on this part and can't find a clue...

@jieweiyang

This comment has been minimized.

Show comment
Hide comment
@jieweiyang

jieweiyang Jan 1, 2017

THe issue should be related to Wifi component.

NOt related to pubsubclient, sorry for the inconvenient.

jieweiyang commented Jan 1, 2017

THe issue should be related to Wifi component.

NOt related to pubsubclient, sorry for the inconvenient.

@jieweiyang

This comment has been minimized.

Show comment
Hide comment
@jieweiyang

jieweiyang Jan 3, 2017

Just found the real reason.
My ESP8266 is connected to Arduino via UART, which far slower then the arduino clock.
In the sample code provided by PubSubClient, "client.loop()" running on every main loop().
The loop caused the UART communication flooded with STATUS message, and corrupted the message from MQTT broker.

After I added the interval for client.loop() and client.connected, like 100ms, then everything works fine.

jieweiyang commented Jan 3, 2017

Just found the real reason.
My ESP8266 is connected to Arduino via UART, which far slower then the arduino clock.
In the sample code provided by PubSubClient, "client.loop()" running on every main loop().
The loop caused the UART communication flooded with STATUS message, and corrupted the message from MQTT broker.

After I added the interval for client.loop() and client.connected, like 100ms, then everything works fine.

@knolleary

This comment has been minimized.

Show comment
Hide comment
@knolleary

knolleary Jan 3, 2017

Owner

Good to know. Thanks for the update.

Owner

knolleary commented Jan 3, 2017

Good to know. Thanks for the update.

@knolleary knolleary closed this Jan 3, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment