# BLE didnt sent the right data from one argon board to the other argon board

**URL:** <https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362>\
**Category:** Troubleshooting\
**Tags:** argon, bluetooth\
**Created:** [July 25, 2019, 12:08am UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362 "2019-07-25T00:08:09Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![RuiyingWu](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@RuiyingWu](https://community.particle.io/u/RuiyingWu)\
**Post date:** [July 25, 2019, 12:08am UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/1 "2019-07-25T00:08:09Z")

</div>

Hi,

I want to set up a Bluetooth connection between two argon boards. I read some tutorials and wrote the code shown below based on two tutorials and the connection was set up. But the data read from the receiver is a strange number. So I would like to ask some questions about how to use BLE APIs to get the data based on my codes.

Here is my code for receiver:

```auto
const size_t SCAN_RESULT_MAX = 30;
const char * serviceUuid = "2baa45e8-1ecc-46b8-ac73-d716bd18696e";
const char * valueUuid = "8b9c77e1-54a4-41c5-bc70-7b5cd4c037cc";

BleCharacteristic valueCharacteristic;

BleScanResult scanResults[SCAN_RESULT_MAX];

BlePeerDevice peer;

void onDataReceived(const uint8_t* data, size_t len, const 
BlePeerDevice& peer, void* context);

void setup() {
    
    Serial.begin();
    
    valueCharacteristic.onDataReceived(onDataReceived, NULL);
    
}

void loop() {
    
    if (BLE.connected())
    {
        //we are currently connected to the board
        Serial.println("connected");
    }
    
    else 
    {
        //we are not connected to the board, scan for it.
        
        int count = BLE.scan(scanResults, SCAN_RESULT_MAX);

        for (int ii = 0; ii < count; ii++) 
        {
            uint8_t buf[BLE_MAX_ADV_DATA_LEN];
            size_t len;
            
            //we are looking for devices that have a the same uuid
            len = scanResults[ii].advertisingData.get(BleAdvertisingDataType::SERVICE_UUID_128BIT_COMPLETE, buf, BLE_MAX_ADV_DATA_LEN);
            
            if (len > 0) 
            {
                for (size_t jj = 0; jj < len; jj += 1)
                { // it should be uint128_t, but it was not able to be complied, so using uint64_t here
                    if(*(uint64_t *)buf[jj] == *serviceUuid) 
                    { 
                        // Found the right device 
                        peer = BLE.connect(scanResults[ii].address);
                        if (peer.connected()) 
                        {
                            Serial.println("successfully connected!");
                            //get the sensing data
                            valueCharacteristic = peer.getCharacteristicByUUID(BleUuid(valueUuid));
                            
                        }
                        else 
                        {
                            Serial.println("connection failed!");    
                        }
                        

                    }
                
                }
            }
        
        }
    }
}
void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) {
    uint16_t value;
    memcpy(&value, &data, sizeof(data));
    
    Serial.println("this is the value:");
    Serial.println(value);
}

```

Here is my code for transmitter:

```auto
const BleUuid serviceUuid("2baa45e8-1ecc-46b8-ac73-d716bd18696e");
const BleUuid valueUuid("8b9c77e1-54a4-41c5-bc70-7b5cd4c037cc");

BleCharacteristic *valueCharacteristic("value", BleCharacteristicProperty::NOTIFY, valueUuid, serviceUuid);

const unsigned long UPDATE_PERIOD_MS = 100;
unsigned long lastUpdate = 0;

void setup() {
  Serial.begin();
  
  // Advertising data
  BLE.addCharacteristic(valueCharacteristic);
  
  BleAdvertisingData advData;
  advData.appendServiceUUID(serviceUuid);
  // Start advertising!
  BLE.advertise(&advData);

}

typedef union {
    struct {
        float x;
        float y;
        float z;
    } sample;
    uint8_t bytes[12];
} Sample;

void loop() {
    if (BLE.connected()){
        if (millis() - lastUpdate >= UPDATE_PERIOD_MS) {
            lastUpdate = millis();
            
            Sample sample;
            sample.sample.x = 1;
            sample.sample.y = 1;
            sample.sample.z = 1;
            
            valueCharacteristic.setValue(sample.bytes, sizeof(Sample));
        }
        Serial.println("connected");
    }
    else{
        Serial.println("connecting");
    }
}

```

**Result:**  
In the transmitter code, I set the x, y z to be 1 respectively. But what the receiver printed out in onDataReceived() function is 41144.

**Question:**  
In the transmitter code, I have valueCharacteristic, and I have this line:

`valueCharacteristic.setValue(sample.bytes, sizeof(Sample));`

based on this webpage, [https://rickkas7.github.io/ble-imu/](https://rickkas7.github.io/ble-imu/)  
But I dont quite understand this line. I am not sure whether the data (x, y, z) needs to be assigned to valueCharacteristic which makes more sense than assigned with a buffer. Not sure why not assign x, y, z to the valueCharacteristic in the tutorial.

Then in the receiver code, I called onDataReceived() based on the tutorial in this link: [https://docs.particle.io/tutorials/device-os/bluetooth-le/#examples](https://docs.particle.io/tutorials/device-os/bluetooth-le/#examples)

But I am also not sure how to get the sensing data from it. I understand it is a callback function. I understand to use BLE.scan to check the match of Uuid. Then get the characteristic based on its Uuid once found the right service. Next, based on the tutorial, the data will be read from onDataReceived(). I am not sure the logic here. I thought the data should be read from the characteristic.

Secondly, I am not sure how to check the 128bit uuid, as it was not able to be compiled and I used uin64\_t instead.

And I am not sure why in the tutorial, the for loop shown below is used to check uuid. Not quite sure the meaning of checking buf[jj] for the serviceUuid. scanResults[ii] is the iith scaned service and buf[] stores its serviceUuid through  
`advertisingData.get(BleAdvertisingDataType::SERVICE_UUID_128BIT_COMPLETE, ....)`  
Not sure why needs for loop.

```auto
for (size_t jj = 0; jj < len; jj += 1)
                { // it should be uint128_t, but it was not able to be complied, so using uint64_t here
                    if(*(uint64_t *)buf[jj] == *serviceUuid) 
                    { 
                        // Found the right device 
...

```

Thank you for your time and help.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 25, 2019, 6:51am UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/2 "2019-07-25T06:51:35Z")

</div>

Your `uint16_t value` in `onDataReceived` _ **cannot** _ hold 12 bytes of data you try to catch.

> [@RuiyingWu](#):
>
> `valueCharacteristic.setValue(sample.bytes, sizeof(Sample));`  
> [...]  
> But I dont quite understand this line.

This line just hands a reference to the "block" of data you want to transmit (along with it's size - 3\*4 = 12 bytes) to the write characteristic for it to send it out.

> [@RuiyingWu](#):
>
> Not sure why not assign x, y, z to the valueCharacteristic in the tutorial.

Because the write characteristic doesn't _care_ what all the individual bytes are meant to be, _it_ just needs to know which bytes to push and how many of them.  
A byte buffer is the common denominator for _all_ collections of data.

> [@RuiyingWu](#):
>
> I am not sure the logic here. I thought the data should be read from the characteristic.

No, the BLE interface does that - the services and characteristics are just there to tell all kinds of datastreams and protocols apart.

> [@RuiyingWu](#):
>
> Not sure why needs for loop.  
> [...]  
> buf stores its serviceUuid through

Not quite, `buf[]` stores the `BleAdvertisingData` object which may consist of multiple parts.  
And the loop would allow you to iterate over individual bytes of the requested data.  
In case of the example you may get more than one `SERVICE_UUID_16BIT_COMPLETE` entries and in order to find the correct one you'd loop over the list in 2byte steps (hence `jj+=2` in the sample).  
But if you want to compare the 128bit UUID you _cannot_ just cast that to `uint64_t*` and expect it to compare correctly to a `const char*`.  
Your should rather use [`BleUuid`](https://docs.particle.io/reference/device-os/firmware/argon/#bleuuid). This class also provides the correct means to _compare_ two instances correctly (and if there should be more than _one_ you'd iterate via `jj+=16` - 128bit equals 16byte).

---

<div class="post-metadata">

**Author:** ![RuiyingWu](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@RuiyingWu](https://community.particle.io/u/RuiyingWu)\
**Post date:** [July 25, 2019, 3:11pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/4 "2019-07-25T15:11:05Z")

</div>

Thanks so much ScruffR!

I made some changes, but now even the connection doesnt work.

> Your `uint16_t value` in `onDataReceived`_ **cannot** _ hold 12 bytes of data you try to catch.

I changed to `const unsigned char*` as shown below:

```auto
void onDataReceived(const unsigned char* data, size_t len, const 
BlePeerDevice& peer, void* context);

```

Does this make sense?

> Not quite, `buf[]` stores the `BleAdvertisingData` object which may consist of multiple parts. And the loop would allow you to iterate over individual bytes of the requested data. In case of the example you may get more than one `SERVICE_UUID_16BIT_COMPLETE` entries and in order to find the correct one you’d loop over the list in 2byte steps (hence `jj+=2` in the sample). But if you want to compare the 128bit UUID you _cannot_ just cast that to `uint64_t*` and expect it to compare correctly to a `const char*` . Your should rather use [`BleUuid`](https://docs.particle.io/reference/device-os/firmware/argon/#bleuuid). This class also provides the correct means to _compare_ two instances correctly (and if there should be more than _one_ you’d iterate via `jj+=16` - 128bit equals 16byte).

I tried BleUuid, but seems wrongly used it as the connection was not set up.

```auto
if (len > 0) 
            {
                for (size_t jj = 0; jj < len; jj += 16)
                {
                    BleUuid receivedUuid(buf[jj]);
                    BleUuid serviceUuid(serviceUuid);
                    // if(*(uint64_t *)buf[jj] == *serviceUuid) 
                    if (receivedUuid == serviceUuid)
                    { 
                        // Found the right device
...

```

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 25, 2019, 3:18pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/5 "2019-07-25T15:18:42Z")

</div>

> [@RuiyingWu](#):
>
> I changed to `const unsigned char*` as shown below:
> 
> ```auto
> void onDataReceived(const unsigned char* data, size_t len, const 
> BlePeerDevice& peer, void* context);
> 
> ```

Actually no, the thing you changed was originally a `const uin8_t* data` but I explicitly said **`uint16_t value`**.  
You need to keep the callback signature unaltered but correct the implementation.

> [@RuiyingWu](#):
>
> ```cpp
> void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice & peer, void* context) { 
> uint16_t value; // <-- this one!!! this can only hold TWO bytes
> memcpy(&value, &data, sizeof(data)); // <-- sizeof(data) is wrong too, this should be len (once value fits the data and its length)
> 
> ```

Here you should have the _same_ struct that you already used in your transmitter in order to receive the _same_ data.

With regards to BleUuid, I rather meant something along this line (in your receiver code)

```cpp
// not this
// const char * serviceUuid = "2baa45e8-1ecc-46b8-ac73-d716bd18696e";
// const char * valueUuid = "8b9c77e1-54a4-41c5-bc70-7b5cd4c037cc";
// but
const BleUuid serviceUuid("2baa45e8-1ecc-46b8-ac73-d716bd18696e");
const BleUuid valueUuid("8b9c77e1-54a4-41c5-bc70-7b5cd4c037cc");
// as you have in your transmiter code
...
                    if(*(BleUuid *)&buf[jj] == serviceUuid) 

```

_(and don't forget to adjust the increment in your `for()` loop)_

---

<div class="post-metadata">

**Author:** ![RuiyingWu](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@RuiyingWu](https://community.particle.io/u/RuiyingWu)\
**Post date:** [July 25, 2019, 3:45pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/7 "2019-07-25T15:45:10Z")

</div>

Thanks ScruffR!

Unfortunately, after correcting the mistakes, the connection was still not built up.

Here is my updated code for receiver.

```auto
const size_t SCAN_RESULT_MAX = 30;

const BleUuid serviceUuid("2baa45e8-1ecc-46b8-ac73-d716bd18696e");
const BleUuid valueUuid("8b9c77e1-54a4-41c5-bc70-7b5cd4c037cc");

BleCharacteristic valueCharacteristic;
BleScanResult scanResults[SCAN_RESULT_MAX];
BlePeerDevice peer;

void onDataReceived(const uint8_t* data, size_t len, const 
BlePeerDevice& peer, void* context);

void setup() {
    
    Serial.begin();
    
    valueCharacteristic.onDataReceived(onDataReceived, NULL);
    
}

void loop() {
    Serial.println("verion 2");
    if (BLE.connected())
    {
        //we are currently connected to the board
        Serial.println("connected");
    }  
    else 
    {
        //we are not connected to the board, scan for it.
        int count = BLE.scan(scanResults, SCAN_RESULT_MAX);
        
        for (int ii = 0; ii < count; ii++) 
        {
            uint8_t buf[BLE_MAX_ADV_DATA_LEN];
            size_t len;
            
            //we are looking for devices that have a the same uuid
            len = scanResults[ii].advertisingData.get(BleAdvertisingDataType::SERVICE_UUID_128BIT_COMPLETE, buf, BLE_MAX_ADV_DATA_LEN);
            
            if (len > 0) 
            { //changed increment from 1 to 16
                for (size_t jj = 0; jj < len; jj += 16)
                {
                    if (*(BleUuid *)buf[jj] == serviceUuid) 
                    { 
                        // Found the device s1
                        peer = BLE.connect(scanResults[ii].address);
                        if (peer.connected()) 
                        {
                            Serial.println("successfully connected!");
                            //get the sensing data
                            // valueCharacteristic = peer.getCharacteristicByUUID(BleUuid(valueUuid));
                            valueCharacteristic = peer.getCharacteristicByUUID(valueUuid);
                        }
                        else 
                        {
                            Serial.println("connection failed!");    
                        }
                    }
                }
            }
        }
    }
}

void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) {
    //changed from uint16_t to uint8_t
    uint8_t value;
    memcpy(&value, &data, sizeof(data));
    
    Serial.println("this is the rate:");
    Serial.println(value);
}

```

Thank you for the help.

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [July 25, 2019, 5:14pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/8 "2019-07-25T17:14:37Z")

</div>

> [@RuiyingWu](#):
>
> Unfortunately, after correcting the mistakes, the connection was still not built up.

How are you building the code and then flashing to the device? Cloud building is not working right for BLE we have found out. Building locally and flashing locally via Workbench does work.

---

<div class="post-metadata">

**Author:** ![RuiyingWu](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@RuiyingWu](https://community.particle.io/u/RuiyingWu)\
**Post date:** [July 25, 2019, 5:27pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/9 "2019-07-25T17:27:49Z")

</div>

Thanks RWB!  
I am using web IDE now. I will try the workbench. But the code I originally posted was able to build up the BLE connection. Was that just an accident?

---

<div class="post-metadata">

**Author:** ![RWB](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/rwb/32/22599_2.png) [@RWB](https://community.particle.io/u/RWB)\
**Post date:** [July 25, 2019, 5:44pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/10 "2019-07-25T17:44:02Z")

</div>

Probably not an accident but we do know that new code dealing with BLE will not properly take effect if flashed over the air. For now it’s best to build and flash locally to avoid any potential issues as others have noticed recently.

---

<div class="post-metadata">

**Author:** ![RuiyingWu](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@RuiyingWu](https://community.particle.io/u/RuiyingWu)\
**Post date:** [July 25, 2019, 5:56pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/11 "2019-07-25T17:56:08Z")

</div>

Thanks RWB!

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 25, 2019, 8:10pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/12 "2019-07-25T20:10:39Z")

</div>

> [@RuiyingWu](#):
>
> ```cpp
> uint8_t value; 
> memcpy(&value, &data, sizeof(data));
> 
> ```

Now you can only store _ **one** _ byte and try to cram _four_ bytes (`sizeof(data )` will be 4 as `data` is a pointer and _not_ an array) into `value`.  
You want to store `len` (probably 12) bytes

> [@RuiyingWu](#):
>
> Unfortunately, after correcting the mistakes, the connection was still not built up.

When you want to debug such an issue you should add some more `Serial.print()` statements in as many strategically important places (e.g. all `else` cases) to get an idea what might be the cause - that's better than guessing it might be some issue _outside_ of your own reach.  
Only _ **after** _ you can be certain your code does everything right, you should assume an "outside" issue.

---

<div class="post-metadata">

**Author:** ![RuiyingWu](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@RuiyingWu](https://community.particle.io/u/RuiyingWu)\
**Post date:** [July 25, 2019, 8:44pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/13 "2019-07-25T20:44:04Z")

</div>

Thanks, ScruffR! I guess here is why you mentioned 12 bytes, which are in my transmitter code.

```auto
typedef union {
    struct {
        float x;
        float y;
        float z;
    } sample;
    // 12 bytes here
    uint8_t bytes[12];
} Sample;

void loop() {
    if (BLE.connected()){
        if (millis() - lastUpdate >= UPDATE_PERIOD_MS) {
            lastUpdate = millis();
            
            Sample sample;
            sample.sample.x = 1;
            sample.sample.y = 1;
            sample.sample.z = 1;
            
            valueCharacteristic.setValue(sample.bytes, sizeof(Sample));

```

Since `uint8_t bytes[12];`, does it make sense to have `uint8_t value;` in onDataReceived()?

Or 12 bytes (3\*4) means 4 bytes for each (x, y, z)?

By the way, thanks for the suggestion on adding serial.println(). I have that in my code but just to make the code in a post more readable, I deleted them before I posted.

I found the problem now is that the BLE connection cannot be set up which worked in my original posted code.

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [July 26, 2019, 7:06am UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/14 "2019-07-26T07:06:05Z")

</div>

> [@RuiyingWu](#):
>
> does it make sense to have `uint8_t value;` in onDataReceived()?

No it doesn't - `uint8_t value` this is _ **one single** _ byte while `uint8_t bytes[12]` are _ **twelve** _ and forcing 12 people on 1 chair won't work, cramming 12 bytes into a single one won't do either.

> [@RuiyingWu](#):
>
> ```cpp
> typedef union {
> struct {
> float x;
> float y;
> float z;
> } sample;
> // 12 bytes here
> uint8_t bytes[12];
> } Sample;
> 
> ```

When this is the data on the sending side why not use the _ **same** _ struct on the receiving side?

> [@RuiyingWu](#):
>
> I found the problem now is that the BLE connection cannot be set up which worked in my original posted code.

Yes, I gathered that, but _ **where** _ in code does it fail?

BTW, there was a minor mistake in my suggested equality check (corrected above)  
Instead of

```cpp
if(*(BleUuid *)buf[jj] == serviceUuid) 

```

it should have been

```cpp
if(*(BleUuid *)&buf[jj] == serviceUuid) 

```

* * *

I normally don't "spoon feed" solutions, but it took long enough to get here so this is working code _ **including** _ strategically well placed `Serial.print()` statements that would help understand _why_ things don't work out as they should.

```cpp
#define IS_RECEIVER 1 // set to 0 when you want to build the transmitter code

// common to receiver and transmitter 

SYSTEM_MODE(MANUAL)
SYSTEM_THREAD(ENABLED)

const BleUuid serviceUuid("2baa45e8-1ecc-46b8-ac73-d716bd18696e");
const BleUuid valueUuid("8b9c77e1-54a4-41c5-bc70-7b5cd4c037cc");
const size_t SCAN_RESULT_MAX = 30;
const uint32_t UPDATE_PERIOD_MS = 500;

typedef union {
  struct
  {
    float x;
    float y;
    float z;
  } coordinates;
  uint8_t bytes[12];
} Sample;
Sample sample;

#if (IS_RECEIVER) // receiver code

BleCharacteristic valueCharacteristic;
BleScanResult scanResults[SCAN_RESULT_MAX];
BlePeerDevice peer;

void onDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context);

void setup()
{
  Mesh.off();
  Serial.begin();
  valueCharacteristic.onDataReceived(onDataReceived, NULL);
}

void loop()
{
  static uint32_t msLastPrint = 0;
  if (millis() - msLastPrint < UPDATE_PERIOD_MS) return;
  msLastPrint = millis();

  if (BLE.connected())
    Serial.println("connected");
  else {
    int count = BLE.scan(scanResults, SCAN_RESULT_MAX);

    for (int ii = 0; ii < count; ii++) {
      uint8_t buf[BLE_MAX_ADV_DATA_LEN];
      size_t len;
      Serial.printlnf("%02x:%02x:%02x:%02x:%02x:%02x"
                     , scanResults[ii].address.addr[0]
                     , scanResults[ii].address.addr[1]
                     , scanResults[ii].address.addr[2]
                     , scanResults[ii].address.addr[3]
                     , scanResults[ii].address.addr[4]
                     , scanResults[ii].address.addr[5]
                     );

      len = scanResults[ii].advertisingData.get(BleAdvertisingDataType::SERVICE_UUID_128BIT_COMPLETE, buf, BLE_MAX_ADV_DATA_LEN);
      if (len > 0) {
        for (size_t jj = 0; jj < len; jj += 16)
        {
          if (*(BleUuid *)&buf[jj] == serviceUuid)
          {
            peer = BLE.connect(scanResults[ii].address);
            if (peer.connected()) {
              Serial.println("successfully connected!");
              valueCharacteristic = peer.getCharacteristicByUUID(BleUuid(valueUuid));
            }
            else {
              Serial.println("connection failed!");
            }
            break; // out of for(jj) loop
          }
          else {
            for (int u = 0; u < 16; u++)
              Serial.printlnf("%02x %c= %02x", ((BleUuid *)&buf[jj])->full()[u], ((BleUuid *)&buf[jj])->full()[u] == serviceUuid.full()[u] ? '=' : '!', serviceUuid.full()[u]);
            Serial.println("not the same UUID");
          }
        }
      }
      else {
        Serial.printlnf("len == %d", len);
      }
    }
  }
}

void onDataReceived(const uint8_t *data, size_t len, const BlePeerDevice &peer, void *context)
{
  memcpy(sample.bytes, data, len);
  Serial.printlnf("%.2f / %.2f / %.2f", sample.coordinates.x, sample.coordinates.y, sample.coordinates.z);
}

#else // transmitter code

BleCharacteristic valueCharacteristic("value", BleCharacteristicProperty::NOTIFY, valueUuid, serviceUuid);

void setup()
{
  Mesh.off();
  Serial.begin();
  BLE.addCharacteristic(valueCharacteristic);
  BleAdvertisingData advData;
  advData.appendServiceUUID(serviceUuid);
  BLE.advertise(&advData);
}

void loop()
{
  static uint32_t msLastUpdate = 0;
  if (BLE.connected()) {
    if (millis() - msLastUpdate >= UPDATE_PERIOD_MS) {
      msLastUpdate = millis();

      sample.coordinates.x = 1.1;
      sample.coordinates.y = 1.2;
      sample.coordinates.z = 1.3;

      valueCharacteristic.setValue(sample.bytes, sizeof(Sample));
      Serial.println("Data sent");
    }
  }
  else {
    Serial.println("Waiting for client to connect");
  }
}

#endif

```

However, there is some issue with your transmitter code (which I haven't looked into at all) that sends the transmitter into SOS+10 panic when you start the receiver after the transmitter.

---

<div class="post-metadata">

**Author:** ![RuiyingWu](https://avatars.discourse-cdn.com/v4/letter/r/ecae2f/32.png) [@RuiyingWu](https://community.particle.io/u/RuiyingWu)\
**Post date:** [July 26, 2019, 4:16pm UTC](https://community.particle.io/t/ble-didnt-sent-the-right-data-from-one-argon-board-to-the-other-argon-board/51362/15 "2019-07-26T16:16:58Z")

</div>

Thanks soooo much ScruffR! 🥰  
That is super nice of you! I have learned a lot by chatting with you! Thanks so much for kindly sharing your knowledge!
