var g_ = {lastResponse:""}; function OnStart() { app.ShowPopup("Service started"); g_.notify=app.CreateNotification(); //Check file SendRequest(); //Check again every 30 seconds g_.interval = setInterval(SendRequest,30000); } //Send an http get request. function SendRequest() { app.HttpRequest( "GET", "http://sgarman.net", "/downloadable.txt", "", HandleReply, "" ); } //Handle the server's reply function HandleReply( error, response ) { if( !error ) { if(g_.lastResponse !== response) { g_.lastResponse = response; g_.notify.SetMessage( response, "File contents", response ); g_.notify.Notify("servFilx"); } else console.log("same"); } else { app.ShowPopup( "Error: " + response ); } } //Called when we get a service message. function OnMessage( msg ) { //Show debug in WiFi IDE. console.log( msg ); //Handle messages from main App. if( msg=="quit" ) { clearInterval(g_.interval); console.log("loop stopped"); g_.notify.Cancel("servFilx"); } }