Managing Multiple IoT Cloud Devices - Same Software

I have already accepted that each Thing needs a duplicate dashboard on the Arduino Cloud side. But since each device (MKR1010) gets a unique Thing ID, I'm wondering if there is a clever way to make sure multiple devices get flashed with the correct one?

For example, right now I have to comment ArduinoCloud.setThingId() calls to make sure my device is getting setup with its Thing ID. It would be nice if I could read that from NVM or something. I've tried using "flash as EEPROM" but it wipes on every upload.

I do have an SD card attached to each where I store data, so I might just use that, but I only like that slightly more than commenting code.

I use the mac address to make a device ID.

void connectToMQTT()
{
  byte mac[5]; // create client ID from mac address
  WiFi.macAddress(mac); // get mac address
  String clientID = String(mac[0]) + String(mac[4]) ; // use mac address to create clientID
  while ( !MQTTclient.connected() )
  {
    MQTTclient.connect( clientID.c_str(), mqtt_username, mqtt_password );
    vTaskDelay( 250 );
  }
  MQTTclient.setCallback ( mqttCallback );
  MQTTclient.subscribe   ( topicOK );
} //void connectToMQTT()

That way I can just copy this function from one project to another.

I don't see exactly how this solves the issue using Arduino Cloud.

ArduinoCloud.setThingId() requires the Thing ID generated from the cloud (e.g., d9f22913-a94c-4278-81d5-8f7374b91c9e).

My understanding is that this ID is cryptographically associated. Unless I'm missing a connection between the Thing ID and MAC...?

Oi! I use my own MQTT Broker. I did not know that the ArduinoCloud thingy required a MQTT Broker generated unique device ID. I can understand why they need to generate unique broker ID's.

Thanks anyways! I guess I’m imagining a common scenario where you want to monitor 15 widgets in some factory using identical Arduinos… I feel like I’m missing something obvious, unless you really have to manually manage all of those thing IDs despite them all running the exact same software.

Here's an interim solution stemming from Shannon's suggestion to get the MAC (which should be unique for each MKR1010). Here is a sketch (DisplayMAC.ino) to get the MAC:

#include <ArduinoIoTCloud.h>

void setup() {
  Serial.begin(9600);
}

void loop() {
  byte mac[5];
  WiFi.macAddress(mac);
  for (int i = 0; i < 5; i++) {
    Serial.print("0x");
    Serial.print(mac[i], HEX);
    if (i < 4) {
      Serial.print(", ");
    } else {
      Serial.println("");
    }
  }
  delay(5000);
}

In a separate file (iot_things.h), paste the Things ID from Arduino Cloud and the MAC from the sketch above (this file can be gitignore'd):

const char THING_ID_G0[] = "c443ac0d-a86A-4f40-a83f-1ebb71b3cbdb";
const char THING_ID_G1[] = "d1f22913-a94c-4228-81d5-8f7374ba1c9e";
const byte MAC_G0[5] = { 0x48, 0x5A, 0x3C, 0x24, 0xBF };
const byte MAC_G1[5] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };

That creates a MAC <-> Thing ID map. Then in the main ino file:

#include <iot_things.h>
...
void initIotProperties() {
  byte mac[5];
  WiFi.macAddress(mac);

  bool doProperties = true;
  if (memcmp(mac, MAC_G0, 5) == 0) {
    ArduinoCloud.setThingId(THING_ID_G0);
  } else if (memcmp(mac, MAC_G1, 5) == 0) {
    ArduinoCloud.setThingId(THING_ID_G1);
  } else {
    doProperties = false; // no match, skip adding properties
  }

  if (doProperties) {
    ArduinoCloud.addProperty(adcGrams, READ, 1 * SECONDS, NULL);
    ArduinoCloud.addProperty(motorActive, READ, ON_CHANGE, NULL);
    ArduinoCloud.addProperty(killSwitch, READWRITE, ON_CHANGE, onKillSwitchChange);
    ArduinoCloud.addProperty(sdCard, READ, ON_CHANGE, NULL);
    ArduinoCloud.addProperty(doClosedLoop, READ, ON_CHANGE, NULL);
    ArduinoCloud.addProperty(temperature, READ, ON_CHANGE, NULL);
    ArduinoCloud.addProperty(humidity, READ, ON_CHANGE, NULL);
    ArduinoCloud.addProperty(version, READ, ON_CHANGE, NULL);
  }
}

So every time there is a new cloud device, these things need to update, but at least it solves OAD/re-flashing headaches.

I am not sure if I understand correctly what you want to do but there's a tool in Arduino IOT, which I think is quite new, called "Arduino Cloud CLI" that might correspond to what you need. Make a search in google and see.

Yup, that appears to be the next best thing! Thank you.

Anther solution can be the one presented here:

https://forum.arduino.cc/t/arduino-iot-cloud-disconnects/1030704/2?u=jarriaga

I have done this to the wifi SSID and PASS but you can adapt to de Device ID

Yesterday I found this video which can be of great use for what you want to do.
And it is the best solution for what I ant to do either.

https://www.youtube.com/watch?v=VnfX9YJbaU8

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