我想将我的日志文件从我的 ESP32 闪存下载到我的 Android 手机。
我知道我们一次只能发送 20 个字节的文件。因此,我将文件分成 20 个字节的块。这是我的代码:
#define PAYLOAD_CHUNK_SIZE 20
for (int i = 0; i < file_size; i = i+PAYLOAD_CHUNK_SIZE){
uint8_t file_buffer[PAYLOAD_CHUNK_SIZE];
for (int j = 0; j <20; j++){
file_buffer[j] = (uint8_t) buffer[i+j];
}
update_char_file_value(file_buffer, PAYLOAD_CHUNK_SIZE);
count++;
printf("sending data! %d", count);
ets_delay_us(10000);
}
void update_char_file_value(uint8_t *data, uint16_t len){
uint16_t handle = sensor_handle_table[IDX_CHAR_FILE_VAL_TX];
esp_ble_gatts_set_attr_value(handle, len, data);
if (isNotifyEnabled == true){
esp_ble_gatts_send_indicate(sensor_profile_tab[PROFILE_APP_IDX].gatts_if, sensor_profile_tab[PROFILE_APP_IDX].conn_id, handle,
len, data, false);
}
}
以下代码适用于小文件(最大 400 字节),但除此之外,我将得到以下结果:
sending data! 1sending data! 2sending data! 3sending data! 4sending data! 5sending data! 6sending data! 7sending data! 8sending data! 9sending data! 10sending data! 11sending data! 12sending data! 13sending data! 14sending
data! 15sending data! 16sending data! 17sending data! 18sending data! 19sending data! 20sending data! 21sending data! 22sending data! 23sending data! 24sending data! 25sending data! 26sending data! 27sending data! 28sending data! 29sending data! 30sending data! 31sending data! 32sending data! 33sending data! 34sending data! 35sending data! 36sending data! 37sending data! 38sending data! 39sending data! 40sending data! 41sending data! 42sending data! 43sending data! 44sending data! 45sending data! 46sending data! 47sending data! 48sending d
打印完之后,ESP32 就会卡住,不响应任何东西,除非你再次重置它。
我不确定这是否是 Android 应用程序的问题,但我认为它更倾向于 esp32 处理文本传输。
这里有没有人曾经通过BLE成功发送过大文件?非常感谢您的帮助!