#include <bluefruit.h>
BLEDfu bledfu;
BLEDis bledis;
BLEUart bleuart;
BLEBas blebas;
uint8_t ch;
void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println("Bluefruit52 BLEUART Example");
Serial.println("---------------------------\n");
Bluefruit.autoConnLed(true);
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.begin();
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
Bluefruit.setName("FettPool_Helmet");
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
bledfu.begin();
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.begin();
bleuart.begin();
blebas.begin();
blebas.write(100);;
startAdv();
Serial.println("Please use Adafruit's Bluefruit LE app to connect in UART mode");
Serial.println("Once connected, enter character(s) that you wish to send");
}
void startAdv(void)
{
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
Bluefruit.Advertising.addService(bleuart);
Bluefruit.ScanResponse.addName();
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244);
Bluefruit.Advertising.setFastTimeout(30);
Bluefruit.Advertising.start(0);
}
void loop()
{
while ( bleuart.available() )
{
ch = (uint8_t) bleuart.read();
Serial.println(ch);
}
}
void connect_callback(uint16_t conn_handle)
{
BLEConnection* connection = Bluefruit.Connection(conn_handle);
char central_name[32] = { 0 };
connection->getPeerName(central_name, sizeof(central_name));
Serial.print("Connected to ");
Serial.println(central_name);
}
void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
(void) conn_handle;
(void) reason;
Serial.println();
Serial.println("Disconnected");
}I don't mind sharing the blocks at all.
I have the svc UUID and the char UUID coded into a variable to make it easy. The end run on this project (after I get this portion working) is to add a second nRF52 and send data to it as well. But one step at a time.
As for the length limit, that isn't an issue now. To this unit, I am sending 0, 1, 2, or 3. That is it. Just a number. I am letting the nRF52 do all the work on what to do when it gets the number.
As you can see in the blocks, I have tried sending as an integer and as a string, just to see if I could see a difference. But neither resulted in any data being "received" by the nRF52. Let me qualify that. I know the app sent the data, and the data was received by the nRF52, it just did not got to a place I could see it.







The delay timer was an older version of the app. I don't need it now and will be deleting. But thank you for the link. I will look into it so I know the proper way if I do need it in the future.
Good news. I have partially accomplished what I wanted. Here are the blocks it took to make it work. I tore it down to pure basics so there was nothing else. Make it easy for those following behind me.
The only issue I am having is when I send an integer over (which is what I want), I get 4 integers. So if I want to send "3", I get 3,0,0,0. The upside is I was able to create an array and have the data sent into the array so i could access what I needed. The downside, I REALLY would like to know how to access those additional spots being sent. Part 2 of this project is connecting a 2nd nRF52 and sending 2 separate integers. So being able to access those additional spots would REALLY come in handy.

/*********************************************************************
based on the Adafruit bleuart.ino example
Used in conjunction with the MIT App Inventor 2 application.
This is the testing code. The MIT App will send a number, and this
will display that number on the serial monitor.
Please note: The MIT App sends 4 sets of data See comments below.
Currently I do not know how to send data to the other 3 postions
in the array from the MIT App, but I am working on it
There may be some extra code in this sketch that is not needed, however
I got the project functioning as this sketch is, and I do not want to
tempt fate.
*********************************************************************/
#include <bluefruit.h>
// BLE Service
BLEDfu bledfu; // Over The Air Device Firmware Update service
BLEDis bledis; // Device Information Service
BLEUart bleuart; // uart over ble
BLEBas blebas; // BAttery Service
uint8_t ch[4] = {0,0,0,0}; // creates 4 storage locations for the data from the MIT App
// The MIT App sends 4 blocks of integers. This separates the 4 blocks into usable sections.
// Each block gets it's own spot in the array so the sketch can access the data
void setup()
{
Serial.begin(115200);
while ( !Serial ) delay(10); // for nrf52840 with native usb
Serial.println("Bluefruit52 BLEUART Example");
Serial.println("---------------------------\n");
// Setup the BLE LED to be enabled on CONNECT
// Note: This is actually the default behaviour, but provided
// here in case you want to control this LED manually via PIN 19
Bluefruit.autoConnLed(true);
// Config the peripheral connection with maximum bandwidth
// more SRAM required by SoftDevice
// Note: All config***() function must be called before begin()
Bluefruit.configPrphBandwidth(BANDWIDTH_MAX);
Bluefruit.begin();
Bluefruit.setTxPower(4); // Check bluefruit.h for supported values
Bluefruit.setName("Bluefruit_nRF52");
Bluefruit.Periph.setConnectCallback(connect_callback);
Bluefruit.Periph.setDisconnectCallback(disconnect_callback);
// To be consistent OTA DFU should be added first if it exists
bledfu.begin();
// Configure and Start Device Information Service
bledis.setManufacturer("Adafruit Industries");
bledis.setModel("Bluefruit Feather52");
bledis.begin();
// Configure and Start BLE Uart Service
bleuart.begin();
// Start BLE Battery Service
blebas.begin();
blebas.write(100);
// Set up and start advertising
startAdv();
Serial.println("nRF52 is ready. Please activate MIT App and connect");
Serial.println("Data from MIT App will display here");
}
void startAdv(void)
{
// Advertising packet
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
Bluefruit.Advertising.addTxPower();
// Include bleuart 128-bit uuid
Bluefruit.Advertising.addService(bleuart);
// Secondary Scan Response packet (optional)
// Since there is no room for 'Name' in Advertising packet
Bluefruit.ScanResponse.addName();
/* Start Advertising
* - Enable auto advertising if disconnected
* - Interval: fast mode = 20 ms, slow mode = 152.5 ms
* - Timeout for fast mode is 30 seconds
* - Start(timeout) with timeout = 0 will advertise forever (until connected)
*
* For recommended advertising interval
* https://developer.apple.com/library/content/qa/qa1931/_index.html
*/
Bluefruit.Advertising.restartOnDisconnect(true);
Bluefruit.Advertising.setInterval(32, 244); // in unit of 0.625 ms
Bluefruit.Advertising.setFastTimeout(30); // number of seconds in fast mode
Bluefruit.Advertising.start(0); // 0 = Don't stop advertising after n seconds
}
void loop()
{
/*
* Whatever number is sent from the MIT App will display here in this format:
* Value - Array Position
* {value} - 0
* 0 - 1
* 0 - 2
* 0 - 3
* end of line
*
*/
while ( bleuart.available() )
{
Serial.println("Value - Array Position");
for (int x = 0; x < 4; x++) {
ch[x] = (uint8_t) bleuart.read();
Serial.print(ch[x]);
Serial.print(" - ");
Serial.println(x);
Serial.println("end of line");
Serial.println(" ");
}
}
}
// callback invoked when central connects
void connect_callback(uint16_t conn_handle)
{
// Get the reference to current connection
BLEConnection* connection = Bluefruit.Connection(conn_handle);
char central_name[32] = { 0 };
connection->getPeerName(central_name, sizeof(central_name));
Serial.print("Connected to ");
Serial.println(central_name);
}
/**
* Callback invoked when a connection is dropped
* @param conn_handle connection where this event happens
* @param reason is a BLE_HCI_STATUS_CODE which can be found in ble_hci.h
*/