adafruit / Adafruit_CircuitPython_ESP_ATcontrol

Use the ESP AT command sent to communicate with the Interwebs
MIT License
20 stars 17 forks source link

Connect fails for ports other than 80, 443 and 1883 #64

Closed bablokb closed 2 years ago

bablokb commented 2 years ago

In adafruit_espatcontrol_socket.py the method connect() only sets the connection-type for the three ports 80, 443 and 1883. This triggers an exception socket_connect a few lines down.

IMHO this is anyhow the wrong osi-level to set the connection-type. It should be done within the requests-module. But adding an additional parameter in the request-module would need additional changes in other modules which implement connect().

The quick fix would be to just change the logic in connect(): use SSL for 443, TCP for other ports. This would fail for all sites running https on port 80 (but this already fails today).

Alternative solution: add a method set_conntype() to adafruit_espatcontrol.py and call this from adafruit_espatcontrol_wifimanager.py before calling requests.get() and so on. Conntype would be set depending on the url.

I can provide a pull request for both solutions. Any opinions?

bablokb commented 2 years ago

Fixed with #66