micropython / micropython-esp32

Old port of MicroPython to the ESP32 -- new port is at https://github.com/micropython/micropython
MIT License
673 stars 216 forks source link

Nonblocking SSL sockets #133

Closed MrSurly closed 7 years ago

MrSurly commented 7 years ago

As discussed in https://github.com/micropython/micropython/issues/3107, and building upon https://github.com/micropython/micropython-esp32/pull/105.

Rationale

A desire to use MQTT without blocking waiting for published events.

Using the umqtt.simple library with AWS requires the use of crypto. This works, but the non-blocking umqtt.check_msg() function will fail, since the underlying SSL socket wrapper (ussl_mbedtls) throws an error when you try to set nonblocking mode. Turns out mbedtls does support non-blocking, but you need to code your wrapper bio callbacks to return the right value when this happens.

I've tested this using the umqtt.simple library, communicating with AWS IoT.

dpgeorge commented 7 years ago

Looks good! Please can you make a PR against upstream since this patch will be applicable to all users of mbedtls, not just esp32.

MrSurly commented 7 years ago

Please can you make a PR against upstream since this patch will be applicable to all users of mbedtls, not just esp32.

Will do, but I don't think I have any HW I can test this against.

MrSurly commented 7 years ago

Reopening -- is there any reason this can't be merged into ESP32? I'll also file a PR against upstream.

dpgeorge commented 7 years ago

is there any reason this can't be merged into ESP32?

This repo should be kept as clean as possible and contain only changes in the esp32/ directory. I'll merge upstream into this repo as soon as this PR lands there.

@MrSurly it looks like you're pushing changes to your esp32 branch, not the mainline one.

MrSurly commented 7 years ago

This repo should be kept as clean as possible and contain only changes in the esp32/ directory. I'll merge upstream into this repo as soon as this PR lands there.

Sounds good.

@MrSurly it looks like you're pushing changes to your esp32 branch, not the mainline one.

Yes, @pfalcon asked for code changes. I'm not comfortable making those without testing on real hardware, thus I'm committing to this repo. Given what you said above, I'm going to close this PR, but I'm still going to do development in my micropython-esp32 repo/branch. When it's good to go, I'll just merge the changes with the micropython (mainline) PR.