Mkr Wan 1310 onChange issue

I have recently started playing around with the Mkr series Lora module together with the Arduino cloud features.

No issues with connection, and sending data from the device to a dashboard on the cloud works well.

However, if I try to set up an onChange variable it only seems to execute the onChange function on the first start up run.

Simplified Code:

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/e22d0a2e-d860-4385-afbe-eba73037fce2 

  Arduino IoT Cloud Variables description

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

  bool testSetting;

  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"

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); 

  // 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 
  
  Serial.println(testSetting);
  delay(500);
}


/*
  Since TestSetting is READ_WRITE variable, onTestSettingChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onTestSettingChange()  {
  // Add your code here to act upon TestSetting change
  Serial.println("Test Setting changed");
}

If I change the variable: testSetting in my dashboard, while the code is running, nothing happens (as in the loop runs, but the onChange function is not called). If I then restart the board the function is called once, reading the new testSetting value. So basically, the onChange function is only called on startup, not on Change as it should.

The exact same code runs flawlessly on a GSM module. And yes, the Wan has a confirmed connection to the LoRa network in the above scenario.

Seems to be a bug with the arduino.update function for the Wan 1310 setup.

How exactly is the testSetting variable defined on the IoT page ?

In the dash the testSetting is just associated with a switch. Boolean 0/1.

The thingProperties.h code looks like this:

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

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


const char THING_ID[] = "e22d0a2e-d860-4385-afbe-eba73037fce2";

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

void onTestSettingChange();

bool testSetting;

void initProperties(){
  ArduinoCloud.setThingId(THING_ID);
  ArduinoCloud.addProperty(testSetting, 1, READWRITE, ON_CHANGE, onTestSettingChange);

}

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

I seem to have exactly the same issue.

Whats weird though, if I have a variable created with a "periodic" update then the readwrite ( onchange ) variable will update shortly after the periodic one does successfully ?

Did you ever get a solution?

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