Cannot import code

How do I fix this error when I try importing the nerd sketch?

You started a topic in the Uncategorised category of the forum

Your topic has been moved to a relevant category. Please be careful in future when deciding where to start new topics

What exactly were you trying to do when you got this error ?

I was trying to import a sketch of a project the nerd

Import a sketch to where exactly and where did you get the sketch ?

got it off here: https://app.arduino.cc/templates/the-nerd

As the problem is to do with the Arduino IoT Cloud I have moved it to a forum category relevant to that application

Hi @timontimon111. Thanks for your report! This is caused by a bug in the sketch used by the template. I have submitted a report to the Arduino Cloud developers.

Until the bug is fixed, it will not be possible to use Arduino Cloud's "IoT Template" feature to create this project. It is possible to create the project manually, and I can provide instructions for doing that, but it turns out that, beyond the bug that caused the import to fail, the sketch is just completely non-functional in multiple ways. So I fear you would only end up with a lot of frustration.

Explanation of Problem

Unfortunately the template import dialog only shows a small fraction of the compiler output and what was shown was not relevant to the problem, which made it difficult to understand what went wrong during the template import process. In case you are interested, I'll provide an explanation below. If you aren't interested, you are welcome to skip reading this part :wink:

The cause of the failure was this part of the code:

https://docs.arduino.cc/tutorials/iot-bundle/the-nerd/#full-code

void onNerdsTimeChange(){
  if(nerdsFood > 0){
    nerdsFood--;
    delay(200);
  }
}

void onNerdsFoodChange(){
  if(nerdsFood == 0 && justWokeUp==false){
    // DIE :(
    SOS();
  }
}
/*
  Since NerdsFood is READ_WRITE variable, onNerdsFoodChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onNerdsFoodChange()  {
  // Add your code here to act upon NerdsFood change
}
/*
  Since NerdsTime is READ_WRITE variable, onNerdsTimeChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onNerdsTimeChange()  {
  // Add your code here to act upon NerdsTime change
}

If you look closely, you can see that the onNerdsTimeChange and onNerdsFoodChange functions are defined twice.

If we were compiling the sketch in the editor, this problem would be communicated by a compiler error message like this:

C:\Users\per\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\e47d8721-f9b6-4f49-b2e3-96dffdb5b98f\The_Nerd_oct17a\The_Nerd_oct17a.ino: In function 'void onNerdsFoodChange()':
C:\Users\per\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\e47d8721-f9b6-4f49-b2e3-96dffdb5b98f\The_Nerd_oct17a\The_Nerd_oct17a.ino:131:6: error: redefinition of 'void onNerdsFoodChange()'
 void onNerdsFoodChange()  {
      ^~~~~~~~~~~~~~~~~
C:\Users\per\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\e47d8721-f9b6-4f49-b2e3-96dffdb5b98f\The_Nerd_oct17a\The_Nerd_oct17a.ino:121:6: note: 'void onNerdsFoodChange()' previously defined here
 void onNerdsFoodChange(){
      ^~~~~~~~~~~~~~~~~
C:\Users\per\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\e47d8721-f9b6-4f49-b2e3-96dffdb5b98f\The_Nerd_oct17a\The_Nerd_oct17a.ino: In function 'void onNerdsTimeChange()':
C:\Users\per\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\e47d8721-f9b6-4f49-b2e3-96dffdb5b98f\The_Nerd_oct17a\The_Nerd_oct17a.ino:138:6: error: redefinition of 'void onNerdsTimeChange()'
 void onNerdsTimeChange()  {
      ^~~~~~~~~~~~~~~~~
C:\Users\per\AppData\Local\Arduino15\RemoteSketchbook\ArduinoCloud\e47d8721-f9b6-4f49-b2e3-96dffdb5b98f\The_Nerd_oct17a\The_Nerd_oct17a.ino:114:6: note: 'void onNerdsTimeChange()' previously defined here
 void onNerdsTimeChange(){
      ^~~~~~~~~~~~~~~~~

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