arduino-libraries / WiFiLink-Firmware

Arduino WiFi Link firmware for ESP8266 based boards
MIT License
11 stars 30 forks source link

MCU OTA with Uno Wifi #28

Open JAndrassy opened 7 years ago

JAndrassy commented 7 years ago

I was successful with MCU OTA on Uno Wifi (dev.ed.). I copied ArduinoMcuOTA.ino from the 'ota' branch and related changes in ArduinoFirmwareEsp.ino into 'master' source code. I did build arduino dfu library from the arduino-debug branch of ciminaghi/libdfu project with libdfu/arduino/build_src_zip. It's great that WiFi Link firmware project is an Arduino IDE 'sketch' for the ESP8266. There is no need to setup 'toolchains' and fight with makefiles. It can be build for the Uno Wifi in Arduino IDE with Arduino core for ESP8266 2.4.0-rc1. I used arduino-org/arduino-tool-mcu-ota for the sketch upload. And it works everything together. I even patched arduino_mcuota into IDE thru platform.txt. There is a small issue: After mcu ota the mcu sketch can't connect with WifiLink library. Only after a power-cycle.

JAndrassy commented 7 years ago

another issue: small hex files wan't ota upload and mcu freezes in programming mode. sketches that use libraries and result in bigger hex files, upload fine

ciminaghi commented 7 years ago

Could you please attach an hex file which triggers the issue ? If that's impossible for some reason, please just tell me about the size of the file. I'm doing some tests next week and will look into this too.

Thanks ! Davide

JAndrassy commented 7 years ago

I tried Blink and other basic Arduino examples.

ciminaghi commented 7 years ago

Blink used to work when I did my tests some months ago, as far as I can remember :-( I see we're running different clients (the one I used for my tests was arduino_mcuota.py.gz, which looks [a little] different from arduino-org/arduino-tool-mcu-ota). Anyway, I'll do some tests next week to see if I can reproduce the bug. Will keep you up to date.

Thanks a lot again for your testing ! Davide

JAndrassy commented 7 years ago

I thank you Davide, for a libdfu library. Your copy of arduino_mcuota.py is effectively the same as arduino-org/arduino-tool-mcu-ota. Only real difference is timeout in requests.post. I used Python 2.7.13

Nix2Fix commented 7 years ago

Hi, I've been trying all different ESP8266 firmware's and this project looks like the best one. The last problem I'm trying to solve is OTA. I've gotten as far as installing the released 1.0 firmware and the python script to upload sketches, but as I'm on ver 1.0 firmware it does not seem to have the included OTA functionality and I get the error: "FileNotFound" and fiddler shows me a 404 /otafile does not exist on the web server.

Is there any chance in getting a bin firmware with OTA in it?

I'm using an "Arduino Uno Wifi".

Thanks in advance for any responses.

ciminaghi commented 7 years ago

On Mon, Jun 26, 2017 at 07:01:06PM -0700, Nix2Fix wrote:

Hi, I've been trying all different ESP8266 firmware's and this project looks like the best one. The last problem I'm trying to solve is OTA.

OTA update of the atmega ? Or of the esp8266 ?

I've gotten as far as installing the released 1.0 firmware and the python script to upload sketches, but as I'm on ver 1.0 firmware it does not seem to have the included OTA functionality and I get the error: "FileNotFound" and fiddler shows me a 404 /otafile does not exist on the web server.

Is there any chance in getting a bin firmware with OTA in it?

As far as I know (I just developed libdfu, which receives hex files and writes the atmega flash) you can write sketches for the esp8266 to do ota update of the atmega. I'm attaching a sketch I used for my tests.

One of the things the library has to know to do its job, is how to talk to the target processor. If you have a look at the sketch, you'll see this:

global_dfu = dfu_init(/ &esp8266_serial_arduinouno_hacked_interface_ops, / &esp8266_serial_arduino_unowifi_interface_ops, NULL, NULL, &stk500_dfu_target_ops, &atmega328p_device_data, &esp8266_dfu_host_ops);

The first argument of the dfu_init() function is a pointer to the "interface operations", i.e. a structure containing pointers to functions which can initialize the interface, read from and write to it, reset the target processor and so on. The fourth argument is a pointer to a target operations structure. These functions have to do with the protocol you want to use to talk to the target.

There are some predefined sets of functions for boards supported "out of the box", but then of course you can write interface operations for any board you like (it's usually pretty simple, actually). If you want to have a look at the predefined sets of functions, they're under src/interface in the library git repository:

ciminaghi@zarro:/home/develop/yun/libdfu/src/interface$ ls dummy.c esp8266-spi-arduinouno-hacked.c esp8266-arduino-serial.h esp8266-spi-arduinouno-hacked.cpp esp8266-serial-arduinouno-hacked.c esp8266-spi.c esp8266-serial-arduinouno-hacked.cpp esp8266-spi.h esp8266-serial-arduinounowifi.cpp linux-dummy.c esp8266-serial-star8.c linux-serial-arduino-uno.c esp8266-serial-star8.cpp linux-serial-stm32.c esp8266-serial.c linux-serial.c esp8266-serial.h linux-serial.h

Now, let's take esp8266-serial-arduinounowifi.cpp for instance. You can see this comment at the top of the file:

/*

This is telling you that the operations implemented in this file set up a programming interface which uses GPIO12 of the esp8266 as target reset and UART0 as a communication channel between the esp8266 and the atmega. This works on arduino wifi V3 or V4, not on V2.

You can also notice that some of the functions (open, read, write, ...) are common to all the interfaces using an esp8266 uart, so they're implemented in esp8266-serial.c.

So the answer is: ota fw update of the atmega should be supported, but you should make sure that your hw version is actually supported.

Hope this helps Davide

include

include

include

include

include

include

include

include

include

include

include

include

include

include

struct dfu_data global_dfu; struct dfu_binary_file global_binary_file;

const char ssid = "VodafoneMobileWiFi-568C8A"; const char password = "4UBWQ44777";

if 0

static void send_dummy_string(void) { const char str[] = { 0, 1, 2, 0, 4, 5, 6, 7, };

if (!global_dfu)
   return;
esp8266_serial_arduino_unowifi_interface_ops.write(global_dfu->interface, str, sizeof(str));
delay(10);

}

endif

static int _setup_dfu(void) { global_dfu = dfu_init(/ &esp8266_serial_arduinouno_hacked_interface_ops, / &esp8266_serial_arduino_unowifi_interface_ops, NULL, NULL, &stk500_dfu_target_ops, &atmega328p_device_data, &esp8266_dfu_host_ops);

if (!global_dfu) { Serial1.printf("Error initializing dfu library"); return -1; }

global_binary_file = dfu_binary_file_start_rx(&dfu_rx_method_http_arduino, global_dfu, NULL); if (!global_binary_file) { Serial1.printf("Error instantiating binary file"); return -1; }

if (dfu_binary_file_flush_start(global_binary_file) < 0) Serial1.printf("Error in dfu_binary_file_flush_start()"); }

void setup() { Serial1.begin(115200, SERIAL_8N1, SERIAL_TX_ONLY); delay(500); WiFi.begin(ssid, password);
}

void loop() { if (!global_dfu) _setup_dfu();
//send_dummy_string(); //return; if (!global_dfu) return; switch (dfu_idle(global_dfu)) { case DFU_ERROR: Serial1.printf("Error programming file"); break; case DFU_ALL_DONE: Serial1.printf("Programming OK"); dfu_target_go(global_dfu); //dfu_binary_file_flush_start(global_binary_file); dfu_binary_file_fini(global_binary_file); dfu_fini(global_dfu); global_dfu = NULL; global_binary_file = NULL; break; case DFU_CONTINUE: break; } }

Nix2Fix commented 7 years ago

Sorry I was not clear, let me elaborate.

I'm trying to use "arduino-tool-mcu-ota" to upload sketches over the IP Address of the Arduino Uno Wifi using the wifilink firmware.

It would seem that the compiled v1.0 of wifilink firmware is missing the OTA components to make this work.

It sounded like "jandrassy" in the first post got this working by building a custom version of this firmware by combining the OTA and Master branch. The OTA branch does contain other files that the Master one does not.

I do not know how to replicate "jandrassy" work, so I was hoping I could get a copy of the compiled version.

Thanks.

ciminaghi commented 7 years ago

On Tue, Jun 27, 2017 at 02:38:02AM -0700, Nix2Fix wrote:

Sorry I was not clear, let me elaborate.

I'm trying to use "arduino-tool-mcu-ota" to upload sketches over the IP Address of the Arduino Uno Wifi using the wifilink firmware.

It would seem that the compiled v1.0 of wifilink firmware is missing the OTA components to make this work.

It sounded like "jandrassy" in the first post got this working by building a custom version of this firmware by combining the OTA and Master branch. The OTA branch does contain other files that the Master one does not.

I do not know how to replicate "jandrassy" work, so I was hoping I could get a copy of the compiled version.

I see, thanks for the explanation. Unfortunately, I don't know much about such branches, so I don't think I can help you with this at the moment :-(

Hoping somebody else can shed some light ... Davide

pieman64 commented 7 years ago

@jandrassy wrote

There is a small issue: After mcu ota the mcu sketch can't connect with WifiLink library. Only after a power-cycle.

This sounds like normal ESP8266 behaviour. With an ESP you need to do a power cycle before any sketch flashed via Serial with a reset function will operate. This is not really considered an issue because once you have flashed an ESP via Serial, that will have subsequent OTA updates, you "automatically" unplug (power -cycle) the device and move it to another site / location. Hope that makes sense.

Once the first flash has been done via Serial and the device "relocated" OTA is fine.

Or are you saying OTA simply doesn't work without a power cycle when you "relocate" the Uno WiFi board after the initial local Serial flash?

JAndrassy commented 7 years ago

@pieman64, this is about ATmega MCU OTA flashing using ESP, not flashing of the ESP8266

JAndrassy commented 6 years ago

@ciminaghi Davide are you here? How do you see the future of the libdfu library?

ciminaghi commented 6 years ago

On Sat, Nov 18, 2017 at 03:06:26PM +0000, Juraj Andr??ssy wrote:

@ciminaghi Davide are you here? How do you see the future of the libdfu library?

At the moment I'm working on a port to the arduino primo (host esp8266, target nrf52, spi interface). The problem is implementing the nordic dfu protocol on the esp8266 and making the whole thing work over spi, so it's not that easy.

Davide

JAndrassy commented 6 years ago

does it mean, that WiFi Link did not end with Arduino.org? I made improvements to WiFi Link firmware and library in my fork. is it worth to make a pull request? will somebody care?

ciminaghi commented 6 years ago

On Mon, Nov 20, 2017 at 09:03:50AM +0000, Juraj Andr??ssy wrote:

does it mean, that WiFi Link did not end with Arduino.org? I made improvements to WiFi Link firmware and library in my fork. is it worth to make a pull request? will somebody care?

I was requested to extend the library for programming the nrf52 on the arduino primo via wifi. Unfortunately, that's the only thing I know for sure. Sorry for not being able to help you on this subject.

Davide