• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

watchdog

 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
public class sender extends MIDlet
{
public TextMessage txtMessage = null;
public MessageConnection smsconn = null;

public void send() {
try {

//Set the message text.
txtMessage.setPayloadText("Alarm trigger");
//Send the message.
smsconn.send(txtMessage);
log("Message sending completed");

} catch (Exception e) {}
}

//To start the MIDlet
protected void startApp () throws MIDletStateChangeException
{
//Start the timer
log("timer started");
WatchdogTimer wd = new WatchdogTimer();
//After start, count towards 0, nokia12 reset after reached 0
wd.setTimeout(30 * 60); // 30 minutes

//Set the correct target address
String targetAddress = "sms://+0180555555:5678";//send a sms to +0180555555 using port 5678
String targetAddress1 = "sms://+0123456789:5678";//send a sms to +0123456789 using port 5678
String url = "sms://:5678";
int counter = 0;

log("Send SMS Program");
try {
while (counter <= 4) {
//Open the message connection.
smsconn = (MessageConnection)Connector.open(url);
//Creating a text message to be send.
txtMessage = (TextMessage)smsconn.newMessage(MessageConnection.TEXT_MESSAGE);
txtMessage.setAddress(targetAddress);
send();
txtMessage.setAddress(targetAddress1);
send();
smsconn.close();
log("Go to reply message");
//replyMessage();
Thread.sleep(30000);
++counter;
}
log("sent 5 times");
//use watchdog to restart if there is no action taken by owner!!!
} catch(Exception e) {/* handle error */ }
}

//A required method
public void destroyApp (boolean unconditional) throws MIDletStateChangeException
{
}

//A required method
public void pauseApp () {}

private void log(String msg) {
SerialPortLogger.getInstance().write(msg);
}
}


Hi.. I'm adding a watchdog into my program.. Above is the program codes that I have written to send a sms.. I need a watchdog to reset everything if there is no reply message by the user after sending 5 times.. so what code shall I add in after the line [log("sent 5 times")] in order to restart after the watchdog count down to 0 And in between of the program when it is running,I need to check whether there is any error with the program and are they running in the right order..I believed that I can use watchdog to do all theses right..but I'm not sure at which interval I must insert the watchdog to make sure the program is running ok
And can also tell me how to write the code or is there any website where it will provide me a clear understanding on how to implement watchdog into the program..thanks
 
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Tracy

We have a "CODE" tag, that can be created by clicking the CODE button,
which is located under the "Add Reply" button, along with URL, BOLD, etc. buttons

This tag will enable you to keep your formatting for your code, like indentation, and makes your code readable. The way your code is posted makes it difficult to read, and therefore, more difficult for us to help you.

Thanks

Mark
 
tracy teo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator



Sorry because I'm first time using it so not very sure. Is this the right way??
 
tracy teo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
so can you provide me some solution after reading my problem.. Thanks alot
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So do you want that loop to occur over and over again untill there is a response from the owner?

One thing you can do is pull out the loop into a seperate method, just to keep the method length smaller, and allow other methods to also use the loop, if needed.

Then in that original method you could have a while loop that checks to see if there was a response after the new method returns, if not then the while continues on to do the loop again.

Is that what you are looking for?

Mark
 
tracy teo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI For the solution that you have provided, is only part of it. I'm still not sure how to implement Watchdog into the source code

What I expected from the outcome:
When I start the program, the watchdog at the same time will start to down down 0..This is the code for starting the watchdog and setting the timeout value.




The maximum number of time I will send the sms to inform the owner is 5 times..After 5 times, if he still never reply the sms, Watchdog timeout will continue to count till 0 and restart the nokia12i. So what I wanted to know is that how to implement Watchdog into the source code? I'm still not very sure how to use Watchdog..Eg..you need to insert Watchdog halfway into your code to check whether the program is working properly right? But I'm not very sure like at where is the best place for you to insert the Watchdog into the code.. Do you get what I meant?
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

restart the nokia12i



Like restart the device. That's not a nice thing to do. Let alone, I don't think Java would let you do such a thing because of the Security.

Maybe I am getting confused as to what Watchdog is. I am thinking that it is the program that you are writing. Maybe it is a third party tool that you are using, that I am unfamiliar with.

Mark
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you mean this dormant Apache project?

Mark
 
tracy teo
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Morning.. Oh ok.. Is WATCHDOG API..It can be use to reboot the Nokia 12 module if the JAVA VM or IMlet fails to execute..Maybe I asked in the wrong way and make you ..Actually I read alots of materials regarding WATCHDOG API and also understand what they are used for but I'm not sure how to implement it into the program so if the IMlet fails to execute, the timeout value will count towards zero and the Nokia 12 module will reset. Therefore the watchdog timer must be placed in the application's main loop . This way it protects against Java VM and IMlet failures such as program deadlock. At the same time, have to set the timeout value at the start of the program. When the program start, the watchdog will start to count toward zero. When zero is reached, nokia 12 module will restart. Therefore what I'm supported to do is reset the timeout value after every run so it will not restart the nokia 12 and interrupt the program when it is running half way..

(1)The correct use of the watchdog timer requires that it be set using a feasible timeout value and refresged at the correct locations in the Java code.(2)Location of the watchdog timer in the code should be such that it ensures that the Nokaia 12 module restarts if the IMlet fails to d the tasks it was designed to do.

So do you have any solution for it? Thanks alot
 
Mark Spritzler
ranger
Posts: 17347
11
Mac IntelliJ IDE Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I still say it is a bad idea to restart the actual device regardless. I don't like that there is a product out there that allows that. That is bad news because it will allow viruses to be created to do evil things. Bad security and should not be allowed to work in a JVM.

Mark
reply
    Bookmark Topic Watch Topic
  • New Topic