-->
Page 1 of 1

WifiClient.write issue with long packets (>2048 bytes)

PostPosted: Tue May 09, 2017 6:16 am
by fededim
Hi,

I am trying to return an image (previously saved into SPIFFS) to a wifi client and I have this strange issue: if I send the image in chunks of maximum 2048 bytes everything works, instead if I send in chunks of 4096 bytes the data gets garbled. Basically I am:

1) Allocating a buffer
2) Reading file into the buffer
3) Writing buffer to wificlient

I checked if it was a read error by dumping some bytes of the read buffer, but the reads are fine as you can see from the two logs (one for 2048 chunks and one for 4096, bytes dumped in i-eth send of 4096 buffer are equal to (2*i)-eth send of 2048 buffer). So there must be some problem with wificlient.write. Do you know if there is a maximum number of bytes which can be sent ? I have tried also with client.flush after a write, but it does not work.

Code:
buf=(char *) os_malloc(4096);

int k=0;
while (f.available() > 0) {
int i = f.readBytes(buf, 4096);
Serial.printf("EspOven: read %d bytes to client (%d): %02x %02x %02x %02x %02x %02x %02x %02x\n",i,k++,buf[0],buf[1],buf[2],buf[3],buf[4],buf[5],buf[6],buf[7]);

client.write((const uint8_t *) buf, i);
client.flush();
Serial.printf("EspOven: written %d bytes to client (%d)\n",i,k++);
delay(1); // pass control to network stack
}

os_free(buf);

f.close();


Log 2048 chunks:
EspOven: Client connected from xxx.yy.zz.www:8917
EspOven: received request:
GET /20150918_235057.jpg HTTP/1.1
EspOven: method GET path /20150918_235057.jpg ver HTTP/1.1 freeheap 43200
EspOven: path /20150918_235057.jpg found, file len 192645 mime image/jpeg
EspOven: read 2048 bytes to client (0): ff d8 ff e0 00 10 4a 46
EspOven: written 2048 bytes to client (0)
EspOven: read 2048 bytes to client (1): 00 00 00 00 00 00 00 00
EspOven: written 2048 bytes to client (1)
EspOven: read 2048 bytes to client (2): 00 00 00 00 00 00 00 00
EspOven: written 2048 bytes to client (2)
EspOven: read 2048 bytes to client (3): d1 cf d2 d0 ce d2 d1 d0
EspOven: written 2048 bytes to client (3)
EspOven: read 2048 bytes to client (4): b4 b3 b3 b2 b2 b4 b2 b2
EspOven: written 2048 bytes to client (4)
EspOven: read 2048 bytes to client (5): fd 31 ff 00 ec a9 8d e0
EspOven: written 2048 bytes to client (5)
EspOven: read 2048 bytes to client (6): 6d 70 3a 43 72 65 61 74
EspOven: written 2048 bytes to client (6)
EspOven: read 2048 bytes to client (7): 20 20 20 20 20 20 20 20
EspOven: written 2048 bytes to client (7)
EspOven: read 2048 bytes to client (8): 0a 20 20 20 20 20 20 20
EspOven: written 2048 bytes to client (8)
EspOven: read 2048 bytes to client (9): 20 20 20 20 20 20 20 20
EspOven: written 2048 bytes to client (9)
EspOven: read 2048 bytes to client (10): 20 20 20 20 20 20 20 20
EspOven: written 2048 bytes to client (10)
EspOven: read 2048 bytes to client (11): 20 20 20 20 20 20 20 20
EspOven: written 2048 bytes to client (11)
EspOven: read 2048 bytes to client (12): 20 20 20 20 20 20 20 20
EspOven: written 2048 bytes to client (12)
EspOven: read 2048 bytes to client (13): 04 e5 bd 41 e0 fd 7f 4c
EspOven: written 2048 bytes to client (13)
EspOven: read 2048 bytes to client (14): c8 ce 70 3a 0a 62 90 d1
EspOven: written 2048 bytes to client (14)
EspOven: read 2048 bytes to client (15): 47 3e e6 84 d9 b1 95 b7
EspOven: written 2048 bytes to client (15)
EspOven: read 2048 bytes to client (16): b4 53 d8 e4 b3 06 0b 9f
EspOven: written 2048 bytes to client (16)
EspOven: read 2048 bytes to client (17): 13 8c 0c 9e 99 3d 8d 32
EspOven: written 2048 bytes to client (17)
EspOven: read 2048 bytes to client (18): 6e 3e 94 b1 fc af cf d3
EspOven: written 2048 bytes to client (18)
EspOven: read 2048 bytes to client (19): 01 51 85 19 00 f3 eb 8c
EspOven: written 2048 bytes to client (19)
EspOven: read 2048 bytes to client (20): d2 91 99 5c af 5f 98 fe
EspOven: written 2048 bytes to client (20)
EspOven: read 2048 bytes to client (21): 85 3d b3 eb f4 06 9f 31
EspOven: written 2048 bytes to client (21)
EspOven: read 2048 bytes to client (22): 60 e7 38 a7 08 ca a6 77
EspOven: written 2048 bytes to client (22)
EspOven: read 2048 bytes to client (23): 55 55 31 49 96 5c f3 9c
EspOven: written 2048 bytes to client (23)
EspOven: read 2048 bytes to client (24): 15 f8 84 a9 aa 6b 11 49
EspOven: written 2048 bytes to client (24)
EspOven: read 2048 bytes to client (25): dc 50 3f ec da 77 3e 2d
EspOven: written 2048 bytes to client (25)
EspOven: read 2048 bytes to client (26): a4 d4 bf 64 2f 88 5a 58
EspOven: written 2048 bytes to client (26)
EspOven: read 2048 bytes to client (27): 72 3d f0 39 cd 69 79 78
EspOven: written 2048 bytes to client (27)
EspOven: read 2048 bytes to client (28): a4 89 b8 11 b9 5b 04 64
EspOven: written 2048 bytes to client (28)
EspOven: read 2048 bytes to client (29): 4d ae 63 2c db b3 d8 8a
EspOven: written 2048 bytes to client (29)
EspOven: read 2048 bytes to client (30): 00 ff 00 0e ec f3 48 8b
EspOven: written 2048 bytes to client (30)
EspOven: read 2048 bytes to client (31): 9b d0 0e 95 69 a1 c7 38
EspOven: written 2048 bytes to client (31)
EspOven: read 2048 bytes to client (32): ce ad ab 6e 2a 57 76 df
EspOven: written 2048 bytes to client (32)
EspOven: read 2048 bytes to client (33): ef 40 d0 14 f2 f8 c0 c7
EspOven: written 2048 bytes to client (33)
EspOven: read 2048 bytes to client (34): f1 66 91 73 79 72 eb 1c
EspOven: written 2048 bytes to client (34)
EspOven: read 2048 bytes to client (35): ee 3a e7 fc fe 54 bb 99
EspOven: written 2048 bytes to client (35)
EspOven: read 2048 bytes to client (36): 28 f7 d9 97 19 5d 1d 7a
EspOven: written 2048 bytes to client (36)
EspOven: read 2048 bytes to client (37): c0 1e 9f e7 fc 2a 44 e2
EspOven: written 2048 bytes to client (37)
EspOven: read 2048 bytes to client (38): b3 f8 6b a4 f8 77 43 d1
EspOven: written 2048 bytes to client (38)
EspOven: read 2048 bytes to client (39): d6 b8 df d8 fb e3 6f 84
EspOven: written 2048 bytes to client (39)
EspOven: read 2048 bytes to client (40): 03 d6 30 58 63 ea 2a ca
EspOven: written 2048 bytes to client (40)
EspOven: read 2048 bytes to client (41): 38 ef 4c 50 1d f8 53 8c
EspOven: written 2048 bytes to client (41)
EspOven: read 2048 bytes to client (42): 01 16 50 ff 00 5a 45 f9
EspOven: written 2048 bytes to client (42)
EspOven: read 2048 bytes to client (43): 4f 43 44 ad 89 46 d3 db
EspOven: written 2048 bytes to client (43)
EspOven: read 2048 bytes to client (44): 5f 46 e3 24 67 a5 35 24
EspOven: written 2048 bytes to client (44)
EspOven: read 2048 bytes to client (45): 73 b9 80 1e f4 ed bf 2f
EspOven: written 2048 bytes to client (45)
EspOven: read 2048 bytes to client (46): ab ce 05 47 1d eb bb 6e
EspOven: written 2048 bytes to client (46)
EspOven: read 2048 bytes to client (47): 2c 5e 25 2e 04 73 01 ba
EspOven: written 2048 bytes to client (47)
EspOven: read 2048 bytes to client (48): 1d be 5c 0e 69 b2 af 9c
EspOven: written 2048 bytes to client (48)
EspOven: read 2048 bytes to client (49): 22 83 85 1f e7 de 9d b3
EspOven: written 2048 bytes to client (49)
EspOven: read 2048 bytes to client (50): f6 e6 a2 8d 03 47 c7 dd
EspOven: written 2048 bytes to client (50)
EspOven: read 2048 bytes to client (51): db 99 46 3e ee 7a 52 03
EspOven: written 2048 bytes to client (51)
EspOven: read 2048 bytes to client (52): fe 9d 48 dc 10 60 75 e9
EspOven: written 2048 bytes to client (52)
EspOven: read 2048 bytes to client (53): b5 bd a7 2a 5c aa f6 5a
EspOven: written 2048 bytes to client (53)
EspOven: read 2048 bytes to client (54): 7c a3 03 9e 94 12 7a 57
EspOven: written 2048 bytes to client (54)
EspOven: read 2048 bytes to client (55): 7e 3f 25 ac 93 5a dc e8
EspOven: written 2048 bytes to client (55)
EspOven: read 2048 bytes to client (56): 04 a3 cc dc 0e 3d 71 8f
EspOven: written 2048 bytes to client (56)
EspOven: read 2048 bytes to client (57): d9 52 49 c4 9a 74 52 67
EspOven: written 2048 bytes to client (57)
EspOven: read 2048 bytes to client (58): f9 56 1b 50 30 39 ce e9
EspOven: written 2048 bytes to client (58)
EspOven: read 2048 bytes to client (59): 95 a4 4d ad c6 7d 38 e0
EspOven: written 2048 bytes to client (59)
EspOven: read 2048 bytes to client (60): fd d9 03 a9 e0 53 40 47
EspOven: written 2048 bytes to client (60)
EspOven: read 2048 bytes to client (61): d2 a2 68 fc c3 b7 eb 83
EspOven: written 2048 bytes to client (61)
EspOven: read 2048 bytes to client (62): c7 00 7a d4 70 6d ff 00
EspOven: written 2048 bytes to client (62)
EspOven: read 2048 bytes to client (63): 84 95 95 d4 ed dd df 34
EspOven: written 2048 bytes to client (63)
EspOven: read 2048 bytes to client (64): ed c1 fe 74 ef b3 c9 24
EspOven: written 2048 bytes to client (64)
EspOven: read 2048 bytes to client (65): af 61 ce 79 cd 4f 0f c0
EspOven: written 2048 bytes to client (65)
EspOven: read 2048 bytes to client (66): 39 2b d7 b7 f9 ff 00 eb
EspOven: written 2048 bytes to client (66)
EspOven: read 2048 bytes to client (67): b6 32 63 ce 76 96 ae c5
EspOven: written 2048 bytes to client (67)
EspOven: read 2048 bytes to client (68): ee cc 40 05 b0 0e 0b 8a
EspOven: written 2048 bytes to client (68)
EspOven: read 2048 bytes to client (69): 70 c7 ad 24 a4 e5 ba 63
EspOven: written 2048 bytes to client (69)
EspOven: read 2048 bytes to client (70): df 5c 39 9a e6 7c 9c 91
EspOven: written 2048 bytes to client (70)
EspOven: read 2048 bytes to client (71): 8b 1f 0a e9 7a 35 bb db
EspOven: written 2048 bytes to client (71)
EspOven: read 2048 bytes to client (72): 71 eb 55 e3 fd d8 2b 9c
EspOven: written 2048 bytes to client (72)
EspOven: read 2048 bytes to client (73): 8d 9e fd 7d 4d 47 39 d9
EspOven: written 2048 bytes to client (73)
EspOven: read 2048 bytes to client (74): ce 73 f4 a8 6d ce 4e 47
EspOven: written 2048 bytes to client (74)
EspOven: read 2048 bytes to client (75): df 8a 3e 2b 7c 56 d1 6c
EspOven: written 2048 bytes to client (75)
EspOven: read 2048 bytes to client (76): af f9 fa 56 75 c0 c2 6d
EspOven: written 2048 bytes to client (76)
EspOven: read 2048 bytes to client (77): 91 56 eb 50 f0 86 a4 f9
EspOven: written 2048 bytes to client (77)
EspOven: read 2048 bytes to client (78): d7 8a 9d 64 bf 96 26 c3
EspOven: written 2048 bytes to client (78)
EspOven: read 2048 bytes to client (79): 83 d3 e9 43 b6 c7 50 d9
EspOven: written 2048 bytes to client (79)
EspOven: read 2048 bytes to client (80): 9a 92 45 c6 33 9e bd 68
EspOven: written 2048 bytes to client (80)
EspOven: read 2048 bytes to client (81): 58 72 6a e9 d0 a4 e3 ca
EspOven: written 2048 bytes to client (81)
EspOven: read 2048 bytes to client (82): bf 95 2a 8d d8 dc 0f af
EspOven: written 2048 bytes to client (82)
EspOven: read 2048 bytes to client (83): 85 52 b7 20 b9 74 e4 f2
EspOven: written 2048 bytes to client (83)
EspOven: read 2048 bytes to client (84): f5 ef 54 04 32 1d c9 f7
EspOven: written 2048 bytes to client (84)
EspOven: read 2048 bytes to client (85): 89 34 25 57 38 18 bd 8f
EspOven: written 2048 bytes to client (85)
EspOven: read 2048 bytes to client (86): e9 42 86 1d 76 ee e3 d4
EspOven: written 2048 bytes to client (86)
EspOven: read 2048 bytes to client (87): 48 55 70 32 a7 2d b7 bd
EspOven: written 2048 bytes to client (87)
EspOven: read 2048 bytes to client (88): 47 cd d3 27 ad 2a 80 cc
EspOven: written 2048 bytes to client (88)
EspOven: read 2048 bytes to client (89): ed 61 d4 9a 7b 47 85 62
EspOven: written 2048 bytes to client (89)
EspOven: read 2048 bytes to client (90): c2 b6 de db 78 3f 85 43
EspOven: written 2048 bytes to client (90)
EspOven: read 2048 bytes to client (91): e4 63 34 2c fe 76 3e bd
EspOven: written 2048 bytes to client (91)
EspOven: read 2048 bytes to client (92): d7 24 da c4 e0 5c 95 cf
EspOven: written 2048 bytes to client (92)
EspOven: read 2048 bytes to client (93): 7a 6a df f5 c6 0f fd 09
EspOven: written 2048 bytes to client (93)
EspOven: read 133 bytes to client (94): a6 7b 77 38 ef ed 9c fe
EspOven: written 133 bytes to client (94)
EspOven: Client 0.0.0.0:0 disconnecting


Log 4096 chunks:
EspOven: Client connected from xxx.yy.zz.www:8916
EspOven: received request:
GET /20150918_235057.jpg HTTP/1.1
EspOven: method GET path /20150918_235057.jpg ver HTTP/1.1 freeheap 43200
EspOven: path /20150918_235057.jpg found, file len 192645 mime image/jpeg
EspOven: read 4096 bytes to client (0): ff d8 ff e0 00 10 4a 46
EspOven: written 4096 bytes to client (0)
EspOven: read 4096 bytes to client (1): 00 00 00 00 00 00 00 00
EspOven: written 4096 bytes to client (1)
EspOven: read 4096 bytes to client (2): b4 b3 b3 b2 b2 b4 b2 b2
EspOven: written 4096 bytes to client (2)
EspOven: read 4096 bytes to client (3): 6d 70 3a 43 72 65 61 74
EspOven: written 4096 bytes to client (3)
EspOven: read 4096 bytes to client (4): 0a 20 20 20 20 20 20 20
EspOven: written 4096 bytes to client (4)
EspOven: read 4096 bytes to client (5): 20 20 20 20 20 20 20 20
EspOven: written 4096 bytes to client (5)
EspOven: read 4096 bytes to client (6): 20 20 20 20 20 20 20 20
EspOven: written 4096 bytes to client (6)
EspOven: read 4096 bytes to client (7): c8 ce 70 3a 0a 62 90 d1
EspOven: written 4096 bytes to client (7)
EspOven: read 4096 bytes to client (8): b4 53 d8 e4 b3 06 0b 9f
EspOven: written 4096 bytes to client (8)
EspOven: read 4096 bytes to client (9): 6e 3e 94 b1 fc af cf d3
EspOven: written 4096 bytes to client (9)
EspOven: read 4096 bytes to client (10): d2 91 99 5c af 5f 98 fe
EspOven: written 4096 bytes to client (10)
EspOven: read 4096 bytes to client (11): 60 e7 38 a7 08 ca a6 77
EspOven: written 4096 bytes to client (11)
EspOven: read 4096 bytes to client (12): 15 f8 84 a9 aa 6b 11 49
EspOven: written 4096 bytes to client (12)
EspOven: read 4096 bytes to client (13): a4 d4 bf 64 2f 88 5a 58
EspOven: written 4096 bytes to client (13)
EspOven: read 4096 bytes to client (14): a4 89 b8 11 b9 5b 04 64
EspOven: written 4096 bytes to client (14)
EspOven: read 4096 bytes to client (15): 00 ff 00 0e ec f3 48 8b
EspOven: written 4096 bytes to client (15)
EspOven: read 4096 bytes to client (16): ce ad ab 6e 2a 57 76 df
EspOven: written 4096 bytes to client (16)
EspOven: read 4096 bytes to client (17): f1 66 91 73 79 72 eb 1c
EspOven: written 4096 bytes to client (17)
EspOven: read 4096 bytes to client (18): 28 f7 d9 97 19 5d 1d 7a
EspOven: written 4096 bytes to client (18)
EspOven: read 4096 bytes to client (19): b3 f8 6b a4 f8 77 43 d1
EspOven: written 4096 bytes to client (19)
EspOven: read 4096 bytes to client (20): 03 d6 30 58 63 ea 2a ca
EspOven: written 4096 bytes to client (20)
EspOven: read 4096 bytes to client (21): 01 16 50 ff 00 5a 45 f9
EspOven: written 4096 bytes to client (21)
EspOven: read 4096 bytes to client (22): 5f 46 e3 24 67 a5 35 24
EspOven: written 4096 bytes to client (22)
EspOven: read 4096 bytes to client (23): ab ce 05 47 1d eb bb 6e
EspOven: written 4096 bytes to client (23)
EspOven: read 4096 bytes to client (24): 1d be 5c 0e 69 b2 af 9c
EspOven: written 4096 bytes to client (24)
EspOven: read 4096 bytes to client (25): f6 e6 a2 8d 03 47 c7 dd
EspOven: written 4096 bytes to client (25)
EspOven: read 4096 bytes to client (26): fe 9d 48 dc 10 60 75 e9
EspOven: written 4096 bytes to client (26)
EspOven: read 4096 bytes to client (27): 7c a3 03 9e 94 12 7a 57
EspOven: written 4096 bytes to client (27)
EspOven: read 4096 bytes to client (28): 04 a3 cc dc 0e 3d 71 8f
EspOven: written 4096 bytes to client (28)
EspOven: read 4096 bytes to client (29): f9 56 1b 50 30 39 ce e9
EspOven: written 4096 bytes to client (29)
EspOven: read 4096 bytes to client (30): fd d9 03 a9 e0 53 40 47
EspOven: written 4096 bytes to client (30)
EspOven: read 4096 bytes to client (31): c7 00 7a d4 70 6d ff 00
EspOven: written 4096 bytes to client (31)
EspOven: read 4096 bytes to client (32): ed c1 fe 74 ef b3 c9 24
EspOven: written 4096 bytes to client (32)
EspOven: read 4096 bytes to client (33): 39 2b d7 b7 f9 ff 00 eb
EspOven: written 4096 bytes to client (33)
EspOven: read 4096 bytes to client (34): ee cc 40 05 b0 0e 0b 8a
EspOven: written 4096 bytes to client (34)
EspOven: read 4096 bytes to client (35): df 5c 39 9a e6 7c 9c 91
EspOven: written 4096 bytes to client (35)
EspOven: read 4096 bytes to client (36): 71 eb 55 e3 fd d8 2b 9c
EspOven: written 4096 bytes to client (36)
EspOven: read 4096 bytes to client (37): ce 73 f4 a8 6d ce 4e 47
EspOven: written 4096 bytes to client (37)
EspOven: read 4096 bytes to client (38): af f9 fa 56 75 c0 c2 6d
EspOven: written 4096 bytes to client (38)
EspOven: read 4096 bytes to client (39): d7 8a 9d 64 bf 96 26 c3
EspOven: written 4096 bytes to client (39)
EspOven: read 4096 bytes to client (40): 9a 92 45 c6 33 9e bd 68
EspOven: written 4096 bytes to client (40)
EspOven: read 4096 bytes to client (41): bf 95 2a 8d d8 dc 0f af
EspOven: written 4096 bytes to client (41)
EspOven: read 4096 bytes to client (42): f5 ef 54 04 32 1d c9 f7
EspOven: written 4096 bytes to client (42)
EspOven: read 4096 bytes to client (43): e9 42 86 1d 76 ee e3 d4
EspOven: written 4096 bytes to client (43)
EspOven: read 4096 bytes to client (44): 47 cd d3 27 ad 2a 80 cc
EspOven: written 4096 bytes to client (44)
EspOven: read 4096 bytes to client (45): c2 b6 de db 78 3f 85 43
EspOven: written 4096 bytes to client (45)
EspOven: read 4096 bytes to client (46): d7 24 da c4 e0 5c 95 cf
EspOven: written 4096 bytes to client (46)
EspOven: read 133 bytes to client (47): a6 7b 77 38 ef ed 9c fe
EspOven: written 133 bytes to client (47)
EspOven: Client 172.16.1.118:8916 disconnecting

Re: WifiClient.write issue with long packets (>2048 bytes)

PostPosted: Thu May 11, 2017 3:10 am
by fededim
Issue solved, there is a limit in the 2.3.0 version of the Arduino library for ESP which limits the maximum bytes sent to almost 3K (see ) , it has been removed in the newest version, but it is still unreleased. You have to remove the version 2.3.0 from Arduino libraries and copy manually the latest sources from github to Arduino folder or, if you aren't in a hurry, just wait for the new version 2.4.0.