Как заставить приложение nrFToolbox for BLE использовать код Arduino, написанный с использованием библиотеки ArduinoBLE? - PullRequest
0 голосов
/ 29 февраля 2020

Для справки, я использую плату Arduino Nano 33 BLE Sense.

В данный момент я могу заставить приложение nrFToolbox распознавать плату как устройство Bluetooth, но это все. Я хотел бы иметь возможность использовать приложение, чтобы получить данные о температуре и отобразить ее.

#include <Arduino_LPS22HB.h> //Pressure sensor, documentation found on https://www.arduino.cc/en/Reference/ArduinoLPS22HB
#include <Arduino_HTS221.h>  //Temperature sensor, documentation found on https://www.arduino.cc/en/Reference/ArduinoHTS221
#include <ArduinoBLE.h>      //Bluetooth LE sensor, documentation found on https://www.arduino.cc/en/Reference/ArduinoBLE


// Service for the BLE module, using a 128-bit UUID.
BLEService TestService("32BC370F-88AF-4928-B8AB-9B56902FA670");

//TODO: BLE temperature characteristic

//TODO: BLE humidity characteristic

//TODO: BLE pressure characteristic

void setup() {
// put your setup code here, to run once:
    Serial.begin(9600); //Initialize the serial connection
    while(!Serial); //Will pause until a serial connection is established.

    if (!BARO.begin() ) { //Initialize the barometer
    Serial.println("Unable to initialize the barometer, stopping.");
    while (1);
    }
    if (!HTS.begin() ) { //Initialize the Temperature & Humidity sensor
        Serial.println("Unable to initialize the temp/humidity sensor, stopping.");
        while (1);
    }
    if (!BLE.begin() ) { //Initialize the bluetooth module
        Serial.println("Unable to initialize the bluetooth module, stopping");
        while (1);
    }


    /* Set a local name for the BLE device
    This name will appear in advertising packets
    and can be used by remote devices to identify this BLE device
    The name can be changed but maybe be truncated based on space left in advertisement packet
    */
    BLE.setLocalName("TestDevice");
    BLE.setAdvertisedService(TestService); // add the service UUID



}

void loop() {
// put your main code here, to run repeatedly:
    Serial.print("Temperature: ");
    Serial.print(HTS.readTemperature(FAHRENHEIT));
    Serial.print(" -- Humidity: ");
    Serial.print(HTS.readHumidity() );
    Serial.print(" -- Pressure: ");
    Serial.println(BARO.readPressure() );
    delay(1000);
}
...