Using AI to upgrade from ESP-IDF 4.1 to 5.5

sysprogs
Posts: 13
Joined: Fri Apr 06, 2018 2:09 am

Using AI to upgrade from ESP-IDF 4.1 to 5.5

Postby sysprogs » Wed Mar 11, 2026 3:40 pm

Hi All,

I've been toying around the idea of using AI to semi-automatically port code to newer SDK versions. It's usually not very practical with C/C++ due to the sheer amount of header files where everything is defined. But now that we got VisualGDB's symbol-level editing working, I decided to give it another try with ESP-IDF, and it worked rather well.

I took an older open-source MQTT demo that was made with ESP-IDF 4.1, and failed to build on v5.5 due to some minor API changes. It was mostly things like this:

Code: Select all

	esp_mqtt_client_config_t mqtt_cfg = {
        .uri = sysCfg.mqtt_host,
		.port = sysCfg.mqtt_port,
		.client_id = sysCfg.device_id,
		.username = sysCfg.mqtt_user,
		.password = sysCfg.mqtt_pass,
		.disable_clean_session = !sysCfg.mqtt_cleansession,
		.keepalive = sysCfg.mqtt_keepalive,
    };
that had to be changed to:

Code: Select all

	esp_mqtt_client_config_t mqtt_cfg = {
		.broker = {
		.address = {
		.uri = sysCfg.mqtt_host,
		.port = sysCfg.mqtt_port,
	}
	},
		.credentials = {
		.client_id = sysCfg.device_id,
		.username = sysCfg.mqtt_user,
		.authentication = {.password = sysCfg.mqtt_pass},
	},
		.session = {
		.disable_clean_session = !sysCfg.mqtt_cleansession,
		.keepalive = sysCfg.mqtt_keepalive,
	},
};
AI totally breezed through it. If you do one relatively small function at once, it takes between 5 and 20 seconds to do, depending on the model. Large files took 20-60 seconds. Really small models (2-3 seconds per huge file) would get confused and start introducing nonsensical variables (like int broker_port inside the function), but Gemini 3 Flash and anything bigger than that did not have that problem.

VisualGDB's magic is that it packs code, definitions, and error messages together. The AI model sees something like this:

Code: Select all

esp_mqtt_client_config_t mqtt_cfg = {
    .uri = sysCfg.mqtt_host,        <<<ERROR: invalid field 'uri'
    .port = sysCfg.mqtt_port,
together with the definition of esp_mqtt_client_config_t, but skipping the irrelevant symbols. So, it doesn't take much tokens, and works pretty accurately.

We made a step-by-step tutorial on the new technique here: https://visualgdb.com/tutorials/ai/esp32/upgrading/
We also just got the VisualGDB's Clang-based C/C++ logic running directly on Linux and MacOS, so it will be soon available as a stand-alone product for folks that don't use Windows.

Any feedback is welcome.

Who is online

Users browsing this forum: Baidu [Spider], Google [Bot] and 8 guests