Este tópico contém resposta, possui 2 vozes e foi atualizado pela última vez por  Rosana Guse 2 meses .

Visualizando 2 posts - 1 até 2 (de 2 do total)
  • Autor
    Posts
  • #92451

    Milton
    Participante

    Colegas, boa tarde! Estou começando a usar as funções de Bluetooth to ESP32 e estou tentando fazer algo bem simples, mas estou sem evoluir. Quero pegar a informação (“Hello World says Neil”) que é definida no pCharacteristic e mostrar na tela oled.

    Já tentei: display.drawString(0, 0, String pCharacteristic);, display.drawString(0, 0, pCharacteristic.toString()) e nada.

    Agradeço desde já!

    <span style=”font-size: 80%;”>#include <BLEDevice.h></span>
    <span style=”font-size: 80%;”>#include <BLEUtils.h></span>
    <span style=”font-size: 80%;”>#include <BLEServer.h></span>

    <span style=”font-size: 80%;”>#include <Wire.h></span>
    <span style=”font-size: 80%;”>#include <SSD1306Wire.h></span>

    <span style=”font-size: 80%;”>SSD1306Wire display(0x3C, 5, 4);</span>

    <span style=”font-size: 80%;”>// See the following for generating UUIDs:</span>
    <span style=”font-size: 80%;”>// https://www.uuidgenerator.net/</span>

    <span style=”font-size: 80%;”>#define SERVICE_UUID “4fafc201-1fb5-459e-8fcc-c5c9c331914b”</span>
    <span style=”font-size: 80%;”>#define CHARACTERISTIC_UUID “beb5483e-36e1-4688-b7f5-ea07361b26a8”</span>

    <span style=”font-size: 80%;”>void setup() {</span>
    <span style=”font-size: 80%;”>display.init();</span>
    <span style=”font-size: 80%;”>display.clear();</span>
    <span style=”font-size: 80%;”>display.flipScreenVertically();</span>

    <span style=”font-size: 80%;”>Serial.begin(115200);</span>
    <span style=”font-size: 80%;”>Serial.println(“Starting BLE work!”);</span>

    <span style=”font-size: 80%;”>BLEDevice::init(“ESP32”);</span>
    <span style=”font-size: 80%;”>BLEServer *pServer = BLEDevice::createServer();</span>
    <span style=”font-size: 80%;”>BLEService *pService = pServer->createService(SERVICE_UUID);</span>
    <span style=”font-size: 80%;”>BLECharacteristic *pCharacteristic = pService->createCharacteristic(</span>
    <span style=”font-size: 80%;”>CHARACTERISTIC_UUID,</span>
    <span style=”font-size: 80%;”>BLECharacteristic::PROPERTY_READ |</span>
    <span style=”font-size: 80%;”>BLECharacteristic::PROPERTY_WRITE</span>
    <span style=”font-size: 80%;”>);</span>

    <span style=”font-size: 80%;”>pCharacteristic->setValue(“Hello World says Neil”);</span>
    <span style=”font-size: 80%;”>pService->start();</span>
    <span style=”font-size: 80%;”>// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility</span>
    <span style=”font-size: 80%;”>BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();</span>
    <span style=”font-size: 80%;”>pAdvertising->addServiceUUID(SERVICE_UUID);</span>
    <span style=”font-size: 80%;”>pAdvertising->setScanResponse(true);</span>
    <span style=”font-size: 80%;”>pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue</span>
    <span style=”font-size: 80%;”>pAdvertising->setMinPreferred(0x12);</span>
    <span style=”font-size: 80%;”>BLEDevice::startAdvertising();</span>
    <span style=”font-size: 80%;”>Serial.println(“Characteristic defined! Now you can read it in your phone!”);</span>

    <span style=”text-decoration: underline;”><span style=”font-size: 80%;”>display.drawString(0, 0, String BLEDevice::getAdvertising());</span></span>
    <span style=”font-size: 80%;”>}</span>

    <span style=”font-size: 80%;”>void loop() {</span>
    <span style=”font-size: 80%;”>// put your main code here, to run repeatedly:</span>
    <span style=”font-size: 80%;”>delay(2000);</span>
    <span style=”font-size: 80%;”>}</span>

    0
    #96278

    Rosana Guse
    Moderador

    Olá Milton,

    Você já viu esse tutorial? https://www.filipeflop.com/blog/caca-aos-ovos-de-chocolate-com-esp32/

    Nele a função Bluetooth não é usada, mas você vai entender melhor o funcionamento da tela OLED

    Abraço!

    Rosana – Equipe FilipeFlop

     

    0
Visualizando 2 posts - 1 até 2 (de 2 do total)

Você deve fazer login para responder a este tópico.