Arduino R4 wifi sketch is not compiling

Hi,
I just bought my plug and make kit and I want to import the Weather Report template.
Every time I try to import I get the same generic error on step 2(compiling sketch):
Template upload failed.

I have no clue what to do or what is wrong. I'd really appreciate some help

Not many members here will know what that is so please post a link to it.
Also we will need to see your code so post it please.
Finally we need to see how things are wired up so please post a schematic.

I haven't written any code myself yet.
do you need a schematic of the arduino itself?

Mike, It's an official Arduino kit: store.arduino.cc/products/plug-and-make-kit.

The template that d2v5d is trying to use is to be found at app.arduino.cc/templates/weather-report.

OK, I have reached https://app.arduino.cc/templates/weather-report

There is a button
image
When I hover over it I get this message


Apparently I need more resources

But I have no idea how or where to get them

I fear that most users here will be in no better position than me to provide help

I've got a 'Plug and Make Kit'.
I 'll see if the template works for me.

1 Like

can you share a screenshot of the error you get while importing the template?

I've tried multiple times now, using both the OTA and the connect by cable methods.
I get the same error message as d2v5d, when using OTA, or a very similar one when using a cable:

I've had some limited success.

I went to my Arduino Cloud Sketches at https://app.arduino.cc/sketches

There I found that 2 new sketches had appeared: Weather_Report_aug21a and Weather_Report_aug21b

Weather_Report_aug21b had 3 tabs:
Weather_Report_aug21b.ino, thingProperties.h and Sketch Secrets.

Weather_Report_aug21a only had 2 tabs. Sketch Secrets was missing.
So I concentrated on Weather_Report_aug21b.

When I inspected 'Sketch Secrets' it did not look like the 'Sketch Secrets' that I had seen in other working sketches.

This is what it should have have looked like:

I clicked on the 'ADD NEW' button and manually entered the correct details:


I'll delete the erroneous entry later on.

When I tried to compile the code, there were errors.

Unfortunately I don't have a screenshot with the errors on, or the error message itself.

Here is the code that was created:

Weather_Report_aug21b.ino
#include "arduino_secrets.h"
#include <WiFiS3.h>
#include <ArduinoJson.h>
#include <ArduinoHttpClient.h>
#include "thingProperties.h"
#include <Arduino_LED_Matrix.h>
#include <Arduino_CloudConnectionFeedback.h>

ArduinoLEDMatrix matrix;

// Number that sets how many days of forecasts that are collected
const int numOfForecasts = 7;

double temperatureMax[numOfForecasts];
double temperatureMin[numOfForecasts];
int weather[numOfForecasts];


void setup() {
  Serial.begin(9600);
  delay(1500);

  matrix.begin();

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);
  waitForArduinoCloudConnection(matrix);
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();

  int status = WL_IDLE_STATUS;
  WiFi.begin(SSID, PASS);
  delay(1000);
  status = WiFi.status();

  // Set location of weather forecasts
  //and display location on the cloud dashboard
  weatherLocation = Location(latitude, longitude);

  getWeatherData();
}

void loop() {
  ArduinoCloud.update();
}

void getWeatherData() {
  int httpPort = 80;
  char serverAddress[] = "api.open-meteo.com"; // server address
  WiFiClient wifi;
  HttpClient client = HttpClient(wifi, serverAddress, httpPort);

  // This loop will look through the JSON response and find the lines
  // that contain the temperature and weather codes,
  // which will then be placed in arrays so they can be easily accessed
  client.get("/v1/forecast?latitude=" + String(latitude) + "&longitude=" + String(longitude) + "&current=temperature_2m,weather_code&daily=weather_code,temperature_2m_max,temperature_2m_min&timezone=Europe%2FBerlin");

  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      client.stop();
      return;
    }
  }

  int statusCode = client.responseStatusCode();
  // The entire response from the API in JSON is then stored in "result"
  String result = client.responseBody();
  // To only get the information that is needed, the JSON response will be parsed using a parsing function
  parseWeatherData(result);
}

void parseWeatherData(const String& json) {
  StaticJsonDocument<7000> doc;
  deserializeJson(doc, json);

  // This loop will look through the JSON response and find the lines
  // that contain the temperature and weather codes,
  // which will then be placed in arrays so they can be easily accessed
  for (int i = 0; i < numOfForecasts; i++) {
    temperatureMax[i] = doc["daily"]["temperature_2m_max"][i];
    temperatureMin[i] = doc["daily"]["temperature_2m_min"][i];
    weather[i] = doc["daily"]["weather_code"][i];
  }
}

void onLongitudeChange(){
  getWeatherData();
  weatherLocation = Location(latitude, longitude);
}

void onLatitudeChange(){
  getWeatherData();
  weatherLocation = Location(latitude, longitude);
}

void onDayChange() {
  
}

void onForecastScheduleChange() {
  
}

/*
  Since Latitude is READ_WRITE variable, onLatitudeChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLatitudeChange()  {
  // Add your code here to act upon Latitude change
}
/*
  Since Longitude is READ_WRITE variable, onLongitudeChange() is
  executed every time a new value is received from IoT Cloud.
*/
void onLongitudeChange()  {
  // Add your code here to act upon Longitude change
}
thingProperties.h
// Code generated by Arduino IoT Cloud, DO NOT EDIT.

#include <ArduinoIoTCloud.h>
#include <Arduino_ConnectionHandler.h>

const char SSID[]     = SECRET_SSID;    // Network SSID (name)
const char PASS[]     = SECRET_OPTIONAL_PASS;    // Network password (use for WPA, or use as key for WEP)

void onLatitudeChange();
void onLongitudeChange();
void onDayChange();
void onForecastScheduleChange();

float latitude;
float longitude;
int day;
CloudLocation weatherLocation;
CloudSchedule forecastSchedule;

void initProperties(){

  ArduinoCloud.addProperty(latitude, READWRITE, ON_CHANGE, onLatitudeChange);
  ArduinoCloud.addProperty(longitude, READWRITE, ON_CHANGE, onLongitudeChange);
  ArduinoCloud.addProperty(day, READWRITE, ON_CHANGE, onDayChange);
  ArduinoCloud.addProperty(weatherLocation, READ, ON_CHANGE, NULL);
  ArduinoCloud.addProperty(forecastSchedule, READWRITE, ON_CHANGE, onForecastScheduleChange);

}

WiFiConnectionHandler ArduinoIoTPreferredConnection(SSID, PASS);
Sketch Secrets
#define SECRET_moto_e_13_ ""

// this is the erroneous arduino_secrets.h 
// as generated by the Arduino Cloud.

The errors were due to void onLatitudeChange() and void onLongitudeChange() in the .ino file being defined twice.

I commented out the second definition and retried the compiling.

Success at last:

Now I have the following Dashboard:

I've got a nice new dashboard, but it does not get populated with any data.

:scream:

I don't know whether the errors that the Arduino Cloud introduced were peculiar to me , or whether @d2v5d will have exactly the same faults.

@mario-r , I don't think that someone new to Arduino would stand any chance of finding the errors that i did.

I've re-created the errors, here is the error report:

In file included from /run/arduino/sketches/Weather_Report_aug21b/Weather_Report_aug21b.ino:5:0:
/run/arduino/sketches/Weather_Report_aug21b/thingProperties.h:6:25: error: 'SECRET_SSID' was not declared in this scope
 const char SSID[]     = SECRET_SSID;    // Network SSID (name)
                         ^~~~~~~~~~~
/run/arduino/sketches/Weather_Report_aug21b/thingProperties.h:6:25: note: suggested alternative: '_GETSSID'
 const char SSID[]     = SECRET_SSID;    // Network SSID (name)
                         ^~~~~~~~~~~
                         _GETSSID
/run/arduino/sketches/Weather_Report_aug21b/thingProperties.h:7:25: error: 'SECRET_OPTIONAL_PASS' was not declared in this scope
 const char PASS[]     = SECRET_OPTIONAL_PASS;    // Network password (use for WPA, or use as key for WEP)
                         ^~~~~~~~~~~~~~~~~~~~
/run/arduino/sketches/Weather_Report_aug21b/Weather_Report_aug21b.ino: In function 'void onLatitudeChange()':
/run/arduino/sketches/Weather_Report_aug21b/Weather_Report_aug21b.ino:112:6: error: redefinition of 'void onLatitudeChange()'
 void onLatitudeChange()  {
      ^~~~~~~~~~~~~~~~
/run/arduino/sketches/Weather_Report_aug21b/Weather_Report_aug21b.ino:95:6: note: 'void onLatitudeChange()' previously defined here
 void onLatitudeChange(){
      ^~~~~~~~~~~~~~~~
/run/arduino/sketches/Weather_Report_aug21b/Weather_Report_aug21b.ino: In function 'void onLongitudeChange()':
/run/arduino/sketches/Weather_Report_aug21b/Weather_Report_aug21b.ino:119:6: error: redefinition of 'void onLongitudeChange()'
 void onLongitudeChange()  {
      ^~~~~~~~~~~~~~~~~
/run/arduino/sketches/Weather_Report_aug21b/Weather_Report_aug21b.ino:90:6: note: 'void onLongitudeChange()' previously defined here
 void onLongitudeChange(){
      ^~~~~~~~~~~~~~~~~
Multiple libraries were found for "RTC.h"
  Used: /run/arduino/directories-data/packages/arduino/hardware/renesas_uno/1.5.0/libraries/RTC
  Not used: /run/arduino/directories-data/internal/M5Core2_0.2.0_b8c417594bcb0714
  Not used: /run/arduino/directories-data/internal/M5StickC_0.3.0_a99c11f2c0b70886
  Not used: /run/arduino/directories-data/internal/M5Station_0.0.1_59c962b74b2e5439
  Not used: /run/arduino/directories-data/internal/M5StickCPlus_0.1.1_3da481354d8492d0
Multiple libraries were found for "ArduinoJson.h"
  Used: /run/arduino/directories-data/internal/ArduinoJson_7.4.2_b2ca4093156386e8
  Not used: /run/arduino/directories-data/internal/ThingsIoT_1.2.0_edc19382eb41a2f2
  Not used: /run/arduino/directories-data/internal/Antares_ESP8266_HTTP_1.3.3_e986087bedd31584
  Not used: /run/arduino/directories-data/internal/ThingESP_1.3.0_208e658d67936be5
  Not used: /run/arduino/directories-data/internal/Antares_ESP8266_MQTT_0.9.2_1274de5a8b70ade9
  Not used: /run/arduino/directories-data/internal/CMMC_MQTT_Connector_1.3.3_dcef02afc5e24717
  Not used: /run/arduino/directories-data/internal/IOTKME_3.0.1_7d34512d830e21de
  Not used: /run/arduino/directories-data/internal/BaleMessengerBot_Arduino_0.1.0_1c24e4f4119896e7
  Not used: /run/arduino/directories-data/internal/CoogleIOT_1.3.1_313ac29f75180276
  Not used: /run/arduino/directories-data/internal/AllThingsTalk_LTE-M_SDK_2.0.4_dc42d2d7f4bad257

You have two options:

  • Delete some of your account's existing items in order to free up sufficient "resources"
  • Purchase a plan that provides more resources

The required and available available are listed on the section of the page under that tooltip:

I can't see for certain because the tooltip is partially covering the information, but it appears the reason you were unable to use the Template is because you have used up your plan's allocation of Things. When you use the Template, it automatically creates a Thing. So if you deleted one of your existing Things, you would then be able to use the Template.

You can see the list of your existing Things here:

https://app.arduino.cc/things

Hi, there were errors in the callback declaration in the template .ino file. A new version that fixes the problem has just been released. Please retry.

Thank you, mirkocurtolo.

It compiled for me.
Would you like to retry now, @d2v5d .

My Arduino Uno R4 WiFi now connects to the WiFi network.
I see the following on the Serial Monitor:

13:46:06.491 -> CONNECTION STATUS: connecting to WiFi
13:46:06.491 -> WiFi.status(): 0
13:46:06.532 -> Current WiFi Firmware: 0.6.0
13:46:06.615 -> Connected to "moto e(13)"
13:46:07.017 -> CONNECTION STATUS: connecting to Arduino Cloud
13:46:10.835 -> ***** Arduino IoT Cloud - 2.7.0 *****
13:46:10.835 -> Device ID: 509e44e0-cdda-4b63-b295-407e015355c6
13:46:10.835 -> MQTT Broker: iot.arduino.cc:8885
13:46:10.876 -> Network Configurator: 0.4.1
13:46:13.999 -> Connected to Arduino IoT Cloud
13:46:13.999 -> Thing ID: 07032486-8571-433b-a917-8d085a2edf52

The Uno is shown as being online:

I've now got the following dashboard:

I can manually set the latitude and longitude, and the marker goes to that location after approximately 30s.
I can manually adjust the date ant time on the scheduler, but can't find out how to change the 'America/New_York' to anything else.

However I don't see anything weather related.
The Uno R4 WiFi LED matrix is off, the modulino pixels are all off, the modulino knob has no effect.

What do I need to do to get some weather information?
Are there instructions on how to use the 'Weather Report' Thing?

I don’t know what this template is supposed to do either. I see adding some logs that the sketch fetches info and among them there are temperature related info, but they are not sent to the cloud or displayed locally.

The result of the fetch goes in

double temperatureMax[numOfForecasts];
double temperatureMin[numOfForecasts];

So I image you can still modify the sketch to send them to the cloud and dispay them on a dashboard.

[update]: they told me that this template is part of a lesson you can follow here: https://courses.arduino.cc/plugandmake/lessons/project-weather-report/

later in the lesson is explained how to add and handle weather info

mirkocurtolo,
Thank you for that information.
I will go and investigate.

My template finally works! Thanks very much @mirkocurtolo.

But I've run into a new problem. When I proceed the weather report lesson at some point it tells me to modify the code that arduino has provided so the modulino pixels work by copy pasting in some new lines of code.

After I did this I got a huge error message wich I can't fix on my own
the error message reads:

/run/arduino/sketches/Weather_Report_aug28b/Weather_Report_aug28b.ino: In function 'void updateLights()':
/run/arduino/sketches/Weather_Report_aug28b/Weather_Report_aug28b.ino:141:1: error: expected '}' at end of input
 }
 ^
Multiple libraries were found for "SPI.h"
  Used: /run/arduino/directories-data/packages/arduino/hardware/renesas_uno/1.5.0/libraries/SPI
  Not used: /run/arduino/directories-data/internal/EventEthernet_1.0.0_bd9dd894ef7641f8
Multiple libraries were found for "Wire.h"
  Used: /run/arduino/directories-data/packages/arduino/hardware/renesas_uno/1.5.0/libraries/Wire
  Not used: /run/arduino/directories-data/internal/FlexWire_1.2.1_1fc5f1d1a14af0e7
Multiple libraries were found for "RTC.h"
  Used: /run/arduino/directories-data/packages/arduino/hardware/renesas_uno/1.5.0/libraries/RTC
  Not used: /run/arduino/directories-data/internal/M5StickCPlus_0.1.1_3da481354d8492d0
  Not used: /run/arduino/directories-data/internal/M5StickC_0.3.0_a99c11f2c0b70886
  Not used: /run/arduino/directories-data/internal/M5Core2_0.2.0_b8c417594bcb0714
  Not used: /run/arduino/directories-data/internal/M5Station_0.0.1_59c962b74b2e5439
Multiple libraries were found for "ArduinoJson.h"
  Used: /run/arduino/directories-data/internal/ArduinoJson_7.4.2_b2ca4093156386e8
  Not used: /run/arduino/directories-data/internal/Antares_ESP8266_HTTP_1.3.3_e986087bedd31584
  Not used: /run/arduino/directories-data/internal/CMMC_MQTT_Connector_1.3.3_dcef02afc5e24717
  Not used: /run/arduino/directories-data/internal/ThingESP_1.3.0_208e658d67936be5
  Not used: /run/arduino/directories-data/internal/ThingsIoT_1.2.0_edc19382eb41a2f2
  Not used: /run/arduino/directories-data/internal/IOTKME_3.0.1_7d34512d830e21de
  Not used: /run/arduino/directories-data/internal/Antares_ESP8266_MQTT_0.9.2_1274de5a8b70ade9
  Not used: /run/arduino/directories-data/internal/CoogleIOT_1.3.1_313ac29f75180276
  Not used: /run/arduino/directories-data/internal/BaleMessengerBot_Arduino_0.1.0_1c24e4f4119896e7
  Not used: /run/arduino/directories-data/internal/AllThingsTalk_LTE-M_SDK_2.0.4_dc42d2d7f4bad257
Multiple libraries were found for "ArduinoBLE.h"
  Used: /run/arduino/directories-data/internal/ArduinoBLE_1.4.1_679f6bc843142a33
  Not used: /run/arduino/directories-data/internal/VEGA_ArduinoBLE_1.0.0_b0f76b1d3c4af35c

Hi @d2v5d. Please post your sketch code.

I'll provide instructions you can follow to do that:

  1. Click on the window that contains your sketch code.
  2. Press the Ctrl+A keyboard shortcut (Command+A for macOS users).
    This will select all the text.
  3. Press the Ctrl+C keyboard shortcut (Command+C for macOS users).
    This will copy the selected text to the clipboard.
  4. Open a reply here on this forum topic by clicking the "Reply" button.
  5. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
  6. Press the Ctrl+V keyboard shortcut (Command+V for macOS users).
    This will paste the copied code into the code block.
  7. Move the cursor outside of the code block markup before you add any additional text to your reply.
  8. Repeat the above process if your sketch has multiple tabs.
  9. Click the "Reply" button to publish the post.