How to save and read the byte array received from the server as a file in littlefs

sharalee
Posts: 1
Joined: Tue Jun 28, 2022 12:35 am

How to save and read the byte array received from the server as a file in littlefs

Postby sharalee » Tue Jun 28, 2022 2:20 am

I have to save the byte array from HttpClient(Http) in Spiffs file system.
So, I get the byte array from server using https -> getStream, and save as ".txt" in spiffs.
And byte array size is almost 320kB.
And I read the ".txt" file, send to data using BLE.

I attached my source code.

boolean Ring_Dfu_FileDownload_data(String URL){
int httpCode;

WiFiClientSecure *client = new WiFiClientSecure;
client->setCACert(ca_cert);
HTTPClient *https = new HTTPClient;

https->begin(*client, URL);
https->addHeader("cartgwUserKey", s_Save_API_GWToken);
https->addHeader("Content-Type", HEADER_Content_type);


Ring_Dfu_Download_Req("dat");
httpCode = https->POST((uint8_t*)pageString, strlen(pageString));
Serial.printf("[HTTPS POST] Code: %d\n", httpCode);

if(httpCode == HTTP_CODE_OK){
int len = https->getSize();
//int8_t *data = (int8_t*)malloc(sizeof(int8_t) * sizeof(len));
//int8_t *data = (int8_t *)ps_malloc(sizeof(len));
// int8_t buf[128] = {0,};
WiFiClient *stream = https->getStreamPtr();
while(https->connected() && (len > 0 || len == -1)){
size_t size = stream->available();
if(size){
//int c = stream->readBytes(buf, ((size > sizeof(buf)) ? sizeof(buf) : size)); //error
//file save code
}
}

}
https->end(); delete https;
client->stop(); if (client != nullptr) delete client;
return true;
}

Who is online

Users browsing this forum: No registered users and 128 guests