Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How Do I Set Up OTA for an Uno R4 WiFi? (Read 4140 times)
BRebey
Newbies
*
Offline


Posts: 4
Joined: Mar 13th, 2024
How Do I Set Up OTA for an Uno R4 WiFi?
Mar 22nd, 2024 at 3:51am
Print Post  
Can anyone point me to help for setting up OTA via WiFi with an "Arduino Uno R4 WiFi" board?  I can't use the Arduino cloud because the core libraries don't compile.  Even if I could, that is a very slow and cumbersome process that I'd rather avoid. 

I need to get OTA working with Visual Micro directly from Visual Studio so that I can use locally-patched libraries, and get the full benefit of vMicro, but I can't figure out how to set it up.  

I've updated my R4 with the latest firmware.

I'm trying to set up the OTA example that's shown on the "Uno R4 Wifi" 'Examples' menu.

It builds and runs, but I get this runtime error:

Port closed
Uploading to I/O board
Opening port
Port open
Please upgrade the firmware
Attempting to connect to SSID: SpectrumSetup-4B
SSID: SpectrumSetup-4B
IP Address: 192.168.1.247
signal strength (RSSI):-47 dBm
ota.begin() error: 
-26


Any help would be appreciated.



« Last Edit: Mar 22nd, 2024 at 4:19am by BRebey »  
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2728
Joined: Feb 13th, 2019
Re: How Do I Set Up OTA for an Uno R4 WiFi?
Reply #1 - Mar 22nd, 2024 at 5:35pm
Print Post  
The below instructions should get you started, we will publish a page for this specifically and link it from here when it is available:

1) Install the ArduinoOTA Library by JAndrassy:
https://github.com/JAndrassy/ArduinoOTA

2) Copy the platform.local.txt entries from the LibraryFolder\extras\reneasas folder, into the installation folder for the board package:
e.g. C:\Users\Username\AppData\Local\Arduino15\packages\arduino\hardware\renesas_uno\...

3) Open a copy of the WiFi101_OTA example from this library

4) Change the #include <WiFiNINA.h> to be #include <WiFiS3.h>

5) Enter the WiFi Credentials into the sketch or arduino_secrets.h

6) Upload this sketch via USB cable, to start allowing OTA Uploads, and look in the Serial Monitor to ensure it has connected OK to the WiFi.

7) Change the selected port for the board to the boards IP Address (it should show up automatically, but can be typed in if needed).

8) Add any relevant code you want to this sketch for the next update.

9) Perform the build and  upload again, and enter the password when prompted (default is "password", and can be changed in the sketch code as part of ArduinoOTA.begin()).

10) The upload over WiFi should work as expected, and can be seen in the Output Window.

Let us know if you have any issues around this, and we will amend our software to have these definitions built in in a future release.
  
Back to top
IP Logged
 
BRebey
Newbies
*
Offline


Posts: 4
Joined: Mar 13th, 2024
Re: How Do I Set Up OTA for an Uno R4 WiFi?
Reply #2 - Mar 22nd, 2024 at 6:14pm
Print Post  
Thanks for the help!

First, a trivial matter:  to get the serial monitor to work, I had to do this to make Serial.printxx() calls work correctly and not "miss" any of the early ones in startup():

Code (C++)
Select All
  //Serial.begin(9600);
  Serial.begin(115200);
  while (!Serial);
  delay(1000);  // Early prints don't show up without this delay 



However, I can't get the second update (the first OTA update) to work.

The build works, and the initial upload works, and then the TCP/IP port shows up as an option for the Board/Port selection in VS.  If I pick that, and attempt an update (I was asked for the password ('password') the very first time, but not on subsequent attempts [is it expected that I would not be asked again after the first time?]), I get this in the VS output window:


# Compute Size: 7-2017q4/bin/arm-none-eabi-size" -A _OTA.ino.elf"

Program WiFi101_OTA size: 76148 bytes (used 29% of a 262144 byte maximum) (2.57 secs)
Minimum Memory Usage: 10012 bytes (31% of a 32768 byte maximum)
 

TRIAL Version of Visual Micro (Expires On 26 April 2024)
(Existing customer? CTRL+click Or go to this link (https://www.visualmicro.com/page/Trial-Mode-VS2022.aspx)

[code]Uploading 'WiFi101_OTA' to 'Arduino UNO R4 WiFi (unor4wifi)' using '192.168.1.247'
Uploader started for board Arduino UNO R4 WiFi (unor4wifi)
Upload method will be: bootloader
Uploading via Bootloader 
Port Properties (network)
     Name=Arduino
     HostName=Arduino
     Address=192.168.1.247
     port=65280
     Protocol=Any
     ssh_upload=no
     tcp_check=no
     auth_upload=yes
     board=arduino
     password=password
{runtime.tools.arduinoOTA.path}\bin\arduinoOTA -address 192.168.1.247 -port 65280 -username arduino -password "password" -sketch _OTA.ino.bin" -upload /sketch -b

The system cannot find the file specified


Any idea what's up here?

« Last Edit: Mar 22nd, 2024 at 6:16pm by BRebey »  
Back to top
 
IP Logged
 
Tim@Visual Micro
Administrator
*****
Offline


Posts: 12191
Location: United Kingdom
Joined: Apr 10th, 2010
Re: How Do I Set Up OTA for an Uno R4 WiFi?
Reply #3 - Mar 22nd, 2024 at 11:15pm
Print Post  
Many boards that use a usb port for serial, instead of hardware serial,, require the wait for port using while (!Serial);

We will review the ota of the R4. It is possible that the built i9n Arduino way of using OTA is similar to their previous wifi boards such as Arduino Yun. That works slightly differently to other non arduino boards but is also supported by Visual Micro.

It will be reviewed over the next week.





  
Back to top
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2728
Joined: Feb 13th, 2019
Re: How Do I Set Up OTA for an Uno R4 WiFi?
Reply #4 - Mar 25th, 2024 at 11:58am
Print Post  
The error you are seeing with the upload is due to the ArduinoOTA tools being missing from your machine.

These are installed as part of a number of board packages such as the Arduino AVR, or Arduino SAMD board package.

If you install one of these board packages, and restart VS it should then be able to use the tool for the upload, if it fails can you attach a fresh build log with the options shown at the top of the page.

Once we have reviewed this area fully we will update this thread again.
  
Back to top
IP Logged
 
BRebey
Newbies
*
Offline


Posts: 4
Joined: Mar 13th, 2024
Re: How Do I Set Up OTA for an Uno R4 WiFi?
Reply #5 - Apr 4th, 2024 at 7:38pm
Print Post  
That got us further, but it still isn't working right.

I've attached the requested output from a build/update session that failed.

The Output window finished like this:

Quote:
n\arduinoOTA -address 192.168.1.247 -port 65280 -username arduino -password "password" -sketch wifi\Release/SolarTracker_oct29a_OrigWorking.ino.bin" -upload /sketch -b
Connecting to board ...  done
Connecting to board ...  done
Uploading sketch ...  done
The uploader returned an error
Uploading sketch ...  done
Flashing sketch ... Error flashing the sketch


With a tiny test program (like the WiFi101 example), the board will sometimes get correctly updated and restart, even though it gets the above error.

With my real sketch, though, it never updates.   My regular loop  code stops running, but it never gets the board re-flashed and re-started.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2728
Joined: Feb 13th, 2019
Re: How Do I Set Up OTA for an Uno R4 WiFi?
Reply #6 - Apr 5th, 2024 at 9:37am
Print Post  
Thanks for the update, and believe there could be a few reasons for the failure of the main sketch to update.

1) Timeout:   
The ArduinoOTA tool I believe will timeout after 10s, however the timeout parameter was only added in a recent version of the tool:
https://github.com/arduino/arduinoOTA/releases/tag/1.4.0

If this (or later) version of the ArduinoOTA tool is downloaded and manually installed over the existing one: %LOCALAPPDATA%\Arduino15\packages\arduino\tools\arduinoOTA\1.3.0\bin\arduinoOTA

And the platform.local.txt file is amended for the below patterns to add the "-t 100" for a 100s timeout:
tools.arduino_ota.upload.pattern
tools.arduinoOTA.program.pattern

Then this should give the uploader longer to do the update before it believes it has failed.  The upload command can be copied from the output window and run via the command line for simpler testing where needed.

2) Sketch Size: 
Normally with OTA updates you have a little under half of the flash size available for your sketch.  This is due to it needing to store the new sketch before restarting, and your log shows it is 53% so it may be slightly too large.  The optimization can be overridden however it may result in a larger compiled sketch even when it is increased (currently it is optimized for size with the -Os flag in the compiler recipes).

Hopefully the Timeout changes above help.

  
Back to top
IP Logged
 
BRebey
Newbies
*
Offline


Posts: 4
Joined: Mar 13th, 2024
Re: How Do I Set Up OTA for an Uno R4 WiFi?
Reply #7 - Apr 15th, 2024 at 8:07pm
Print Post  
Using v.1.4.0 of the OTA Upload Tool, with a longer timeout than 10 seconds, combined with a reduction in the Sketch size by removing the Arduino cloud library (i'll have to use my own server to manage "cloud" data) seems to have solved the problem.  Thanks for the tips!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint