Give a static string to VALUE widget using sketch

Hello Everyone,

I've been trying to give static string to the Value Widget in the sketch but the value does not reflect in the Value Widget. I have already made the variable and attached it to the widget.

e.g,

The variable which I created in things is "abc" with string datatype.
in the setup() function I am trying to assign it in this way:

abc = "Hello";

But its not reflecting.

The basic logic which I want to apply is like when I give a certain degree to my servo variable, I want to print some string against the value;

e.g: if my servo I turn servo using another widgets and it retrun 90 degrees, so I want to display "Hot" against 90 in Value Widget.

if ( servo1 == 90)
{
     abc = "Hot";
}

May be I am missing out something in my logic.

even by returning a static string to the Value will get me going from there. Thanks in advance for the help.

We need to see your complete code. If that is too long, please post a short sketch which illustrates the problem.

For example, in C/C++ there is string (array of char) and there is String, and they are different. This confusion may be the reason for your problem. With string (array of char) you cannot use abc = "123". You must use strcpy(), and you must ensure the char array will always be large enough. With String, it is easier, but if your "widget" is expecting a string (array of char) you may need to use abc.c_str().

Data between a board and the Cloud are synchronized whenever the

ArduinoCloud.update()

function is executed ➜ do you have that in your loop() and do you execute it often? (ie you don't have long delays or blocking code)

Currently the code is very simple. I removed the default comments from the code to avoid verbosity.

String temp;
int servo;

#include "thingProperties.h"
#include "Servo.h"

Servo servo1;

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(9600);

  delay(1500); 

  servo1.attach(D1);

  initProperties();

  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  servo1.write(servo);
  
// Your code here 
  if(servo == 105)
  {
    temp = "Hot";  //Here I want to change the variable data of temp on servo degree change.
  }
}

as it's in the loop() function, it executes all the time getting the current value.

are you sure you made temp a thing Property ?

I believe did:

why do you have it in the main .ino too then?

please, please never ever again post pictures of text... Not only they are not readable nor usable directly for copy&paste but they use up lots of storage and internet bandwidth which contributes to polluting the planet.

➜ do your part and do yourself a favour and please read How to get the best out of this forum and modify your post accordingly (including code tags and necessary documentation for your ask).

Got it. Thanks for the info.

Well about the variable on the top, I was removing the comments and left these variables which were present in the comments. At first I thought it was part of the code but later I realized it was part of comments which I should have removed.

The variable that sync with the cloud are defined in the .h

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