IOT CLOUD using MKR1310 via LORA - Possible Bug ?

Hi There,

I've been struggling for days over this issue, and now have tried 3x different MKR1310's and 2x different LORA gateways just to confirm there isn't a hardware issue that is complicating things.

The problem is as follows :
I'm connecting to the IOT Cloud using a MKR1310 via LORA communication.
Sensor data is read by the arduino and submitted to the cloud via read only variables periodically.
This works perfectly.

But the issue starts when you create a read&write variable which updates "on change".
Like turning on the builtin LED via a switch on the cloud. Sounds simple enough, but the switch never does anything. ( this same example works perfectly with a Nano BLE 33 via wifi ).

After a lot of trial and error, I found a work-around : if you add another variable ( updated periodically) which isn't even used, then the "onchange" variable will action straight after the period lapses. A minimum time of 20 seconds update period seems to be stable, any quicker and I get LORA errors.

My code ( sunshine.ino ) is as follows :

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/5487850d-3cf8-4a56-a73c-719d5e278a19 

  Arduino IoT Cloud Variables description

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

  int watchD;
  bool led;

  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"

const int ledpin = 6;

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); 
pinMode(ledpin,OUTPUT);
  // 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();
}

void loop() {
  ArduinoCloud.update();
  // Your code here 
  
  
}



/*
  Since Led is READ_WRITE variable, onLedChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLedChange()  {
  // Add your code here to act upon Led change
if(led)
  {
    digitalWrite(ledpin,HIGH);
    Serial.println("ON");
  }
  else
  {
    digitalWrite(ledpin,LOW);
    Serial.println("OFF");
  }
  
}

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

And the thingProperties.h is as follow :

// Code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>


const char THING_ID[] = "5487850d-3cf8-4a56-a73c-719d5e278a19";

const char APPEUI[]   = SECRET_APP_EUI;
const char APPKEY[]   = SECRET_APP_KEY;

void onWatchDChange();
void onLedChange();

int watchD;
bool led;

void initProperties(){
  ArduinoCloud.setThingId(THING_ID);
//  ArduinoCloud.addProperty(watchD, 2, READWRITE, 20 * SECONDS, onWatchDChange);
  ArduinoCloud.addProperty(led, 1, READWRITE, ON_CHANGE, onLedChange);

}

LoRaConnectionHandler ArduinoIoTPreferredConnection(APPEUI, APPKEY, _lora_band::EU868);

The switch in the Cloud App is :

The code above doesn't work, even thought the same setup via WIFI and a BLE33 works great.

Uncommenting the last function in the Sunshine.ino and "onWatchDChange" line in the thingProperies.h should cause the program to at least function with a 20sec delay before cloud switch is actioned.

I would appreciate if someone with a MKR1310 could confirm if they have the same behaviour on the Arduino IOT Cloud ?

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