void ICACHE_FLASH_ATTR handle_response(fota_client_t *fota_client) { INFO("Final response: %s\n", get_version_body); /* parse json, get version */ char *n_host, *n_path, *n_version, *n_protocol; if (parse_fota(get_version_body, get_version_body_len, &n_version, &n_host, &n_path, &n_protocol) < 0) { INFO("FOTA Client: Invalid response\n"); goto CLEAN_MEM; } INFO("\tVersion %s\n", n_version); INFO("\tHost %s\n", n_host); INFO("\tPath %s\n", n_path); INFO("\tProtocol %s\n", n_protocol); /* then, we have valide JSON response */ uint32_t version; if (convert_version(n_version, os_strlen(n_version), &version) < 0) { REPORT("FOTA Client: Invalide version return %s\n", n_version); goto CLEAN_MEM; } /* if we still have lastest version */ if (version <= version_fwr) { INFO("FOTA Client: We have lastest firmware (current %u.%u.%u vs online %u.%u.%u)\n", (version_fwr/256/256)%256, (version_fwr/256)%256, version_fwr%256, (version/256/256)%256, (version/256)%256, version%256); goto CLEAN_MEM; } INFO("FOTA Client: Preparing to get firmware\n"); fota_client->status = FOTA_GETTING_FIRMWARE; start_cdn(&fota_client->fw_server, n_version, n_host, n_path, n_protocol); CLEAN_MEM: FREE(n_host); FREE(n_path); FREE(n_version); FREE(n_protocol); }
/** * @brief response for get version request. * parse answer, save online version to flash. * @param arg: contain the ip link information * pusrdata: data * len: len of data (strlen) * @retval None */ LOCAL void ICACHE_FLASH_ATTR get_version_recv(void *arg, char *pusrdata, unsigned short len) { struct espconn *pespconn = arg; fota_client_t *fota_client = (fota_client_t *)pespconn->reverse; /* get body */ char *body = (char*)os_strstr(pusrdata, "\r\n\r\n"); if (body == NULL) { INFO("Invalide response\n"); return; } INFO("Body: %s\n", body+4); uint32_t bodylen = os_strlen(body); /* parse json, get version */ char *n_host, *n_url, *n_version, *n_protocol; if (parse_fota(body, bodylen, &n_version, &n_host, &n_url, &n_protocol) < 0) { INFO("FOTA Client: Invalid response\n"); goto CLEAN_MEM; } INFO("\tVersion %s\n", n_version); INFO("\tHost %s\n", n_host); INFO("\tURL %s\n", n_url); INFO("\tProtocol %s\n", n_protocol); /* then, we have valide JSON response */ // disable data receiving timeout handing // and close connection os_timer_disarm(&fota_client->request_timeout); #if (FOTA_SECURE) espconn_secure_disconnect(pespconn); #else espconn_disconnect(pespconn); #endif uint32_t version; if (convert_version(n_version, os_strlen(n_version), &version) < 0) { REPORT("FOTA Client: Invalide version return %s\n", n_version); goto CLEAN_MEM; } /* if we still have lastest version */ if (version <= version_fwr) { INFO("FOTA Client: We have lastest firmware (current %u.%u.%u vs online %u.%u.%u)\n", (version_fwr/256/256)%256, (version_fwr/256)%256, version_fwr%256, (version/256/256)%256, (version/256)%256, version%256); goto CLEAN_MEM; } INFO("FOTA Client: Preparing to get firmware\n"); start_cdn(&fota_client->fw_server, n_version, n_host, n_url, n_protocol); CLEAN_MEM: FREE(n_host); FREE(n_url); FREE(n_version); FREE(n_protocol); }