7,662
社区成员
发帖
与我相关
我的任务
分享IoT 模组上部署 AI 模型时,如何处理网络断连后的推理结果上报问题?
网络断连场景下,不能直接丢弃推理结果,应先本地缓存,网络恢复后再批量上报。
void save_result_locally(Result result) {
FILE* fp = fopen("/flash/result_cache.txt", "a");
if (fp) {
fprintf(fp, "%d,%d,%.2f\\n", result.timestamp, result.type, result.score);
fclose(fp);
}
}
if (network_connected()) {
upload_cached_results();
clear_cache();
}
if (cache_count() > 1000) {
remove_oldest_result();
}