hey, please i have the same issue as reported at Uno R4 WiFi not connecting to iot.arduino.cc, but i use a portenta h7 and a 4G GLOBAL module. I have provisioned the device twice, but it is still not working. Does anyone has an idea of what I should do ?? @arduino_team. Below is the code...
#include "thingProperties.h"
#include <Arduino_Cellular.h>
#include <Timezone.h>
ArduinoCellular cellular;
const int LED_PIN = LED_BUILTIN; // Using built-in LED
// Example rules (adjust the specifics to match your locale)
/
// with DST starting on the second last Sunday in March and ending on the first Sunday in November.
TimeChangeRule dstRule = {"DST", Second, Sun, Mar, 2, 1 * 3600}; // DST offset: +1 hours
TimeChangeRule stdRule = {"STD", First, Sun, Nov, 2, 0 * 3600}; // Standard time: +0 hours
Timezone myTZ(dstRule, stdRule);
String getCurrentTime() {
// Retrieve the current UTC time from ArduinoCloud
long utcTime = ArduinoCloud.getLocalTime();
if (utcTime < 100000) {
return "Time not available";
}
// Convert to local time using the Timezone library
time_t localTime = myTZ.toLocal(utcTime);
// Convert Unix timestamp to human-readable format
struct tm *timeInfo = localtime(&localTime);
char buffer[80];
strftime(buffer, sizeof(buffer), "%Y-%m-%d %H:%M:%S", timeInfo);
return String(buffer);
}
/
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(115200);
Serial1.begin(115200);
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
// Defined in thingProperties.h
initProperties();
cellular.setDebugStream(Serial); // Enable debug output
cellular.begin();
for(unsigned long const serialBeginTime = millis(); !Serial && (millis() - serialBeginTime <= 5000); ) { }
Serial.println("Connecting to cellular network...");
if (!cellular.connect()) {
Serial.println("Failed to connect to cellular network!");
while (1);
}
Serial.println("Connected to cellular network!");
// 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 OR DBG_INFO
*/
setDebugMessageLevel(DBG_INFO);
ArduinoCloud.printDebugInfo();
/*
Invoking addCallback
on the ArduinoCloud object allows you to subscribe
to any of the available events and decide which functions to call when they are fired.
The functions `doThisOnConnect`, `doThisOnSync`, `doThisOnDisconnect`
are custom functions and can be named to your likings and for this example
they are defined/implemented at the bottom of the Sketch
*/
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::CONNECT, doThisOnConnect);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::SYNC, doThisOnSync);
ArduinoCloud.addCallback(ArduinoIoTCloudEvent::DISCONNECT, doThisOnDisconnect);
}
unsigned long lastTimePrint = 0;
void loop() {
ArduinoCloud.update();
/
digitalWrite(LED_PIN, (millis() % 2000) < 1000);
/if (millis() - lastTimePrint > 10000) {
Serial.println("Current UK Time: " + getCurrentTime());
lastTimePrint = millis();
}/
}
void doThisOnConnect(){
/* add your custom code here /
Serial.println("Board successfully connected to Arduino IoT Cloud");
}
void doThisOnSync(){
/ add your custom code here /
Serial.println("Thing Properties synchronised");
}
void doThisOnDisconnect(){
/ add your custom code here */
Serial.println("Board disconnected from Arduino IoT Cloud");
}