Note that there are some explanatory texts on larger screens.

plurals
  1. POArduino Knolleary PubSubClient will publish messages but can't receive them
    primarykey
    data
    text
    <p>I am using the Knolleary PubSubClient to make a connection to my MQTT server. I have been able to successfully authenticate and make a connection after not much work. I can even publish messages to topics. However, the issue I am having is that I can subscribe to topics and get no error, but when I publish to that topic (from mosquitto on my Mac) the callback does not get called and the message to the subscribe topic does not appear to be received. I have tried running a mosquitto subscription to the same topic at the same time, and that does receive the published message. Not sure if there is a problem in my callback code or what is going on here. Any help would be appreciated. Arduino code is below:</p> <pre><code>/* Basic MQTT example - connects to an MQTT server - publishes "hello world" to the topic "outTopic" - subscribes to the topic "inTopic" */ #include &lt;SPI.h&gt; #include &lt;Ethernet.h&gt; #include &lt;PubSubClient.h&gt; // Update these with values suitable for your network. byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; byte server[] = { 10, 2, 63, 123 }; byte ip[] = { 192, 168, 1, 10 }; void callback(char* topic, byte* payload, unsigned int length) { Serial.println(topic); //convert byte to char payload[length] = '\0'; String strPayload = String((char*)payload); Serial.println(strPayload); //int valoc = strPayload.lastIndexOf(','); //String val = strPayload.substring(valoc+1); //Serial.println(val); } EthernetClient ethClient; PubSubClient client(server, 1883, callback, ethClient); void setup() { Serial.begin(19200); Serial.println("==STARTING=="); // start the Ethernet connection: if (Ethernet.begin(mac) == 0) { Serial.println("Failed to configure Ethernet using DHCP"); // no point in carrying on, so do nothing forevermore: // try to congifure using IP address instead of DHCP: Ethernet.begin(mac, ip); } // give the Ethernet shield a second to initialize: delay(1000); Serial.println("connecting..."); for (byte thisByte = 0; thisByte &lt; 4; thisByte++) { // print the value of each byte of the IP address: Serial.print(Ethernet.localIP()[thisByte], DEC); Serial.print("."); } //delay(500); boolean con = client.connect("1", "3snzzon5dyade:abc", "OBSCURED_FOR_SEC"); while(con != 1){ Serial.println("no con-while"); con = client.connect("1", "3snzzon5dyade:abc", "OBSCURED_FOR_SEC"); } //Serial.println(con); if(con){ Serial.println("got con"); client.publish("testq","hello world"); client.subscribe("testq"); }else Serial.println("no con"); } void loop() { client.loop(); } </code></pre> <p>Like I said, I can see everything working properly with mosquitto. I have even tried matching up client_ids with no luck. Any help or ideas would be greatly appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload