Prototype for 4-byte BLE communication

This commit is contained in:
Tempest 2024-11-04 21:14:20 +07:00
parent 703a3e0c38
commit b2e0851c77
2 changed files with 11 additions and 6 deletions

View File

@ -70,8 +70,8 @@ void setup() {
void loop() { void loop() {
// notify changed value // notify changed value
if (deviceConnected) { if (deviceConnected) {
btmessage = pCharacteristic->getValue().c_str(); btmessage = pCharacteristic->getData();
mode = btmessage; mode = btmessage;
} }
// disconnecting // disconnecting
if (!deviceConnected && oldDeviceConnected) { if (!deviceConnected && oldDeviceConnected) {

View File

@ -255,6 +255,7 @@ void dmxSetup() {
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
delay(2000);
Serial.print("\nIf you receive this message, ESP32 module has finished setting up Serial Interface for communication."); Serial.print("\nIf you receive this message, ESP32 module has finished setting up Serial Interface for communication.");
// Create the BLE Device // Create the BLE Device
BLEDevice::init("Pupilometer LED Billboard"); BLEDevice::init("Pupilometer LED Billboard");
@ -288,11 +289,10 @@ void setup() {
pAdvertising->setScanResponse(false); pAdvertising->setScanResponse(false);
pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter pAdvertising->setMinPreferred(0x0); // set value to 0x00 to not advertise this parameter
BLEDevice::startAdvertising(); BLEDevice::startAdvertising();
Serial.println("Waiting a client connection to notify..."); Serial.println("\nWaiting a client connection to notify...");
pinMode(INTERRUPT_PIN, INPUT_PULLUP); pinMode(INTERRUPT_PIN, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING); attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), isr, RISING);
delay(2000);
dmxSetup(); dmxSetup();
const dmx_port_t dmx_num = DMX_NUM_1; const dmx_port_t dmx_num = DMX_NUM_1;
Serial.println("Welcome to Pupilometer LED Billboard!"); Serial.println("Welcome to Pupilometer LED Billboard!");
@ -305,8 +305,13 @@ void loop() {
// notify changed value // notify changed value
if (deviceConnected) { if (deviceConnected) {
btmessage = pCharacteristic->getValue().c_str(); Serial.printf("\nI received the following string: %s",String(pCharacteristic->getValue()));
mode = btmessage.toInt(); Serial.printf("\nI received the following bytes: ");
uint8_t* btMessage = pCharacteristic->getData();
for (int i = 0; i < sizeof(btMessage); i++){
Serial.printf("%d ",btMessage[i]);
};
delay(100);
} }
// disconnecting // disconnecting
if (!deviceConnected && oldDeviceConnected) { if (!deviceConnected && oldDeviceConnected) {