My project use particle photon to send data packets to nodejs backend. However the data chunk is very large (~2 to 3 KB) and messaging frequency is quite high (~10Hz).
Currently I met some bad crypto transform error on nodejs server, and after careful examing the source code, I am able narrow down the problem which shall occur at firmware side.
In short, I used the blocking_send function which exists in original particle firmware code. I noticed that fundamentally, the blocking_send uses the function of socket_send, which exist in /hal/src/photon/socket_hal.cpp. Interestingly, the sending process of this function is wiced_tcp_send_buffer, which used the bcm-wiced-sdk library.
I noticed that when I send packets (10Hz, 2~3KB/packet) from photon, after few iterations (sometimes 10 to 20, sometimes 900 to 1000), the wiced_tcp_send_buffer function will return 16!!?? causing many subsequent errors. Driven by strong curiously, I checked the error code definition of this library, whose interpretations is “WOULD_BLOCK”??!! After that I checked this article which said it may due to the fact that socket stream buffer is filled, which seems make sense!! Here are some some of my curious and any suggestions and comments are welcome!!
I observed that when this wiced_tcp_buffer_send function returns 16, it actually sends data, which is in fact corrupted, i.e. send wrong data causing deciphering error at node backend. Is there any way to coding in this philosophy: if success, then send, if failed then don’t send, instead send corrupted data…?
How can I check the available socket stream buffer size before each send?? it looks like the fundamental system call does not really works here. For example, I tried to include sys/socket.h and use getsockopt to monitor the socket state, but did not work successfully though…
If it is indeed the socket buffer issues, my philosophy is:
if (socket buffer is full) then skip it!
else send data packet!
however, the hardest part is same as previous, the system does not really works here while the api in wiced lib is limited.
finally can some one indicates what’s the available socket buffer size of BCM chip used in photon, is there any way to increase it by coding manually?
Thanks for the help!