Hi, I hope this is the right place to post this, because I don’t know where the problem lies.
I’ve created a iot-cloud project, but once I upload it using PlatformIO the board gets stuck on ArduinoCloud.begin(ArduinoIoTPreferredConnection) (connect to wifi). This didn’t happened while uploading the (same) code over the official Arduino IDE.
The problem could be in the Arduino_ConnectionHandler library, or in the board renesas-ra/uno_r4_wifi itself. Does anyone has a iot-cloud project on an Arduino UNO R4 wifi?
You can find the project sourcecode on rogermiranda1000/ArduinoIotCloudWeatherStation.
The first step is to turn up debug log verbosity to the absolute maximum and compare.
The ArduinoIoTCloud library does use the Arduino_DebugUtils library for optional debug output. That’s actually runtime configurable. You just have to add
Adding those instructions (before initProperties()) didn’t make any difference at all (maybe setDebugMessageLevel(2) already does that?). The logs with PlatformIO were inexistent, while Arduino IDE provided:
***** Arduino IoT Cloud - configuration info *****
Device ID: [device ID]
MQTT Broker: mqtts-up.iot.arduino.cc:8884
WiFi.status(): 0
Current WiFi Firmware: 0.2.0
Connected to [SSID]
ArduinoIoTCloudTCP::handle_SubscribeDeviceTopic could not subscribe to /a/d/[device ID]/e/i
ArduinoIoTCloudTCP::handle_Disconnect MQTT client connection lost
Connected to Arduino IoT Cloud
Thing ID: [thing ID]
Okay. After hotfixing the debugging non-working debugger, I can see strange behavior: In the .begin() call, the call to RTC.begin() fails (it goes in the else path) and then the code… just stops executing. No matter whether I type continue or step in the GDB client or press the play / step over button, the code won’t advance. I haven’t see anything like this before…
the first line loads r3 with 1, aka the value for true. It then does a store byte (strb) of the r3 value into the memory addresses (r4 + 0), aka r4. After that, is_initialized = true. But then it unconditionally loads r3 with 0 again (false) and stores that again in r4. So it gets set to false again. Then, the b.n is an unconditional branch that takes the execution back to the begining of the code where it calls openRtc().
What the hell. The compiler output is just insane.
Also, the function has an obvious bug: It is supposed to return bool, but there is not a single return statement in that function. There should be a return is_initialized; at the end. I’ll correct that and see if the compiler’s head clears up.
Now, after the strb, it correctly loads the just-saved value into r0, which is the “return value register” and does a pop {r4, pc} to cleanup the stack and return from the freaking function.
And what do you know, now it also prints stuff to the serial monitor.
It’s the same bug again. The compiler is generating garbage code because there is no return in that function, execution falls through in a place where it’s not supposed to be and it ends up decoding very weird instructions.
***** Arduino IoT Cloud - configuration info *****
Device ID: My Device Login Name
MQTT Broker: mqtts-up.iot.arduino.cc:8884
WiFi.status(): 0
Current WiFi Firmware: 0.1.0
Connected to "Vodafone-XXXX"
I2C error.
ArduinoIoTCloudTCP::handle_ConnectMqttBroker In order to connect to Arduino IoT Cloud, WiFi firmware needs to be >= 0.2.0, current 0.1.0
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to mqtts-up.iot.arduino.cc:8884
ArduinoIoTCloudTCP::handle_ConnectMqttBroker 1 connection attempt at tick time 20030
I2C error.
I2C error.
I2C error.
Are you sure about that? After the fix I get two I2C error, and then nothing (just like the fatal crash from the beginning).
Note: getting I2C error means that you don’t have the sensors I have, don’t worry about that part.
Seems that it works now. It was indeed read_needed, but from WiFiSSLClient (not WiFiUDP). @maxgerhardt would you propose a PR, just like you did with the first “missing return”?
is broken as well, but I can’t PR a fix into that because it’s already been fixed in the 1.0.2 version of the framework. PlatformIO currently uses 1.0.1.
1.0.2 does have the bug in RTC.begin(), but not in the WiFi library anymore. I’ve also added that as info to the opened issue. Hope PlatformIO can get out a package update soon.
Then you should have framework version 1.0.2 (fixes the bugs in WiFiUDP/WiFiSSLClient library) that has on top that of my RTC fix included. Then no manual file modifications should be needed.
Can you test whether that then works out-of-the-box?