Sming - Open Source framework for high efficiency native ESP8266 development

User avatar
By piperpilot
#24583 I'm integrating rboot into my project to update firmware from an http server. I'd like to use a hostname instead of an IP address, but need to do a DNS lookup. Does anyone have an example of using the DNS client services in lwip to resolve a hostname?
User avatar
By gschmott
#24588 I just made a call to dns_gethostbyname() prior to starting my the OTA using rboot, e.g.

dns_gethostbyname(url.c_str(), &ipAddr, OtaUpdater::onUrlResolved, this);

Once the URL is resolved, I made a call to

rboot_ota_start(&inst->ota)

with the ota structure filled in with the resolved IP address, e.g.

// Create the update structure
memcpy(&inst->ota.ip, ip, sizeof(*ip));
inst->ota.port = inst->port;
inst->ota.callback = OtaUpdater::onFirmwareFetched;
inst->ota.user_arg = inst;

// Select rom slot to flash
slot = rboot_get_current_rom();
if (slot == 0) slot = 1; else slot = 0;
inst->ota.rom_slot = slot;

// Actual HTTP request
os_sprintf((char*)inst->ota.request,
"GET /%s HTTP/1.1\r\nHost: " IPSTR "\r\n" HTTP_HEADER,
(slot == 0 ? "rom0.bin" : "rom1.bin"),
IP2STR(inst->ota.ip));

debugf("OtaUpdater: HTTP request: %s\n", inst->ota.request);
// Start the upgrade process
if ( rboot_ota_start(&inst->ota) )
{
inst->status = OTA_STATUS_FETCHING_FIRMWARE;
debugf("Fetching firmware...\r\n");
}

Hope this helps . . .