robert-hh / FTP-Server-for-ESP8266-ESP32-and-PYBD

Small FTP server for ESP8266/ESP32/PYBD on the MicroPython platform
MIT License
148 stars 39 forks source link

cannot implicitly convert int to string #18

Closed uraich closed 1 year ago

uraich commented 1 year ago

I get this error in line 483: datasocket.bind(('0.0.0.0', _DATA_PORT)) I put datasocket.bind(('0.0.0.0', str(_DATA_PORT))) instead

robert-hh commented 1 year ago

Thank you for the report. Which port and board do you use?

uraich commented 1 year ago

The esp32 port. With this small modification everything works fine.

robert-hh commented 1 year ago

That's strange, because socket.bind() expects a tuple of (string, int), and it worked like that since the beginning. Which firmware version do you use?

uraich commented 1 year ago

I agree that it's strange. I use the very latest version of MP (just pulled it and recompiled). In fact I had it running before without this problem but I didn't use it for some time. Now I want to play with tinyML where I record sound snippets using an I2S MEMS microphone. I store wav files in flash, which I want to transfer to the PC for treatment and I do this with ftp. image There is a very slight change I made to uftpd, which does not affect this problem however: I check if the WiFi connection is established and if not, I connect to the network.

robert-hh commented 1 year ago

The version I use for testing is: MicroPython v1.19.1-443-g30e50ab19 on 2022-09-24; ESP32 module (spiram) with ESP32 There not problem using an integer as port number. Using a string works however as well, which is new to me.

uraich commented 1 year ago

Well, it is really weird! The error only crops up when I freeze uftpd into the firmware (uftpd.py goes into modules) . When I upload uftpd e.g. onto /lib on the ESP32, then the error does not appear and this independently of uploading the source version or the pre-compiled version. My micropython version is the same as yours except that I use an esp32-wroom (no spiram) Well, in fact I also tried it on an esp32-cam, which has spiram and the symptoms are the same.

robert-hh commented 1 year ago

With a WROOM like device I can reproduce the error. It happens, when the port argument to socket.bind is a numeric constant. Setting line 36 to: _DATA_PORT = 13333 avoids the problem. And it reoccurs, if the bind statement is written as: datasocket.bind(('0.0.0.0', 13333)).

But there are other problems with the WROOM version. Calling ifconfig before connect causes the device to crash. Does not happen with the WROVER version. So there seem to be a memory corruption problem somewhere, like a non-initialized pointer.

uraich commented 1 year ago

Hi Robert, Many thanks for your analysis. I decided to go for your solution removing the "const" when defining _DATA_PORT. It works for me as well. True, I have been working much more with the WROVER-B lately and maybe because of this I did not see the problem before. I did not know about the ifconfig problem neither. I am using the ESP32 for a course on IoT I prepared for the University of Cape Coast, Ghana. Quite a bit of material has been collected for this in the meantime: iot course and exercise solutions In fact some of the material could be interesting for others. Do you think I should announce this on the forum?

robert-hh commented 1 year ago

In preparation of a issue report, I made this little script to isolate the error:

import socket

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 12345))

Funny (or luckily) enough, that one fails on a WROVER type board as well.