I'm getting started with Circuit Python on the Metro M4 Airlift Lite board. I've got the latest boot loader, Python stable libraries, and ESP32 firmware. I am trying to get the adafruit_requests.py sample code to run. It does connect properly to WiFi, and pings Google without any trouble, but when it tries to get text from the Adafruit test URL it gives the following Traceback:
IP lookup adafruit.com: 104.20.38.240
Ping google.com: 30 ms
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
Traceback (most recent call last):
File "code.py", line 71, in <module>
File "adafruit_requests.py", line 291, in get
File "adafruit_requests.py", line 251, in request
File "adafruit_requests.py", line 197, in request
AttributeError: 'socket' object has no attribute 'send'
Using the requests_simpletest.py sample code from the adafruit_requests library I get a slightly different error from the same place:
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
Traceback (most recent call last):
File "code.py", line 53, in <module>
File "adafruit_requests.py", line 291, in get
File "adafruit_requests.py", line 182, in request
File "adafruit_esp32spi/adafruit_esp32spi_socket.py", line 54, in getaddrinfo
File "adafruit_esp32spi/adafruit_esp32spi.py", line 461, in get_host_by_name
RuntimeError: Failed to request hostname
It looks like there's something wrong with the socket being generated.
Thanks for any ideas how to resolve these issues.
Problem with adafruit_requests library Metro M4 Airlift Lite
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
- tannewt
- Posts: 3315
- Joined: Thu Oct 06, 2016 8:48 pm
Re: Problem with adafruit_requests library Metro M4 Airlift
Hi! Please post the current version of the code you are trying. That way it's possible to know exactly what you are doing.
One debug step would be to print out the socket object before the error.
One debug step would be to print out the socket object before the error.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
Re: Problem with adafruit_requests library Metro M4 Airlift
Thanks for your reply. The code is taken from the esp32spi_simpletest.py example in the Adafruit_CircuitPython_ESP32SPI repository.
(I use my actual network name and password in the running code)
The output from running this is:
ESP32 SPI webclient test
Connecting to AP...
Connected to MYNET RSSI: -66
print socket:
<module 'adafruit_esp32spi.adafruit_esp32spi_socket' from '/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy'>
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
*** Get host by name
*** Get socket
Allocated socket #0
*** Socket connect mode 0
*** Open socket
Traceback (most recent call last):
File "code.py", line 65, in <module>
File "adafruit_requests.py", line 291, in get
File "adafruit_requests.py", line 251, in request
File "adafruit_requests.py", line 197, in request
AttributeError: 'socket' object has no attribute 'send'
It looks like the 'allocated socket' isn't set up properly, but I don't know what to make of the debug output.
Thanks for any word on this.
Code: Select all
import board
import busio
from digitalio import DigitalInOut
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi
import adafruit_requests as requests
print("ESP32 SPI webclient test")
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_URL = "http://api.coindesk.com/v1/bpi/currentprice/USD.json"
# If you are using a board with pre-defined ESP32 Pins:
esp32_cs = DigitalInOut(board.ESP_CS)
esp32_ready = DigitalInOut(board.ESP_BUSY)
esp32_reset = DigitalInOut(board.ESP_RESET)
# If you have an AirLift Shield:
# esp32_cs = DigitalInOut(board.D10)
# esp32_ready = DigitalInOut(board.D7)
# esp32_reset = DigitalInOut(board.D5)
# If you have an AirLift Featherwing or ItsyBitsy Airlift:
# esp32_cs = DigitalInOut(board.D13)
# esp32_ready = DigitalInOut(board.D11)
# esp32_reset = DigitalInOut(board.D12)
# If you have an externally connected ESP32:
# NOTE: You may need to change the pins to reflect your wiring
# esp32_cs = DigitalInOut(board.D9)
# esp32_ready = DigitalInOut(board.D10)
# esp32_reset = DigitalInOut(board.D5)
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
print("Connecting to AP...")
while not esp.is_connected:
try:
esp.connect_AP(b"MYNET", b"PASSWORD")
except RuntimeError as e:
print("could not connect to AP, retrying: ", e)
continue
print("Connected to", str(esp.ssid, "utf-8"), "\tRSSI:", esp.rssi)
# Initialize a requests object with a socket and esp32spi interface
requests.set_socket(socket, esp)
TEXT_URL = "http://wifitest.adafruit.com/testwifi/index.html"
JSON_GET_URL = "http://httpbin.org/get"
JSON_POST_URL = "http://httpbin.org/post"
print("print socket: ")
print(socket)
esp._debug = True
print("Fetching text from %s" % TEXT_URL)
response = requests.get(TEXT_URL)
print("-" * 40)
The output from running this is:
ESP32 SPI webclient test
Connecting to AP...
Connected to MYNET RSSI: -66
print socket:
<module 'adafruit_esp32spi.adafruit_esp32spi_socket' from '/lib/adafruit_esp32spi/adafruit_esp32spi_socket.mpy'>
Fetching text from http://wifitest.adafruit.com/testwifi/index.html
*** Get host by name
*** Get socket
Allocated socket #0
*** Socket connect mode 0
*** Open socket
Traceback (most recent call last):
File "code.py", line 65, in <module>
File "adafruit_requests.py", line 291, in get
File "adafruit_requests.py", line 251, in request
File "adafruit_requests.py", line 197, in request
AttributeError: 'socket' object has no attribute 'send'
It looks like the 'allocated socket' isn't set up properly, but I don't know what to make of the debug output.
Thanks for any word on this.
- brubell
- Learn User Page
- Posts: 2017
- Joined: Fri Jul 17, 2015 10:33 pm
Re: Problem with adafruit_requests library Metro M4 Airlift
Hi jstanle1,
You may have a mismatch between the libraries on your Metro Airlift, an older version of esp32spi_socket used write instead of send.
Could you navigate to: https://circuitpython.org/libraries
and download the latest library bundle.
Replace the ESP32SPI library and the Requests library on your device.
Then, try running code.py again.
You may have a mismatch between the libraries on your Metro Airlift, an older version of esp32spi_socket used write instead of send.
Could you navigate to: https://circuitpython.org/libraries
and download the latest library bundle.
Replace the ESP32SPI library and the Requests library on your device.
Then, try running code.py again.
- jstanle1
- Posts: 47
- Joined: Sat Dec 12, 2015 5:53 pm
Re: Problem with adafruit_requests library Metro M4 Airlift
Thanks for your prompt reply -- that fixed it, socket and connection to the test web page are working fine.
Please be positive and constructive with your questions and comments.