DataLogger IoT & ThingSpeak Connection Issue

I had an issue with getting the DataLogger IoT connected with ThingSpeak. I keep getting the error:

[W] ThingSpeak MQTT disconnected - reconnecting.......[E] ThingSpeak MQTT: Connection Error [-2]
36.710,23.561,99605.406,33429.094,176
[W] ThingSpeak MQTT disconnected - reconnecting.......[E] ThingSpeak MQTT: Connection Error [-2]
36.710,23.390,99603.187,16636.340,176

I’ve double-checked everything multiple times but cannot find the issue…

Settings on DataLogger:
    Settings
         1)  Enabled - Enable or Disable the MQTT Client  : true
         2)  Port - The MQTT broker port to connect to  : 8883
         3)  Server - The MQTT server to connect to  : mqtt3.thingspeak.com
         4)  MQTT Topic - The MQTT topic to publish to  : 
         5)  Client Name - Name of this device used for MQTT Communications  : PAoLFDAHNjITKw4pNQkbGic
         6)  Username - Username to connect to an MQTT broker, if required  : PAoLFDAHNjITKw4pNQkbGic
         7)  Password - Password to connect to an MQTT broker, if required  : ************************
         8)  Buffer Size - MQTT payload buffer size. If 0, the buffer size is dynamic  : 0
         9)  CA Cert Filename - File to load the certificate from  : ThingsSpeakCertificate.cer
        10)  Client Cert Filename - File to load the client certificate from  :
        11)  Client Key Filename - File to load the client key from  :
        12)  Channels - Comma separated list of <device name>=<channel ID>  : BME68x=2783896

Is there anybody having the same issue or having an idea what could cause the problem?

Thanks a lot! :slight_smile:

You can try most of the suggestions here ThingSpeak MQTT: Connection Error [-2] - Google Search ; I’d start with regenerating credentials and maybe trying the alternate port number (1883), set your router/firewall, ensure you aren’t already using the username or cert on another client, etc

Ok I’ve figured it out :slight_smile:

I have built a Python script to test sending data to ThingSpeak, which gave me a more detailed feedback to debug the issue. The problem was indeed the certificate. I’ve proceeded according to the instructions on Mathworks (linked in original post) - but due to domain forwarding, that ended up not working (the URL gets forwarded to thingspeak.mathworks.com ). Not having too much knowledge how certificates work did not help either.

What ended up working is using the URL api.thingspeak.com (doesn’t get forwarded) and export the certificate from there. DataLogger is successfully publishing data now.

1 Like