OTA for slave MODBUS

alhadi
Posts: 15
Joined: Thu Apr 14, 2022 9:29 am

OTA for slave MODBUS

Postby alhadi » Mon Jun 20, 2022 12:47 pm

Hello

I have 2 boards connected to each other using Modbus
The master board is connected to the internet using Ethernet
I can ota the master board using the http_ota example
Is there a way to perform ota for the slave board through master board since slave board has no access to internet?

marbalon
Posts: 23
Joined: Wed Dec 20, 2017 11:02 am

Re: OTA for slave MODBUS

Postby marbalon » Thu Jun 23, 2022 12:50 pm

Hi,

I'm using UART or TCP communication to update slave ESP32 MCU. All you have to do is use these steps:

Begin update with:

Code: Select all

static esp_ota_handle_t update_handle = 0;
static const esp_partition_t *update_partition = NULL;
...
update_partition = esp_ota_get_next_update_partition(NULL);
esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
Then write data to partition:

Code: Select all

esp_ota_write(update_handle, (const void *)buff, len);
End then finish update with:

Code: Select all

	if (esp_ota_end(update_handle) != ESP_OK)
	{
		ESP_LOGE(TAG, "esp_ota_end failed!");
		return;
	}

	err = esp_ota_set_boot_partition(update_partition);
	if (err != ESP_OK)
	{
		ESP_LOGE(TAG, "esp_ota_set_boot_partition failed! err=0x%x", err);
		return;
	}
I think the source partition can be read in a similar way to ota write. But maybe it better is to read flash to most send unused empty space after firmware.

alhadi
Posts: 15
Joined: Thu Apr 14, 2022 9:29 am

Re: OTA for slave MODBUS

Postby alhadi » Mon Jun 27, 2022 8:16 am

marbalon wrote:
Thu Jun 23, 2022 12:50 pm
Hi,

I'm using UART or TCP communication to update slave ESP32 MCU. All you have to do is use these steps:

Begin update with:

Code: Select all

static esp_ota_handle_t update_handle = 0;
static const esp_partition_t *update_partition = NULL;
...
update_partition = esp_ota_get_next_update_partition(NULL);
esp_ota_begin(update_partition, OTA_SIZE_UNKNOWN, &update_handle);
Then write data to partition:

Code: Select all

esp_ota_write(update_handle, (const void *)buff, len);
End then finish update with:

Code: Select all

	if (esp_ota_end(update_handle) != ESP_OK)
	{
		ESP_LOGE(TAG, "esp_ota_end failed!");
		return;
	}

	err = esp_ota_set_boot_partition(update_partition);
	if (err != ESP_OK)
	{
		ESP_LOGE(TAG, "esp_ota_set_boot_partition failed! err=0x%x", err);
		return;
	}
I think the source partition can be read in a similar way to ota write. But maybe it better is to read flash to most send unused empty space after firmware.
Thank you, will test that. The code is on the receiving end, how about the sending end?
I get the fw using http ota library already provided by esp32

marbalon
Posts: 23
Joined: Wed Dec 20, 2017 11:02 am

Re: OTA for slave MODBUS

Postby marbalon » Wed Jun 29, 2022 7:26 am

If you haev toe hsame firmware in two boards you can use esp_partition_read() to get data from first device and send it to second one. If the firmware is different you can use bin files embedded into the firmware of the first/master device.

Who is online

Users browsing this forum: No registered users and 80 guests