Pico Enviro+ Urban upload error

Hi all,

I have an issue with a Pico Enviro+ Urban. I follow the instructions to connect via WiFi to the Pico, enter details etc. After pressing the “We’re done!” the Pico led flashes quickly, and seems to hang.

I’ve tried leaving it in this state for >5m and it doesn’t appear to complete the provisioning.

When I open config.py in Thonny, *some of the data (WiFi access point and password) are completed from the provisioning pages but not the rest. For example the provisioned status line is:

provisioned = False

If I manually enter details, I can run the code with main.py, the pico connects to my WiFi, makes a reading than fails to connnect to my http endpoint (the endpoint is up and functioning).

I have installed uping and tested that the Pico can connect to my WiFi and successfully ping the IP address of the endpoint.

It’s clearly not faulty, so I’m loathe to send it back. It fails to upload to http, mqtt & influxdb (I haven’t tried adafruit).

Any ideas?

> connecting to wifi network '****'
- ip address:
> uploading cached readings to url:
- upload issue (404 b'Not Found')
! failed to upload '2022-12-09T17_08_00Z.json' to http
! reading upload failed
> going to sleep

Thanks in advance for any thoughts.

Have you updated to the most recent firmware?

Do you need a trailing slash for the URL if it is directory you are uploading to?

Hi - yes. Version is 1.19.10

good suggestion and the error has improved… I know get:

! failed to upload '2022-12-12T10_59_51Z.json' to http
! reading upload failed

thank you for getting this closer.

I have not tried the HTTP client but have three urbans all working fine on mqtt.

could you post a redacted version of your config.py?

Here you go @warwickhw

# enviro config file

# you may edit this file by hand but if you enter provisioning mode
# then the file will be automatically overwritten with new details

provisioned = True

# enter a nickname for this board
nickname = 'urban2'

# network access details
wifi_ssid = 'WIFINAME'
wifi_password = 'WIFIPASSWORD'

# how often to wake up and take a reading (in minutes)
reading_frequency = 10

# where to upload to ("web_hook", "mqtt", "adafruitio")
destination = 'mqtt'

# how often to upload data (number of cached readings)
upload_frequency = 3

# web hook settings
custom_http_url = ''
custom_http_username = ''
custom_http_password = ''

# mqtt broker settings
mqtt_broker_address = 'MQTT_IP_ADDRESS'
mqtt_broker_username = 'USERNAME'
mqtt_broker_password = 'PASSWORD'

# adafruit ui settings
adafruit_io_username = ''
adafruit_io_key = ''

# influxdb settings
influxdb_org = ''
influxdb_url = ''
influxdb_token = ''
influxdb_bucket = ''

# grow specific settings
auto_water = False
moisture_target_1 = 50
moisture_target_2 = 50
moisture_target_3 = 50

Thanks @dave1979 that’s really helpful… unfortunately “http” and “mqtt” both fail with an unspecified error like:

! reading upload failed

So frustrating.

I’ve used Picos very successfully and they work because everything is open, and I can use code I’ve written. I wonder if anyone has a uf2 file that is basic, so I can write code from scratch, rather than the pre-compiled files on the enviro with the Pimoroni firmware.

Hi, if you have an mqtt broker setup I would try the following:
1 > On thonny backup your config.py file that is setup for mqtt
2 > Delete all the files directories on the urban pico onboard using thonny
3 > Flash the pico with this build for enviro (Shopuld be about 4MB in size)- https://github.com/pimoroni/enviro/suites/9684241395/artifacts/463755200
4 > Upload your saved config file to the pico that sio setup for mqtt.
5 > Update the enviro/destinations/mqtt.py in Thonny with the following for extened logging.

from enviro import logging
from enviro.constants import UPLOAD_SUCCESS, UPLOAD_FAILED
from enviro.mqttsimple import MQTTClient
import ujson
import config

def log_destination():
  logging.info(f"> uploading cached readings to MQTT broker: {config.mqtt_broker_address}")

def upload_reading(reading):
  server = config.mqtt_broker_address
  username = config.mqtt_broker_username
  password = config.mqtt_broker_password
  nickname = reading["nickname"]

    # attempt to publish reading
    mqtt_client = MQTTClient(reading["uid"], server, user=username, password=password, keepalive=60)
    mqtt_client.publish(f"enviro/{nickname}", ujson.dumps(reading), retain=True)
  except Exception as exc:
    import sys, io
    buf = io.StringIO()
    sys.print_exception(exc, buf)
    logging.debug(f"  - an exception occurred when uploading.", buf.getvalue())


6 > Start main.py and then check the log file it fails

Hope that helps.

Thanks again - this was really helpful. The extended logging showed:

2022-12-14 15:10:36 [debug    /  89kB]   - an exception occurred when uploading. Traceback (most recent call last):
  File "enviro/destinations/mqtt.py", line 25, in upload_reading
  File "enviro/mqttsimple.py", line 69, in connect
OSError: -2

Line 69 is:

addr = socket.getaddrinfo(self.server, self.port)[0][-1]

I installed mqttsimple using upip to /Lib and compared simple.py with mqttsimple.py and they are similar but not identical. I replaced mqttsimple.py’s contents with simple.py’s contents and the failure occured on the same line:

addr = socket.getaddrinfo(self.server, self.port)[0][-1]

I appreciate the help in debugging, I’m really grateful; but not sure where to go next…

@hel as part of the Pimoroni crew, do you have any ideas where I might troubleshoot further?


Sorry to hear you’re still having problems!

Please could you open up an issue on the Enviro repo so our software team can have a look? If you can include as much detail as you can about your issue (logs, a redacted config.py and some details about the http endpoint or MQTT broker you’re using?) that will help us try to figure out what’s going on.

I wonder if anyone has a uf2 file that is basic, so I can write code from scratch, rather than the pre-compiled files on the enviro with the Pimoroni firmware.

If you want an Enviro .uf2 without any of the built in Python scripts you can grab that from the releases page of the pimoroni-pico repo:

@warwickhw what mqtt server are using? Have you tested you can connect to it on the right port with the user credentials and ip address from the server it is running on?

yeah - i have tested (node-red btw) a pico writing to the same MQTT server and port… using both with and without a password required…

the fact this fails on http as well as MQTT and the socket error tells me this is not my endpoint *necessarily

If that is the case and you are using the latest software might be a hardware issue. Perhaps if you raise the issue on GitHub as @hel suggested perhaps they can offer some other things to try.