Publish Property -- Strange Behavior

So, I'm trying to update the variable through API. Arduino IoT Cloud API

The problem is that, it doesn't actually perform variable update on the actual device if "device_id" is supplied on the request. But, it's working when I don't supply the "device_id", only the value param.

I'm certain that the device_id is correct, it appears to be strange behavior.

Hello @xenoblade, that is normal.

If you specify a device_id, you are "acting" as a device (like that value is sent from the device to the cloud). If you don't specify it, you are acting as an external actor (ex. a dashboard, an external app, etc.) that wants to send a value from the cloud to the device (as if you are doing it from a dashboard).

Can anybody help me out with changing the parameters ("bri"/"hue"/"sat"/"swi") of a RGB LED Shield with a complete curl example?

I'm able to get a token.

The problem is that I do not know what API I should use... possibly "devicesV2UpdateProperties"?

Basically I want to do the same things I can do using the dashboard but via curl only (cli for scripting purposes).

Here the data of my things and dashboard.

#------------------#
# dashboardsV2List #
#------------------#

[
  {
    "created_by": {
      "user_id": "1d37efc1-72c3-40da-9d21-04aa4b73c5f9",
      "username": "xxxxxxxxxxxxxxx"
    },
    "id": "ce529420-5c4e-486d-a331-eaf7e40abea0",
    "name": "SHIELDS",
    "updated_at": "2022-07-18T07:26:52.050975Z",
    "widgets": [
      {
        "has_permission_incompatibility": false,
        "has_type_incompatibility": false,
        "height": 8,
        "height_mobile": 8,
        "id": "27ec023e-0270-4a79-a845-bdf213883ea0",
        "name": "Colored light",
        "options": {
          "frameless": false,
          "icon": "colored-lamp",
          "section": "section-1",
          "showThing": true,
          "thingId": "d8dw9bc9-a222-4558-b307-7e7cd77a48be"
        },
        "type": "Colored light",
        "variables": [
          {
            "id": "83hwlbb7-d229-42f8-94c7-02s6h2785f11",
            "last_value": {
              "bri": 30.350698471069336,
              "hue": 240,
              "sat": 100,
              "swi": 0
            },
            "last_value_updated_at": "2022-07-20T11:54:00.699Z",
            "name": "MATRIX1",
            "permission": "READ_WRITE",
            "thing_id": "d8dw9bc9-a222-4558-b307-7e7cd77a48be",
            "thing_name": "SHIELD1",
            "thing_timezone": {
              "name": "America/New_York",
              "offset": -14400,
              "until": "2022-11-06T06:00:00Z"
            },
            "type": "HOME_COLORED_LIGHT",
            "variable_name": "mATRIX1"
          }
        ],
        "width": 7,
        "width_mobile": 7,
        "x": 3,
        "x_mobile": 0,
        "y": 3,
        "y_mobile": 0
      },
      {
        "has_permission_incompatibility": false,
        "has_type_incompatibility": false,
        "height": 8,
        "height_mobile": 8,
        "id": "8e0837ce-5aaa-4ed4-92cd-9b397a9a4143",
        "name": "Colored light",
        "options": {
          "icon": "colored-lamp",
          "section": "section-1",
          "showThing": true,
          "thingId": "gd53j2o9-f850-47a9-a024-aa7c7bdda564"
        },
        "type": "Colored light",
        "variables": [
          {
            "id": "5g02d542-5160-40ce-ass3-06fe30dd93fc",
            "last_value": {
              "bri": 30.09757423400879,
              "hue": 0,
              "sat": 100,
              "swi": 1
            },
            "last_value_updated_at": "2022-07-20T12:22:55.524Z",
            "name": "MATRIX2",
            "permission": "READ_WRITE",
            "thing_id": "gd53j2o9-f850-47a9-a024-aa7c7bdda564",
            "thing_name": "SHIELD2",
            "thing_timezone": {
              "name": "Europe/Zurich",
              "offset": 7200,
              "until": "2022-10-30T01:00:00Z"
            },
            "type": "HOME_COLORED_LIGHT",
            "variable_name": "mATRIX2"
          }
        ],
        "width": 7,
        "width_mobile": 7,
        "x": 14,
        "x_mobile": 0,
        "y": 3,
        "y_mobile": 8
      }
    ]
  }
]

#---------------#
# devicesV2List #
#---------------#

[
  {
    "created_at": "2022-07-18T05:28:46.487433Z",
    "events": [
      {
        "name": "LIB_VERSION",
        "updated_at": "2022-07-20T02:38:49.77Z",
        "value": "1.6.1"
      },
      {
        "name": "thing_id",
        "updated_at": "2022-07-20T02:38:50.302Z",
        "value": "gd53j2o9-f850-47a9-a024-aa7c7bdda564"
      },
      {
        "name": "r_topicStatus",
        "updated_at": "2022-07-20T02:38:51.027Z",
        "value": "SUBSCRIBED_TO:/a/t/gd53j2o9-f850-47a9-a024-aa7c7bdda564/shadow/i"
      },
      {
        "name": "r_thingTopicStatus",
        "updated_at": "2022-07-20T02:38:51.033Z",
        "value": "SUBSCRIBED"
      },
      {
        "name": "r_status",
        "updated_at": "2022-07-20T02:38:49.283Z",
        "value": "CONNECTED"
      }
    ],
    "fqbn": "arduino:samd:mkrwifi1010",
    "href": "/iot/v2/devices/2b5263b0-6867-4082-b3c7-62d86109f9f0",
    "id": "2b5263b0-6867-4082-b3c7-62d86109f9f0",
    "label": "Arduino MKR WiFi 1010",
    "last_activity_at": "2022-07-20T12:22:55.524Z",
    "latest_wifi_fw_version": "1.4.8",
    "name": "Windy",
    "ota_available": true,
    "ota_compatible": true,
    "required_wifi_fw_version": "1.4.7",
    "serial": "D8CF2A6850553439392E3120FF132F28",
    "thing": {
      "created_at": "2022-07-18T05:29:34.162503Z",
      "device_fqbn": "arduino:samd:mkrwifi1010",
      "device_id": "2b5263b0-6867-4082-b3c7-62d86109f9f0",
      "device_name": "Windy",
      "device_type": "mkrwifi1010",
      "href": "/iot/v1/things/gd53j2o9-f850-47a9-a024-aa7c7bdda564",
      "id": "gd53j2o9-f850-47a9-a024-aa7c7bdda564",
      "name": "SHIELD2",
      "properties": [
        {
          "created_at": "2022-07-18T05:30:30.130982Z",
          "href": "/iot/v1/things/gd53j2o9-f850-47a9-a024-aa7c7bdda564/properties/5g02d542-5160-40ce-ass3-06fe30dd93fc",
          "id": "5g02d542-5160-40ce-ass3-06fe30dd93fc",
          "last_value": {
            "bri": 30.09757423400879,
            "hue": 0,
            "sat": 100,
            "swi": 1
          },
          "name": "MATRIX2",
          "permission": "READ_WRITE",
          "persist": true,
          "tag": 1,
          "thing_id": "gd53j2o9-f850-47a9-a024-aa7c7bdda564",
          "type": "HOME_COLORED_LIGHT",
          "update_parameter": 0,
          "update_strategy": "ON_CHANGE",
          "updated_at": "2022-07-18T05:30:30.130982Z",
          "value_updated_at": "2022-07-20T12:22:55.524Z",
          "variable_name": "mATRIX2"
        }
      ],
      "properties_count": 1,
      "sketch_id": "e412784d-3285-4e57-a52e-e24eb7d375ad",
      "timezone": "Europe/Zurich",
      "updated_at": "2022-07-18T05:42:11.448103Z",
      "user_id": "1d37efc1-72c3-40da-9d21-04aa4b73c5f9",
      "webhook_active": false
    },
    "type": "mkrwifi1010",
    "user_id": "1d37efc1-72c3-40da-9d21-04aa4b73c5f9",
    "wifi_fw_version": "1.4.8"
  },
  {
    "created_at": "2022-04-12T15:28:09.320949Z",
    "events": [
      {
        "name": "LIB_VERSION",
        "updated_at": "2022-07-20T06:26:22.06Z",
        "value": "1.6.1"
      },
      {
        "name": "r_topicStatus",
        "updated_at": "2022-07-20T06:25:52.548Z",
        "value": "SUBSCRIBED_TO:/a/t/d8dw9bc9-a222-4558-b307-7e7cd77a48be/shadow/i"
      },
      {
        "name": "r_thingTopicStatus",
        "updated_at": "2022-07-20T06:25:52.558Z",
        "value": "SUBSCRIBED"
      },
      {
        "name": "r_status",
        "updated_at": "2022-07-20T06:26:21.504Z",
        "value": "CONNECTED"
      },
      {
        "name": "thing_id",
        "updated_at": "2022-07-20T06:26:22.872Z",
        "value": "d8dw9bc9-a222-4558-b307-7e7cd77a48be"
      }
    ],
    "fqbn": "arduino:samd:mkrwifi1010",
    "href": "/iot/v2/devices/303635cf-654d-4da8-99de-94983d38608a",
    "id": "303635cf-654d-4da8-99de-94983d38608a",
    "label": "Arduino MKR WiFi 1010",
    "last_activity_at": "2022-07-20T11:54:00.699Z",
    "latest_wifi_fw_version": "1.4.8",
    "name": "Evie",
    "ota_available": true,
    "ota_compatible": true,
    "required_wifi_fw_version": "1.4.7",
    "serial": "067044DC50593730372E3120FF0D1624",
    "thing": {
      "created_at": "2022-04-12T16:27:37.930403Z",
      "device_fqbn": "arduino:samd:mkrwifi1010",
      "device_id": "303635cf-654d-4da8-99de-94983d38608a",
      "device_name": "Evie",
      "device_type": "mkrwifi1010",
      "href": "/iot/v1/things/d8dw9bc9-a222-4558-b307-7e7cd77a48be",
      "id": "d8dw9bc9-a222-4558-b307-7e7cd77a48be",
      "name": "SHIELD1",
      "properties": [
        {
          "created_at": "2022-04-12T16:28:05.005693Z",
          "href": "/iot/v1/things/d8dw9bc9-a222-4558-b307-7e7cd77a48be/properties/83hwlbb7-d229-42f8-94c7-02s6h2785f11",
          "id": "83hwlbb7-d229-42f8-94c7-02s6h2785f11",
          "last_value": {
            "bri": 30.350698471069336,
            "hue": 240,
            "sat": 100,
            "swi": 0
          },
          "name": "MATRIX1",
          "permission": "READ_WRITE",
          "persist": true,
          "tag": 1,
          "thing_id": "d8dw9bc9-a222-4558-b307-7e7cd77a48be",
          "type": "HOME_COLORED_LIGHT",
          "update_parameter": 0,
          "update_strategy": "ON_CHANGE",
          "updated_at": "2022-07-18T05:43:59.163796Z",
          "value_updated_at": "2022-07-20T11:54:00.699Z",
          "variable_name": "mATRIX1"
        }
      ],
      "properties_count": 1,
      "sketch_id": "60b76ef3-102b-4c7d-b906-7a6db9a10d59",
      "timezone": "America/New_York",
      "updated_at": "2022-07-18T04:42:12.153963Z",
      "user_id": "1d37efc1-72c3-40da-9d21-04aa4b73c5f9",
      "webhook_active": false
    },
    "type": "mkrwifi1010",
    "user_id": "1d37efc1-72c3-40da-9d21-04aa4b73c5f9",
    "wifi_fw_version": "1.4.8"
  }
]

#------------------#
# propertiesV2List #
#------------------#

[
  {
    "created_at": "2022-07-18T05:30:30.130982Z",
    "href": "/iot/v1/things/gd53j2o9-f850-47a9-a024-aa7c7bdda564/properties/5g02d542-5160-40ce-ass3-06fe30dd93fc",
    "id": "5g02d542-5160-40ce-ass3-06fe30dd93fc",
    "last_value": {
      "bri": 30.09757423400879,
      "hue": 0,
      "sat": 100,
      "swi": 1
    },
    "name": "MATRIX2",
    "permission": "READ_WRITE",
    "persist": true,
    "tag": 1,
    "thing_id": "gd53j2o9-f850-47a9-a024-aa7c7bdda564",
    "thing_name": "SHIELD2",
    "type": "HOME_COLORED_LIGHT",
    "update_parameter": 0,
    "update_strategy": "ON_CHANGE",
    "updated_at": "2022-07-18T05:30:30.130982Z",
    "value_updated_at": "2022-07-20T12:22:55.524Z",
    "variable_name": "mATRIX2"
  }
]

[
  {
    "created_at": "2022-04-12T16:28:05.005693Z",
    "href": "/iot/v1/things/d8dw9bc9-a222-4558-b307-7e7cd77a48be/properties/83hwlbb7-d229-42f8-94c7-02s6h2785f11",
    "id": "83hwlbb7-d229-42f8-94c7-02s6h2785f11",
    "last_value": {
      "bri": 30.350698471069336,
      "hue": 240,
      "sat": 100,
      "swi": 0
    },
    "name": "MATRIX1",
    "permission": "READ_WRITE",
    "persist": true,
    "tag": 1,
    "thing_id": "d8dw9bc9-a222-4558-b307-7e7cd77a48be",
    "thing_name": "SHIELD1",
    "type": "HOME_COLORED_LIGHT",
    "update_parameter": 0,
    "update_strategy": "ON_CHANGE",
    "updated_at": "2022-07-18T05:43:59.163796Z",
    "value_updated_at": "2022-07-20T11:54:00.699Z",
    "variable_name": "mATRIX1"
  }
]

@matteoguglielmi

curl --location --request PUT 'https://api2.arduino.cc/iot/v1/things/YOUR_THING_ID/properties/YOUR_PROPERTY_ID/publish' \
--header 'Authorization: Bearer YOUR_TOKEN_HERE' \
--header 'Content-Type: application/json' \
--data-raw '{
	"value":{
        "swi":1,
        "bri":50,
        "hue":50,
        "sat":10
    }
}'

That worked!

Last question:

how to convert from RGB to HS?

Conversion formulae do exist online for RGB to HSV or to HSL... is arduino doing something different there (why only two parameters instead of three)?

Thank you!

I've found this, it should help

Thank you for the link!

I'm now facing a quite weird issue... wondering if you have an answer for it.

In the cloud I can now set a boolean value and an integer value to drive the following piece of code:

void onRedPulsingChange() {
  if (red_pulsing) {
    int n = pulsing_times;

    Serial.println("N:"+String(n));

    for (int j = 0; j < n; j++) {
      for (int i = 0; i <= 180; i++) {
        MATRIX.beginDraw();
        MATRIX.fill(i, 0, 0);
        MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height());
        MATRIX.endDraw();
        delay(10);
      }

      for (int i = 180; i >= 0; i--) {
        MATRIX.beginDraw();
        MATRIX.fill(i, 0, 0);
        MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height());
        MATRIX.endDraw();
        delay(10);
      }
    }

    red_pulsing = false;
  }
}

but it only works up to pulsing_times = 4.

Starting from 5, the Arduino disconnects from the WiFi after the 4th pulse:

N:5
Connected to "ASUS"
Connected to Arduino IoT Cloud
Thing ID: xxxxx-xxxx

and I really can't explain that since the Arduino never disconnects if I do not ask for more than 4 pulses.

Is there a wall time set somewhere for the onRedPulsingChange function to complete?

I found the answer to the problem.

Indeed there is a (new) default watchdog feature in the IoT cloud library which causes the reset of the arduino board if it stops communicating with the cloud for more than ~13 seconds.

The watchdog is reset when calling this function:

ArduinoCloud.update();

Thus, I've now added it to my pulse counting for loop and everything works as expected (for any n):

void onRedPulsingChange() {
  if (red_pulsing) {
    int n = pulsing_times;

    Serial.println("N:"+String(n));

    for (int j = 0; j < n; j++) {
      ArduinoCloud.update();

      for (int i = 0; i <= 180; i++) {
        MATRIX.beginDraw();
        MATRIX.fill(i, 0, 0);
        MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height());
        MATRIX.endDraw();
        delay(10);
      }

      for (int i = 180; i >= 0; i--) {
        MATRIX.beginDraw();
        MATRIX.fill(i, 0, 0);
        MATRIX.rect(0, 0, MATRIX.width(), MATRIX.height());
        MATRIX.endDraw();
        delay(10);
      }
    }

    red_pulsing = false;
  }
}

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