ESP32-CAM socket.connect() problem #10029
-
Trying to send an image over a 50 metre path and when it fails to connect, after awhile the board appears to do a machine.reset(). Unfortunately, this leaves the camera in a bad state, so no more images after that. I have tried many different solutions to attempt raising an error when the socket fails, without success. For example: def send_file(filename, host, port):
# create the client socket
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
print(f'[+] Connecting to {host}:{port}')
s.connect((host, port))
print(f'[+] Connected to server')
# try select.poll ... didn't work
# poller = select.poll()
# poller.register(s, select.POLLIN)
# res = poller.poll(5000) # 5 seconds
# print (f'{res}')
# if not res: # didn't work
# if bool (res):
# print (f'no connection to the server')
# utime.sleep(0.1)
# s.close()
# config.poweron_reset.on() I can see res is an empty list but I don't seem to be able to test for it. That snippet is straight from the docs. Are there other setup conditions for this "sending" socket that I haven't done. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 3 replies
-
I am pretty sure you are mixing 2-3 mostly unrelated things here.
I have no idea why the check for the empty tuple is not working in your case. Regarding the camera in an invalid state after reboot, you should find a way to reset it (maybe additional hardware like a transistor to cut it's power supply?). |
Beta Was this translation helpful? Give feedback.
-
Gave up trying to get socket.connect() or sendall() to throw any errors on the sending-end. I have noticed that the device starts to struggle sending packets through in a timely manner below -93dBm. So, my solution for now is to not connect to WiFi if the RSSI is less than -90dBm. |
Beta Was this translation helpful? Give feedback.
-
The apparent behaviour of the ESP32 being able to connect to WiFi then return a message that the RSSI is too low to display a value and then stay connected (?) seems a bit suspect to me. Then again I have heard stories about the ESP32 automagically going through a re-connect sequence. I use UDP to talk to a 3 remote devices, but that is only for simple 10-20 byte messages. For longer-range comms ESP-Now does the job. |
Beta Was this translation helpful? Give feedback.
I am pretty sure you are mixing 2-3 mostly unrelated things here.
connect()
should not fail.connect()
call should not cause a reboot.Depending upon the protocol used (if any), this might never return anything else than false (the empty tuple).
I would poll for POLLOUT, as you want to send data over the link.
In my opinion, after connect() succeeds, a check using poll() is useless, anyway. Just write() your data. You need poll() if you want to avoid blocking write() and read() calls, of course.
…