Arduino IOT Cloud not working with ESP32 [SOLVED]

I have been trying to connect a ESP32 to IOT Cloud unsuccessfully (one day lost on this :-((). Even that I am able to load programs from the web editor to the ESP32 through the USB cable in my computer, the serial monitor does not work and I am not able to run my program without commenting out the arduinoCloud.update() in my program: this function is entered but never exits. It is out of question that without running this function, variables in the cloud are not updated and the cloud is no longer a cloud.

I have been doing ESP32 and Arduino projects with my own MQTT and NodeRed servers. The next step was to go for a "commercial" cloud but the Arduino one does not seem to work.

Before definitely surrending, does anybody have any idea about why arduinoCloud.update() function does not work and why the serial monitor does not work neither when running the web editor ?

I would greatly appreciate any hint because I have no idea about how to proceed to make any progress.

Thanks and best regards

Joan

Hi @arduino1001xxx.

I apologize for the problem with the Arduino Cloud Editor Serial Monitor. The developers are aware of this bug and a fix is in progress. I'll post an update here if I receive any news about a resolution.

Workaround

As a workaround for now, you can use any desktop serial terminal application. Arduino IDE has an easy to use Serial Monitor. You can download Arduino IDE from the links on Arduino's official "Software" page here:


You can also use any of the many nice 3rd party terminal applications that are available if for some reason you don't want to use Arduino IDE. I can recommend the free open source PuTTY:

https://www.chiark.greenend.org.uk/~sgtatham/putty/


:exclamation: If you use a serial terminal application, make sure to close it before uploading a sketch to your board with Cloud Editor the reason is that Cloud Editor needs to use the serial port to upload the sketch and only one application can have the port open at a time. The Cloud Editor Serial Monitor is smart enough to automatically close the port during the upload, but such automatic coordination with Cloud Editor is not possible when using an independent terminal.


I should make it clear that this problem is unrelated to the Serial Monitor bug.

Please post your full sketch.

I'll provide instructions you can follow to do that:

  1. If you are not already, log in to your Arduino account:
    https://login.arduino.cc/login
  2. Click the following link to open the list of your Arduino Cloud Things in the web browser:
    https://app.arduino.cc/things
  3. Click on the Thing you are referring to in your post.
    The Thing's "Setup" page will open.
  4. Click the "Sketch" tab at the top of the page.
    The Thing's "Sketch" page will open.
  5. Click the "Auto indent" button on the toolbar:

    This is done to make the code easier for us to read.
  6. Click on the editor panel of the window.
  7. Press the Ctrl+A keyboard shortcut (Command+A for macOS users).
    This will select all the code.
  8. Press the Ctrl+C keyboard shortcut (Command+C for macOS users).
    This will copy the selected text to the clipboard.
  9. Open a forum reply here by clicking the "Reply" button.
  10. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code block icon on toolbar
  11. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the copied code into the code block.
  12. Move the cursor outside of the code block markup before you add any additional text to your reply.
  13. Click the "Reply" button to post the output.

If your code uses a library that you imported to your Arduino Cloud account (as opposed to the standard libraries that are pre-installed), please post a link to where you downloaded that imported library from.

Thanks very much for your feedback. I need some time to go through it. In the meantime, please find enclosed the program that I have downloaded to the ESP32 and that works if getting rid of arduinoCloud.update().

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/c6a017bf-4abc-484a-b222-8fb47a7cabca 

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int onda;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"

#define LED 17
int timerPeriod = 100; // milliseconds
unsigned long time_now = 0;
bool ledStatus = false;

void setup() {
  
  // Initialize serial and wait for port to open:
  Serial.begin(9600);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500); 

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
 */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

  pinMode(LED, OUTPUT);
  onda=0;
}

void loop() {
  // ArduinoCloud.update();  // blocks main loop !

  // Your code here   
  if (millis() - time_now >= timerPeriod){ // this block will be executed every timerPeriod millis
    time_now = millis();
    ledStatus = !ledStatus;  // toggle led
    digitalWrite(LED, ledStatus);
  } 
  onda = onda+1;   // generating a saw for testing purposes
  if (onda > 20) onda= 0;
}

/*
  Since Onda is READ_WRITE variable, onOndaChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onOndaChange()  {
  // Add your code here to act upon Onda change
}

1- @ptillisch, following your suggestion I have opened the Arduino IDE in my computer when the code in the ESP32 downloaded from the web editor was running and the ESP32 was still connected to the computer with the USB cable, and I have been able to use the serial monitor of the IDE to view the serial messages sent by the program. Thus, while the problem of "serial monitor in the web editor not working" is not solved it has been effectively circumvented following your suggestion. Thanks very much !

2- Going one step further, I have copied the program files in the web editor to the IDE in the computer, I have uncommented the call to arduinoCloud.update(), I have reloaded the program to the ESP32 (now from the IDE, not from the web editor), and I have been able to check that the program not only was not blocked in the call to arduinoCloud.update(), but that the cloud variables were effectively uploaded to the cloud and I could use the cloud dashboard to track them. In other words, the cloud was working.

Once this said, I can work with arduino cloud with the ESP32 in a way that is not the perfect one but that allows to proceed by copying the code from the web editor to the IDE editor and working with it as a "normal" (that is non cloud) program.

It would be great that the development team could definitely solve the problems mentioned, but in the meantime, it is worth mentioning that it is possible to work with the arduino cloud when facing them with a small additional effort.

Thanks very much for your help, @ptillisch !

Joan

Great news!

This should not be required. There isn't any fundamental functional difference in the sketch program when compiled and uploaded by Cloud Editor vs. Arduino IDE.

You are of course welcome to use Arduino IDE for Arduino Cloud IoT Thing sketch development (and if so, you might find this feature useful), but if you consider this approach to be less preferable compared to using Cloud Editor then I'm confident you can solve whatever problem is preventing the use of Cloud Editor.

Please try uploading the Thing sketch using Cloud Editor once again, and then checking to see whether the Thing and dashboard work as expected after you do that. If so, then you will know that you can switch back from Arduino IDE to using Cloud Editor for development of the sketch (with the exception of Cloud Editor's currently bugged Serial Monitor). If you have Arduino IDE running, make sure to close the "Serial Monitor" tab (by clicking the X icon) in Arduino IDE before uploading the sketch via Cloud Editor.

You should still consider it an Arduino Cloud IoT Thing program regardless of which development tool you are using. The program runs on the ESP32 microcontroller, so the development program that happened to be used to compile and upload that program binary is irrelevant.

You should still consider it an Arduino Cloud IoT Thing program regardless of which development tool you are using. The program runs on the ESP32 microcontroller, so the development program that happened to be used to compile and upload that program binary is irrelevant.

As far as I understand it not irrelevant. Cloud variables and related files (thingProperties.h) are created by the Web Editor, not by the local IDE, and thus, when having to change anything related to the variables (number, name, type,...), it has to be done on the web editor.

My statement stands.

It is true that you can't set up an Arduino Cloud IoT Thing via Arduino IDE, but that is a different subject from the question of whether a Thing sketch developed, compiled, and uploaded via Arduino IDE should be considered "non cloud".

The Arduino Cloud web interface will be the most convenient way to set up a thing. Alternatively, you can use Arduino Cloud CLI. After that initial setup, you can use Arduino IDE for all further development.

Hello again @arduino1001xxx. The bug that caused Cloud Editor's Serial Monitor to be stuck in the "Connecting..." state has now been fixed. So you can now return to using Cloud Editor exclusively if you prefer it over Arduino IDE.

Please let us know if you still experience any problems while using it.

I apologize for any inconvenience this has caused.

It works. Thanks !!

I'm glad it is working now. Thanks for taking the time to post an update.

Regards,
Per