MQTT connection options #639
Replies: 9 comments
-
Posted at 2016-10-03 by jfox In the code above protocolname, should be protocol_name... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-03 by jfox Well, I believe that I have proved one of my assumptions wrong. So for my one last test I removed the connection options from my code and powered them both up for a test. And now they work as expected. I've done several power cycles on both and cannot get a failure. I don't know what I did right, but I like the result. I would still like to know how to set a client_id and/or set connection options. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-19 by Ollie Just a thought on this. Espruino on ESP8266 now has many more JSvars available to it than the early versions of the port did - and I've been meaning to try the core espruino MQTT module on it to see if it runs - but, back in day, on the development versions, the module was just too big to load and then run any sort of application on the back of. The errors you mention here would suggest to me that it is still too big. Just wondering if merely dumping the connections options as you did was enough to keep within memory.. Can you check |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-26 by jfox Here is the code that works without error:
Here is what process.memory() shows:
Change line 31 from:
to:
This is the result:
Here is what process.memory() shows:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-26 by jfox My MQTT broker is Mosquitto running on a Raspberry Pi. I have three different esp8266s running that use the same wifi and MQTT connection code. 2 of the 3 devices get a different client_id assigned from Mosquitto. The third device ( a Sonoff wifi switch) gets the same client_id as one of the other devices, which disconnects the first device with that client_id to be connected. I understand that this is default and desirable configuration for Mosquitto. I looked at the documentation for the conf file to see if there was a way to have it generate other types of client_ids if the clients are anonymous. I found no way to do this. It looks like my only hope is to be able to set the client_id on the es8266 when the mqtt.connect() happens. I thought that maybe I would have luck with a different MQTT broker. I tried http://andsel.github.io/moquette/. Which runs and appears to work just fine, but it behaves exactly like Mosquitto. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-26 by jfox I thought that maybe the client_id that Mosquitto provided to anonymous clients may somehow be tied to the hardware, MAC address, or IP address. I tried loading the code on to yet another esp8266 that I have. When it does the mqtt.connect() it gets the same client_id from Mosquitto as the other two. I have my router configured to assign each esp8266 (I have six of them so far) a different IP address. But each device gets the same IP each time it connects. Apparently Mosquitto does not pay attention to the IP address of the clients. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-26 by jfox I tried two other things to get Mosquitto to use totally unique client_ids. Then I took out the code that set the hostname and time and uploaded to the sonoff again.
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-26 by jfox I found the cause. WHITESPACE! Yep, if I change the number of spaces at the end of the line of code, after the ; I am using the Web IDE. I have my source code in Atom (because I edit everything in Atom) and then copy/paste the code into the Web IDE. I use the 'Send to Espruino' icon to upload/flash the code to the esp8266. I connect to the esp8266 over wifi to upload/flash. I reset() before every upload/flash and save() after. In WebIDE under Communications I have Reset before Send set, and Set Current Time set. Minification Settings: Later I may toggle some settings and see if I get different results. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2016-10-26 by @gfwilliams Strange... If you're minifying then whitespace shouldn't have an effect - perhaps you could check in the 'setting->console' area and see if it does change what gets sent to Espruino... I'm not sure how well tested the upload over Wifi is... I guess it's possible that you could upload code so quickly over WiFi that buffers get full and Espruino ends up dropping characters... |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2016-10-03 by jfox
I am running v1.87 on an esp8266. I am able to subscribe to an MQTT broker running on my local network. I can publish and subscribe successfully.
I am attempting to publish from one esp8266 and subscribe from another. I believe that both boards use the same default client_id, because when I connect the second one, the first is disconnected.
I would expect to be able to work around this by setting a client_id in the MQTT connection options, as described here: http://www.espruino.com/MQTT
My code looks like this:
I get these errors:
I have tried putting in other things in the connection options, like protocol_name: "MQTT" and get the same result. I get errors regardless of what I put in as a connection option.
If I leave out the connection option I am able to connect and both publish and subscribe.
Beta Was this translation helpful? Give feedback.
All reactions