Controller Board Raspberry Pico W
This class implements the controller base class functionality by communicating directly with the actual hardware. This class is only to be employed in a MicroPython environment.
- class firmware.board_pico.BoardPico
Bases:
BoardBaseThis class implements the controller API using actual hardware calls to the Pico board via MicroPython. This is generally a thin class, whose role is mostly to just courier data back and forth once constructed.
- DEV_MODE_PIN = 14
The Pico pin controlling developer mode: jump pin GP14 over to GND
- ONE_WIRE_SENSOR_PIN = 28
The Pico pin where the DS18x20 sensors are wired
- active(active: bool) None
Sets the Wi-Fi chip and system active status. If active, it is ready to connect or create a network access point.
- Parameters:
active – The desired active mode, either True or False
- Returns:
Nothing
- config(key: str) str
Returns a single configuration variable for the given key, such as ‘ssid’
- Parameters:
key – The configuration key name
- connect(ssid: str, pw: str) None
Attempts to connect to the specified Wi-Fi network.
- Parameters:
ssid – The Wi-Fi network ssid (name)
pw – The Wi-Fi network password
- Returns:
Nothing
- create_watchdog(timeout_ms: int) None
If developer mode is active, nothing is done here. For normal operation, this will create the system watchdog. This watchdog must be fed regularly before the timeout is reached. if not fed, it will force the whole system to reboot. Note that this means if you intend to perform a sleep while the watchdog is active, you need to do it in a loop and regularly feed the watchdog to avoid a system reset.
- Parameters:
timeout_ms – The target interval, or timeout, between feedings.
- Returns:
Nothing
- developer_mode() bool
Returns whether the board is in developer mode. For this hardware board, the decision is based on the developer pin being jumped.
- Returns:
True or False whether the board is in developer mode
- ds18x20_convert_temp()
Asks all DS18x20 devices connected to the one-wire pin to refresh the latest temperature in their scratchpad.
Must be called before reading temperatures, and give at least 750 ms in between.
- Returns:
Nothing
- ds18x20_read_temp(rom: bytes) float
Reads the temperature from the specific DS18x20 ROM scratchpad.
- Parameters:
rom – The ROM for the sensor of interest, as bytes.
- Returns:
The temperature, in degrees Celsius.
- ds18x20_scan() list[bytes]
Performs a scan of one-wire DS18x20 connected to the board, returning sensor IDs
- Returns:
A list of ROMs connected to the device, each as a bytes variable.
- feed_watchdog() None
If developer mode is active, nothing is done here, because there is no watchdog on patrol. For normal operation, the watchdog is fed, resetting the timer back to zero.
- Returns:
Nothing
- get_ntp_timestamp() int | None
Attempts to read the current Linux timestamp from an NTP server (pool.ntp.org). The Linux timestamp is calculated based on the NTP response timestamp.
- Returns:
Returns the Linux timestamp (seconds since epoch) if successful, otherwise returns None
- http_get(url: str)
Attempts to dispatch an HTTP GET request to the specified URL using the urequests library.
- Parameters:
url – The url to request
- Returns:
A Response object, including status code and response data.
- http_put(url: str, headers: dict, json: dict)
Attempts to dispatch an HTTP PUT request to the specified URL using the urequests library, with given headers and JSON payload.
- Parameters:
url – The url to request
headers – Additional data, which could include branch name, data mime type, authentication, etc.
json – A dict payload to submit with the PUT request
- Returns:
A Response object, including status code and response data.
- ifconfig() tuple[str, str, str, str]
Returns ifconfig information
- Returns:
A tuple of network configuration: (IP, Subnet, Gateway, DNS)
- isconnected() bool
Returns whether the Wi-Fi system is connected to a network.
- Returns:
True or False if connected or not.
- load_json(json_readable_bytes) dict
Reads from the provided JSON bytes read-able object using the ujson library, and provides a Python dict.
- Parameters:
json_readable_bytes – A read-able object of JSON content bytes, such as a file opened with ‘rb’
- Returns:
A Python dict representing the JSON content
- localtime(linux_time_seconds: int = None)
Converts the provided Linux time, or the converted time if passed in, into a tuple of timestamp values.
- Parameters:
linux_time_seconds – Number of seconds since the Epoch; a Linux timestamp.
- Returns:
A tuple timestamp, with (year, month, day, hour, minute, second, weekday, year-day)
- print(message: str)
Prints the given message to the console, if connected, otherwise this just goes to sys.stdout, which will be a void USB serial device where the content is briefly buffered then vanishes.
- Parameters:
message – A string message to print.
- Returns:
Nothing
- rtc_datetime(timestamp: tuple[int, int, int, int, int, int, int, int]) None
Attempts to set the Pico’s Real Time Clock (RTC) to the specified timestamp.
- Parameters:
timestamp – A timestamp of (year, month, day, weekday, hour, minute, second, microsecond)
- Returns:
Nothing
- run_forever() bool
Returns whether this controller should actually run “forever”. For this Pico hardware board, the answer is yes, the sensing system should run continually.
- Returns:
True
- scan() list[tuple]
Scans for Wi-Fi networks, returning a list of network instances.
- Returns:
A list of network tuples, where each contains: (ssid, bssid, channel, RSSI, security, hidden)
- sleep(seconds: float)
Sleeps the system for the specified amount of time. The watchdog is fed throughout the time to ensure the system does not reboot.
- Parameters:
seconds – The floating point number of seconds to sleep.
- Returns:
Nothing
- system_hang(seconds: int = None)
Provides a single place for causing the system to “hang” for either an amount of seconds, or forever.
There are some scenarios where the system may need to hang for a few seconds, such as if an error pops up, and you want to hold the sensor for 30 seconds then let the machine reboot. That way the message may be seen on the sensor. In that case, call this with a positive integer number of seconds. The machine will hang that long, feeding the watchdog as needed to ensure the machine does not reboot during this hang.
There are some scenarios where the system may need to hang forever, such as if the sensor initialization fails immediately upon boot. In that case, call this with no argument, or None. The machine will hang forever, feeding the watchdog as needed to ensure the machine does not reboot automatically.
- Parameters:
seconds – Number of seconds to hang, or None to hang forever
- Returns:
Nothing
- ticks_diff(milliseconds_a: int, milliseconds_b: int) int
Calculates the difference between two ticks, including ring arithmetic to try to handle wrap-around scenarios.
- Parameters:
milliseconds_a – Higher of the two values returned from ticks_ms
milliseconds_b – Lower of the two values returned from ticks_ms
- Returns:
Effectively just milliseconds_a - milliseconds_b but attempts to handle wrap-around scenarios.
- ticks_ms() int
Returns an increasing millisecond counter, used for checking durations, not absolute time. It may overflow. Be sure to use ticks_diff to help support the condition of overflow.
- Returns:
An integer timestamp, milliseconds since some arbitrary but fixed time for a given boot.