|
| 1 | +# Get More Logs out of the Arduino IoTCloudLibrary |
| 2 | + |
| 3 | +As of today, the [ArduinoIoTCloud](https://github.com/arduino-libraries/ArduinoIoTCloud) library does not have any specific verbose logs, so tracing complex workflows like the Over-the-Air (OTA) update process can become quite challenging. |
| 4 | + |
| 5 | +I created a humble [fork](https://github.com/zmoog/ArduinoIoTCloud) of the library, with just a very few additional log statements. |
| 6 | + |
| 7 | +## Get the Library Fork |
| 8 | + |
| 9 | +Visit https://github.com/zmoog/ArduinoIoTCloud and: |
| 10 | + |
| 11 | +- select `zmoog/more-logs-in-ota-process` from the branch dropdown on the left; |
| 12 | +- select Code > Download ZIP from the green actions dropdown on the right; |
| 13 | + |
| 14 | +Save the ZIP file on your computer to use it as a custom library on the Cloud Editor. |
| 15 | + |
| 16 | +## Set up your Sketch |
| 17 | + |
| 18 | +Make sure your sketch is configured to use the most verbose log level: |
| 19 | + |
| 20 | +```c |
| 21 | +//Get Cloud Info/errors , 0 (only errors) up to 4 |
| 22 | +setDebugMessageLevel(4); |
| 23 | +``` |
| 24 | +
|
| 25 | +## Upload the IoTCloudLibrary as a Custom Library on the Arduino Cloud Editor |
| 26 | +
|
| 27 | +Visit https://create.arduino.cc/editor and click on Libraries > Custom. |
| 28 | +
|
| 29 | +Click on the import icon (near the "Library Manager" button), and upload your custom version of the library. |
| 30 | +
|
| 31 | +Great! Starting from now, every time you build a sketch that requires the IoTCloudLibrary this custom version will be used! |
| 32 | +
|
| 33 | +TIP: remove this custom library after the test, or you won't get new updates to the original library. |
| 34 | +
|
| 35 | +## Upload and Run the Sketch on the Board |
| 36 | +
|
| 37 | +Run a new “verify and upload” using an Over-the-Air device, and now you will see additional information in the Serial Monitor, like the following output (this is a successful OTA update): |
| 38 | +
|
| 39 | +``` |
| 40 | +## Comment: board 1st boot |
| 41 | + |
| 42 | +[2021-10-26 11:48:22] ***** Arduino IoT Cloud - configuration info ***** |
| 43 | +[2021-10-26 11:48:22] Device ID: 46854c56-8237-49a6-93d7-217be67b1951 |
| 44 | +[2021-10-26 11:48:22] Thing ID: 298a6dc2-4018-46cd-9255-6b6c6a5007a0 |
| 45 | +[2021-10-26 11:48:22] MQTT Broker: mqtts-sa.iot.arduino.cc:8883 |
| 46 | +[2021-10-26 11:48:22] WiFi.status(): 0 |
| 47 | +[2021-10-26 11:48:22] Current WiFi Firmware: 1.4.8 |
| 48 | +[2021-10-26 11:48:26] Connected to "Middle Earth" |
| 49 | +[2021-10-26 11:48:26] ArduinoIoTCloudTCP::handle_SyncTime internal clock configured to posix timestamp 1635241707 |
| 50 | +[2021-10-26 11:48:27] ArduinoIoTCloudTCP::handle_ConnectMqttBroker connecting to mqtts-sa.iot.arduino.cc:8883 (attempt 0) |
| 51 | +[2021-10-26 11:48:30] ArduinoIoTCloudTCP::handle_ConnectMqttBroker connected to mqtts-sa.iot.arduino.cc:8883 |
| 52 | +[2021-10-26 11:48:34] Sd card not detected |
| 53 | +[2021-10-26 11:48:34] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribing to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/e/i ... |
| 54 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribed to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/e/i |
| 55 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribing to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/shadow/i ... |
| 56 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribed to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/shadow/i |
| 57 | +[2021-10-26 11:48:35] Connected to Arduino IoT Cloud |
| 58 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_RequestLastValues [15670] last values requested |
| 59 | +[2021-10-26 11:48:37] ArduinoIoTCloudTCP::handleMessage [17497] last values received |
| 60 | + |
| 61 | +## Comment: 1st boot completed, now the sketch is running. |
| 62 | + |
| 63 | + |
| 64 | +... time passes ... |
| 65 | + |
| 66 | + |
| 67 | +## Comment: I click on “verify and upload” and the OTA process starts |
| 68 | + |
| 69 | +[2021-10-26 11:50:30] ArduinoIoTCloudTCP::onOTARequest _ota_url = https://api2.arduino.cc/iot/ota/38d59aee-e004-4dd7-8b79-716c4e7678dc |
| 70 | +[2021-10-26 11:50:30] ArduinoIoTCloudTCP::samd_onOTARequest downloading to nina: https://api2.arduino.cc/iot/ota/38d59aee-e004-4dd7-8b79-716c |
| 71 | +[2021-10-26 11:50:44] ArduinoIoTCloudTCP::samd_onOTARequest download successful |
| 72 | +[2021-10-26 11:50:44] ArduinoIoTCloudTCP::samd_onOTARequest performing reset to reboot |
| 73 | + |
| 74 | +## Comment: the board resets |
| 75 | + |
| 76 | +[2021-10-26 11:51:04] ***** Arduino IoT Cloud - configuration info ***** |
| 77 | +[2021-10-26 11:51:04] Device ID: 46854c56-8237-49a6-93d7-217be67b1951 |
| 78 | +[2021-10-26 11:51:04] Thing ID: 298a6dc2-4018-46cd-9255-6b6c6a5007a0 |
| 79 | +[2021-10-26 11:51:04] MQTT Broker: mqtts-sa.iot.arduino.cc:8883 |
| 80 | +[2021-10-26 11:51:04] WiFi.status(): 0 |
| 81 | +[2021-10-26 11:51:04] Current WiFi Firmware: 1.4.8 |
| 82 | +[2021-10-26 11:51:08] Connected to "Middle Earth" |
| 83 | +[2021-10-26 11:51:08] ArduinoIoTCloudTCP::handle_SyncTime internal clock configured to posix timestamp 1635241868 |
| 84 | +[2021-10-26 11:51:09] ArduinoIoTCloudTCP::handle_ConnectMqttBroker connecting to mqtts-sa.iot.arduino.cc:8883 (attempt 0) |
| 85 | +[2021-10-26 11:51:12] ArduinoIoTCloudTCP::handle_ConnectMqttBroker connected to mqtts-sa.iot.arduino.cc:8883 |
| 86 | +[2021-10-26 11:51:16] Sd card not detected |
| 87 | +[2021-10-26 11:51:16] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribing to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/e/i ... |
| 88 | +[2021-10-26 11:51:16] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribed to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/e/i |
| 89 | +[2021-10-26 11:51:16] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribing to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/shadow/i ... |
| 90 | +[2021-10-26 11:51:17] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribed to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/shadow/i |
| 91 | +[2021-10-26 11:51:17] Connected to Arduino IoT Cloud |
| 92 | +[2021-10-26 11:51:17] ArduinoIoTCloudTCP::handle_RequestLastValues [15249] last values requested |
| 93 | +[2021-10-26 11:51:18] ArduinoIoTCloudTCP::handleMessage [16648] last values received |
| 94 | + |
| 95 | +## Comment: the process completed successfully. |
| 96 | +``` |
| 97 | +
|
| 98 | +## Optional: How to access the serial port from the terminal |
| 99 | +
|
| 100 | +Personally, during these troubleshooting sessions I use the `minicom` utility. |
| 101 | +
|
| 102 | +Get the port currently used by the board: |
| 103 | +
|
| 104 | +```shell |
| 105 | +$ arduino-cli board list |
| 106 | +Port Protocol Type Board Name FQBN Core |
| 107 | +/dev/cu.URT0 serial Unknown |
| 108 | +/dev/cu.usbmodem1101 serial Serial Port (USB) Arduino NANO 33 IoT arduino:samd:nano_33_iot arduino:samd |
| 109 | +``` |
| 110 | + |
| 111 | +Open minicom using the serial port `/dev/cu.usbmodem1101`: |
| 112 | + |
| 113 | +```shell |
| 114 | +$ minicom -D /dev/cu.usbmodem1101 |
| 115 | +``` |
| 116 | + |
| 117 | +TIP: Pressing `Meta-N` on the `minicom` console you also get a nice timestamp on each line: |
| 118 | + |
| 119 | +``` |
| 120 | +[2021-10-26 11:48:22] ***** Arduino IoT Cloud - configuration info ***** |
| 121 | +[2021-10-26 11:48:22] Device ID: 46854c56-8237-49a6-93d7-217be67b1951 |
| 122 | +[2021-10-26 11:48:22] Thing ID: 298a6dc2-4018-46cd-9255-6b6c6a5007a0 |
| 123 | +[2021-10-26 11:48:22] MQTT Broker: mqtts-sa.iot.arduino.cc:8883 |
| 124 | +[2021-10-26 11:48:22] WiFi.status(): 0 |
| 125 | +[2021-10-26 11:48:22] Current WiFi Firmware: 1.4.8 |
| 126 | +[2021-10-26 11:48:26] Connected to "Middle Earth" |
| 127 | +[2021-10-26 11:48:26] ArduinoIoTCloudTCP::handle_SyncTime internal clock configured to posix timestamp 1635241707 |
| 128 | +[2021-10-26 11:48:27] ArduinoIoTCloudTCP::handle_ConnectMqttBroker connecting to mqtts-sa.iot.arduino.cc:8883 (attempt 0) |
| 129 | +[2021-10-26 11:48:30] ArduinoIoTCloudTCP::handle_ConnectMqttBroker connected to mqtts-sa.iot.arduino.cc:8883 |
| 130 | +[2021-10-26 11:48:34] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribing to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/e/i ... |
| 131 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribed to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/e/i |
| 132 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribing to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/shadow/i ... |
| 133 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_SubscribeMqttTopics subscribed to /a/t/298a6dc2-4018-46cd-9255-6b6c6a5007a0/shadow/i |
| 134 | +[2021-10-26 11:48:35] Connected to Arduino IoT Cloud |
| 135 | +[2021-10-26 11:48:35] ArduinoIoTCloudTCP::handle_RequestLastValues [15670] last values requested |
| 136 | +[2021-10-26 11:48:37] ArduinoIoTCloudTCP::handleMessage [17497] last values received |
| 137 | +
|
| 138 | +``` |
0 commit comments