Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

Pyportal Pynt IO and SSL
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Re: Pyportal Pynt IO and SSL

by oldblackcrow on Fri Mar 12, 2021 3:21 pm

MakerMelissa wrote:Ok, I just tried your code (updated to my user account) and am getting the same error, so I'm going to hack on it a bit and see if I can get it to work.


Awesome sauce... Thank you!

BTW, so, my original PyPortal (and I'm not worried about this one because I'm not going to use it) won't update at all. This is a weird bug... I did the exact same process and still won't update. But if it's like the one that now works, it will probably just update in a few days if I turn it on again. But, seriously... no worries on this one, just thought it's worth mentioning.

oldblackcrow
 
Posts: 212
Joined: Tue Jun 20, 2017 5:54 pm

Re: Pyportal Pynt IO and SSL

by MakerMelissa on Fri Mar 12, 2021 3:25 pm

Ok, I found the source for your code here: https://github.com/adafruit/Adafruit_Ci ... io_post.py. I went ahead and slightly modified your code to work the way I think you were trying to get it to work:

Code: Select all | TOGGLE FULL SIZE
import time
import board
import busio
from digitalio import DigitalInOut
import neopixel
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 secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

# 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)

spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
esp = adafruit_esp32spi.ESP_SPIcontrol(spi, esp32_cs, esp32_ready, esp32_reset)
"""Use below for Most Boards"""
status_light = neopixel.NeoPixel(
    board.NEOPIXEL, 1, brightness=0.2
)  # Uncomment for Most Boards

wifi = adafruit_esp32spi_wifimanager.ESPSPI_WiFiManager(esp, secrets, status_light)

counter = 0

while True:
    try:
        print("Posting data...", end="")
        data = counter
        feed = "rx"
        payload = {"value": data}
        response = wifi.post(
            "https://io.adafruit.com/api/v2/"
            + secrets["aio_username"]
            + "/feeds/"
            + feed
            + "/data",
            json=payload,
            headers={"X-AIO-KEY": secrets["aio_key"]},
        )
        print(response.json())
        response.close()
        counter = counter + 1
        print("OK")
    except (ValueError, RuntimeError) as e:
        print("Failed to get data, retrying\n", e)
        wifi.reset()
        continue
    response = None
    time.sleep(15)

MakerMelissa
 
Posts: 252
Joined: Wed Jun 05, 2013 2:10 am

Re: Pyportal Pynt IO and SSL

by MakerMelissa on Fri Mar 12, 2021 3:30 pm

Also, there's a library for Adafruit IO (https://github.com/adafruit/Adafruit_Ci ... AdafruitIO) with a bunch of examples. It might make things a bit easier.

Melissa

MakerMelissa
 
Posts: 252
Joined: Wed Jun 05, 2013 2:10 am

Re: Pyportal Pynt IO and SSL

by oldblackcrow on Fri Mar 12, 2021 3:36 pm

MakerMelissa wrote:Also, there's a library for Adafruit IO (https://github.com/adafruit/Adafruit_Ci ... AdafruitIO) with a bunch of examples. It might make things a bit easier.

Melissa


The code you modified did work! You rock! The data is a bit cryptic for me, so, I will look to the other examples. I did pull the code you modified from an example... and all I did was change the web address to connect to my AdafruitIO page. But thank you so very much!!!!

oldblackcrow
 
Posts: 212
Joined: Tue Jun 20, 2017 5:54 pm

Re: Pyportal Pynt IO and SSL

by MakerMelissa on Fri Mar 12, 2021 3:41 pm

Excellent and glad to hear it. Thank you so much for your patience.

MakerMelissa
 
Posts: 252
Joined: Wed Jun 05, 2013 2:10 am

Re: Pyportal Pynt IO and SSL

by oldblackcrow on Sun Mar 14, 2021 10:09 pm

Just an update on updating my original PyPortal... this is using the ESPTool.py provided above.

I found that using a power only usb cable has s better chance to update. This one actually made to 100% but somehow managed to fail. So, it's still not updated.

I've had to plug in, unplug many, many times and then the code works to a point. It seems this is a tricky bugger, so I'll keep trying. But thought it would be worth it to note to hopefully improve the software.

If you want me to create a new post for this, I am happy to do so.

oldblackcrow
 
Posts: 212
Joined: Tue Jun 20, 2017 5:54 pm

Re: Pyportal Pynt IO and SSL

by oldblackcrow on Fri Apr 02, 2021 5:29 pm

Finally! Got my original PyPortal updated to 1.7.1!

For those of you with the same issue:
I just kept at it every weekend... I've probably rebooted the thing 1000 times. Today, I erased everything, upgraded to Python 6.2.0-rc.0 and rebooted probably 5 or 6 times and then it worked... but specifically from a charge only cable... I've been experimenting between plugging in to my computer and a dedicated power source. It seems as though it obtained a higher percentage when on power only. Maybe this is just a coincidence, but I felt I should at least note it.

So just run the esptool.py:
Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import board
import busio
from digitalio import DigitalInOut, Direction  # pylint: disable=unused-import
import adafruit_miniesptool

print("ESP32 Nina-FW")

# Override these if you are manually wiring. Otherwise, this will use ESP pins from board.
tx = board.ESP_TX
rx = board.ESP_RX
resetpin = board.ESP_RESET
gpio0pin = board.ESP_GPIO0

uart = busio.UART(tx, rx, baudrate=115200, timeout=1)

esptool = adafruit_miniesptool.miniesptool(
    uart, DigitalInOut(gpio0pin), DigitalInOut(resetpin), flashsize=4 * 1024 * 1024
)
esptool.sync()

print("Synced")
print("Found:", esptool.chip_name)
if esptool.chip_name != "ESP32":
    raise RuntimeError("This example is for ESP32 only")
esptool.baudrate = 912600
print("MAC ADDR: ", [hex(i) for i in esptool.mac_addr])

# Note: Make sure to use the LATEST nina-fw binary release!
esptool.flash_file("NINA_W102-1.7.1.bin", 0x0, "dc81f0433dfba6de33c78b5c5911261d")

esptool.reset()
time.sleep(0.5)



Then check to see if it works... The green light should come on, but always confirm:

Code: Select all | TOGGLE FULL SIZE
# SPDX-FileCopyrightText: 2019 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT

import board
import busio
from digitalio import DigitalInOut
import adafruit_requests as requests
import adafruit_esp32spi.adafruit_esp32spi_socket as socket
from adafruit_esp32spi import adafruit_esp32spi

# Get wifi details and more from a secrets.py file
try:
    from secrets import secrets
except ImportError:
    print("WiFi secrets are kept in secrets.py, please add them there!")
    raise

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)

requests.set_socket(socket, esp)

if esp.status == adafruit_esp32spi.WL_IDLE_STATUS:
    print("ESP32 found and in idle mode")
print("Firmware vers.", esp.firmware_version)
print("MAC addr:", [hex(i) for i in esp.MAC_address])

for ap in esp.scan_networks():
    print("\t%s\t\tRSSI: %d" % (str(ap["ssid"], "utf-8"), ap["rssi"]))

print("Connecting to AP...")
while not esp.is_connected:
    try:
        esp.connect_AP(secrets["ssid"], secrets["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)
print("My IP address is", esp.pretty_ip(esp.ip_address))
print(
    "IP lookup adafruit.com: %s" % esp.pretty_ip(esp.get_host_by_name("adafruit.com"))
)
print("Ping google.com: %d ms" % esp.ping("google.com"))

# esp._debug = True
print("Fetching text from", TEXT_URL)
r = requests.get(TEXT_URL)
print("-" * 40)
print(r.text)
print("-" * 40)
r.close()

print()
print("Fetching json from", JSON_URL)
r = requests.get(JSON_URL)
print("-" * 40)
print(r.json())
print("-" * 40)
r.close()

print("Done!")


Keep trying! :-)

oldblackcrow
 
Posts: 212
Joined: Tue Jun 20, 2017 5:54 pm

Re: Pyportal Pynt IO and SSL

by oldblackcrow on Fri Apr 30, 2021 4:40 pm

@MakerMelissa

Ok... just an update on 1.7.3 - I successfully updated the NINA file to NINA_W102-1.7.3.bin from 1.7.1 on one of my two PyPortals.

However, my other PyPortal is just being stubborn. I've rebooted the PyPortal at least 100 times (literally) and for some reason, this just won't update. I've done nothing different than the instructions I've detailed above, save the following so I can obtain the error codes to hopefully help to make the ESPtool better. The attempt was done with the PyPortal plugged into my computer while running Mu. Unfortunately, Mu crashes at the same point the PyPortal gives up at around 90%. Since Mu crashes, the only way I could show the error codes is by taking a picture... so here it is.

NINA-Update-1.7.3.jpg
NINA-Update-1.7.3.jpg (134.25 KiB) Viewed 12 times


Maybe this should be posted to Github? Please let me know. Thanks!

oldblackcrow
 
Posts: 212
Joined: Tue Jun 20, 2017 5:54 pm

Re: Pyportal Pynt IO and SSL

by MakerMelissa on Fri Apr 30, 2021 5:24 pm

Yes, please file an issue to https://github.com/adafruit/Adafruit_Ci ... ool/issues and reference this thread.

Thanks,
Melissa

MakerMelissa
 
Posts: 252
Joined: Wed Jun 05, 2013 2:10 am

Please be positive and constructive with your questions and comments.