Is using a Template a way to duplicate/replicate my Things & Sketches ?

I have refined a sketch to the point where it is ready to be deployed to several devices/Things.
I'm happy to have a unique "copy" of the base Sketch initially for each device/Thing, which I can then tweak ( customise ) for each THING. A method I tested today was to literally "select All" , "copy" then "paste" overwriting an existing sketch ( in a different device/Thing, but the process was a bit clunky as it involved 19k lines and a sluggish cloud editor.

typically you would have an included file which contains the specific parameters for a given thing and the rest of the code will stay the same.

#include "config.h" // this is how you import the specific settings 

void setup() {
 ... // use some of the settings to configure the thing
}

void loop() {
  ...// use some of the settings to run the thing
}
1 Like

yes, there is a tab containing unique data. I was wondering if the use of a template encompassed retaining the unique elements. Do I first create a device ( with its unique tab) then apply a template to duplicate the sketch and any widgets ?

are you talking about C++ templates ?

are you talking about Arduino Cloud "things" ?

I might have misunderstood the function of the Template feature.

Here is my objective :-

I have five ArduinoCloud "Things". Each has a device ( a Nano33 IOT ) and each of those has a unique identity and a similar but slightly different sketch. One of the five sketches has recently been edited and is now considered to be an ideal BASE for creating future Things.

I would like to replicate that BASE sketch in any future Things ( e.g. #6, #7, #8 ... etc ) that I create.
I am assuming that I can do that by creating a Template... is that correct ?
I will then slightly modify some of the new sketches to customise the functionality of the devices, and retain a unique identity in the ArduinoCloud for each sketch, as any customisation renders them to be unique too, no longer merely clones of the BASE sketch.

I would also like to replace the code in my other four original devices with the BASE code in the most efficient manner possible, but also retain a unique identity in the ArduinoCloud (for reasons described above).

I’m still confused about your use of the word « template »

A template in C++ is a powerful tool that allows you to define functions or classes with a placeholder for a data type or some parameters, which can be specified later when the function or class is used. This enables you to write generic, reusable code that can operate on different data types without needing to rewrite the same logic for each type. Templates are commonly used in situations where the same functionality is needed for different data types, such as in containers like std::vector or algorithms in the Standard Template Library (STL).

Is that what you have in mind ?

If your problem is that you have several projects which share more or less the same code base and you don't want to maintain separate versions of the sketch for each project to accommodate any minor differences, then one possible solution is to have jumper settings so the code "knows" on which application it is running and adapts accordingly.

Other possible solutions to distinguish an instance of an application are an eeprom entry, a pair of resistors on one analog pin, a one-wire device with a unique serial number etc.

Templates : as available as an option in the Cloud Editor. I guess they are templates of “Things “ i.e. a collection of elements ( not just the sketch ) to aid creation of similar “Things”.

Do you not use the ArduinoCloud editor ?

OK - no I don't use the Arduino Cloud but I had looked at the capability.

Sure that's an option âžś by definition a template creates variables, sketch files, device and network information and you can configure them based on your preferences, so it could be a good starting point but you would still have to generate one project per thing.

Using @6v6gt approach, or building a library that is shared across your projects with config files could be also an option. It really depends on the level of customisation you are talking about.

My primary requirement is to create clones of an existing “Thing” so that it has all the characteristics and it’s own unique copy of the sketch which I will probably customise and associate with a new or existing Nano33 IOT. I accept this is perhaps not the best solution at present, something I will improve with time … after a rewrite :slight_smile:

cloud things.

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