arduino-libraries / ArduinoMqttClient

ArduinoMqttClient Library for Arduino
GNU Lesser General Public License v2.1
186 stars 73 forks source link

MQTT won't connect to AWS IoT without serial connection. #62

Open weimiao86 opened 2 years ago

weimiao86 commented 2 years ago

Hi,

I am using the Arduino MKR NB1500 to connect to the AWS IoT. My current issue is the MQTT won't connect to AWS if the USB serial port is not recognized by my computer. Scenarios as below.

  1. Power the Arduino from computer USB and the serial port shows up (COM6). MQTT works fine, it can connect to the cellular network and AWS.
  2. Power the Arduino from computer USB with charging only USB cable, which means there is no serial port showing up in computer device manager. the cellular network connection is fine, but the MQTT won't connect.
  3. Power the Arduino from a power bank with a data-supported USB (the one used to download code to Arduino). The cellular network connection is fine, but the MQTT won't connect.
  4. I tried to power the Arduino from the VIN pin, got the same result, it can connect to the cellular network, but won't connect to AWS.

My final goal is to power the Arduino from the power bank or VIN pin, but none of them work.

Please help, thank you! here is the log.

124

per1234 commented 2 years ago

Hi @weimiao86. Do you have something like this in your sketch?

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

This code will cause the sketch to wait there until the serial port is opened. That is useful because, without it, you would not be able to see important information printed to Serial between the time the program started and when you got Serial Monitor open.

However, you must not have this code in a sketch that is intended to run without a serial connection because that would mean the program hangs at that line forever.

weimiao86 commented 2 years ago

@per1234 No, I don't have while (!Serial) in my code. The code will run and it stops when establishing the MQTT connection.

robauto commented 2 years ago

A question related: So this could could be our AWS endpoint refusing (we can't ping the device either) - assuming this is not the serial loop (this has been addressed) what is the recommendation for learning what is causing the connection to fail? We have used AT tests, viewed log files.

weimiao86 commented 2 years ago

The Pubsubclient works with a battery. I don't understand why this library requires the serial connection to work.

hcorn82 commented 1 year ago

I am having the same issue with MK1000 and ArduinoMqttClient. Keeping the board plugged into a computer isn't really feasible for my application. And for Pubsubclient I can't seem to get it to work with MK1000 and wifi101 library. Anyone have success with alternatives to ArduinoMqttClient and wifi101 or something that works on MK1000?

weimiao86 commented 1 year ago

@hcorn82 From my test, I found it may also be related to the computer or the driver. Try downloading the code to Arduino on a different computer, or try the Arduino online IDE https://create.arduino.cc/editor, it works for me.

hcorn82 commented 1 year ago

@weimiao86 I've been using the Arduino web editor. But with my limited knowledge I am unable to get Wifi101 working without while (!Serial).