I'm working in WiFi Sniffer that Sniff during a period of time and then turns off to send the legs to pastebin page.
My current code is able to create the log file and Log into them, but when it comes to send the data, I just cant:
while (f.available()) {
cleint.write(f.read());
}
client.flush();
I'm doing all of this in a POST request, doing this code above I get nothing. If I do the same using client.print, I get numbers, that SHOULD correspond to the Unicode characters that i see in the Serial terminal, but some of they not. I have this couple of "wired" functions to write the headers of the file:
void filewrite_32(uint32_t n){
uint8_t buf[4];
buf[0] = n;
buf[1] = n >> 8;
buf[2] = n >> 16;
buf[3] = n >> 24;
Serial.write(buf, 4);
file.write(buf, 4);
}
void filewrite_16(uint16_t n){
uint8_t buf[2];
buf[0] = n;
buf[1] = n >> 8;
Serial.write(buf, 2);
file.write(buf, 2);
}
This is how I init the file:
void pcap_create() {
filewrite_32(0xa1b2c3d4);
filewrite_16(2);
filewrite_16(4);
filewrite_32(0);
filewrite_32(0);
filewrite_32(2500);
filewrite_32(105);
}
and this is the callback that I use to read packges:
void rx_cb(uint8_t *buf, uint16_t len) {
if (file) {
filewrite_32(now());
filewrite_32((unsigned int)(micros() - millis() * 1000));
filewrite_32(len);
filewrite_32(len);
Serial.write(buf, len);
file.write(buf, len);
}
}
But then, when I fill 245 kB of data in a flash file, I start sending it with:
Serial.printf("Sending file to dpaste.com...\n");
c->printf("POST /api/v2/ HTTP/1.1\r\n");
c->printf("Host: dpaste.com\r\n");
c->printf("User-Agent: ESP8266EX\r\n");
c->printf("Authorization: Bearer <TOKEN>\r\n");
c->printf("Content-Type: application/x-www-form-urlencoded\r\n");
c->printf("Cache-Control: no-cache\r\n");
c->printf("Content-Length: %u\r\n", 30 + title.length() + f.size());
c->printf("\r\n");
c->printf("title=%s&expiry_days=30&content=", title.c_str());
while (f.available()) {
c->write(f.read());
}
c->flush();
c->printf("\r\n");
f.close();
but nothing happens in the other side. I know that the function to send works becouse i was able to send strings using print.
This is the log that I get in the serial terminal:
And when i tried to use print:
while (f.available()) {
c->printf("%x,", f.read());
}
I got: dpaste.com output
d4,c3,b2,a1,2,0,4,0,0,0,0,0,0,0,0,0,c4,9,0,0,69,0,0,0,22,0,0,0,a4,1,0,0,80,0,0,0,80,0,0,0,b9,10,34,51,0,0,0,0,0,0,1,0,80,0,0,0,ff,ff,ff,ff,ff,ff,60,14,b3,8,e4,80,60,14,b3,8,e4,80,20,38,80,61,86,e7,2b,1,0,0,64,0,31,0,0,17,46,69,62,65,72,74,65,6c,20,57,69,46,69,32,31,35,20,32,2e,34,47,48,7a,1,8,82,84,8b,96,c,12,18,24,3,1,1,5,4,0,1,0,0,7,6,41,52,20,1,d,1a,2a,1,0,32,4,30,48,60,6c,b,5,3,0,e,0,0,2d,1a,ad,1,1b,ff,ff,ff,1,0,34,1,23,0,0,0,d1,2,0,0,80,0,0,0,80,0,0,0,b9,10,34,51,0,0,0,0,0,0,1,0,....
But if you translate those values to Unicode, they aren't the same as showed in the terminal.
If someone knows or has some idea what can help me, I would really appreciate. Thanks all.
