Go Down

Topic: Latest/Best Ethernet Bootloader for Mega2560 & W5100 (Read 1 time) previous topic - next topic

m_elias

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.

Code: [Select]
#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);
}

Juraj

how is com port closed? I would suspect powering
try one of the examples of the Ethernet library.

m_elias

how is com port closed? I would suspect powering
try one of the examples of the Ethernet library.
I closed the serial monitor.

m_elias

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.

Juraj

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

m_elias

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
There is something funny going on with this USB connection. I will try a different port.

m_elias

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
1172 bytes less program memory and 175 bytes less dynamic memory usage as reported by the IDE.


It's working quite well now on my bench test Arduino. I will try it next on a non-critical production Arduino.

darcio

I have Arduino Mega 2560 (R3 ?) board with Ethernet shield W5100, and I have issues using LAN upload (ArduinoOTA library). Here my setup and tests.

Arduino IDE path: C:\P\iot\arduino-1.8.5

Arduino sketch path: C:\W\Devs\Arduino

Arduino home path: C:\Users\User\AppData\Local\Arduino15

Arduino version: 1.8.5

I create "platform.local.txt" near and filled with previous indications:
C:\P\iot\arduino-1.8.5\hardware\platform.txt

I installed ArduinoOTA version 1.0.1 via "Library Manager".

I copied "my boards definitions" to:
C:\W\Devs\Arduino\hardware\my_boards-jandrassy-2019-02-22

I burn bootloader to Arduino Mega 2560 board using "Arduino Mega 2560 (Optiboot)".

I load the example OTEthernet and make some changes to blink a led:

---------------------------------------
#include <SPI.h>
#include <Ethernet.h>
#include <ArduinoOTA.h>


byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
byte ip[] = { 192, 168, 1, 177 }; 

void setup() {
  Serial.begin(9600);
  while (!Serial);
  Ethernet.begin(mac, ip);
  Serial.println(Ethernet.localIP());
  ArduinoOTA.begin(Ethernet.localIP(), "arduino", "password", InternalStorage);
  pinMode(LED_BUILTIN, OUTPUT);
}

void loop() {
  ArduinoOTA.poll();

  digitalWrite(LED_BUILTIN, HIGH);
  delay(500);                     
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);                   
}

---------------------------------------

I was able to burn the sketch via USB, the LED blink, and the ping from PC to board worked.

In the menu "Tools -> Ports" now display a new section "Network Ports" and a new entry "arduino at 192.168.1.177".

I choose this new entry and try again to upload the sketch, it display a window to enter the password "Type board password to uload a new sketch", I enter the password, and after it show the next message "Failed to reset the board, upload failed" (and then show again the password window):

---------------------------------------
Archiving built core (caching) in: C:\Users\User\AppData\Local\Temp\arduino_cache_988023\core\core_my_boards-jandrassy-2019-02-22_avr_mega_ac0f034b8350182b96c74d39de33e27f.a
Sketch uses 17008 bytes (6%) of program storage space. Maximum is 261120 bytes.
Global variables use 1012 bytes (12%) of dynamic memory, leaving 7180 bytes for local variables. Maximum is 8192 bytes.
Resetting the board
Failed to reset the board, upload failed
---------------------------------------

Please help me!


Juraj

platform.local.txt goes to C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.21
or to
C:\Program Files (x86)\Arduino\hardware\arduino\avr

darcio

Ok, I corrected the location. I installed full Arduino 1.8.5, and now the paths are:
Arduino IDE path: C:\Program Files (x86)\Arduino
Arduino sketch location: C:\W\Devs\Arduino
Arduino preferences path: C:\Users\User\AppData\Local\Arduino15

I copied file "platform.local.txt" from
C:\W\Devs\Arduino\libraries\ArduinoOTA\extras\avr
to
C:\Program Files (x86)\Arduino\hardware\arduino\avr

Now, when I try to upload via OTA, the message after entering the password is "flag provided but not defined: -username" as below:

Archiving built core (caching) in: C:\Users\User\AppData\Local\Temp\arduino_cache_886878\core\core_arduino_avr_mega_cpu_atmega2560_0c812875ac70eb4a9b385d8fb077f54c.a
Sketch uses 17008 bytes (6%) of program storage space. Maximum is 253952 bytes.
Global variables use 1012 bytes (12%) of dynamic memory, leaving 7180 bytes for local variables. Maximum is 8192 bytes.
flag provided but not defined: -username
Usage of C:\Program Files (x86)\Arduino\hardware\tools\avr\bin\arduinoOTA:
  -address string
       The address of the board (default "localhost")
  -b   Upload binary mode
  -port string
       The board needs to be listening on this port (default "80")
  -q   Quiet flag
  -reset string
       Upload endpoint
  -sketch string
       Sketch path
  -ssl string
       SSL flag
  -sync string
       Upload endpoint
  -sync_exp string
       sync expected return code in format code:string
  -upload string
       Upload endpoint
  -v   Verbose flag (default true)
  -version
       Prints program version

Juraj

turn on verbose mode in Preferences to see the command

darcio

I attached verbose.txt because exceed the limit allowed to post.

Juraj

the Arduino IDE 1.8.5 has some older version of the arduinoOTA upload tool. update the AVR package in Boards Manager to 1.6.23. it will update the tool

darcio

I updated to version 1.6.23.

Also I copied "platform.local.txt" to
C:\Users\User\AppData\Local\Arduino15\packages\arduino\hardware\avr\1.6.23

I attached the new verbose. Now the message window show again:
Resetting the board
Failed to reset the board, upload failed

darcio

I restarted Arduino, and it works  :)

Below the message:

Code: [Select]
Sketch uses 16940 bytes (6%) of program storage space. Maximum is 261120 bytes.
Global variables use 966 bytes (11%) of dynamic memory, leaving 7226 bytes for local variables. Maximum is 8192 bytes.
C:\Users\User\AppData\Local\Arduino15\packages\arduino\tools\arduinoOTA\1.2.1/bin/arduinoOTA -address 192.168.0.22 -port 65280 -username arduino -password password -sketch C:\Users\User\AppData\Local\Temp\arduino_build_381075/s_ota.ino.bin -upload /sketch -b
Connecting to board ...  done
Uploading sketch ...  done
Flashing sketch ...  done

Sketch uploaded successfully


Many thanks Juraj!!!

Go Up