Hi all, I am new to this forum and leJOS. Well I am working on code which includes sending sensor data thru bluetooth on mobile phone.
As of now I am working on a prototype functionality code in which I am trying to send data(see in the code below) from leJOS NXT to mobile phone(J2ME). So far I am able to send the data from NXT to mobile phone using Bluetooth. However on mobile phone I am getting some extra values along with the required ones.
On connection NXT is able to send 1,2,3,4,5 integers successfully and the mobile phone is able to receive and display data(all the numbers sent by NXT) on the phone screen but the problem is instead of showing me the exact data received such as 1,2,3,4,5, it shows me 1,1,0,2,1,0,3,1,0,4,1,0,5 and then it ends after every required int there is not required number such as 1 , 0 please help me get rid this. I have already spent couple of sleepless nights on it and I don't know how many more..I will... I don't know if anyone has worked on sending data from NXT to mobile phone but any help in this direction will be valuable. Thanks in advance.
Below are the code snippets
=========================================
NXT Code-
=======
BTConnection btc = Bluetooth.waitForConnection();
DataInputStream dis = btc.openDataInputStream();
DataOutputStream dos = btc.openDataOutputStream();
try {
for (int i = 1; i <=5; i++) {
dos.write(i);
dos.flush();
Thread.sleep(1000);
}
} catch (Exception e) {
}
dis.close();
dos.close();
Thread.sleep(100);
btc.close();
LCD.clear();
}
}
======================================
Mobile code(J2ME) -
========
private void makeConnection(final String url) {
Thread t = new Thread() {
public void run() {
StreamConnection dataStr = null;
try {
dataStr = (StreamConnection) Connector.open(url);
InputStream in = dataStr.openInputStream();
OutputStream out = dataStr.openOutputStream();
while(true){
int k = in.readInt();
printAll("Reading Data Recieved " + k);
if (k == 5) {
printAll("Stop this thread loop.");
// printAll function displays msgs on mobile screen
break;
}
}
} catch (IOException e) {
} finally {
printAll("Blutetooth Stream Closed.");
if (Datastr != null) {
try {
Datastr.close();
} catch (IOException e) {
}
}
}
}
};
t.start();
}
=======================================
Once Again thanks in advance!!!
RoboRig
