usocket and uselect reboots board

Discussion related to "under the hood" OpenMV topics.
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

usocket and uselect reboots board

Postby zeb » Fri Apr 12, 2019 3:37 am

Hi guys

Im doing a project where im using tcp sockets on the openMV - that actually works quite well but the usocket.recv() is a blocking operation.
Following general suggestions online in how to do non blocking tcp in python i found the "select" session - and found the uselect library in openMVs micropython - i was happy! but!

Everytime i do anything regarding uselect and usockets the openmv board simply reboots ... doesnt even matter HOW simple a piece of code i write :( is this a known bug/thing?
Or am i missing something?

Like even doing a poll with socketEvent = poller.poll(100) resets the board - no matter the length of the timeout
User avatar
iabdalkader
Posts: 912
Joined: Sun May 24, 2015 3:53 pm

Re: usocket and uselect reboots board

Postby iabdalkader » Fri Apr 12, 2019 8:49 am

Can you post a test script ? We can debug and fix it then.
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

Re: usocket and uselect reboots board

Postby zeb » Mon Apr 15, 2019 5:12 am

hmm, doesnt seem im allowed to write the script here - i tried commenting with it - but i keep getting an error about "/posting.php"
But anyways - the code ive attached is just a test script that connects to a wifi then to a tcp server (i wrote one in nodejs - but any tcp server should do)
as soon as the line

Code: Select all

fdVsEvents = pollObj.poll(1000)
is run - the board reboots - ive tried this with two separate openMV boards both running firmware 3.2.0

hope it helps ;)
Attachments
tcp-select-test-forum.py
(938 Bytes) Downloaded 44 times
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

Re: usocket and uselect reboots board

Postby zeb » Mon Apr 15, 2019 5:13 am

I should probably note that any function in the uselect library ive tried reboot the board -

Code: Select all

uselect.select 
for instance also reboots
User avatar
iabdalkader
Posts: 912
Joined: Sun May 24, 2015 3:53 pm

Re: usocket and uselect reboots board

Postby iabdalkader » Mon Apr 15, 2019 3:32 pm

Okay I see the problem, actually we don't implement select/poll in the WINC1500 driver. The ioctl function is not even set (it shouldn't crash the cam however, I'll debug this). You can't use this module for now, but you can use the set timeout function to zero instead to set the socket to non-blocking (it's basically the same effect).
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

Re: usocket and uselect reboots board

Postby zeb » Mon Apr 29, 2019 7:26 am

i cant for the life of me make this nonblocking - neither settimeout or setblocking commands are doing anything
the openmv cam is the client and server is written in nodejs, do i need something on the server side to fix this?
User avatar
iabdalkader
Posts: 912
Joined: Sun May 24, 2015 3:53 pm

Re: usocket and uselect reboots board

Postby iabdalkader » Tue Apr 30, 2019 10:45 am

zeb wrote: i cant for the life of me make this nonblocking - neither settimeout or setblocking commands are doing anything
Hi, settimeout works, in the tcp_client.py example if you set the timeout to 0.01 (10ms) you will get an exception.
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

Re: usocket and uselect reboots board

Postby zeb » Wed May 01, 2019 4:10 am

i might have misunderstood something basic about tcp sockets :)
i got the timeout to work but now i get access denied when attempting to read from the socket again
do i need to open the connection again to keep reading from the socket? the funny thing is that if i disable the timeout i can keep communicating via the socket
but the program will hang until it gets data from the server
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

Re: usocket and uselect reboots board

Postby zeb » Wed May 01, 2019 6:52 am

okay, so the plot kind of thickens
I rewrote my code to use MQTT - whenever i use

Code: Select all

client.check_msg()
the code hangs like when im doing my own TCP stuff - it seems that something is broken in the way OpenMV handles tcp sockets ...
as far as i can tell the mqtt check_msg function should return immediately if there is no message pending from the server - but it doesn't
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

Re: usocket and uselect reboots board

Postby zeb » Wed May 01, 2019 6:57 am

again - further madness here (i think - i might be wrong)
if i do a

Code: Select all

client.ping()
before doing

Code: Select all

client.check_msg()
the code behaves as expected
zeb
Posts: 8
Joined: Fri Apr 12, 2019 3:17 am

Re: usocket and uselect reboots board

Postby zeb » Wed May 01, 2019 7:03 am

okay - so my thinking is that the ping -> response cycle is returning something that makes the

Code: Select all

socket.recv()
function do it's thing and allowing the code to progress while still accepting actual messages from the server with data in it - im still pretty new at the whole python and networking thing so this might be wrong or actually the right way to do it - i don't know - but basically its working as intended now - thx for your help btw ;)

Return to “Technical Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 101 guests