and I need the WiFiClient object that gets initialized when the Arduino gets connected to the wifi, and since that procedure is handled automatically by WiFiConnectionHandler when using the Arduino "thing" Editor, i have no idea how to get that object.
Is there any ArduinoCloud docs I can check, or does anyone know any function that should return said object?
Related question on this note. I'm trying to use the Nano RP 2040 Connect as a Modbus Client.
I want to:
read from the modbus server over TCP via WiFi
publish result to IoT Cloud
I can get the ArduinoModbus library to work without ArduinoCloud connection. I can also get the ArduinoCloud Connection up and running. But, when I combine the two the device crashes when trying to open the connection to the Modbus Client.
Would be most grateful of some help! Thanks!
MWE:
#include "thingProperties.h"
#include "ArduinoRS485_RP2040.h"
#include "ArduinoModbus_RP2040.h"
#include "WiFiNINA.h"
WiFiClient wifiClient;
ModbusTCPClient modbusTCPClient(wifiClient);
IPAddress server(192, 168, 1, 10); // ip address of modbus server
bool iotCloudConnected = false;
void setup() {
Serial.begin(9600);
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, onArduinoIOTCloudConnect);
}
void loop() {
// Update cloud with new values
ArduinoCloud.update();
// Modbus connection only if connected to IOT cloud
if (iotCloudConnected) {
// DOESN'T CRASH HERE
if (!modbusTCPClient.begin(server)) {
// CRASHES AS SOON AS modbusTCPClient.begin(server) called
Serial.println("Modbus TCP Client failed to connect!");
} else {
...
}
}
}
void onArduinoIOTCloudConnect() {
Serial.println("Board successfully connected to Arduino IoT Cloud");
// Reassign modbus client to use arduino IOT connection
modbusTCPClient = ModbusTCPClient(ArduinoIoTPreferredConnection.getClient());
iotCloudConnected = true;
}
From my experience, i can say the behaviour can change depending on the library used with ArduinoIoTCloud.
I can suggest you to try 3 things:
Use the ArduinoIoTPreferredConnection.getClient() client instead of WiFiNINA, to connect your library to the internet ( This rarely works, most of the time libraries are compatible with different internet client connections, but just a few are compatible with ArduinoIoTCloud's client)
however, it is clearly not comprehensive because the functions mentioned by the developer in that issue are not mentioned there or in any other official documentation I have seen.
If you feel that this is something Arduino needs to resolve, I would recommend you to reopen https://github.com/arduino-libraries/ArduinoIoTCloud/issues/314 so that they can effectively track the task. Closing the issue indicates that the problem is resolved and I don't feel that is so.
Hoah! This is awesome, didn't know about this cheatsheet, it really must be new since the last revision was today.
I've been struggling hard for the past 3 months on finding docs about the arduinoCloud library, and most of the time I just found solutions on projects that were similar to my aim, so this cheatsheet is a lifesaver
I agree, I closed the issue because mine was just a question, and I had it solved, but considering that I'll reopen it so they can add those methods to the documentation.