BLE_comunication #63
Labels
Hardware:Dev Board
Coral Dev Board issues
subtype:ubuntu/linux
type:docs-feature
Doc issues for new feature, or clarifications about functionality
Description
I want to utilize the wireless addon to establish a connection between my phone and the Coral Dev Board Micro. However, the Bluetooth examples provided are insufficient for comprehending its functionality. Upon inspecting the library folder, it appears that there is no function available for sending and receiving data within the library, edgefast_bluetooth.h. I've got a code for the ESP32, which illustrates the functionality I intend to implement:
`#include <Wire.h> // Library for I2C
#include <SparkFunMLX90614.h> // SparkFunMLX90614 Library
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>
BLECharacteristic *characteristicTX; // This object is used to send data to the client
// Object responsible for communication with the infrared temperature sensor
IRTherm sensor;
bool deviceConnected = false; // Device connected control
const int LED = 2; // ESP32 internal LED (this pin may vary from board to board)
const int BUZZER = 23; // Buzzer pin
// See the following for generating UUIDs:
// https://www.uuidgenerator.net/
#define SERVICE_UUID "ab0828b1-198e-4351-b779-901fa0e0371e" // UART service UUID
#define CHARACTERISTIC_UUID_RX "4ac8a682-9736-4e5d-932b-e9b31405049c"
#define CHARACTERISTIC_UUID_TX "0972EF8C-7613-4075-AD52-756F33D4DA91"
// Callback to receive device connection events
class ServerCallbacks: public BLEServerCallbacks {
void onConnect(BLEServer* pServer) {
deviceConnected = true;
};
};
// Callback for handling characteristics writes
class CharacteristicCallbacks: public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic characteristic) {
// Returns a pointer to the register containing the current characteristic value
std::string rxValue = characteristic->getValue();
// Check if there is data (length greater than zero)
if (rxValue.length() > 0) {
Serial.println("********");
Serial.print("Received Value: ");
};
void setup() {
Serial.begin(115200);
pinMode(LED, OUTPUT);
pinMode(BUZZER, OUTPUT);
// Create the BLE Device
BLEDevice::init("ESP32-BLE"); // Bluetooth device name
// Create the BLE Server
BLEServer *server = BLEDevice::createServer(); // Create a BLE server
server->setCallbacks(new ServerCallbacks()); // Set the server callback
// Create the BLE Service
BLEService *service = server->createService(SERVICE_UUID);
// Create a BLE Characteristic for data transmission
characteristicTX = service->createCharacteristic(
CHARACTERISTIC_UUID_TX,
BLECharacteristic::PROPERTY_NOTIFY
);
characteristicTX->addDescriptor(new BLE2902());
// Create a BLE Characteristic for data reception
BLECharacteristic *characteristic = service->createCharacteristic(
CHARACTERISTIC_UUID_RX,
BLECharacteristic::PROPERTY_WRITE
);
characteristic->setCallbacks(new CharacteristicCallbacks());
// Start the service
service->start();
// Start advertising (ESP32 discovery)
server->getAdvertising()->start();
// Initialize the infrared temperature sensor
sensor.begin();
// Select temperature in Celsius
sensor.setUnit(TEMP_C);// You can also use TEMP_F for Fahrenheit or TEMP_K for Kelvin
Serial.println("Waiting for a client connection to notify...");
}
void loop() {
// If a device is connected
if (deviceConnected) {
// Call the "read" method of the sensor to perform the temperature reading
// read will return 1 if it can perform the reading, or 0 otherwise
if (sensor.read())
{
// Retrieve the ambient temperature reading
float tempAmbiente = sensor.ambient();
// Retrieve the temperature reading of the object pointed to by the sensor
float tempObjeto = sensor.object();
/*
delay(1000);
}
delay(1000);
}`
Click to expand!
Issue Type
Feature Request, Documentation Feature Request
Operating System
Ubuntu
Coral Device
Dev Board Micro
Other Devices
No response
Programming Language
C++
Relevant Log Output
No response
The text was updated successfully, but these errors were encountered: