Page 1 of 1

OTA for slave MODBUS

Posted: Mon Jun 20, 2022 12:47 pm
by alhadi
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?

Re: OTA for slave MODBUS

Posted: Thu Jun 23, 2022 12:50 pm
by marbalon
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.

Re: OTA for slave MODBUS

Posted: Mon Jun 27, 2022 8:16 am
by alhadi
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

Re: OTA for slave MODBUS

Posted: Wed Jun 29, 2022 7:26 am
by marbalon
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.