Pictured above: the system as installed in New Zealand
As DIY electronics projects become more popular, the Raspberry Pi is proving its mettle in remote sensor platforms in orbit, at sea level, in backyards, and even underwater. With the introduction of the Pi4 in particular, machine learning at the edge has become significantly easier thanks to TensorFlow Lite and OpenCV support. At the same time, these devices need power, and in remote sensors placed in austere environments, power systems can be unreliable. While one can reduce power requirements, a Pi4 would drain a couple of good AA batteries in a couple of hours, even without any sensors or peripherals. A remote sensing system using a Pi, or another similar single-board computer (SBC), needs a way to adjust power consumption – taking into account available power and the sensing task at hand.
After tackling this problem for AISonobuoy, our smart buoy project, IQT Labs took on an added challenge: detecting poachers in a remote location. This use case had all the essential elements of the power management problem we hoped to investigate: operating a Pi-based sensor that draws power (in this case, a security camera), in an often wet and cold remote location with limited solar power, and with only cellular data available. Our main objective was to use the Pi SBC to process the video feed and send analytics back to a home base. Ideally, the camera should operate continuously. When batteries are low, however, the camera should capture footage only when it detects movement or follow an unpredictable capture schedule (so poachers cannot time their movements to sneak past the sleeping sensor). The system also needs to provide continuous wireless internet access to a remote rural residence.
These requirements require the system to have a robust and dynamic ability to manage its power requirements and prioritize activities. The top priority is remote internet access which should be the last to go when power is very low. The secondary priority should be operating the sensor system.
While the system operator has the option to replace batteries in the event of extended cloud cover (which involves a steep uphill hike through dense forest, where the physical fitness benefits may not outweigh the risks of running into poachers), battery replacement is not an option on a deployed buoy. Being able to recover and manage a system remotely after total loss of power is key to a resilient remote sensing system.
The existing Pi hardware and software universe met most of these needs – combined with an IP camera, industry-standard LiPo batteries, solar charging system, WiFi and 4G modems, and weatherproof enclosures. The missing piece was hardware that the Pi could use to control power loads (including its own power).
After reviewing our options, we decided the SleepyPi hat might be a practical solution. The hat contains an entire Arduino Uno with user-programmable firmware as well as software-controllable power outputs and sensors. The user can supply additional firmware connected to these sensors (e.g., battery voltage) to turn power on and off, or perhaps on a timed schedule using the hat’s battery-backed clock.
We created firmware for the hat and an accompanying Python-based systemd service, called sleepypid, that runs on the Pi. Sleepypid communicates with the hat over a serial port and monitors the battery voltage level and power consumption (in mA). This allows us to calculate State of Charge (SoC), an estimate of the battery capacity at a specific point in time. These variables are inputs to an algorithm (in Python, making it easy to update and unit test offline for correctness) which attempts to maximize sensor availability. If the battery is at 100% SoC and the sun is shining, the sensor runs continuously. If the SoC is less than 100%, then the algorithm schedules snooze periods which have durations proportional to the SoC value. The lower the SoC, the longer the snooze periods. In addition, the timing of the snooze period is randomized, so that even if a poacher knows the power limits of the system, they risk being spotted if the system wakes up mid-snooze.
When sleepypid decides to snooze, it sends a command to the hat to power down the Pi for a period calculated by the algorithm and executes a shutdown script. The hat sets an internal alarm clock, waits for the Pi to complete its full shutdown (by monitoring when current consumption drops, or after a timeout), and turns off the Pi’s power. When the snooze period elapses, the Pi will power on instantly. The hat also has watchdog features. If voltage drops below a failsafe threshold, the hat will power off the Pi and only power on again when the battery reaches a recovery level. The system also always wakes up at least once a day, even when the batteries are extremely low, allowing the operator to confirm it’s still operating.
Once the batteries reach a critical point where they cannot feasibly power on the Pi and its various sensors, the SleepyPi hat will continue to run, requiring only 1mA to remain up. This allows the system to withstand prolonged periods in between recharges while still keeping track of the SoC to bring the system back up, even weeks later.
Having been in operation for a few months, our system has endured stormy New Zealand weather and successfully spotted deer (a threat to NZ’s native forests), but also poachers hunting for deer. All the while, it has provided WiFi internet access to rural residents, managed its own power supply independently, and provided IQT Labs with periodic updates.
This system might not be in orbit, but the conditions it faces are also challenging. Accordingly, we believe the open-source power management system we developed could prove useful in a variety of other settings and remote sensing applications. With a flexible power input of 5.5-30 volts, it allows both big and small solar-powered systems and batteries to operate smoothly.
Stay tuned for another post where we’ll detail how we integrated this power management system into a buoy.