ESP32 wroom 32E - Size limit sending data using socket ? #13649
-
Using a nonBlocking server from this forum - for sending data to Google Chart to get ScatterCharts. import socket, select, time, api
def doReq(request): # handles all requests
import B_userMenu, C_graphPrep
if request.find('GET / HTTP/1.1')>0:
t=B_userMenu.getMenu()
return t
if request.find('GET /favicon.ico')>0: # ett juste svar
return ''
if request.find('GET /action_page.php')>0:
h = C_graphPrep.getGraph(request)
return h
# set up nonBlockingServer in background,
bresp=bytes('HTTP/1.1 200 OK\n'+'Content-Type: text/html\n'+'Connection: close\n\n', 'utf-8')
def req_handler(cs): # main loop
try:
req = cs.read()
if req:
print('req:', req)
rep=doReq(str(req)) # act on request
rep=rep + "\n\n"
brep=bytes(rep, 'utf-8')
cs.write(bresp)
#while len(brep)>2000: # > ~5700 bytes GoggleChart dont answer!
# part=brep[:2000] # no diff sending smaller group size
# cs.write(part)
# print(len(part))
# brep=brep[2000:]
cs.write(brep)
print(len(brep))
else:
print('Client close connection')
except Exception as e:
print('Err:', e)
cs.close()
def cln_handler(srv):
cs,ca = srv.accept()
print('Serving:', ca)
cs.setblocking(False)
cs.setsockopt(socket.SOL_SOCKET, 20, req_handler)
api.doConnectWIFI()
port = 80
addr = socket.getaddrinfo('0.0.0.0', port)[0][-1]
srv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
srv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
srv.bind(addr)
srv.listen(5) # at most 5 clients
srv.setblocking(False)
srv.setsockopt(socket.SOL_SOCKET, 20, cln_handler)
`
BR /Stefan |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 4 replies
-
On a ESP32 WROOM 32U when sending email to Gmail's SMPT server I had to use file chunking to have success. On the ESP32 SPIRAM variant it didn't seem to be necessary. # send data in 1024 chunks
try:
with open('datalog.csv', 'rb') as file:
for chunk in range(0, file_size, chunk_size):
this_chunk_size = min(chunk_size, file_size-chunk)
# handles the last dangling chunk that would be smaller than the full 1024 bytes
smtp.write(file.read(this_chunk_size))
time.sleep_ms(200) # guarantee consecutive writes
except OSError as error:
try:
with open('errors.txt', 'a') as outfile:
outfile.write('error = ' + str(error) + '\n')
outfile.write('did not handle datalog.csv properly' + '\n')
except OSError:
pass Note the |
Beta Was this translation helpful? Give feedback.
-
Next step: ESP32 WROOM 32U, python v1.22, Using my socket (see start question) to feed Goole Chart html body - is ok with body size up to ~5k bytes. Clients Windows 10 PC, Android mobile and PADs. CHAT GPT about this: Socket Options: The ESP-IDF provides socket options that allow developers to control aspects of socket behavior, including buffer sizes. For example, the setsockopt() function can be used to set the receive buffer size (SO_RCVBUF) and the send buffer size (SO_SNDBUF) for a socket. Why a limit at 5k - I need >15 k. Any ideas ? BR /Stefan |
Beta Was this translation helpful? Give feedback.
On a ESP32 WROOM 32U when sending email to Gmail's SMPT server I had to use file chunking to have success. On the ESP32 SPIRAM variant it didn't seem to be necessary.