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.
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?
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.
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.
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.