Primary Sensor Box Logic Class
This module contains the logic and classes for actually running the sensor boxes. The controller, screen, and configuration classes are abstracted out so that this code is not aware of whether it is running on an actual controller or with an emulated environment. This code can be imported from Python or MicroPython.
- class firmware.sensing.Sensor(rom: bytes)
Bases:
object
- class firmware.sensing.SensorBox(board: BoardBase, screen: ScreenBase, config: ConfigBase)
Bases:
object- enter_dev_mode() None
This function displays the developer screen as a signal (mostly a reminder) that the debug jumper is connected
- Returns:
Nothing
- phase_error(e: Exception) None
“Error” run phase, which is just the generalized error reporter, including a sleep to hold it on the screen.
- Returns:
Nothing
- phase_idle() None
“Idle” run phase, which is basically just sleep for a little while between sensing loops
- Returns:
Nothing
- phase_network() None
“Network” run phase which is basically just trying to connect to Wi-Fi again, and once connected, trying to sync time and do an http request for active sensor info.
- Returns:
Nothing
- phase_push(first_time: bool) None
“Push” run phase, which is basically waiting until connected and enough time has passed, then pushing data up to GitHub, and logging the time.
- Parameters:
first_time – If True, it forces an attempted GitHub push, regardless of time passed
- Returns:
Nothing
- phase_sensing() None
“Sensing” run phase which is basically just reading new temperatures and logging the current time
- Returns:
Nothing
- post() None
This functions performs the boot process, kind of mocking a POST step. There are some failure conditions which will cause the boot to hang indefinitely. There are also some conditions which will cause the boot to pause, then continue, leaving setup incomplete. Basic flow is: - Report the version and screen status. - Check connected sensor ROMs and make sure they can be properly initialized, if not then HANG FOREVER. - If not already connected to Wi-Fi, try to connect – this will only try for a few seconds before giving up. - Gather Wi-Fi details, but If still not connected, we can’t do anything else, so report no Wi-Fi and leave. - Try to sync the clock from the network – this will only try for a few seconds before giving up. - Try to get the sensor details from the centralized dashboard config file.
- Returns:
Nothing
- push_to_github() bool
This function is responsible for pushing updated temperature results to GitHub for all connected sensors. The content is a simple YAML file header with a few variables at the top and no body HTML content beneath —. The push is actually a “put” http action where it will live at the repo’s gh-pages branch at: /_posts/romHexAbc123Def/2026-02-24-10-30-02_romHexAbc123Def_Sensor_Name_Here.html. If any fail, it will return False, and the sensor box can alert that the last push failed. Also, if this keeps failing for any reason, the periodic sensor responsiveness check will alert us.
- Returns:
True if successful, False otherwise
- run() None
This function performs the “infinite” loop of actually running the sensor. Some of the logic is just like the post function, where it is continually checking what has been completed. This function is small to keep a clear and obvious understanding of what is required on a typical iteration. In summary, this has an infinite loop, where each loop performs sensing, network, GitHub, display, and idling. This function will trap all exceptions - keyboard interrupts lead to a graceful exit, all others will return. In development, this will result in a reset() call to reboot the pico and restart everything.
- Returns:
Nothing
- show_fatal_error(error: str) None
This function is responsible for issuing a fatal message to the user. This includes printing the message according to the board instance’s print capability, as well as attempting to break up the message and display it on the screen.
- Parameters:
error – Error message
- Returns:
Nothing
- try_to_connect_to_wifi() None
This function tries to connect the device to Wi-Fi. It first resets the known ssid/ip, loops over known Wi-Fi data, connects up to a given timeout interval, and either succeeds or ultimately just gives up and leaves it disconnected.
- Returns:
Nothing
- try_to_get_sensor_details() None
This function is responsible for trying to download and parse the sensor configuration from the centralized JSON config on the dashboard repo. The config file should be a static URL so that we don’t have to get back on the sensor box code to update the location. The function is pretty standard - just go to the prescribed URL, parse the JSON sensor data, and then update the local array of Sensor information.
- Returns:
Nothing
- try_to_sync_time() None
This function tries to synchronize the clock (RTC) using an NTP server response. The UDP packet is prepared, sent, the response is parsed into a Unix time, and stored back on the board clock. If any failures arise, this function just returns, leaving the time un-synchronized, so that it will try again.
- Returns:
Nothing
- update_display() None
This function does a normal update of the screen, gathering data and presenting on whatever screen is registered
- Returns:
Nothing
- update_temperatures() None
This function is responsible for updating the sensed temperature values on all connected sensors. The process is pretty simple, just call to convert_temp on the sensors, which resets the sensor scratchpad, sends a signal to read “all” sensors, and then actually converts the live reading from the sensor into a meaningful temperature. This is why you need to call this with each pass, since that convert_temp call is actually what updates the temperatures on the sensor’s scratchpad. Once the temperature is there, we simply update the Sensor wrapper instance with the new temperature and move on.
- Returns:
Nothing