Particle Argon Uart Central

So I’ve been working on Uart Central example documentation found here https://docs.particle.io/tutorials/device-os/bluetooth-le/#uart-central

There are some questions I have about this,
what are

const BleUuid serviceUuid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
const BleUuid rxUuid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E");
const BleUuid txUuid("6E400003-B5A3-F393-E0A9-E50E24DCCA9E");

At the moment I have a UART peripheral sending data out every couple of minutes and I’m trying to turn my Particle Argon into a UART Central to read the data then Publish the data to google cloud.

I don’t have UUID of the UART Peripheral or any other info. Just the name of it.

While you could write a BLE scanner application for the Argon it’s probably easiest for you to use a mobile app like nRF Connect to scan and connect to your peripheral to investigate its exposed services and characteristics.

@ScruffR

I downloaded the app you recommended.

The following pictures are all the information I could get on the UART Peripheral I am trying to get data on.

Is it possible for me to read data from my Argon with this current information?

Have you tried hitting the Connect button top right on that screen?
Have you got some info about the type of that sensor? Or even better some datasheet?

I just connected and got its UUID!

const BleUuid serviceUuid("6E400001-B5A3-F393-E0A9-E50E24DCCA9E");
const BleUuid rxUuid("6E400002-B5A3-F393-E0A9-E50E24DCCA9E");
const BleUuid txUuid("6E400003-B5A3-F393-E0A9-E50E24DCCA9E");

Out of these 3 lines, which one do I apply the UUID that I just acquired?

That depends which UUID you got from the device.
I’d guess you ran with the first one you got, which is most likely the service UUID, but when you tap on that service you’ll probably see that service expanded revealing which characteristics this service provides and what UUIDs they have.

The information I get is the same as the example
https://docs.particle.io/tutorials/device-os/bluetooth-le/#uart-central
As seen in the above link

In the Example Code provided, I just want to do Particle.publish() the data I get from the BLE device.

OK, so what is the exact question?
You have all the data you need to connect to the peripheral and the code (as it already uses exactly these UUIDs). That should put you in a good spot to build ontop of.

Have you tried to understand what the BLE UART central code does and why?
When you haven’t yet, do (and maybe ask specific questions when you don’t quite understand some portions of the code).
Once you have, you will know where to grab the desired data and pass it on to a Particle.publish() call.

Our primary focus here is not to provide you with ready-meal solutions but enable you to find them for yourself.

1 Like

Okay, I’ve successfully connected to the device.

At the moment I am not sure what function to call to get the exact data from the Device I’m connected to.

I was thinking it would be scanResults[ii].advertisingData.data()
This function only returns the name of the device back.

My question is what function do I call to get the message / data from the device being sent out?
I should be able to convert it to a readable string on my own.

The data you are looking for is not in the advertising data.

But if you had a look at the USB Serial output of the example while the central is connected to the peripheral you could look for the Serial.write() statements that cause that output and hence trace back where the printed data was received.

It’s provided via the respective characteristic (aptly named peerTxCharacteristic - as the device transmits data to the central) and this characteristic hooks to a callback function that deals with the incoming data.

Yeah, thanks the data I was looking for wasn’t advertising data.

So I installed a Serial Port terminal called CoolTerm to see if my UART peripheral was properly sending data to my Particle Argon.

When the application CoolTerm writes a String in the Serial Log,
my Argon properly gets the data and does what it pleases with it.

However, when the UART peripheral sends over a message, it never triggers the Serial.available() function.
The CoolTerm Serial Log does show the data displayed here from the UART peripheral.

I’ll continue to do digging to see how exactly the UART peripheral sends over data.

char string[32];
    if (BLE.connected()) {
        while (Serial.available() && txLen < UART_TX_BUF_SIZE) 
        {
            delay(3);
            //read the data
            int availableBytes = Serial.available();
            for(int i=0; i<availableBytes; i++)
            {
             string[i] = Serial.read();
             string[i+1] = '\0'; // Append a null
            }

            txBuf[txLen++] = Serial.read();
            Serial.write(txBuf[txLen - 1]);
            Particle.publish("firebase_upload", string);
        }

       

        if (txLen > 0) 
        {
            // Transmit the data to the BLE peripheral
            peerRxCharacteristic.setValue(txBuf, txLen);
            txLen = 0;
        }
    }

Why would/should it?
Serial.available() will only tell you whether you sent data from CoolTerm to the Argon it has no bearing on the BLE data transfer whatsoever.

The data from the BLE peripheral will be caught by the peerTxCharacteristic (since the peripheral does the transmitting) and consequently the onDataReceived() (on the central from the peripheral) callback that’s hooked up to that characteristic.

Thank you!

void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) 
{
  char string[32];
  int i = 0;
    for (size_t ii = 0; ii < len; ii++) {
        delay(3);
       // Serial.write(data[ii]);
        string[i] = data[ii];
        string[i+1] = '\0'; // Append a null
        i++;
    }
    Particle.publish("firebase_upload", string);
}

It works!

1 Like

You should be able to write this a bit shorter like this tho’

void onDataReceived(const uint8_t* data, size_t len, const BlePeerDevice& peer, void* context) 
{
  char str[len+1];
  memcpy(str, data, len);
  str[len] = '\0';
  Particle.publish("firebase_upload", str, PRIVATE);
}
1 Like