From: Eloy P. <pe...@ch...> - 2012-07-26 01:21:31
|
On 07/25/2012 08:24 PM, Michelle Dupuis wrote: > I see that this would work to turn a device on/off, but how would I tell MH to run a perl file (eg: mycode.pl) on command? It's not that easy -- the code in mycode.pl is always executing (by the MH main loop). Only things like functions and variable initializations, or blocks enclosed by "# noloop=start" and "# noloop=stop" are not executed in the main loop. From a high-level point of view what happens is that MH "takes apart" your user code file and puts parts of it together with all the rest of the code that is executed during each pass through the main loop, and puts other parts of it in a section that gets executed just once. The typical user code development cycle goes like this: 1. Edit and save mycode.pl. 2. Use some way (telnet, web, etc.) to execute the command "reload code" so MH brings in the latest mycode.pl. 3. Somehow test the new code in mycode.pl. How to test depends on your code -- if it is time-triggered then you may need to "fake" the time in mycode.pl so the current time can trigger the event. For example, if your code needs to test for October 30th, and right now it is Jul. 25th, then change your code for testing purposes so it tests for Jul. 25th. If you are testing a voice command, then execute that voice command. And so on. 4. In your user code, use the print_log function to send debugging information to the log file. Then review the log file to see what your code is doing. Cheers, Eloy Paris.- |