# Pico Enviro+ Urban upload error

**URL:** <https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933>\
**Category:** Support\
**Created:** [December 9, 2022, 5:28pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933 "2022-12-09T17:28:38Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![warwickhw](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@warwickhw](https://forums.pimoroni.com/u/warwickhw)\
**Post date:** [December 9, 2022, 5:28pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/1 "2022-12-09T17:28:38Z")

</div>

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:

```auto
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?

```auto
> connecting to wifi network ' ****'
- ip address: 192.168.1.51
> uploading cached readings to url: http://192.168.1.26:1880/urban
- 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.

---

<div class="post-metadata">

**Author:** ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)\
**Post date:** [December 12, 2022, 9:06am UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/2 "2022-12-12T09:06:13Z")

</div>

Have you updated to the most recent firmware?

> **[Releases · pimoroni/enviro](https://github.com/pimoroni/enviro/releases)**
>
> Contribute to pimoroni/enviro development by creating an account on GitHub.

---

<div class="post-metadata">

**Author:** ![dave1979](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dave1979](https://forums.pimoroni.com/u/dave1979)\
**Post date:** [December 12, 2022, 10:27am UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/3 "2022-12-12T10:27:23Z")

</div>

Do you need a trailing slash for the URL if it is directory you are uploading to?  
`http://192.168.1.26:1880/urban/`

---

<div class="post-metadata">

**Author:** ![warwickhw](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@warwickhw](https://forums.pimoroni.com/u/warwickhw)\
**Post date:** [December 12, 2022, 10:52am UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/4 "2022-12-12T10:52:13Z")

</div>

Hi - yes. Version is 1.19.10

---

<div class="post-metadata">

**Author:** ![warwickhw](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@warwickhw](https://forums.pimoroni.com/u/warwickhw)\
**Post date:** [December 12, 2022, 11:04am UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/5 "2022-12-12T11:04:19Z")

</div>

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

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

```

thank you for getting this closer.

---

<div class="post-metadata">

**Author:** ![dave1979](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dave1979](https://forums.pimoroni.com/u/dave1979)\
**Post date:** [December 12, 2022, 12:52pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/6 "2022-12-12T12:52:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![warwickhw](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@warwickhw](https://forums.pimoroni.com/u/warwickhw)\
**Post date:** [December 12, 2022, 4:49pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/7 "2022-12-12T16:49:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dave1979](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dave1979](https://forums.pimoroni.com/u/dave1979)\
**Post date:** [December 12, 2022, 5:00pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/8 "2022-12-12T17:00:10Z")

</div>

Here you go @warwickhw

```auto
# 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

```

---

<div class="post-metadata">

**Author:** ![warwickhw](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@warwickhw](https://forums.pimoroni.com/u/warwickhw)\
**Post date:** [December 13, 2022, 9:24am UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/9 "2022-12-13T09:24:52Z")

</div>

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

```auto
! 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.

---

<div class="post-metadata">

**Author:** ![dave1979](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dave1979](https://forums.pimoroni.com/u/dave1979)\
**Post date:** [December 13, 2022, 9:59am UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/10 "2022-12-13T09:59:33Z")

</div>

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](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.

```auto
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"]

  try:
    # attempt to publish reading
    mqtt_client = MQTTClient(reading["uid"], server, user=username, password=password, keepalive=60)
    mqtt_client.connect()
    mqtt_client.publish(f"enviro/{nickname}", ujson.dumps(reading), retain=True)
    mqtt_client.disconnect()
    return UPLOAD_SUCCESS
  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())

  return UPLOAD_FAILED

```

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

Hope that helps.

---

<div class="post-metadata">

**Author:** ![warwickhw](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@warwickhw](https://forums.pimoroni.com/u/warwickhw)\
**Post date:** [December 14, 2022, 3:43pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/11 "2022-12-14T15:43:42Z")

</div>

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

```auto
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:

```auto
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:

```auto
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?

TIA

---

<div class="post-metadata">

**Author:** ![hel](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/hel/32/6075_2.png) [@hel](https://forums.pimoroni.com/u/hel)\
**Post date:** [December 14, 2022, 4:30pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/12 "2022-12-14T16:30:31Z")

</div>

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.

> **[Issues · pimoroni/enviro](https://github.com/pimoroni/enviro/issues)**
>
> Contribute to pimoroni/enviro development by creating an account on GitHub.

> 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:

> **[Releases · pimoroni/pimoroni-pico](https://github.com/pimoroni/pimoroni-pico/releases)**
>
> Libraries and examples to support Pimoroni Pico add-ons in C++ and MicroPython. - pimoroni/pimoroni-pico

---

<div class="post-metadata">

**Author:** ![dave1979](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dave1979](https://forums.pimoroni.com/u/dave1979)\
**Post date:** [December 14, 2022, 4:47pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/13 "2022-12-14T16:47:56Z")

</div>

@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?

---

<div class="post-metadata">

**Author:** ![warwickhw](https://avatars.discourse-cdn.com/v4/letter/w/f9ae1b/32.png) [@warwickhw](https://forums.pimoroni.com/u/warwickhw)\
**Post date:** [December 15, 2022, 2:34pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/14 "2022-12-15T14:34:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dave1979](https://avatars.discourse-cdn.com/v4/letter/d/e274bd/32.png) [@dave1979](https://forums.pimoroni.com/u/dave1979)\
**Post date:** [December 15, 2022, 5:21pm UTC](https://forums.pimoroni.com/t/pico-enviro-urban-upload-error/20933/15 "2022-12-15T17:21:20Z")

</div>

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.
