sockets - Bluetooth SPP (serial) glitchs (Android) -


I am running a curious problem I have developed an app that will install a Bluetooth SPP link with an RDIO. Bluetooth device on Arduino is configured on 9600 baud. I can get data from arduino, but I think there is something wrong with price 0 or higher peaks. It is very upset because I need exact value for the graphing part and I know that arduino sends good data That's because I send it to a file.

Why am I trying to fix or understand it instead of making an average or something similar instead of making it "patched"?

Thank you for your help.

Here is a picture that can explain my problem, arduino data is around 101 to 103:

And here is the code Where I create a connection and get the data:

  Private class connected thread extended threads {Private end data inputstream mm instream; Private end data output stream mmOutStream; Public ConnectedRed (BluetoothSocket Socket) {InputStream tmpIn = null; OutputStream tmpOut = null; // Receive input and output stream, use temp objects because try // member stream last {tmpIn = socket.getInputStream (); TmpOut = socket.getOutputStream (); } Grip (IOException E) {} mmInStream = New DataInputTream (TMPI); MmOutStream = New DataOutputTerm (tmpOut); } Public Zero run () {byte [] buffer = new byte [1024]; // buffer store for stream int byte; // Read bytes read (), keep listening to the I / InputStream until an exception occurs unless (true) read from {try {// InputStream bytes = mmInStream.read (buffer); // Receive the number of bytes and messages in "buffer" hBluetooth.ShareMessage (RECEIVE_MESSAGE, bytes, -1, buffer) .endToTarget (); // Send message queue handler} hold (IOE EXPRESS E) {break; }}} Private Zero Connect Device () {Bluetooth Device Devices = mBluetoothAdapter.getRemoteDevice (Address); Try {btSocket = createBluetoothSocket (Device); } Hold (IOE EXPRESS E) {errorExit ("Fatal error", "On Resumes () and failed to create socket:" + e.getMessage () + "."); } MblluetoothAdapter.cancelDiscovery (); // Establish the connection It will be blocked until it connects. Log D. (Tag, "... connecting ..."); Try {btSocket.connect (); Log D. (Tag, ".... connection is fine ..."); // Create a data stream so that we can talk to the server. Log D. (Tag, "... create socket ..."); MConnectedThread = New ConnectedStread (BTSket); MConnectedThread.start (); MActionBar.setSubtitle ("Connecta ©"); // If unsuccessful, we disconnect or display an error warning regarding the situation} hold (IOException e) {try {btSocket.close (); MActionBar.setSubtitle ("Deconnectà ©"); } {EO.exception E2} {errorExit ("fatal error", "unsafe") and unable to turn off the socket during connection failure "+ e2.getMessage () +". "); }} Return; }   

and finally handler:

  hBluetooth = new handler () {public zero handle message (android.os.Message msg) {switch (message What) {case RECEIVE_MESSAGE: // If we receive a message byte [] readBuf = (byte []) msg.obj; String string ink = new string (readBuf, 0, msg.arg1); Create string with // byte array string Builder.append (stringIncome); Int endOfLineIndex = stringBuilder.indexOf ("\ r \ n"); // Set the end-of-line if (Endless index & gt; 0) {// If we are in the end-of-line, then we've parsed all data sent to rmsgBluetooth = stringBuilder.substring (0, endOfLineIndex) I went; // string string object is extracted in rmsgBluetooth stringbuilder. Delete (0, stringbilder. Length); If (btSocket! = Null & amp; amp; amp; btSocket.isConnected ()) {// Here we send the value of the string to a txtbox txtArduino.setText ("Arduino:" + rmsgBluetooth); If (rmsgBluetooth.matches ("-? \\ d + (\\. \\ d +)?") {Try (sensor reading = float. Prsflot (RMSG bluetooth);} hold (NumberFormatException e) {}} < / Code>   

I think your error is most likely when string is parsed carefully Try debugging

  if (rmsgBluetooth.matches ("-? \\ d + (\\. \\ d +)?") {Try {sensor = float.parseFloat ( RmsgBluetooth);} hold (number formatting e) {}}    

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -