Using dimmedlight or slider the device does not track the value

Hello,
I am using Uno R4 wifi. I have setup a 'Thing' to control a light, on/off and brightness.
Initially the dashboard had 'Switch' and 'Slider'. It all worked fine except the light brightness did not track the slider in real time. Only when I took my finger off the slider did the light show the new brightness value.
I then looked at dimmedlight and it showed a dimmer switch type interface with a rotary brightness selector and a push on/push off type switch.
Set it all up to use dimmedlight and it all worked fine except the brightness did not track the rotary selector until I took my finger off.
I was hoping for a dimmer that dimmed the light as you rotate (as in physical dimmer) so you can decide the light level by eye not by value.
Is this a limitation of the IOT system as is now?

Hi,

Disclaimer: there are a lot of more knowledgeable/experiences users here then me but this if my first guess...

I would apply the following line of code after you update the value of variable assigned to a widget:

ArduinoCloud.update();

See code example below:

void onWaterStatusChange()  {
  // Add your code here to act upon WaterStatus change
  digitalWrite(13,HIGH);
  Serial.println("Pump: ON");
  delay(1000);
  Serial.println("Pump: OFF");
  digitalWrite(13,LOW);
  pumpControl=OFF; //this is a "Status Widget" which is not controlled within this function
  ArduinoCloud.update(); //this was required to change the status of the above widget
}

Hi!

Could you please share your sketch?

Sketch as requested. Thank you for your time.

#include "arduino_secrets.h"
/* 
  Sketch generated by the Arduino IoT Cloud Thing "Untitled"
  https://create.arduino.cc/cloud/things/cbb927ce-74ee-4c94-8bb1-d5551db5d3aa 

  Arduino IoT Cloud Variables description

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

  CloudDimmedLight light;

  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"
int onval = 0;
int bval = 0;
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() {
  // Your code here
  ArduinoCloud.update();
  //Serial.print(onval);
  //Serial.print("   ");
  //Serial.println(bval);
  
  if(onval) analogWrite(5, bval);
  if(!onval) analogWrite(5, 0);
  
}


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

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





/*
  Since Light is READ_WRITE variable, onLightChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLightChange()  {
  // Add your code here to act upon Light change
  bval = light.getBrightness();
  bval = map(bval, 0, 100, 0, 255);
  onval = light.getSwitch();
  
}









I think you need to add this line:

ArduinoCloud.update();

so your function would look like this:

void onLightChange()  {
  // Add your code here to act upon Light change
  bval = light.getBrightness();
  bval = map(bval, 0, 100, 0, 255);
  onval = light.getSwitch();
  ArduinoCloud.update(); //think this will work? did the trick in my function   
}

Thanks. I'll give it a go.

I did as you suggested.
It made no difference. You still have to lift your finger off the phone screen for any change to take effect.
Using the widget on the PC dashboard it does track with delayed response. I suppose 'cos it has to go round the universe first!

You don't actually need this. The update() method will be called on the next loop() iteration which will happen shortly after stepping out of the onXxxxxChange function.
And, in this case, you are not changing any cloud variable, so you don't need to call that method at all inside the callback.

In relation to your issue, I can confirm that the behaviour you observe is the expected.

  • In the browser, the value is sent to the device when you stop moving the knob. You don't have to release the mouser button.
  • In the app, the value is sent to the device when you release your finger from the knob.
    Anyway, we will check if this behaviour can be improved.

Out of curiosity, what is the delay you get from your action on the widget and the real effect on the board? What is the policy you have for the variable (on change or periodic)?

Thanks again for your time on this.
It is nice to know what I am doing is correct, and the results are the expected, even when results are not the desired.

The delay, as best as I can measure, is 0.3 - 0.4 seconds.
The variable policy is 'on change'.

Is the 0.3 - 0.4s delay not acceptable for you?
For most of the applications it is actually a very low latency.

What would be your expected latency?

Many thanks again. It was a little slow for my application. The wifi solution was a bit of an overkill in all reality. Changed tack completely now.
I will mark it as solved, as what I was hoping for was unrealistic in the real world.
Thank you.