|
Home
| PODdevices
| WebStringTemplates
| Java/J2EE
| Unix
| Torches
| Superannuation
|
| About
Us
|
|
Mobile Phone Controlled PODdevices™
|
by Matthew Ford 5st December 2010 (revised
21st November 2011)
© Forward Computing and
Control Pty. Ltd. Ltd. NSW Australia
All rights reserved.
Part 1 of the tutorial introduced PODdevices™ and the covered the specification of the operation discovery protocol. This part of the tutorial covers a reference implementation of a J2ME mobile phone Java application the supports the protocol. This application can be used to control any PODdevice™ that has a bluetooth/serial connection. This is what makes this mobile phone application so useful. It is the PODdevice™ that tells the phone what functionality is available. The phone then just displays the commands and lets you choose.
To use the PODapp, you need a suitable mobile phone. Your Mobile Phone needs that supports the Java JSR-82 Java Bluetooth API. My old phone did not so I purchased an inexpensive Samsung C3110. I used the website http://www.club-java.com/TastePhone/J2ME/MIDP_Benchmark.jsp to check if the phone would support Java JSR-82. Or you can just down load the PODapp™ and see if it runs.
The PODapp.jar (updated 14th Feb 2011 to V1.1.0) and PODapp.jad files are available for download. Right click on the links and choose Save Link As.. and save both these files to your hard drive and then transfer them to your phone. (See Loading Java Programs to your Phone)
When you run the program you should see a display something like this.
Once you have confirmed the PODapp™ runs on your phone, you need to set your own connection list. This is done by editing the PODapp.jad text file. First take a copy of the file in case your changes don't work.
The
last line is the only line you need to change
PODdevices:
001E3DEDBC88~PC,0|00066601E6A0~POD Led Controller
The PODdevices:
line is where you define the
bluetooth addresses and display names and timeouts for each PODdevice
you want to connect to. The format is
<bluetoothAddress>
[[ ~
<displayName> ]
[ , <charTimeOut>]]
[ | <bluetoothAddress>
[[ ~
<displayName> ]
[ , <charTimeOut>]]
]*
The [ ] indicate optional sections, [ ]*
means zero or more of these sections.
That is, one PODdevice™ connection must be defined and you can add as many others as you like each separated by the | character. Within each connection the display name and timeout are optional. If the displayName is omitted then the bluetooth address is displayed in the Connect To menu. If the character timeout is omitted, then the default of 10mS is used. Setting a character timeout of 0 means the connection never times out. This is useful for testing.
Looking at the current settings,
PODdevices:
002F3DFDBC77~PC,0|00176521F6A1~POD Led Controller
This
line defines two PODdevice™ connections separated by |
For the first connection the bluetooth address is 002F3DFDBC77 , you should change this to the bluetooth address of your laptop. Look in the Control Panel under Bluetooth Connection for your Device Address address. The screen shots below are from my Sony Vaio running Windows 2000. Your Bluetooth configuration screen may look different.
Don't enter the :'s just put in the 12 characters, shown below blanked out.
Following
the bluetooth address is the menu display name separated by ~
in this case just PC
Then comes the character timeout,
separated by , in
this case 0 which
means the connection never times out waiting for the start of message
or for the next character in a message.
The second connection is separated from the first by | and defines the bluetooth address of the POD Led Controller. You can read the bluetooth address off the label on the SparkFun's bluetooth module. This connection does not define a character timeout so the default of 10mS is used. This means the POD Led Controller must start to respond to a command within 5 x 10mS = 50mS and must send each message character within 10mS of sending the last one, otherwise the PODapp™ will assume the connection is broken and will disconnect.
The second last
line is the PODdebug: setting.
If this setting starts with y or
Y then the debug mode
is turned on and the PODapp™ will add a Msgs button
item which will display all the messages to and from the PODdevices.
When you have finished your debugging either delete this line or just
change it back to
PODdebug: no
Once you have edited the PODapp.jad file with your PC's bluetooth address, you can transfer the edited file to your phone and connect to your PC to test the PODapp. This lets you compose the messages your PODdevice™ will send to advertise its functionality and see what responses the PODapp™ will send when the user selects a menu item.
To connect to your PC, you can and should leave your PC bluetooth set to NOT be discoverable. This is your primary security protection. With this option un-ticked only devices that know your bluetooth address can request a connection.
Next
setup your Serial Bluetooth Connection. In my case this dialog is
accessed from the LocalServces tab.
Set
it to start up Automatically but do NOT secure it. This free version
of PODapp™ does not support secure connections. Security is
provided by having to know the exact address of the PODdevice™
in order to connect to it.
Clicking OK on the above dialog updates the Local Services Dialog below.
When I upgraded my notebook to a Windows 7 OS I found it was much simpler to connect via a USB serial Bluetooth card. This same method can also be used for connecting to Mac and Linux.
I used a Bluetooth to USB serial adapter from SparkFun, Bluetooth Modem - BlueDongle USB sku: WRL-08180 with a compatible miniB (5pin) USB cable (e.g. sku: CAB-00598). This card is based on the FTDI chip set. http://www.ftdichip.com/Drivers/VCP.htm provides Virtual Com Port (VCP) drivers for Windows, Mac and Linux. I used the Windows driver.
To install the drive, I unzip the CDM20814_WHQL_Certified.zip file to a directory and then plugged in the USB serial Bluetooth card. In the device manager (click on Start and type device manager in the search box) and look for a COM device with an ! mark. Right click on it and choose Update Driver software... and Browse to the directory where you unzipped the CDM20814_WHQL_Certified let Windows install the appropriate driver.
Go back to the Device Manager. It should now show you a COM port number for this device. Right click on the USB Serial COM device and choose Properties and the Port Settings tab and make sure the port speed is set to 115200 which is the default speed for this card.

Next Install the PC Terminal Emulator, as described below in order to configure the USB Serial Bluetooth card.
This assumes you are using a Windows PC. If you are using a Mac or Linux you will need to install similar terminal software to connect to the Serial port provided by the USB serial Bluetooth card.
To communicate with the PODapp™ via the bluetooth serial connection on your PC, you need a terminal emulator. I use TeraTerm (http://ttssh2.sourceforge.jp) but there are lots of other possibilities, including Hyperterminal
Open TeraTerm and start a new connection. Choose the COM port that matches your Bluetooth Serial Port.
Open
the Setup → Terminal dialog and tick Local Echo and set New-Line
Receive: to CR+LF. Local echo lets you see what you are typing and
Receive CR+LF makes the display more readable.
Open the Setup → Serial Port.. and check the Baud rate is set to 115200 (the default for this card).

The factory default settings suitable except for the BUAD rate which we will reduce from the default 115200 to 9600.
Start the PC terminal emulator and open a connection the Bluetooth Serial COM port. The baud rate at this point should be 115200. If not select Setup → Serial Port.. and set 115200 Baud rate (as above)
Type $$$ in the terminal to enter CMD mode and then type D and press the Enter key to display the current settings

Note the pin code 1234 and the BTA (Bluetooth Address) 00066601E8B2
Now set the Baud rate to
9600 by entering the command
SU,96
press the Enter key.
OPTIONAL: You can also
change the pin code to something else if you want to. For example to
change the pin code to 5678 using the command
SP,5678
press
the Enter key. (I left the code unchanged)
Then type
---
and press the Enter key to exit
the command mode.

Then close Terminal Emulator and unplug the USB Serial Bluetooth, wait 20sec and plug it in again. Go back to the Device Manager and select 9600 for the Com Port Settings. Then open the Terminal Emulator, connect to the USB Com port and set the Setup → Serial Port.. baud rate to 9600.
Typing $$$ should get you back into CMD mode but this time at 9600 baud. Type --- and press the Enter key to exit the command mode.
Finally if you are using the USB
Serial Bluetooth card, you need to update the podapp.jad file, as
described above, to replace the PC bluetooth address with the
bluetooth address for this card, e.g.
PODdevices:
00066601E8B2~PC,0|00066601E6A0~POD
Led Controller
You need to start TeraTerm before connecting from your mobile phone PODapp, because the PODapp™ sends the getMainMenu message, {.}, immediately after the connection is established. If TeraTerm is not already running and listening to the bluetooth COM port, then you will miss this message.
Start the PODapp™ on your mobile phone and connect to your PC.
The
TeraTerm window shows the {.} message from the PODapp.
The
PODapp™ expects the PODdevice™ to reply with its main
menu of functionality. Type in the Main Menu response. Actually it is
easier to type up the command in a text editor and then cut and paste
it to the TeraTerm window because TeraTerm sends every character you
type, immediately, including your typos.
The
PODapp™ will display
The next sections of this tutorial will cover defining the functionality of the POD Led Controller and coding it into micro-controller.
PODdevice™ and PODapp™ are trade marks of Forward Computing and Control Pty. Ltd.
Contact Forward Computing and Control by
©Copyright 1996-2012 Forward Computing and Control Pty. Ltd.
ACN 003 669 994