adafruit / adafruit/Adafruit_CircuitPython_ESP32SPI
json error in get
- Dominant language
- Python
- Stars
- 102
- Forks
- 71
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 1
Description
I was trying to test @brentru adafruit_io library and started getting jason errors when trying to use his "get_all_feeds" function -- I then tried the same "get" just using esp32spi (via wifimanager) and get the same error so there seems to be an underlying issue in esp32spi
here is the test case
```
import time
import board
import busio
from digitalio import DigitalInOut
from adafruit_esp32spi import adafruit_esp32spi
from adafruit_esp32spi import adafruit_esp32spi_wifimanager
print("ESP32 SPI webclient test")
# Get wifi details and more from a settings.py file
try:
from esp32spi_settings import settings
except ImportError:
print("WiFi settings are kept in esp32spi_settings.py, please add them there!")
raise
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)
wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, settings, board.NEOPIXEL)
esp._debug=True
while True:
try:
print("Get data...", end='')
response = wifi.get(
"https://io.adafruit.com/api/v2/"+settings['aio_username']+"/feeds",
headers={bytes("X-AIO-KEY","utf-8"):bytes(settings['aio_key'],"utf-8")})
print(response.json())
response.close()
print("OK")
except (ValueError, RuntimeError) as e:
print("Failed to get data, retrying\n", e)
wifi.reset()
continue
response = None
time.sleep(15)
```
here is the log -- with some repeated lines removed
```
Press any key to enter the REPL. Use CTRL-D to reload.
Adafruit CircuitPython 4.0.0-beta.2-97-g0dc260058 on 2019-02-19; Adafruit Feather nRF52840 Express with nRF52840
>>>
>>> import aio_get_esp32spi
ESP32 SPI webclient test
Get data...Connection status
Conn status: 0
Connection status
Conn status: 0
Connect to AP b'REDACTED' b'REDACTED'
Connection status
Conn status: 1
repeated lines removed
Connection status
Conn status: 1
Connection status
Conn status: 3
Connection status
Conn status: 3
*** Get host by name
*** Get socket
Allocated socket #0
*** Socket connect mode 2
*** Open socket
Writing: b'GET /api/v2/REDACTED/feeds HTTP/1.0\r\n'
Writing: b'Host: io.adafruit.com\r\n'
Writing: b'User-Agent: Adafruit CircuitPython\r\n'
Writing: b'X-AIO-KEY'
Writing: b': '
Writing: b'REDACTED'
Writing: b'\r\n'
Writing: b'\r\n'
ESPSocket: 0 bytes available
ESPSocket: 0 bytes available
repeated lines removed
ESPSocket: 0 bytes available
ESPSocket: 0 bytes available
ESPSocket: 8308 bytes available
Reading 4000 bytes from ESP socket with status 4
ESPSocket: 4308 bytes available
Reading 4000 bytes from ESP socket with status 4
ESPSocket: 308 bytes available
Reading 308 bytes from ESP socket with status 4
ESPSocket: 0 bytes available
Failed to get data, retrying
syntax error in JSON
Reset ESP32
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the supplied ESP32 SPI webclient test, especially wifi.get and response.json(), and reproduce the syntax error using the logged response sizes and request headers. Trace how the response is read before JSON parsing; done means the reported GET response can be parsed successfully without the JSON error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- embedded-iot, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100