Mqtt not connecting problems


#1

Im trying to use the mqtt library with a particle photon. I created my own internal mqtt (mosquitto) broker server, connecting fine to it from other clients.

with the photon and the mqtt library, even with the example script in the mqtt library, i get wierd connecting issues connecting to a mqtt server. sometimes it thinks it connects, sometimes it doesnt, if it does it never last longer then 15 secoonds. sometimes i can push through a message or two when it does connect. it also seems to be trying to constantly reconnect, even though it says the connection was successful in the script. I imagine that this is the mqtt client thread running still. Then, it looks like the photon crashes (ill get red flashing light and it pops off the wireless)

i cant seem to see why it crashes, tried 2 different photons. I wrapped eveything up in try: clauses to try to get an error, but nothing. I really wish I could see a crash report somehow.

the errors I get on the mqtt server is socket error from the client connecting and also the server saying client is already connected, and closing the connection and establishing a new, over and over, like the client keeps trying to reconnect anyway.

the wireless connection is tested and solid, im sitting los next to the ap. i get 1-5ms ping times to the photon.

anyone have any insight why is all this happening? I was really hoping this part would be stable.

update: crashes and reconnecting issues seem to all stop when I comment out the client.loop line. It actually connects the first time and holds. So the problem is in the client.loop thread function?


#2

Hi @Rykker,

can you tell me if the particle photon is connecting with a client ID already used by a connected client?
If so, can you try using a different client ID?

Thank you


#3

It is the only client connecting at the moment, I plan on adding more later, but just trying to get the first one to work.

I tried changing up the client ID a few times to try to get different results, but all the same

It holds a connection to the mqtt broker only if the client.loop is not initialized, still.

I tried a seperate command line connection with a different client id to verify the mqtt broker is working correctly.

The socket error i get on the mqtt server from the client after client.loop starts, is much more common then the client already connected error. the client already connected error seems to only pop up after its been getting repeated socket errors. maybe some compatibility problem with mosquitto mqtt broker server?

I’m going to try to dive deeper in it tonight, try to get some more verbose logging, and see if i can get it to act any different to get more clues on the problem.


#4

more testing got me nowhere. no matter what the client name, what i publish or subscribe to,even if i dont publish or subscribe to anything, the second i start the client.loop the connection breaks and retries over and over giving the socket errors on the mqtt server.

So it appears the inital connection from the client.connect() is successful, its the client.loop thread that throws it into a reconnect

So if im NOT publishing or subscribing anything, what is the client.loop doing exactly then? Cause whatever that is , is having the issue. Its not the client.connect or the initial connection, Its whatever that client.loop is doing when its initialized.

here is a sample of the mqtt broker log, you can see it happens very fast (this log snapshot is only 1 second long as you can see):

1528891625: New client connected from 192.168.1.76 as zerynth-mqtt (c1, k60).
1528891625: Socket error on client zerynth-mqtt, disconnecting.
1528891625: New connection from 192.168.1.76 on port 1883.
1528891625: New client connected from 192.168.1.76 as zerynth-mqtt (c1, k60).
1528891625: Socket error on client zerynth-mqtt, disconnecting.
1528891625: New connection from 192.168.1.76 on port 1883.
1528891625: New client connected from 192.168.1.76 as zerynth-mqtt (c1, k60).
1528891625: Socket error on client zerynth-mqtt, disconnecting.
1528891625: New connection from 192.168.1.76 on port 1883.
1528891625: New client connected from 192.168.1.76 as zerynth-mqtt (c1, k60).
1528891625: Socket error on client zerynth-mqtt, disconnecting.


#5

Hi @Rykker,

I made some investigation and unfortunately an issue with non-TLS connections has been introduced in the latest bcm43362 update: we’re working to fix it.

In the meantime you could replace installed driver with an older one that you can find on our GitHub repo (checkout version r2.1.0) which would not support TLS but will work for your case. (driver folder: zerynth2/dist/r2.1.1/libs/official/zerynth/mqtt).

Let me know if this works :slight_smile:


#6

I pulled down the r2.1.0 bcm43362 and i was a bit confused and couldnt get it to work in the zerynth2/dist/r2.1.1/libs/official/zerynth/mqtt directory, but when I just overwrite the original one in the zerynth2/dist/r2.1.1/libs/official/broadcom/bcm43362 it works!

I can work with this until the patch makes it in the next version.
Thanks!