Automatically starting btmon in Windows after reboot
Posted: Fri Jan 04, 2013 4:23 pm
Hi,
After some initial experimentation with my new GEM, btmon, and storing to MySQL and uploading to OpenEnergyMonitor using a laptop, I wanted to move btmon to our desktop computer which can be always on so btmon is always up and doing its thing. However, I wanted to have btmon automatically re-started anytime my desktop gets rebooted. My desktop is a Windows XP box and I thought I'd pass along what I did to get things working the way I wanted. I imagine there is a simpler solution but this is what seems to work for me until I get around to any fine tuning.
I created a ScheduledTask in Windows (Start->All Programs->Accessories->System Tools->ScheduledTasks) scheduled to run at boot time. I assigned the task to an account with Administrator privilege. Since, I presumed there would be no console window when the task started I used pythonw.exe to run the script whose name I changed to btmon.pyw. I also added python code to ignore MySQL warnings - no console. In the advanced properties for the scheduled task I specified the command line to run btmon w/ arguments. At this point in the process I discovered that after a boot I did not see pythonw running but I could execute the task just fine after I logged into an account. I finally discovered that btmon was being started before the MySQL service was ready for connections. So, I modified btmon in the Monitor class' run method where it calls p.setup() for each packet processor. I simply changed it so that if the setup caused an exception to sleep for 10 seconds and try again for that processor. That worked fine. I know this is a hack but until I come up with something better it seems to work.
Hope it helps
After some initial experimentation with my new GEM, btmon, and storing to MySQL and uploading to OpenEnergyMonitor using a laptop, I wanted to move btmon to our desktop computer which can be always on so btmon is always up and doing its thing. However, I wanted to have btmon automatically re-started anytime my desktop gets rebooted. My desktop is a Windows XP box and I thought I'd pass along what I did to get things working the way I wanted. I imagine there is a simpler solution but this is what seems to work for me until I get around to any fine tuning.
I created a ScheduledTask in Windows (Start->All Programs->Accessories->System Tools->ScheduledTasks) scheduled to run at boot time. I assigned the task to an account with Administrator privilege. Since, I presumed there would be no console window when the task started I used pythonw.exe to run the script whose name I changed to btmon.pyw. I also added python code to ignore MySQL warnings - no console. In the advanced properties for the scheduled task I specified the command line to run btmon w/ arguments. At this point in the process I discovered that after a boot I did not see pythonw running but I could execute the task just fine after I logged into an account. I finally discovered that btmon was being started before the MySQL service was ready for connections. So, I modified btmon in the Monitor class' run method where it calls p.setup() for each packet processor. I simply changed it so that if the setup caused an exception to sleep for 10 seconds and try again for that processor. That worked fine. I know this is a hack but until I come up with something better it seems to work.
Hope it helps