What's the latest on ethernet or TFTP bootloaders for Arduinos? Specifically, I'm looking to use it on a mega2560 with w5100 shield. I see the following:
I'd like to compile with the Arduino IDE, and upload. I like how simple the Esp OTA library works but from what I've read I expect to use a TFTP client and wdt reset. I have a little experience writing bootloaders.
Any recommendations from experience? Updated/working tutorials for using the bootloader?
This library allows you to update sketches from IDE to your board over WiFi or Ethernet. It is a modification of the Arduino WiFi101OTA library.
On AVR for upload over InternalStorage, Optiboot bootloader with copy_flash_pages function is required. Arduino AVR package doesn't use Optiboot for Arduino Mega. For Arduino Mega you can download my boards definitions and use it to burn the modified Optiboot and to upload sketches to your Mega over USB and over network.
The freetronics thing is very outdated, not actively maintained, and doesn't have ATmega2560 support out of the box (if at all).
The d0ughb0y repository was created in a fit of anger after their suggestion for Ariadne was rejected. They did add some features that are interesting (some of which likely would have been welcomed into Ariadne) but unfortunately they did not follow proper development practices and instead mashed a bunch of unrelated changes into a single commit. The effort that would be required to untangle each of the changes from each other and review then is more than it would take to just implement them from scratch. That repository has not been maintained at all since that initial commit and so has not benefited from a lot of further development work on Ariadne. Considering the conditions it was created under, I would not trust the code in that repository to be well tested.
I'm a big fan of Ariadne, but I would definitely recommend considering ArduinoOTA as well, since Juraj does very good work.
I'm not sure when I will have time to dig into this and try it. I'm interested in your method, can you recommend a good step by step tutorial for flashing the bootloader and modifying the IDE?
to use Mega with Optiboot, you need to define an alternative Mega.
under your sketches folder usually in Documents/Arduino, create folder hardware if it doesn't exist. in hardware create my_boards folder.
download GitHub - JAndrassy/my_boards: My Arduino boards custom variants. You can use it as starting point for your boards specialities. as .zip using the green button
copy the avr subfolder from the zip so you have a final folder structure like this: Documents/Arduino/hardware/my_boards/avr/bootloaders/optiboot8
prepare the board and the programmer for flashing and then choose "Arduino Mega 2560 (Optiboot)" at the end of the Tools menu. And use "Burn bootloader'. After burning Optiboot always use this custom definition of the Mega to upload sketch over USB or network.
Now you must find the active official boards package file for the avr boards. It could be installed with IDE, so under the IDE installation folder or under arduino15 folder in home directory. If you can't find it, write us, what OS do you have.
In the boards package folder create file platform.local.txt next to platform.txt file and put only this one line into this new platform.local.txt file (it overrides the key defined in platform.txt for Yun)
The ArduinoOTA library listens for uploads from arduinoOTA tool used by the IDE. It must be version 1.2.0 of the tool (installed with AVR package 1.6.23).
Any time now the ArduinoOTA library should by available in Library Manager.
You can try the OTEthernet example.
to use Mega with Optiboot, you need to define an alternative Mega.
under your sketches folder usually in Documents/Arduino, create folder hardware if it doesn't exist. in hardware create my_boards folder.
download GitHub - JAndrassy/my_boards: My Arduino boards custom variants. You can use it as starting point for your boards specialities. as .zip using the green button
copy the avr subfolder from the zip so you have a final folder structure like this: Documents/Arduino/hardware/my_boards/avr/bootloaders/optiboot8
I'm using a portable installation on Windows 7, so my path is arduino-1.8.8\portable\sketchbook\hardware\my_boards\avr\bootloaders\optiboot8
Juraj:
prepare the board and the programmer for flashing and then choose "Arduino Mega 2560 (Optiboot)" at the end of the Tools menu. And use "Burn bootloader'. After burning Optiboot always use this custom definition of the Mega to upload sketch over USB or network.
I was able to flash the bootloader using my AVRISP mkII (after installing it's drivers) and I am able to flash sketches via USB with the new optiboot8 bootloader.
Juraj:
Now you must find the active official boards package file for the avr boards. It could be installed with IDE, so under the IDE installation folder or under arduino15 folder in home directory. If you can't find it, write us, what OS do you have.
In the boards package folder create file platform.local.txt next to platform.txt file and put only this one line into this new platform.local.txt file (it overrides the key defined in platform.txt for Yun)
The ArduinoOTA library listens for uploads from arduinoOTA tool used by the IDE. It must be version 1.2.0 of the tool (installed with AVR package 1.6.23).
Any time now the ArduinoOTA library should by available in Library Manager.
You can try the OTEthernet example.
This last part I'm not clear on. I have created the file arduino-1.8.8\hardware\arduino\avr\platform.local.txt and added the line
but I'm not sure it's in the correct location. I have also installed your ArduinoOTA library.
I flashed the OTEthernet example via USB. The serial output shows it has an IP assigned via DHCP. How do I now upload via network? Should there be a new option in tools->ports?
m_elias:
but I'm not sure it's in the correct location. I have also installed your ArduinoOTA library.
I flashed the OTEthernet example via USB. The serial output shows it has an IP assigned via DHCP. How do I now upload via network? Should there be a new option in tools->ports?
yes a network port should appear in Ports menu. sometimes it takes time or a restart of IDE
on Windows the location of Boards Manager installed packages is %userprofile%\AppData\Local\Arduino15\packages\ (AppData is a hidden folder)
the location of avr package installed with IDE is C:\Program Files (x86)\Arduino\hardware\arduino\avr
Juraj:
on Windows the location of Boards Manager installed packages is %userprofile%\AppData\Local\Arduino15\packages\ (AppData is a hidden folder)
the location of avr package installed with IDE is C:\Program Files (x86)\Arduino\hardware\arduino\avr
https://www.arduino.cc/en/Guide/PortableIDE
As I mentioned, I'm using a portable installation so neither of those two locations exist. I do have 3 instances of platform.txt.
arduino-1.8.8\hardware
arduino-1.8.8\hardware\arduino\avr
arduino-1.8.8\portable\sketchbook\hardware\my_boards\avr
Is my platform.local.txt file correct? I have tried with it in all 3 locations, my network firewall is disabled and the only ports I see are my COM ports. COM24 is the Mega2560.
m_elias: https://www.arduino.cc/en/Guide/PortableIDE
As I mentioned, I'm using a portable installation so neither of those two locations exist. I do have 3 instances of platform.txt.
arduino-1.8.8\hardware
arduino-1.8.8\hardware\arduino\avr
arduino-1.8.8\portable\sketchbook\hardware\my_boards\avr
Is my platform.local.txt file correct? I have tried with it in all 3 locations, my network firewall is disabled and the only ports I see are my COM ports. COM24 is the Mega2560.
arduino-1.8.8\hardware\arduino\avr is the location for platform.local.txt, but this has no influence on network port detection in IDE.
the library propagates a mDns record with UDP broadcast and this record should be received by mdns service on the computer. IDE reads mdns records detected by the OS. when you used the esp8266 ArduinoOTA library did you have the network port in IDE? do you have mdns enabled on your computer?
Juraj:
arduino-1.8.8\hardware\arduino\avr is the location for platform.local.txt, but this has no influence on network port detection in IDE.
So is this file there just for the Yun?
Juraj:
the library propagates a mDns record with UDP broadcast and this record should be received by mdns service on the computer. IDE reads mdns records detected by the OS. when you used the esp8266 ArduinoOTA library did you have the network port in IDE? do you have mdns enabled on your computer?
Do I need the esp8266 boards installed? I installed your ArduinoOTA library from github.
I did some googling and it sounds like Apple's Bonjour service is the best option for a lightweight mDNS on Windows 7 so I installed it. Then I started testing the ESP8266 OTA examples on my nodeMCU. I can successfully flash my nodeMCU via the IDE & network with the OTA-mDNS-SPIFFS example. Then I managed to flash my optiboot mega once and the IDE thought it worked and I could see the mega rebooting several times but the LED13 blink pattern never changed according to my sketch. Then neither network port showed up even after several IDE restarts. This mDNS business seems quite unreliable. Is there an easy way to flash via command line if I know my IP address?
m_elias:
So is this file there just for the Yun?Do I need the esp8266 boards installed? I installed your ArduinoOTA library from github.
I did some googling and it sounds like Apple's Bonjour service is the best option for a lightweight mDNS on Windows 7 so I installed it. Then I started testing the ESP8266 OTA examples on my nodeMCU. I can successfully flash my nodeMCU via the IDE & network with the OTA-mDNS-SPIFFS example. Then I managed to flash my optiboot mega once and the IDE thought it worked and I could see the mega rebooting several times but the LED13 blink pattern never changed according to my sketch. Then neither network port showed up even after several IDE restarts. This mDNS business seems quite unreliable. Is there an easy way to flash via command line if I know my IP address?
no no it has nothing to do with esp8266. only the same system is used in for network port detection.
do you use the latest Ethernet library? (2.00). does Ethernet shield connect to network, get IP address? WebClient example works?
yes the mDNS is whimsical. but more with esp8266 then Ethernet shield so I wonder what is wrong.
things are independent.
the special bootloader is required only for the flash operations, it has nothing to do with networking.
the TCP upload server in the library is independent from the UDP mDns network-port propagation part.
and the upload tool doesn't need mdns, only the IDE doesn't allow to enter the IP address directly.
you could try the upload from command line.
I have the newest Ethernet library. Everything else works except mDNS is unreliable. Command line flashing over network is working well!
Is there much memory to be saved by eliminating the mDNS parts of your ArduinoOTA library? I won't be flashing much via network, only the occasional update so manual command line is not too much effort for me. I don't think I need to bother with mDNS at all then. For testing at my desk, I will use USB.
m_elias:
I have the newest Ethernet library. Everything else works except mDNS is unreliable. Command line flashing over network is working well!
Is there much memory to be saved by eliminating the mDNS parts of your ArduinoOTA library? I won't be flashing much via network, only the occasional update so manual command line is not too much effort for me. I don't think I need to bother with mDNS at all then. For testing at my desk, I will use USB.
you can modify ArduinoOTA.h in the library. replace
ArduinoOTAMdnsClass <EthernetServer, EthernetClient, EthernetUDP> ArduinoOTA;
with
ArduinoOTAClass <EthernetServer, EthernetClient> ArduinoOTA;
but I don't know if it makes a difference for Mega
I'm ok without the IDE automatically finding the mdns broadcasts, it's working here with the manual command line.
Something though that I've observed with my modified version of the OTEthernet example, I'm seeing frequent Arduino reboots while doing almost nothing. At first, I was using DHCP which was working, except for when the COM port is closed, the Arduino frequently reboots. I can see the Ethernet shield LEDs go off, (pings momentarily timeout) and then it boots back up. So I switched to using a static IP, which at first seemed to work better but now it has the same symptom, without an active Serial/COM connection, the Arduino reboots approx every 10-15 secs. If I open the serial monitor, then it stays nice and steady.
#include <EEPROM.h>
/*
This example polls for sketch updates over Ethernet, sketches
can be updated by selecting a network port from within
the Arduino IDE: Tools -> Port -> Network Ports ...
Circuit:
* W5100, W5200 or W5500 Ethernet shield attached
created 13 July 2010
by dlf (Metodo2 srl)
modified 31 May 2012
by Tom Igoe
modified 16 January 2017
by Sandeep Mistry
Ethernet version August 2018
by Juraj Andrassy
modified by Matt Elias for static IP, LED output & EEPROM reboot counter
*/
#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoOTA.h>
//#define Serial SerialUSB
// Enter a MAC address for your controller below.
// Newer Ethernet shields have a MAC address printed on a sticker on the shield
IPAddress ip(192, 168, 12, 69);
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, ip[2], ip[3] };
// OTA port is 65280
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
//while (!Serial); // only needed for Leo?
Serial.print("\n\nVer: 2\nReboots: ");
int reboots;
EEPROM.get(1, reboots);
reboots++;
EEPROM.put(1, reboots);
Serial.println(reboots);
// start the Ethernet connection:
Serial.println("Initialize Ethernet");
Ethernet.begin(mac, ip);
Serial.println(Ethernet.localIP());
// start the OTEthernet library with internal (flash) based storage
ArduinoOTA.begin(Ethernet.localIP(), "Arduino", "password", InternalStorage);
}
void loop() {
// check for updates
ArduinoOTA.poll();
// add your normal loop code below ...
digitalWrite(LED_BUILTIN, HIGH);
delay(10);
digitalWrite(LED_BUILTIN, LOW);
delay(150);
digitalWrite(LED_BUILTIN, HIGH);
delay(10);
digitalWrite(LED_BUILTIN, LOW);
delay(2000);
}
Here are a couple graphs to show how consistently your ArduinoOTA library causes reboots on my mega2560. The graphs are my Arduino's reboot count, tracked in EEPROM and reported via mqtt. They are scaled according the the right axis. You can see it reboots about every 15 pings (15s) until I open the COM port via the IDE Serial Monitor. I'm using IDE 1.8.8 on Windows 7 64 bit. Static IP on the Arduino. The code I posted March 1 replicates this issue for me.
so the same sketch without ArduinoOTA runs in same conditions without resets? can I see the sketch?
the library does nothing special while no upload occurs.
my wild guess is that Windows is turning off power for the port for power saving