Set variable value with API

Hello, i would like to know if it is possible to change a variable value of a thing in arduino IoT cloud.
im talking about the api from this link Arduino IoT Cloud API

hi @isaksen

of course it can be done.
please check the documentation related to properties
https://www.arduino.cc/reference/en/iot/api/#api-PropertiesV2

thank you!
im stuck at setting the 'model_property'
how do i change the variable value of ether 'cloud_led' or 'steps'

im such a noob :smiley:
see image of code
Imgur

you seem to be omitting the property value in your update call
I see the question marks

Yes, but i dont know the syntax, i cant seem to figure it out by looking in the documentation.
Do you have an example of setting an integer or boolean value?

Imgur
i tried following the example in the documentation of property_value

I MADE IT WORK :smiley:
Im so happy :smiley:
property_value had to have device_id and value written in json.
also it was a bit confusing that there where no respons when running the code

id = '076b831d-0fea-4398-a093-xxxxxxx'.     #id of the thing
    pid = '35c98583-6bc0-4c93-90a7-xxxxxx'. #id of the property ( integer )
    propertyValue = {'device_id':'558799eb-7488-4cad-ab9c-6xxxxxx','value': 12}. 
    
    try:
        resp = thing.properties_v2_publish(id,pid,propertyValue)
        print("Response from server:")
        print(resp)
    except iot.ApiException as e:
        print("An exception occurred: {}".format(e))

happy to read that
I would have prepared some sample code for you but you beat me to it.

I understand your confusion when it comes to having to add the device_id,
but you got it!

good luck moving forward :slight_smile:

Well, i got the api working with IoT Cloud but the arduino does not update.
It is connected to WiFi.
I made a short video showing me toggling the LED on the arduino through the Dashboard with my cursor, it works fine. But when i toggle the LED through the API, the Dashboard updates but the LED on the arduino does not turn on/off.
https://streamable.com/fltwk9

/* 
  Sketch generated by the Arduino IoT Cloud Thing "Step-counter"
  https://create.arduino.cc/cloud/things/076b831d-0fea-4398-a093-1be14e84b865 

  Arduino IoT Cloud Properties description

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

  int current_steps;
  bool cloud_led;

  Properties 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();
  cloud_led = false;
  pinMode(LED_BUILTIN, OUTPUT);
}

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


void onCloudLedChange() {
  digitalWrite(LED_BUILTIN, cloud_led);
  
  
}




void onCurrentStepsChange() {
  // Do something
}

ok, that used to be a bug but it was fixed a while back.
I'll report to the Cloud team tomorrow.

VERY IMPORTANT: please remove your boards from that anti-static foam.
That material is conductive and you are basically shorting your board as if you placed it on a piece of metal.
It offers a certain degree of resistance but it's not safe :slight_smile:

Hello @isaksen

can you just try to remove the device_id from propertyValue? Using that API you can act

  • as a client (like a web UI that reads/sets property values to the board), without specify the device_id
  • as a device (like an arduino board that sends data to the web UI), specifying a device_id

Your case should be the first one.

Please give it a try and let us know :slight_smile:

1 Like

ubidefeo:
ok, that used to be a bug but it was fixed a while back.
I'll report to the Cloud team tomorrow.

VERY IMPORTANT: please remove your boards from that anti-static foam.
That material is conductive and you are basically shorting your board as if you placed it on a piece of metal.
It offers a certain degree of resistance but it's not safe :slight_smile:

That explains why it kept disconnecting :smiley:

eclipse1985:
Hello @isaksen

can you just try to remove the device_id from propertyValue? Using that API you can act

  • as a client (like a web UI that reads/sets property values to the board), without specify the device_id
  • as a device (like an arduino board that sends data to the web UI), specifying a device_id

Your case should be the first one.
Please give it a try and let us know :slight_smile:

Aaahhh ok,
I removed the device_id and now it works every time :smiley:
Thank you all for the help! im really happy now :smiley:

thank you @eclipse1985 for chiming in

@isaksen, we're glad to help out