IoT Cloud Variables not updated from Dashboard

Hello

I have created the simplest possible application for Nano IoT 33 with just one LED connected to one output. The idea is to control the LED via a Dashboard switch.

However nothing happens when I change the state of the switch on the dashboard. The cloud variable is not updated and the LED is not turned on.

According to serial port output the Nano is connected to my WiFi and also connected to the IoT cloud:

***** Arduino IoT Cloud - 2.4.0 *****
Device ID: 63fbed88-b031-4322-bdc7-42ff8bea4b8a
MQTT Broker: iot.arduino.cc:8885
WiFi.status(): 0
Current WiFi Firmware: 2.0.0
Connected to "xxxxxxx"
ArduinoIoTCloudTCP::handle_ConnectMqttBroker could not connect to iot.arduino.cc:8885 Error: -2
Connected to Arduino IoT Cloud
Thing ID: 5693eb61-3e97-42b3-b3be-f14070de3ecd

The sketch looks like this:

type or paste code here

  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/5693eb61-3e97-42b3-b3be-f14070de3ecd 

  Arduino IoT Cloud Variables description

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

  bool ledKytkin;

  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 ledLahto = 5;

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

  pinMode(ledLahto,OUTPUT);
}

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

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

  if(ledKytkin==true)  {
    digitalWrite(ledLahto, HIGH);
  }
  else
    digitalWrite(ledLahto,LOW);
}

I can't understand what could be wrong? I have re-installed the Cloud Agent several times and deleted and recreated the Device and the Thing and the Dashboard and the Cloud Variable several times but nothing seems to help.

Any help would be welcome.

Hi, the code seems fine.
You're defining pin 5 as output, with pinMode(ledLahto,OUTPUT);

Have you connected a LED or something to pin 5?
Can you share a schema or a picture?

Also, can you try to print something to the serial monitor, in onLedKytkinChange.
Something like

if(ledKytkin==true)  {
    Serial.println("LED ON");
    digitalWrite(ledLahto, HIGH);
  }
  else {
    Serial.println("LED OFF");
    digitalWrite(ledLahto,LOW);
  }

Warning: I haven't tested this code... in case a semicolon or a parenthesis is missing :smile:

Hi

Thanks for replying

Yes, I have connected an LED via a resistor to pin 5 and I have tested that it works. I tried a version of the program where I defined a pin as input that switches on the LED when activated and it worked fine. So the connection is all right.

I also have tried printing a notification to the serial monitor, but nothing happens. It seems that the OnledKytkinChange() routine is not called at all even though I change the state of the switch in the dashboard. As I wrote earlier, it seems that the variable ledKytkin is not updated at all even though I change its state in the dashboard.

I have also tried updating the ledKytkin variable in the program (it is a read/write variable) but the modified value is not passed to the dashboard. it simply stays False all the time.

I tested your code and it seems to work fine.
Can you please check that ledKytkin has "On change" as Variable Update Policy, like in the screenshot below?

Yes, it is defined as "On change".

I don't know if this is pertinent info, but the mobile dashboard via Android remote IOT is not working. The dashboard takes ages to load and when it finally is loaded the control
is greyed out (disabled).

What I can suggest is to increase the debug verbosity updating this line in your code

setDebugMessageLevel(2);

using 4 instead of 2. This way you should be able to see additional info in the serial monitor, in case there are connection problems.
As I wrote above, I successfully tested your code (on a different board though) so I would say that everything is fine from a coding point of view.

Can you please check if something useful appears in the serial monitor after increasing verbosity?

And by the way, can you give us some details about the browser and operating system?

Hi, and apologies for late replying

My system is a Windows 11 laptop/tablet. I always install the latest Windows updates so the computer should be OK. My antivirus software is Windows Defender and the Windows firewall is enabled.

I checked the firewall settings in both the computer and my cable wifi unit and in both cases there are no restrictions. Everything should pass through.

Finally I got hold of a Huawei portable Wifi unit and connected both the Nano and my computer through it ... and it worked!

Apparently my cable wifi modem is to blame. The firewall settings seem to be OK (no restrictions) and yet the connection failed every time. There were no error messages etc. butt it just didn't work. With the mobile unit it worked like a charm every time.

Perhaps my cable system provider places some restrictions, I don't know and haven't asked them.

Thank you for your assistance in solving this issue.

2 Likes