pimoroni / enviro

MIT License
101 stars 79 forks source link

Enviro Urban wifi connection is failed #80

Open DatCodeWork opened 1 year ago

DatCodeWork commented 1 year ago

Hi Everyone,

I just flashed the new firmware "enviro-v0.0.8.uf2" to my Enviro Urban and the wifi connection has some issues.

When I connected it to my pc and used Thonny to run main.py, it had never successfully connected to my wifi. When I used an external battery to power it, it connected to the wifi, sent data successfully, then the light turned red. I checked the log and I saw the connection to my wifi failed again. However, it just connected successfully 20 seconds before that.

Also, my Enviro Urban is new, it just came today. With the older firmware that come with the board, I dont see this behavior. So I guess the new firmware causes it.

This is the log:

2000-01-01 00:00:02 [debug    / 115kB] > performing startup
2000-01-01 00:00:02 [info     / 127kB]   - wake reason: external_trigger
2000-01-01 00:00:02 [debug    / 125kB]   - turn on activity led
2000-01-01 00:00:02 [info     / 123kB] > clock not set, synchronise from ntp server
2000-01-01 00:00:02 [info     / 121kB] > connecting to wifi network '1102'
2000-01-01 00:00:04 [debug    / 115kB]   - connecting
2000-01-01 00:00:07 [debug    / 102kB]   - connecting
2000-01-01 00:00:09 [info     /  94kB]   - ip address:  192.168.0.44
2022-09-10 01:13:31 [info     /  91kB]   - rtc synched
2022-09-10 01:13:31 [debug    /  88kB]   - starting sensor
2022-09-10 01:13:31 [debug    / 126kB]   - wait 5 seconds for airflow
2022-09-10 01:13:36 [debug    / 107kB]   - taking pms5003i reading
2022-09-10 01:13:36 [info     / 117kB] > 2 cache files need uploading
2022-09-10 01:13:37 [info     / 115kB] > already connected to wifi
2022-09-10 01:13:37 [info     / 104kB]   - uploaded 2022-09-10T01:13:36Z.json to http
2022-09-10 01:13:38 [info     /  96kB]   - uploaded 2040-09-10T00:42:47Z.json to http
2022-09-10 01:13:38 [info     /  93kB] > going to sleep
2022-09-10 01:13:38 [debug    /  91kB]   - clearing and disabling timer and alarm
2022-09-10 01:13:38 [info     /  89kB]   - setting alarm to wake at 01:15am
2022-09-10 01:13:38 [info     / 110kB]   - shutting down
2022-09-10 01:13:46 [debug    / 115kB] > performing startup
2022-09-10 01:13:46 [info     / 127kB]   - wake reason: external_trigger
2022-09-10 01:13:46 [debug    / 125kB]   - turn on activity led
2022-09-10 01:13:46 [debug    / 122kB]   - starting sensor
2022-09-10 01:13:46 [debug    / 120kB]   - wait 5 seconds for airflow
2022-09-10 01:13:51 [debug    / 101kB]   - taking pms5003i reading
2022-09-10 01:13:52 [info     / 105kB] > 1 cache files need uploading
2022-09-10 01:13:52 [info     / 102kB] > connecting to wifi network '1102'
2022-09-10 01:13:54 [debug    /  96kB]   - connecting
2022-09-10 01:13:57 [debug    /  82kB]   - connecting
2022-09-10 01:14:24 [error    /  84kB] ! failed to connect to wireless network 1102
2022-09-10 01:14:24 [error    /  82kB] ! reading upload failed
2022-09-10 01:14:24 [info     / 128kB] > going to sleep
2022-09-10 01:14:24 [debug    / 125kB]   - clearing and disabling timer and alarm
2022-09-10 01:14:24 [info     / 123kB]   - setting alarm to wake at 01:15am
2022-09-10 01:14:24 [info     / 121kB]   - shutting down
2022-09-10 01:14:33 [debug    / 115kB] > performing startup
2022-09-10 01:14:33 [info     / 127kB]   - wake reason: external_trigger
2022-09-10 01:14:33 [debug    / 125kB]   - turn on activity led
2022-09-10 01:14:33 [debug    / 122kB]   - starting sensor
2022-09-10 01:14:33 [debug    / 120kB]   - wait 5 seconds for airflow
2022-09-10 01:14:38 [debug    / 101kB]   - taking pms5003i reading
2022-09-10 01:14:39 [info     / 104kB] > 2 cache files need uploading
2022-09-10 01:14:39 [info     / 102kB] > connecting to wifi network '1102'
2022-09-10 01:14:41 [debug    /  96kB]   - connecting
2022-09-10 01:14:44 [info     /  82kB]   - ip address:  192.168.0.44
2022-09-10 01:14:44 [info     / 117kB]   - uploaded 2022-09-10T01:13:52Z.json to http
2022-09-10 01:14:45 [info     / 109kB]   - uploaded 2022-09-10T01:14:39Z.json to http
2022-09-10 01:14:45 [info     / 107kB] > going to sleep
2022-09-10 01:14:45 [debug    / 105kB]   - clearing and disabling timer and alarm
2022-09-10 01:14:45 [info     / 103kB]   - setting alarm to wake at 01:15am
2022-09-10 01:14:45 [info     / 100kB]   - shutting down
2022-09-10 01:15:02 [debug    / 115kB] > performing startup
2022-09-10 01:15:02 [info     / 127kB]   - wake reason: external_trigger
2022-09-10 01:15:02 [debug    / 125kB]   - turn on activity led
2022-09-10 01:15:02 [debug    / 122kB]   - starting sensor
2022-09-10 01:15:02 [debug    / 120kB]   - wait 5 seconds for airflow
2022-09-10 01:15:07 [debug    / 101kB]   - taking pms5003i reading
2022-09-10 01:15:08 [info     / 105kB] > 1 cache files need uploading
2022-09-10 01:15:08 [info     / 103kB] > connecting to wifi network '1102'
2022-09-10 01:15:10 [debug    /  96kB]   - connecting
2022-09-10 01:15:13 [debug    /  82kB]   - connecting
2022-09-10 01:15:40 [error    /  84kB] ! failed to connect to wireless network 1102
2022-09-10 01:15:40 [error    /  82kB] ! reading upload failed
2022-09-10 01:15:40 [info     / 128kB] > going to sleep
2022-09-10 01:15:40 [debug    / 126kB]   - clearing and disabling timer and alarm
2022-09-10 01:15:40 [info     / 124kB]   - setting alarm to wake at 01:20am
2022-09-10 01:15:40 [info     / 121kB]   - shutting down
ZodiusInfuser commented 1 year ago

@DatCodeWork Thanks for reporting this. I have also encountered the issues with Thonny that you mention, and from my investigation it seems to be related to the addition of battery monitoring code.

Until I push a fix you could try commenting out the below section of code from enviro/__init__.py

old_state = Pin(WIFI_CS_PIN).value()
Pin(WIFI_CS_PIN, Pin.OUT, value=True)
sample_count = 10
battery_voltage = 0
for i in range(0, sample_count):
  battery_voltage += (ADC(29).read_u16() * 3.3 / 65535) * 3
battery_voltage /= sample_count
battery_voltage = round(battery_voltage, 3)
Pin(WIFI_CS_PIN).value(old_state)

Then add a line like battery_voltage = 0.0 so that later code still works