This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF51822 BLE UART message control

Hi I'm an undergrade student in dongguk Univ. in South Korea.

I want to control the sending message and receiving message.

I use the android studio.

What do I do ?

Please tell me about that .

I use the Android-BLE-UART source code in GitHub/Nordic.

I think

  • Sending message part-

          	EditText editText = (EditText) findViewById(R.id.sendText);
          	String message = editText.getText().toString();
          	byte[] value;
      		try {
      			//send data to service
      			value = message.getBytes("UTF-8");
      			mService.writeRXCharacteristic(value);
      			//Update the log with time stamp
      			String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
      			listAdapter.add("["+currentDateTimeString+"] TX: "+ message);
             	 	messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
             	 	edtMessage.setText("");
      		} catch (UnsupportedEncodingException e) {
      			// TODO Auto-generated catch block
      			e.printStackTrace();
      		}
    
          }
      });
    
  • Receiving message part-

    if (action.equals(UartService.ACTION_DATA_AVAILABLE)) { // final byte[] tx = intent.getByteArrayExtra(UartService.EXTRA_DATA);

             final  byte[] txValue = intent.getByteArrayExtra(UartService.EXTRA_DATA);
    
    
              runOnUiThread(new Runnable() {
                   public void run() {
    
                       try {
                         String currentDateTimeString = DateFormat.getTimeInstance().format(new Date());
                           String text = new String(txValue,"UTF-8");
                                  	 	listAdapter.add("["+currentDateTimeString+"] : RX "+ text);
                      	 	messageListView.smoothScrollToPosition(listAdapter.getCount() - 1);
                       } catch (Exception e) {
                           Log.e(TAG, e.toString());
                       }
                   }
               });
    

I think that change this two part to control sending message and receiving message.

How to control the sending message and receiving message?

Please, Please, Please tell me about that.

I really want to answer this as fast as possible.