I am using an Arduino MKR WiFi 1010 for my IoT project. When I try to upload the sketch to my board using OTA, I get an error: "Error: Uploading Garden_jul20a". After verifying, the console window only shows "Start Uploading sketch Garden_jul20a Over-the-Air".
Here is the sketch I am trying to load:
// RTCZero - Version: Latest
#include <RTCZero.h>
// Arduino Low Power - Version: Latest
#include <ArduinoLowPower.h>
// WiFiNINA - Version: Latest
#include <WiFiNINA.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/42e09ae2-5d37-46e7-a9ad-e51ddf875472
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
CloudPercentage moisture;
CloudIlluminance illumination;
CloudElectricPotention battery;
CloudTime runtime;
CloudTemperatureSensor temperature;
bool resetRuntime;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
/* Create an rtc object */
RTCZero rtc2;
float startHours = 0.0;
bool resetStartHours = false;
// for MKR boards, can use 12-bit analog resolution. range 0 to 4095; Other boards are 8 bit, 0 - 1023
const int A_RES = 12;
const float A_MAX = 4095;
const int DELAY_TIME = 10000; // note: for sleep level 0 & 1, too long and the cpu will reset
const int WAKE_TIME = 500;
const int tempPin = A1;
const int illumPin = A2;
const int moistPin = A3;
const int sleepLevel = 1;
void blinkLed(int times = 1) {
for (int i = 0; i < times; i++) {
digitalWrite(LED_BUILTIN, HIGH);
delay(250);
digitalWrite(LED_BUILTIN, LOW);
delay(250);
}
}
void setup() {
rtc2.begin();
// set up analog pins
analogReadResolution(A_RES);
pinMode(tempPin, INPUT); //temperature
pinMode(illumPin, INPUT); //illumination
pinMode(moistPin, INPUT); //moisture
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
// Initialize serial and wait for port to open:
Serial.begin(9600);
// This delay gives the chance to wait for a Serial Monitor without blocking if none is found
delay(1500);
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
// use the NINA low power mode
WiFi.lowPowerMode();
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(4);
ArduinoCloud.printDebugInfo();
blinkLed(3);
resetStartHours = true;
}
void loop() {
ArduinoCloud.update();
// Your code here
//Temp in °C = [(Vout in mV) - 500] / 10
int temperatureRaw = analogRead(tempPin);
float temperaturemV = scale(temperatureRaw, 0.0, A_MAX, 0.0, 3300.0);
float temperatureC = scale(temperaturemV, -500, 750, 0.0, 25.0);
temperature=scale(temperatureC, 0.0, 100.0, 32.0, 212.0);
Serial.print("Temperature = ");
Serial.print(temperatureRaw);
Serial.print(" / ");
Serial.print(temperaturemV);
Serial.print(" mV / ");
Serial.print(temperatureC);
Serial.print(" C / ");
Serial.print(temperature);
Serial.println(" F");
int illuminationRaw = analogRead(illumPin);
//Bright resistance @ 10 lux = 50-100 kOhm; Dark =5 MOhm
float illuminationmV = scale(illuminationRaw, 0, A_MAX, 0.0, 3300.0);
//The circuit has a 10k resistor to divide the voltange, so 10 lux = 300 mV
illumination = scale(illuminationmV, 0.0, 300.0, 0.0, 10.0);
Serial.print("Illumination = ");
Serial.print(illuminationRaw);
Serial.print(" / ");
Serial.print(illuminationmV);
Serial.print( " mV / ");
Serial.print(illumination);
Serial.println(" lux");
int moistureRaw = analogRead(moistPin);
moisture = scale(moistureRaw,0, A_MAX, 0.0, 100.0);
Serial.print("Moisture = ");
Serial.print(moistureRaw);
Serial.print(" / ");
Serial.print(moisture);
Serial.println(" %");
// read the input for the battery voltage:
int batteryRaw = analogRead(ADC_BATTERY);
// Convert the analog reading (which goes from 0 - A_MAX) to a voltage (0 - 4.3V):
battery = scale(batteryRaw, 0, A_MAX, 0.0, 4.3);
// print out the value you read:
Serial.print("Battery = ");
Serial.print(batteryRaw);
Serial.print(" / ");
Serial.print(battery);
Serial.println(" V");
runtime = getElapsed();
Serial.print("runtime hours = ");
Serial.println(runtime);
Serial.println("--");
blinkLed();
switch (sleepLevel){
case 1:
LowPower.idle(DELAY_TIME);
delay(DELAY_TIME);
break;
case 2:
LowPower.sleep(DELAY_TIME);
break;
case 3:
LowPower.deepSleep(DELAY_TIME);
break;
default:
delay(DELAY_TIME);
break;
}
}
float scale(float x, float in_min, float in_max, float out_min, float out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float getHoursNow(){
int previousDays;
switch(rtc2.getMonth()){
case 1:
previousDays = 0;
break;
case 2:
previousDays = 31;
break;
case 3:
previousDays = 59;
break;
case 4:
previousDays = 90;
break;
case 5:
previousDays = 120;
break;
case 6:
previousDays = 151;
break;
case 7:
previousDays = 181;
break;
case 8:
previousDays = 212;
break;
case 9:
previousDays = 243;
break;
case 10:
previousDays = 273;
break;
case 11:
previousDays = 304;
break;
case 12:
previousDays = 334;
break;
}
return (((previousDays + rtc2.getDay()) * 24.0) + rtc2.getHours() + (rtc2.getMinutes()/60.0)
+ (rtc2.getSeconds()/3600.0));
}
float getElapsed () {
float hoursNow = getHoursNow();
if (resetStartHours || startHours == 0.0) {
startHours = hoursNow;
resetStartHours = false;
}
return hoursNow - startHours;
}
void onResetRuntimeChange() {
// Do something
resetStartHours = true;
resetRuntime = false;
}
See attached for the entire console trace.
OTA error trace.zip (21.5 KB)