MemoryError When Connecting Pico W with Azure IoT Central

CircuitPython on hardware including Adafruit's boards, and CircuitPython libraries using Blinka on host computers.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

https://docs.circuitpython.org/en/late ... ry/gc.html
For description of garbage collection and all its options.

User avatar
jbenowitz
 
Posts: 15
Joined: Tue Nov 01, 2022 6:45 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by jbenowitz »

Great idea, that would make a lot of sense. Also thanks for the link, good read.

Printing the free memory immediately before the program crashes, I get 93568. That is much larger (~3x) than the MemoryError "allocating 32768 bytes".

Adding gc.collect() made a minor difference, this time printing free memory of 94928. The program still crashes, though.

Code: Select all

>>> %Run -c $EDITOR_CONTENT
--- .env variables ---
test_string: Hello World
SSID: RedSpoon
id_scope: 0ne00824092
device_id: 1ymiyal5o9n
device_primary_key: AeGcEjdBN4U6VYLa/bM4LQbDhwl+LO3orVKHsk0XNZo=
-----------------
Connecting to WiFi...
Connected to WiFi!
Year seems good, skipping set time.
Check free memory on Pico
94928
Connecting to Azure IoT Central...
Traceback (most recent call last):
  File "<stdin>", line 61, in <module>
  File "adafruit_azureiot/iotcentral_device.py", line 159, in connect
  File "adafruit_azureiot/device_registration.py", line 204, in register_device
  File "adafruit_azureiot/device_registration.py", line 141, in _start_registration
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 874, in loop
MemoryError: memory allocation failed, allocating 32768 bytes
>>> 
If the Pico has enough free memory before running device.connect(), does that mean more than 94928 bytes are being used in that method call? Would using a microSD for additional memory be any help? My guess is no, since the MemoryError stems from RAM not ROM, but at this point I'm not sure about anything, haha.

- Jacob
Attachments
Added garbage collection.png
Added garbage collection.png (175.45 KiB) Viewed 547 times
Printing free memory before crash.png
Printing free memory before crash.png (169.28 KiB) Viewed 547 times

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

OK, This works on my machine. Give it a try.

Code: Select all

# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT

import time
import os
import json
import busio
import microcontroller
import board
import rtc
import socketpool
import wifi
import adafruit_ntp
import adafruit_ahtx0
from adafruit_azureiot import IoTCentralDevice

#  use Pico W's GP0 for SDA and GP1 for SCL
#i2c = busio.I2C(board.GP9, board.GP8)
#aht20 = adafruit_ahtx0.AHTx0(i2c)

print("Connecting to WiFi...", end='\r')
wifi.radio.connect(os.getenv('WIFI_SSID0'), os.getenv('WIFI_PASSWORD0'))

print("Connected to WiFi!", os.getenv('WIFI_SSID0'))

#  ntp clock
pool = socketpool.SocketPool(wifi.radio)
ntp = adafruit_ntp.NTP(pool)
got_time = False ###
while not got_time: ###
  try: ###
    rtc.RTC().datetime = ntp.datetime ###
    got_time = True ###
  except: ###
    print(".", end=' ')
    time.sleep(1) ###
print("")
###rtc.RTC().datetime = ntp.datetime

if time.localtime().tm_year < 2022:
    print("Setting System Time to UTC")
    rtc.RTC().datetime = ntp.datetime
else:
    print("Year seems good, skipping set time.")

# Create an IoT Hub device client and connect
esp = None
pool = socketpool.SocketPool(wifi.radio)
print("Finis")
#while True: pass

device = IoTCentralDevice(pool, esp, os.getenv('id_scope'), os.getenv('device_id'), os.getenv('device_primary_key'))
print(os.getenv('id_scope'), os.getenv('device_id'), os.getenv('device_primary_key'))
print("Connecting to Azure IoT Central...")
device.connect()
print("Connected to Azure IoT Central!")

#  clock to count down to sending data to Azure
azure_clock = 500
#while True: pass
while True:
    try:
		#  when the azure clock runs out
        if azure_clock > 500:
			#  pack message
            message = {"Temperature = 30.0", #: aht20.temperature,
                       "Humidity = 35%"} #: aht20.relative_humidity}
            print("sending json")
            #device.send_telemetry(json.dumps(message))
            print("data sent")
			#  reset azure clock
            azure_clock = 0
        else:
            azure_clock += 1
		#  ping azure
        device.loop()
	#  if something disrupts the loop, reconnect
    # pylint: disable=broad-except
    #  any errors, reset Pico W
    except Exception as e:
        print("Error:\n", str(e))
        print("Resetting microcontroller in 10 seconds")
        time.sleep(10)
        microcontroller.reset()
	#  delay
    time.sleep(1)
    print(azure_clock)

User avatar
jbenowitz
 
Posts: 15
Joined: Tue Nov 01, 2022 6:45 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by jbenowitz »

Still no luck :(

Code: Select all

>>> %Run -c $EDITOR_CONTENT
Connected to WiFi! RedSpoon

Year seems good, skipping set time.
Finis
0ne00824092 1ymiyal5o9n AeGcEjdBN4U6VYLa/bM4LQbDhwl+LO3orVKHsk0XNZo=
Connecting to Azure IoT Central...
Traceback (most recent call last):
  File "<stdin>", line 55, in <module>
  File "adafruit_azureiot/iotcentral_device.py", line 159, in connect
  File "adafruit_azureiot/device_registration.py", line 204, in register_device
  File "adafruit_azureiot/device_registration.py", line 141, in _start_registration
  File "adafruit_minimqtt/adafruit_minimqtt.py", line 874, in loop
MemoryError: memory allocation failed, allocating 32768 bytes
>>> 
Attachments
Screen Shot 2022-11-16 at 10.24.49 PM.png
Screen Shot 2022-11-16 at 10.24.49 PM.png (242.96 KiB) Viewed 538 times
Screen Shot 2022-11-16 at 10.25.01 PM.png
Screen Shot 2022-11-16 at 10.25.01 PM.png (197.47 KiB) Viewed 538 times

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

Hmm,
Your first post shows
Thonny 4.0.1
Darwin 21.6.0
Python 3.10.6
Tk 8.6.12
Why does it show Python 3.10.6, and not CircuitPython 8.0.0? The selection of Python and not CircuitPython may be confusing things. Mu is the IDE that AdaFruit recommends. I use notepad++ and Putty for CircuitPython and Thonny for MicroPython. This helps me remember the differences between Circuit and Micro.

Bruce

User avatar
jbenowitz
 
Posts: 15
Joined: Tue Nov 01, 2022 6:45 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by jbenowitz »

Sorry to confuse things, was just confirming I have Python 3 on my computer (read there were issues with 2.X).

I always select CircuitPython from the list of devices in Thonny after plugging the Pico in. I've tried Mu and it did not seem to play well with the Pico... I got the impression that Mu specifically was build for Adafruit boards only, but I could be wrong.

I'll look into Putty and give it a try!
Attachments
CircuitPython selected in Thonny
CircuitPython selected in Thonny
Screen Shot 2022-11-17 at 3.36.34 PM.png (198.68 KiB) Viewed 528 times

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

I am easily confused.

Todays issue is why does your code run with my Windows 10 machine with my RPi Pico W and not on your machine with your Pico W.

Mu is advertised to play well with all that AdaFruit sells. I tried it and didn't like the feel of it. notepad++ for the text editing and Putty for the REPL readout vis USB is a bit complex but to me has a more sturdy feel. Arduino, Tunny and Mu try to pull everything into one package. The one thing that will keep me on notepad++ for a long time is the features. The one I use the most is; I can double click a variable or word and all those words light up green. Bigger words with the word I clicked in it light up grey. ++ will configure itself based on the file extender. A .txt file gets treated like a text file, a .py file gets treated like a Python file. It remembers things. I can have 6 files open when I close down ++. When I open it up those 6 files are still there. It shows you what lines of code have been modified in orange, when the file is saved those orange indicators are changed to green.

My son who was a system administrator for out community collage, Towson University, Johns Hopkins, and now for the US Federal Courts turned me on to notepad++. I am a bit partial toward his opinions on some things.

Bruce

User avatar
jbenowitz
 
Posts: 15
Joined: Tue Nov 01, 2022 6:45 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by jbenowitz »

Todays issue is why does your code run with my Windows 10 machine with my RPi Pico W and not on your machine with your Pico W.
I have a Windows 10 machine as well, let me try running the code from that machine.

The last issue I can think of is I am incorrectly setting up the device / application on Azure IoT. I have created an Azure IoT Central application, created a device and device template. Am I missing something there?

Noted on ++, I'll use that on Windows.
Attachments
Screen Shot 2022-11-17 at 4.23.19 PM.png
Screen Shot 2022-11-17 at 4.23.19 PM.png (503.43 KiB) Viewed 522 times

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

My ignorance about Azure is only exceeded by my ignorance of women.
I have been married for 52 years, don't ask me anything.

I took the Azure code off of the AdaFruit web page and modified it only to use my WiFi and password, and my BME280 temperature & humidity device. Beyond that I don't know what to tell you. I am using your access codes. They will be forgot as soon as we get your code working. I couldn't figure out how to setup an account for me.

Bruce

User avatar
jbenowitz
 
Posts: 15
Joined: Tue Nov 01, 2022 6:45 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by jbenowitz »

Haha, Azure isn't very intuitive - I just followed this Adafruit guide step-by-step: https://learn.adafruit.com/getting-star ... cuitpython.

On Windows now, deleted the files in lib just for fun and replaced with fresh downloads. Ran the script you provided... and same error again. I'm starting to consider this may be a hardware issue?
Attachments
Windows 10
Windows 10
Screenshot 2022-11-17 170720.jpg (225.18 KiB) Viewed 517 times

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

Here is the code I am using right now. You will need to modify the lines where I reference my BME280. I have added a couple try:/except: traps. it has some other changes too.

Code: Select all

# SPDX-FileCopyrightText: 2022 Liz Clark for Adafruit Industries
# SPDX-License-Identifier: MIT

from   time import time, sleep, localtime
import os
import json
import wifi
import busio
import board
import rtc
import socketpool
import microcontroller
import adafruit_ntp
import adafruit_ahtx0
from   adafruit_azureiot import IoTCentralDevice
from   adafruit_bme280 import advanced as adafruit_bme280

i2c = busio.I2C(board.GP7, board.GP6)
bme280 = adafruit_bme280.Adafruit_BME280_I2C(i2c, address=0x76)

print("Connecting to WiFi...", end='\r')
wifi.radio.connect(os.getenv('WIFI_SSID0'), os.getenv('WIFI_PASSWORD0'))

print("Connected to WiFi!", os.getenv('WIFI_SSID0'))

#  ntp clock
pool = socketpool.SocketPool(wifi.radio)
ntp = adafruit_ntp.NTP(pool)
got_time = False ###
while not got_time: ###
  try: ###
    rtc.RTC().datetime = ntp.datetime ###
    got_time = True ###
  except: ###
    print(".", end=' ')
    sleep(1) ###
print("")

if localtime().tm_year < 2022:
    print("Setting System Time to UTC")
    rtc.RTC().datetime = ntp.datetime
else:
    print("Year seems good, skipping set time.")

# Create an IoT Hub device client and connect
pool = socketpool.SocketPool(wifi.radio)
esp = None
device = IoTCentralDevice(pool, esp, os.getenv('id_scope'), os.getenv('device_id'), os.getenv('device_primary_key'))
print(os.getenv('id_scope'), os.getenv('device_id'), os.getenv('device_primary_key'))

print("Connecting to Azure IoT Central...")
got_connect = False
while not got_connect:
  try:
    device.connect()
    got_connect = True
  except:
    print(".", end=' ')
    sleep(1)
print("Connected to Azure IoT Central!")

#  clock to count down to sending data to Azure
counts = 300
azure_clock = counts
while True:
    _ = time()
    while (_ == time()): pass
    try:
		#  when the azure clock runs out
        if azure_clock > counts:
			#  pack message
            message = {"Temperature": bme280.temperature,
                          "Humidity": bme280.humidity}
#                          "Pressure": bme280.pressure}
            print("sending json")
            #device.send_telemetry(json.dumps(message))
            print("data sent")
			#  reset azure clock
            azure_clock = 0
        else:
            azure_clock += 1
		#  ping azure
        device.loop()
	#  if something disrupts the loop, reconnect
    #  any errors, reset Pico W
    except Exception as e:
        print("Error:\n", str(e))
        print("Resetting microcontroller in 10 seconds")
        sleep(10)
        microcontroller.reset()
    print(azure_clock, end=' ')
I find it difficult to believe both of your RPi Pico W boards are bad in the same way. Not impossible, but very low probability.

Bruce

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

This is the output I get

Code: Select all

Connected to WiFi! adafruit

Year seems good, skipping set time.
0ne00824092 1ymiyal5o9n AeGcEjdBN4U6VYLa/bM4LQbDhwl+LO3orVKHsk0XNZo=
Connecting to Azure IoT Central...
70640 *********Before
19421.922: DEBUG - Attempting to establish MQTT connection...
19421.930: INFO - Establishing a SECURE SSL connection to global.azure-devices-provisioning.net:8883
19425.703: DEBUG - Sending CONNECT to broker...
19425.711: DEBUG - Fixed Header: bytearray(b'\x10\xeb\x01\x00')
Variable Header: bytearray(b'\x04MQTT\x04\xc2\x00x')
19425.719: DEBUG - Receiving CONNACK packet from broker
19425.945: INFO - - device_registration :: _on_connect :: rc = 0, userdata = None
19425.953: INFO -  - device_registration :: connect :: created mqtt client. connecting..
19425.961: INFO -  - device_registration :: connect :: on_connect must be fired. Connected ? True
19425.969: DEBUG - SUBSCRIBING to topic $dps/registrations/res/# with QoS 0
19426.250: DEBUG - Sending PUBLISH
Topic: $dps/registrations/PUT/iotdps-register/?$rid=1ymiyal5o9n
Msg: b'{"registrationId": "1ymiyal5o9n"}'
QoS: 0
Retain? False
19427.266: DEBUG - Receiving SUBSCRIBE
Topic: $dps/registrations/res/202/?$rid=1ymiyal5o9n&retry-after=3
Msg: bytearray(b'{"operationId":"5.38b19bc03b9a3993.05c75c47-62e1-423c-b681-9b88b102117e","status":"assigning"}')

19427.273: INFO - Received registration results on topic $dps/registrations/res/202/?$rid=1ymiyal5o9n&retry-after=3 - {"operationId":"5.38b19bc03b9a3993.05c75c47-62e1-423c-b681-9b88b102117e","status":"assigning"}
19427.289: DEBUG - Retrying after 3s
19430.297: DEBUG - Sending PUBLISH
Topic: $dps/registrations/GET/iotdps-get-operationstatus/?$rid=1ymiyal5o9n&operationId=5.38b19bc03b9a3993.05c75c47-62e1-423c-b681-9b88b102117e
Msg: b'{"operationId": "5.38b19bc03b9a3993.05c75c47-62e1-423c-b681-9b88b102117e"}'
QoS: 0
Retain? False
19431.320: DEBUG - Receiving SUBSCRIBE
Topic: $dps/registrations/res/202/?$rid=1ymiyal5o9n&retry-after=3
Msg: bytearray(b'{"operationId":"5.38b19bc03b9a3993.05c75c47-62e1-423c-b681-9b88b102117e","status":"assigning","registrationState":{"registrationId":"1ymiyal5o9n","status":"assigning"}}')

19431.328: INFO - Received registration results on topic $dps/registrations/res/202/?$rid=1ymiyal5o9n&retry-after=3 - {"operationId":"5.38b19bc03b9a3993.05c75c47-62e1-423c-b681-9b88b102117e","status":"assigning","registrationState":{"registrationId":"1ymiyal5o9n","status":"assigning"}}
19431.336: DEBUG - Retrying after 3s
. 18384 *********Before
19453.961: DEBUG - Attempting to establish MQTT connection...
19453.969: INFO - Establishing a SECURE SSL connection to global.azure-devices-provisioning.net:8883
19457.508: DEBUG - Sending CONNECT to broker...
19457.516: DEBUG - Fixed Header: bytearray(b'\x10\xed\x01\x00')
Variable Header: bytearray(b'\x04MQTT\x04\xc2\x00x')
19457.531: DEBUG - Receiving CONNACK packet from broker
19457.758: INFO - - device_registration :: _on_connect :: rc = 0, userdata = None
19457.766: INFO -  - device_registration :: connect :: created mqtt client. connecting..
19457.766: INFO -  - device_registration :: connect :: on_connect must be fired. Connected ? True
19457.773: DEBUG - SUBSCRIBING to topic $dps/registrations/res/# with QoS 0
19458.055: DEBUG - Sending PUBLISH
Topic: $dps/registrations/PUT/iotdps-register/?$rid=1ymiyal5o9n
Msg: b'{"registrationId": "1ymiyal5o9n"}'
QoS: 0
Retain? False
19459.070: DEBUG - Receiving SUBSCRIBE
Topic: $dps/registrations/res/202/?$rid=1ymiyal5o9n&retry-after=3
Msg: bytearray(b'{"operationId":"5.38b19bc03b9a3993.e16851c5-1a5b-4e4d-bd40-9fa0d0b25b1b","status":"assigning"}')

19459.086: INFO - Received registration results on topic $dps/registrations/res/202/?$rid=1ymiyal5o9n&retry-after=3 - {"operationId":"5.38b19bc03b9a3993.e16851c5-1a5b-4e4d-bd40-9fa0d0b25b1b","status":"assigning"}
19459.094: DEBUG - Retrying after 3s
19462.102: DEBUG - Sending PUBLISH
Topic: $dps/registrations/GET/iotdps-get-operationstatus/?$rid=1ymiyal5o9n&operationId=5.38b19bc03b9a3993.e16851c5-1a5b-4e4d-bd40-9fa0d0b25b1b
Msg: b'{"operationId": "5.38b19bc03b9a3993.e16851c5-1a5b-4e4d-bd40-9fa0d0b25b1b"}'
QoS: 0
Retain? False
19463.125: DEBUG - Receiving SUBSCRIBE
Topic: $dps/registrations/res/200/?$rid=1ymiyal5o9n
Msg: bytearray(b'{"operationId":"5.38b19bc03b9a3993.e16851c5-1a5b-4e4d-bd40-9fa0d0b25b1b","status":"assigned","registrationState":{"registrationId":"1ymiyal5o9n","createdDateTimeUtc":"2022-11-17T22:39:44.3387581Z","assignedHub":"iotc-85f27096-d5c7-464c-802c-405894df78c2.azure-devices.net","deviceId":"1ymiyal5o9n","status":"assigned","substatus":"initialAssignment","lastUpdatedDateTimeUtc":"2022-11-17T22:39:44.6434002Z","etag":"ImRmMDAzMTgzLTAwMDAtMDEwMC0wMDAwLTYzNzZiODMwMDAwMCI="}}')

19463.141: INFO - Received registration results on topic $dps/registrations/res/200/?$rid=1ymiyal5o9n - {"operationId":"5.38b19bc03b9a3993.e16851c5-1a5b-4e4d-bd40-9fa0d0b25b1b","status":"assigned","registrationState":{"registrationId":"1ymiyal5o9n","createdDateTimeUtc":"2022-11-17T22:39:44.3387581Z","assignedHub":"iotc-85f27096-d5c7-464c-802c-405894df78c2.azure-devices.net","deviceId":"1ymiyal5o9n","status":"assigned","substatus":"initialAssignment","lastUpdatedDateTimeUtc":"2022-11-17T22:39:44.6434002Z","etag":"ImRmMDAzMTgzLTAwMDAtMDEwMC0wMDAwLTYzNzZiODMwMDAwMCI="}}
19463.148: DEBUG - Sending DISCONNECT packet to broker
19463.156: DEBUG - Closing socket
19463.922: DEBUG - Hostname: iotc-85f27096-d5c7-464c-802c-405894df78c2.azure-devices.net
19463.922: DEBUG - Device Id: 1ymiyal5o9n
19463.930: DEBUG - Shared Access Key: AeGcEjdBN4U6VYLa/bM4LQbDhwl+LO3orVKHsk0XNZo=
19463.938: INFO - - iot_mqtt :: connect :: iotc-85f27096-d5c7-464c-802c-405894df78c2.azure-devices.net
19463.945: DEBUG - - iot_mqtt :: _on_connect :: username = iotc-85f27096-d5c7-464c-802c-405894df78c2.azure-devices.net/1ymiyal5o9n/?api-version=2019-10-01, password = SharedAccessSignature sr=iotc-85f27096-d5c7-464c-802c-405894df78c2.azure-devices.net%2Fdevices%2F1ymiyal5o9n&sig=aPHMbx3lDuUQrHuZVQJLPqx%2FNWr81p3jMvcmtl6TOno%3D&se=1668746388
19463.953: DEBUG - Attempting to establish MQTT connection...
19463.961: INFO - Establishing a SECURE SSL connection to iotc-85f27096-d5c7-464c-802c-405894df78c2.azure-devices.net:8883
19465.875: DEBUG - Sending CONNECT to broker...
19465.875: DEBUG - Fixed Header: bytearray(b'\x10\xa9\x02\x00')
Variable Header: bytearray(b'\x04MQTT\x04\xc2\x00x')
19465.898: DEBUG - Receiving CONNACK packet from broker
19466.219: INFO - - iot_mqtt :: _on_connect :: rc = 0, userdata = None
19466.227: INFO -  - iot_mqtt :: connect :: created mqtt client. connecting..
19466.227: INFO -  - iot_mqtt :: connect :: on_connect must be fired. Connected ? True
19466.242: DEBUG - SUBSCRIBING to topic devices/1ymiyal5o9n/messages/devicebound/# with QoS 0
19466.422: DEBUG - SUBSCRIBING to topic $iothub/methods/# with QoS 0
19466.734: DEBUG - SUBSCRIBING to topic $iothub/twin/PATCH/properties/desired/# with QoS 0
19467.016: DEBUG - SUBSCRIBING to topic $iothub/twin/res/200/# with QoS 0
19467.289: INFO - - iot_mqtt :: _get_device_settings ::
19468.313: DEBUG - Sending message on topic: $iothub/twin/GET/?$rid=0
19468.320: DEBUG - Sending message:
19468.336: DEBUG - Trying to send...
19468.344: DEBUG - Sending PUBLISH
Topic: $iothub/twin/GET/?$rid=0
Msg: b' '
QoS: 0
Retain? False
19468.359: INFO - - iot_mqtt :: _on_publish :: None on topic $iothub/twin/GET/?$rid=0
19468.359: DEBUG - Data sent
33216 *********After 14832
. Connected to Azure IoT Central!
19470.313: DEBUG - Receiving SUBSCRIBE
Topic: $iothub/twin/res/200/?$rid=0
Msg: bytearray(b'{"desired":{"$version":1},"reported":{"$version":1}}')

19470.328: DEBUG - - iot_mqtt :: _echo_desired :: $iothub/twin/res/200/?$rid=0
301 sending json
data sent

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

Free Memory: 70640 *********Before # Before first attempt at device.connect()
So 52256 bytes have gone someplace
Free Memory: . 18384 *********Before # After first failure (dot shows failure), Before second attempt success
So second attempt released 14832 bytes
Free Memory: 33216 *********After 14832 # After success of second attempt
So start to finish 37424 bytes went someplace. 70640 - 33216 = 37424

The time you used garbage collection you started with ~ 90000 free bytes. There should be more than enough space for device.connect() to do its thing. We need the help of one of the support admins.

Bruce

User avatar
jbenowitz
 
Posts: 15
Joined: Tue Nov 01, 2022 6:45 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by jbenowitz »

I've got news! I tried your latest script on both Picos. The first Pico got stuck in the device.connect() loop, screenshot attached. Then I tried the second Pico, fresh install of CircuitPython and... it connected! I can see the connection log in Azure, but the actual message with Temp and Humidity are not coming through. Happy to work on that problem now!

Code: Select all

Connected to WiFi! RedSpoon

Year seems good, skipping set time.
0ne0082429D 17bdmyzn3hz ZFiwCMwSsB5ky2LAwqpCsT0E+HZeSlUHX2kvlcOi9XI=
Connecting to Azure IoT Central...
Connected to Azure IoT Central!
26 sending json
data sent
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 sending json
I also need to figure out why it worked on one Pico and not the other.

Thank you Bruce for sticking this one out with me! Really appreciate all your time!

- Jacob
Attachments
pico-1-azure.jpg
pico-1-azure.jpg (151.93 KiB) Viewed 505 times

User avatar
blakebr
 
Posts: 942
Joined: Tue Apr 17, 2012 6:23 pm

Re: MemoryError When Connecting Pico W with Azure IoT Central

Post by blakebr »

Jacob,

It is good to hear you have one working RPi Pico W. I will address the other in another post.

The code you show has my BME280 as part of the code. I assume you plugged in the stuff for your temperature/humidity sensor.

Do you have a paid subscription to Azure or a free 30 day subscription? If it is a free subscription, could it have expired?

Your output looks like stuff was sent. Line 76: #device.send_telemetry... is commented out in the screen dump shown. How do you determine that the information was received by Azure? My guess is you built a web page in Azure that your data populates. You then can access that web page to see that data from anywhere there is internet access using a web browser. From your post, I gather that you don't see your data on that web page.

I am glad to help.

Bruce

Locked
Please be positive and constructive with your questions and comments.

Return to “Adafruit CircuitPython”