Pusu will report the motion several ways. Via SMS, MMS, Bluetooth. The simplest one is SMS so firstly we do SMS to report. With WMA, sending SMS in J2ME very simple. A generic MessageConnection opens the reporting way to connect the desired user about the situation. The receiving section comes with some obstacles. Since we want our Motion Detector controlled by simple SMS which is sent by an ordinary mobile phone message, the application should access the SMS messages targetted towards it. But an application running on the mobile phone is listenning to the messages which is specified to its port number. Unfortunately, at the time being we could not find a decent way to specify an SMS message which is not only defines the phone number but also the port number of the application. We will work on that matter. Now we explain the SMS reporting of the system.
WMA is supported through javax.microedition.messaging package, which includes the interfaces below:
Message: The basic interface for a message. Commonly needed methods are defined such as the ability to get or set the address associated with the message and to retrieve the timestamp of when the message was sent.
BinaryMessage: Extends the Message interface, allowing an application to extract the binary payload of the message.
TextMessage: Extends the Message interface, allowing an application to extract the ASCII payload of the message.
MessageConnection: Supports the functionary for sending and receiving messages based on the underlying protocol.
MessageListener: Allows classes that implement this interface to register with an instance of MessageConnection to be notified when a new message is received.
Sending SMS with WMA (Wireless Messaging API) is done as below code:
1: //destination is the user specified mobile phone number
2: // an example for destination = "+905335555555"
3: String addr = "sms://" + destination;
4: MessageConnection sender = null;
5: try {
6: try {
7: //connection creation
8: sender = (MessageConnection) Connector.open(addr);
9: //message creation
10: TextMessage msg = (TextMessage) sender.newMessage(MessageConnection.TEXT_MESSAGE);
11: //message is load
12: msg.setPayloadText(message);
13: //send it
14: sender.send(msg);
15: } finally {
16: sender.close();
17: }
18: } catch (Exception ex) {
19: //handle exception
20: }
No matter which protocol you are using, the messaging operations are nearly the same. There is a minor difference between SMS and CBS. SMS listens to a port where CBS listens to a channel.
Specific to Pusu, when the motion detection system detects a motion, the reporter class is invoked. Reporter class can have various implementations according to the user definition for reporting. The destination phone number is also defined by user. The message to be send is build by the application.
Originally posted in 2005.03.30 by Cahit Güngör - The Pusu Project Blog