ESP8266 socket read without allocating new objects.

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
MyUsername
Posts: 5
Joined: Mon Jan 02, 2017 4:06 pm

ESP8266 socket read without allocating new objects.

Post by MyUsername » Mon Feb 06, 2017 8:07 pm

My aim is to read from socket without allocating new objects. There is no recv_into or readinto methods in esp sockets. Moreover I have found out that basic onrecv callback is also not implemented in ESP. However, I have found this topic http://forum.micropython.org/viewtopic. ... ket#p17505 and have revealed the possibility of registering callback. But I still do not understand, what is the purpose for registering that handler, because according to the corresponding commit https://github.com/micropython/micropyt ... abe0ea66e3 only socket object is passed into the handler. Which gives us no information about an event and gives no opportunity not to allocate new buffer.

I feel like I'm missing something. If I am not, is there any way to read from socket without allocations?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: ESP8266 socket read without allocating new objects.

Post by Roberthh » Tue Feb 07, 2017 6:53 am

In one of the recent builds, the readinto() was added. Maybe that helps.
About the socket callback: You can actually allocate memory in that callback. In the callback, you can do almost everything allowed in Python. if you look at my ftp server (https://github.com/robert-hh/ESP8266-FTP-Server) or similar other projects (e.g. @gpopp's telnet server), you'll find that the bulk of the code runs in the callback, including file operations.
And you have the value of the socket. You may register different callbacks for different sockets, or one callback and determine from the value of the socket the purpose of the call.

MyUsername
Posts: 5
Joined: Mon Jan 02, 2017 4:06 pm

Re: ESP8266 socket read without allocating new objects.

Post by MyUsername » Thu Feb 09, 2017 12:01 pm

Roberthh wrote:In one of the recent builds, the readinto() was added. Maybe that helps.
About the socket callback: You can actually allocate memory in that callback. In the callback, you can do almost everything allowed in Python. if you look at my ftp server (https://github.com/robert-hh/ESP8266-FTP-Server) or similar other projects (e.g. @gpopp's telnet server), you'll find that the bulk of the code runs in the callback, including file operations.
And you have the value of the socket. You may register different callbacks for different sockets, or one callback and determine from the value of the socket the purpose of the call.
Yes, it helped. Thanks!

Post Reply