-
Notifications
You must be signed in to change notification settings - Fork 35
Add Adafruit_CircuitPython_Requests Compatibility #7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…ting query types, TODO: same approach for ans. response
Not sure if I've pieced together all the right things, but... My boot_out says Running example code from with Wiznet5k WebClient Test
* Initializing DHCP
*** Get socket
Allocated socket #0:68
*** Connecting: Socket# 0, conn_mode: 2
*** Opening socket 0
w5k socket begin, protocol=2, port=67, ip=255.255.255.255
* DHCP: Discover
* DHCP: Parsing OFFER
* socket_available called with protocol 2
* socket_available called with protocol 2
* socket_available called with protocol 2
Bytes avail. on sock: 556
* Processing 8 bytes of data
* UDP Bytes Remaining: 548
Bytes avail. on sock: 548
* Processing 548 bytes of data
* UDP Bytes Remaining: 0
DHCP Response: b'\x02\x01\x06\x00\xca\x02\x00\x00\x00\x00\x80\x00\x00\x00\x00\x00\xc0\xa8\x03\xdb\x00\x00\x00\x00\x00\x00\x00\x00\xde\xad\xbe\xef\xfe\xed\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00c\x82Sc5\x01\x026\x04\xc0\xa8\x04\x013\x04\x00\x01Q\x80\x01\x04\xff\xff\xf8\x00\x03\x04\xc0\xa8\x04\x01\x06\x08\x01\x01\x01\x01\x01\x00\x00\x01\x8a\x04\xc0\xa8\x04\x01\xff\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'
* DHCP: Request
Traceback (most recent call last):
File "code.py", line 17, in <module>
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 186, in __init__
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k.py", line 200, in set_dhcp
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py", line 361, in request_dhcp_lease
File "/lib/adafruit_wiznet5k/adafruit_wiznet5k_dhcp.py", line 210, in send_dhcp_message
NotImplementedError: array/bytes required on right side``` |
With commit
(all preceding is same) There's an end mark on the discovery, but not on offer (at least on wikipedia). It's a reputable router, whatever it's sending I would expect to be legit. |
@anecdata CircuitPython doesn't have a native SSL client, nina-fw uses a mbedTLS implementation. I'll add a commit to make that error more readable. EDIT: fixed in 088421e,
I haven't been able to replicate the ValueError you're getting, though. |
Looks good to me. Got the friendlier AssertionError for TLS. Other errors are rare, seem similar to communication glitches on esp. I'd expect to catch exceptions and handle in user code. If any patterns emerge, I'll report back. CircuitPython takes flight on Cat5e. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tried on feather_nrf52840 with eathernet featherwing
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 5.0.0-15-ge98991fd7 on 2020-03-03; Adafruit Feather nRF52840 Express with nRF52840
> import wiznet5k_simpletest
> Wiznet5k WebClient Test
> Chip Version: w5500
> MAC Address: ['0xde', '0xad', '0xbe', '0xef', '0xfe', '0xed']
> My IP address is: 192.168.2.32
> IP lookup adafruit.com: 104.20.39.240
> Fetching text from http://wifitest.adafruit.com/testwifi/index.html
> Traceback (most recent call last):
> File "<stdin>", line 1, in <module>
> File "wiznet5k_simpletest.py", line 30, in <module>
> File "adafruit_requests.py", line 280, in get
> File "adafruit_requests.py", line 242, in request
> File "adafruit_requests.py", line 194, in request
> File "adafruit_wiznet5k/adafruit_wiznet5k_socket.py", line 149, in connect
> File "adafruit_wiznet5k/adafruit_wiznet5k.py", line 520, in socket_connect
> RuntimeError: Failed to establish connection.
> >>>
enabled debug at @brentru request
https://gist.github.com/jerryneedell/48367e4c0cc05fe11d4ce2be4d5ac104
@jerryneedell seems it's closing the socket immediately after opening it, which causes the failure. Your trace:
My trace:
|
@jerryneedell Figured it out - code was sometimes re-using a registered port number for TCP sockets, which was causing the server to send an ACK-RST back to the device disconnecting it. 406c7fb switches to randomly assigned dynamic port numbers. |
tried with same result -- updated gist https://gist.github.com/jerryneedell/48367e4c0cc05fe11d4ce2be4d5ac104 |
…, not set anything
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Works for me!
Auto-reload is on. Simply save files over USB to run them or enter REPL to disable.
code.py output:
Wiznet5k WebClient Test
Chip Version: w5500
MAC Address: ['0xde', '0xad', '0xbe', '0xef', '0xfe', '0xed']
My IP address is: 192.168.11.145
IP lookup adafruit.com: 104.20.39.240
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
----------------------------------------
This is a test of Adafruit WiFi!
If you can read this, its working :)
----------------------------------------
Fetching json from http://api.coindesk.com/v1/bpi/currentprice/USD.json
----------------------------------------
{'time': {'updated': 'Mar 5, 2020 21:22:00 UTC', 'updatedISO': '2020-03-05T21:22:00+00:00', 'updateduk': 'Mar 5, 2020 at 21:22 GMT'}, 'disclaimer': 'This data was produced from the CoinDesk Bitcoin Price Index (USD). Non-USD currency data converted using hourly conversion rate from openexchangerates.org', 'bpi': {'USD': {'code': 'USD', 'description': 'United States Dollar', 'rate_float': 9147.05, 'rate': '9,147.0517'}}}
----------------------------------------
Done!
Press any key to enter the REPL. Use CTRL-D to reload.
@jerryneedell Could you test again if you have time? |
still not working -
|
hmmm --- FYI -- the example/library from the master branch is also not workig for me -- it just hangs after displaying the IP address |
it is working for me now
|
also test on feather_nrf52840 -- works |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tested on feather_m4_express and feather_nrf52840_express with ethernet_featherwing -- both work now.
Tested working on Metro M4 Express w/Ethernet Shield (https://www.adafruit.com/product/2971)
|
Updated
_socket
for compatibility withAdafruit_CircuitPython_Requests
libraryAdded: NEW EXAMPLE to post to Adafruit IO using Requests
Fixed:
_socket
readline
not parsing multiple lines correctlyFixed:
_socket
'srecv
for UDP packetsFixed:
adafruit_wiznet5k_dhcp
w.r.t incorrect address parsingUpdated
wiznet5k_simpletest
to mirror https://github.com/adafruit/Adafruit_CircuitPython_ESP32SPI/blob/master/examples/esp32spi_simpletest.pysprinkled some
gc.collect()
's where i could inadafruit_wiznet5k_dhcp
Tested on:
Adafruit CircuitPython 5.0.0-beta.5 on 2020-02-05; Adafruit Feather M4 Express with samd51j19
Test output:
wiznet5k_simpletest
Test:
requests_simpletest.py
(https://github.com/adafruit/Adafruit_CircuitPython_Requests/blob/master/examples/requests_simpletest.py), modified for eth. object instead of esp32spi object.