MKR WIFI 1010 is working but just can't connect to Cloud

Hi all,

I am new to here. I facing issue when MKR wifi 1010 connecting to Arduino cloud. The Wifi is 2.4g and is stable. This mkr able to connect to cloud, sometime or just few day it just not able to connect to cloud. I have restart mkr few time. sometime it works.
I attached my code here. it is simple. wonder is my code issue or any place can improve it.

> #include "thingProperties.h"
> #include <ArduinoModbus.h>
> 
>   
> // Declaration
> const int ledPin = LED_BUILTIN;
> int ledState = LOW;
> unsigned long previousMillis = 0;
> const long interval = 1000;
> 
> void setup() {
>   Serial.begin(9600);
>   delay(1500); 
> 
>   // Defined in thingProperties.h
>   initProperties();
> 
>   // Connect to Arduino IoT Cloud
>   ArduinoCloud.begin(ArduinoIoTPreferredConnection);
>   
>   setDebugMessageLevel(2);
>   ArduinoCloud.printDebugInfo();
>   //My Code start here
>   delay(5000);
>   pinMode(LED_BUILTIN, OUTPUT);
>   
>   //start Modbus RTU client
>   if (!ModbusRTUClient.begin(9600)) {
>     Serial.println("Failed to start Modbus RTU Client");
>     while(1){
>       digitalWrite(LED_BUILTIN, LOW);
>     }
>   }
> }
> 
> void loop() {
>   ArduinoCloud.update();
>   
>   //*****Modbus Code start here*****
>   if (!ModbusRTUClient.requestFrom(1,HOLDING_REGISTERS,0X2600,4)) {
>     Serial.println("Failed to read rgister");
>     digitalWrite(LED_BUILTIN, HIGH);
>     led = HIGH;
>   } else 
>   {
>     //*****this is to check arduino heart beat*****
>     unsigned long currentMillis = millis();
>     if (currentMillis - previousMillis >= interval) {
>       previousMillis = currentMillis;
>     
>       if (ledState == LOW) {
>         ledState = HIGH;
>       } else {
>         ledState = LOW;
>       }
>     }
>     digitalWrite(LED_BUILTIN, ledState);
>     led = ledState;
>     
>     uint16_t word1 = ModbusRTUClient.read();
>     uint16_t word2 = ModbusRTUClient.read();
>     uint16_t word3 = ModbusRTUClient.read();
>     uint16_t word4 = ModbusRTUClient.read();
>    
>     value1 = word1;
>     value2 = word2;
>     value3 = word3;
>     value4 = word4;
>   }
>   
> }

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.