Not Connecting to MQTT Server

Attempting to create my first Arduino IoT cloud project. I have done F/W for dozens of years - so in theory this should not be an issue.
I have tested this both with the BASIC CLOUD environment and by porting it to a VSCode/PlatformIO environment - no difference.

I have a basic ESP8266 which connects to my network without issue - and can access things on the internet (NTP server for example) - however when it attempts to connect to the MQTT server - it simply prints out the typical failure message - and continue to re-attempt it.

I have seen two different MQTT servers:

  1. iot.arduino.cc (which is what the CLOUD environment provides)
  2. mqtts-up.iot.arduino.cc - which i have seen in other comments

Neither work - and i have tested them with ports 8883 and 8884.

I am at a loss - and after playing for a couple days - feel that it is either not a viable solution - or I am missing something REAL SILLY (hope the latter).

The one area I dont have a clue about is the SECRET DEVICE KEY - does that have to have anything specific within it - or just a simple STRING.

Thanks

Hi @jime77. Are you writing the code from scratch?

I suggest you start by using the Arduino Cloud website to set up a Thing and provision a Device for your ESP8266 board. Arduino Cloud generates a basic skeleton for your sketch, which contains all the code necessary to communicate with Arduino Cloud via MQTT. There is an overview of the process here:

https://docs.arduino.cc/arduino-cloud/guides/overview/#a-walkthrough-the-arduino-cloud

This will give you a starting point of a fully working project. You can then use that as a reference if you want to go back to your original endeavor of writing the code from scratch.

Hi there - please understand that while I started coding from my environment - when it failed -- I SHIFTED to using the JUST the cloud environment and downloaded it directly from the Cloud service to my board via the USB port (I did follow that "walkthrough" you linked)

It still did NOT work - same error displayed. Sidenote I turned on ALL DEBUG messages in case there was some oddity.

Note too that I can not "ping" the Address provided - but I know that it may be disabled at the Cloud end of things.

I am going to attempt to create a totally NEW instance (i.e. delete ALL THINGS) in case I have done something silly.

I do ask again - the SECRET DEVICE KEY - is this just a STRING that I provide - and/or does it have any requirements as to length, contents, or such? Note I have tried a simple numeric code - and a STRING - with no difference.

It is provided to you when you create the Device. If you didn't record it at that time, delete the existing Device and then create it again. Make sure to use that Device in your Thing, and the secret key in the Thing's "network configuration".

OK

I deleted ALL the parts and pieces - and started from Ground Zero - strictly using the CLOUD at this moment - and behold at least the UPLOAD aspects work. Important part is that the MQTT server is connecting - which was initial stumbling block.

Now to begin the fine tuning and learning the features and functions. And see what flexibility exist in the Charts and such (I am spoiled from Blynk Legacy).

The Button is not working at this moment - but that could be something silly on my part.

Will port to my "Local Environment" shortly - and we will see how it unfolds.

Thanks for the support.

So the Button issue is resolved (appears using D8 is not viable for some reason - even though D6 and D7 are fine - OH well - that is another challenge) - But overall it is a Yea.

Ported it to my Local Environment (VSCode w/ PlatformIO) - and it still FAILS. My design uses my standard WiFi configuration logic - so I had to make a shift to the Library to use its instance vs doing one it self. That seemed to work from a WiFI point - but no MQTT connection.
So i removed my WiFi configuration and restored the Library - and it fails to connect to my WiFi (even though it works fine with the CLOUD or my configuration).

In short - something is serious amiss with regards to the system if not using the Cloud - which is not my first choice (i.e. my environment has been built over several years - and using multiple "external agents" without issue (Blynk, MQTT/NodeRed, HomeAssistant, RemoteXY, etc.) - so at this moment I am going to step away from this solution. Bummer - but I have spent WAY too much time - just attempting to get the basics working.

Thanks

ESP pins can have several functions. D8 is such a pin.
See this page (click).
Leo..

I can tell you from personal experience that there is no problem developing Arduino Cloud IoT Thing projects locally using Arduino IDE. This is not surprising since the same build system is used by both Cloud Editor and Arduino IDE.

I would also be willing to bet that there would be no problem developing a Thing project using Microsoft's "Arduino" VS Code extension (which also uses the same build system).

PlatformIO is a different animal, and not something I am knowledgeable about. However, I've never heard of a case of a technical limitation of the flexible PlatformIO framework preventing someone from being unable to accomplish something with PlatformIO that can be accomplished with the Arduino development tools.

I'm sorry that Arduino Cloud didn't work out for you. If you ever decide to give it another try, you are welcome to resume the discussion here. I have essentially no experience with PlatformIO, but I know some of the other forum helpers use it so they might be able to assist you.

Ptillisch
So my final comments for this moment.
I went to my local Arduino IDE - and copied things down and installed the Library - and behold it compiled and works.
I went back to the VSCode/PlatformIO environment ( which i need to use for a bunch of reasons ). NOTE this is using Version 2.0 library too. And found the following after many hours of playing around and recompiling things - with initially allowing the IoTCloud to handle all the WiFi stuff (this would need work later ) it is basically just the ArduinoIDE files - with a small wrapper of my existing setup/loop code - but otherwise it is strictly the ArdinoIoTCloud code doing all the work.

FIRST: It would NOT connect to my WiFi - however the solution was that the timeout of the WiFi was at 3 seconds - and can take upto 10sec. So with that change - it would connect - YEA

SECOND: Two different situations manifested.

  1. It simply would NOT connect to the MQTT server (and note it was using the same host and port as the Arduino IDE). Even with multiple cycles of allowing it to connect. And basically was stuck in the State-Machine of connecting.
  2. It would connect to the MQTT server - but in attempting to finish the connection and report "success" it caused a RESET-FAILURE of accessing an invalid memory location (could be at 0x0 but not certain yet). Learned this much by putting in numerous prints to track the code flow.

Anyway - I don't know the version of the Arduino IDE library (compared to GitHub/PlatformIO) - so don't know if this is new to 2.0 - or ????? Saying this as i thought I had a single success cycle when I used 1.5.1 version - but it was not real consistent and was not duplicatable.

Anyway - if you hear of any issue with the Opensource Library - please let me know.

Thanks for the time and support

1 Like