Moving to dotenv.
This commit is contained in:
@@ -1,34 +1,39 @@
|
|||||||
import machine
|
import machine
|
||||||
import network
|
import network
|
||||||
import wifi_config
|
|
||||||
import time
|
import time
|
||||||
|
import os
|
||||||
|
from dotenv import load_dotenv
|
||||||
|
|
||||||
'''
|
load_dotenv()
|
||||||
|
|
||||||
|
"""
|
||||||
pico_funcs: Helper functions for things the pico can do.
|
pico_funcs: Helper functions for things the pico can do.
|
||||||
'''
|
"""
|
||||||
|
|
||||||
|
|
||||||
def read_cpu_temp():
|
def read_cpu_temp():
|
||||||
"""
|
"""
|
||||||
If you print the value of the temperature value you are going to get an integer number between 0 and 65535.
|
If you print the value of the temperature value you are going to get an integer number between 0 and 65535.
|
||||||
So, we have to convert this value either to the Celsius degree scales.
|
So, we have to convert this value either to the Celsius degree scales.
|
||||||
|
|
||||||
The temperature sensor works by delivering a voltage to the ADC4 pin that is proportional to the temperature.
|
The temperature sensor works by delivering a voltage to the ADC4 pin that is proportional to the temperature.
|
||||||
From the datasheet, a temperature of 27 degrees Celsius delivers a voltage of 0.706 V.
|
From the datasheet, a temperature of 27 degrees Celsius delivers a voltage of 0.706 V.
|
||||||
With each additional degree the voltage reduces by 1.721 mV or 0.001721 V.
|
With each additional degree the voltage reduces by 1.721 mV or 0.001721 V.
|
||||||
The first step in converting the 16-bit temperature is to convert it back to volts, which is done based on the 3.3 V maximum voltage used by the Pico board.
|
The first step in converting the 16-bit temperature is to convert it back to volts, which is done based on the 3.3 V maximum voltage used by the Pico board.
|
||||||
ref: https://how2electronics.com/read-temperature-sensor-value-from-raspberry-pi-pico/
|
ref: https://how2electronics.com/read-temperature-sensor-value-from-raspberry-pi-pico/
|
||||||
"""
|
"""
|
||||||
cpu_temp_conversion_factor = 3.3 / 65535
|
cpu_temp_conversion_factor = 3.3 / 65535
|
||||||
cpu_temp_sensor = machine.ADC(4)
|
cpu_temp_sensor = machine.ADC(4)
|
||||||
reading = cpu_temp_sensor.read_u16() * cpu_temp_conversion_factor
|
reading = cpu_temp_sensor.read_u16() * cpu_temp_conversion_factor
|
||||||
temperature_c = 27 - (reading - 0.706) / 0.001721
|
temperature_c = 27 - (reading - 0.706) / 0.001721
|
||||||
temperature_f = temperature_c * 9/5. + 32.0
|
temperature_f = temperature_c * 9 / 5.0 + 32.0
|
||||||
return temperature_f
|
return temperature_f
|
||||||
|
|
||||||
|
|
||||||
def wlan_up(wlan):
|
def wlan_up(wlan):
|
||||||
wlan.active(True)
|
wlan.active(True)
|
||||||
wlan.connect(wifi_config.HOME_WIFI_SSID, wifi_config.HOME_WIFI_PWD)
|
wlan.connect(os.getenv("HOME_WIFI_SSID"), os.getenv("HOME_WIFI_PWD"))
|
||||||
|
|
||||||
# Wait for connect or fail
|
# Wait for connect or fail
|
||||||
max_wait = 10
|
max_wait = 10
|
||||||
while max_wait > 0:
|
while max_wait > 0:
|
||||||
@@ -39,13 +44,14 @@ def wlan_up(wlan):
|
|||||||
|
|
||||||
if max_wait == 0:
|
if max_wait == 0:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
ifconfig = wlan.ifconfig()
|
ifconfig = wlan.ifconfig()
|
||||||
return ifconfig
|
return ifconfig
|
||||||
|
|
||||||
|
|
||||||
def led_error_code(led, error_code: int):
|
def led_error_code(led, error_code: int):
|
||||||
"""Blink LED for a given error code (int). error code == number of times to blink"""
|
"""Blink LED for a given error code (int). error code == number of times to blink"""
|
||||||
|
|
||||||
# Run a quick 'start error code sequence'
|
# Run a quick 'start error code sequence'
|
||||||
# So we know when LED error sequence starts
|
# So we know when LED error sequence starts
|
||||||
start_sequence_counter = 0
|
start_sequence_counter = 0
|
||||||
@@ -55,7 +61,7 @@ def led_error_code(led, error_code: int):
|
|||||||
led.value(False)
|
led.value(False)
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
start_sequence_counter += 1
|
start_sequence_counter += 1
|
||||||
|
|
||||||
# Run real error code sequence
|
# Run real error code sequence
|
||||||
blink_counter = 0
|
blink_counter = 0
|
||||||
while blink_counter < error_code:
|
while blink_counter < error_code:
|
||||||
@@ -65,4 +71,5 @@ def led_error_code(led, error_code: int):
|
|||||||
led.value(False)
|
led.value(False)
|
||||||
blink_counter += 1
|
blink_counter += 1
|
||||||
# Make sure to turn off LED when this subroutine finished
|
# Make sure to turn off LED when this subroutine finished
|
||||||
led.value(False)
|
led.value(False)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user