Every time i make a new thing on Arduino cloud, and add a variable, it just makes a new default sketch. Not sure how to get it to add the variables to my existing sketch which i have uploaded.
Nothing from this forum post worked for me.
I cant see any option to change the main sketch that a thing uses
tia
Hi @anon91915878.
By "existing sketch", are you referring to an existing Arduino Cloud IoT Thing sketch?
If so, you can add additional variables to the sketch by following these instructions:
- If you are not already, log in to your Arduino account:
https://login.arduino.cc/login
- Click the following link to open the list of your Arduino Cloud Things in the web browser:
https://app.arduino.cc/things
- Click the name of the Thing.
The "Setup" page for the Thing will open.
- Click the "ADD" button on the "Setup" page.
The "Add variable" dialog will open.
- Complete the dialog to add the additional Variable to the Thing.
- Repeat the above steps if you want to add more than one additional Variables.
- Select the "Sketch" tab at the top of the page.
The Thing sketch will open in Arduino Cloud Editor.
You will now find that the existing Thing sketch has been updated to include support for the newly added Variables.
However, if by "existing sketch" you are instead referring to a non-IoT sketch, then there is no way to do this. It would be too difficult and error prone for Arduino Cloud to inject the IoT Thing skeleton code into an arbitrary sketch.
So in this case you must instead merge the non-IoT sketch code into the skeleton code that is automatically generated when you create a Thing. When you think about it, this approach actually makes more sense anyway because you are going to need to adapt that non-IoT sketch code to be relevant to the IoT application anyway. Surely it isn't reasonable to expect such a thing to be done automagically by Arduino Cloud.
Right! i did not realise that there were 2 types of sketches.
Merging my offline sketch with the IoT one shouldnt be too hard, and you answered my question. Thanks!
Does this mean that in the future if i am developing a sketch for arduino, i should create and work on it in the cloud instead of offline?
You are welcome. I'm glad if I was able to be of assistance.
If you are developing an Arduino Cloud IoT Thing sketch, then it probably does make sense to start from the automatically generated "skeleton" sketch rather than having to merge the code into the skeleton later.
If you are developing non-IoT sketches, then there is no technical reason why one is better than the other. It is merely a matter of preference of which tool you use for the development work.
Note that Arduino IDE 2.x has an integration with your Arduino Cloud sketchbook:
https://docs.arduino.cc/software/ide-v2/tutorials/ide-v2-cloud-sketch-sync
This makes it easy to generate an IoT Thing sketch via the Arduino Cloud website, then "pull" that sketch to make it available for editing using your local Arduino IDE. You can also "push" the edits you made via Arduino IDE back to your Arduino Cloud sketchbook so that you can use it via the Arduino Cloud website as well as Arduino IDE.