Raspberry Pi Battery Test

The following script was created to test the Raspberry Pi under a moderate system load.  This was done to simulate the process of scanning a network while maintaining a wireless connection with the Raspberry Pi to achieve realistic results of actual battery life with a Limeade 15,600mAh battery.  During this test the following was running simultaneously on the Raspberry Pi:

  • SSH session over an Ad-Hoc network running Arpspoof continuously
  • SSH session over an Ad-Hoc wireless connection running Wireshark in X-forwarding mode sitting idle
  • The following script running continuously that
    • Opened a log file and appended the time every loop
    • Ran tcpdump and captured 300 packets at a time and logged them to a separate file
    • Paused for 30 seconds

The total runtime for the Limeade battery was:  22 Hours and 51 Minutes. 

Please use the following script freely.

Battery Test Script

#!/usr/bin/env python2.7
# Script to run tcpdump and store the output to a log file and pause for 30 seconds
# This will simulate the process of being on network and logging packets
# A time stamp will be recorded to a separate log file to track the length of running time
# By: Brett A. Hansen
# http://bahansen.info

import time
import subprocess
from time import gmtime, strftime

def write_log(logline):
    logfile = open('battery_test.log', 'a')
    logfile.write(logline + '\n')

# Start logging to file
item = 'Battery Log: '
logfile = open('battery_test.log', 'w')
logfile.write(item + '\n')

# Write the Date & Time to the screen and logfile.  
# Log 300 packets with tcpdump & wait for 30 seconds
while True:
    logline = "RPI Still Up At : " + str(strftime("%Y-%m-%d %H:%M:%S", gmtime()))
    print "%s" % logline
    p = subprocess.Popen(["tcpdump", "-wtcpdump.log", "-c300", "-ieth0"], stderr=subprocess.PIPE)