4. M1 va M2 tugmalarini bosing!
Keyin quyida biriktirilgan gif-da ko'rsatilganidek, siz LEDni yoqishingiz va o'chirishingiz kerak.
Tugmani bosish asosida LEDni yoqish va o'chirish.
2-loyiha: Kirish
Ikkinchi loyiha uchun biz ESP32 BLE serverini yaratamiz va uni skanerlash va uning xizmatlari va xususiyatlarini ko'rish uchun smartfonimizdan foydalanamiz.
Ushbu loyihalarda biz foydalanadigan komponentlar quyida keltirilgan.
ESP32 ishlab chiqish kengashi
Micro-USB kabeli
Non taxtasi
a Android smartfon
Arduino IDE o'rnatilgan va o'rnatilgan noutbuk/kompyuter
2-loyiha: ESP32 BLE serveri
ESP32 BLE serveringizni smartfon bilan sinab ko'rish uchun quyidagi amallarni bajaring!
Smartfoningizga Nordic’dan “ nRF Connect for Mobile” ni o‘rnating .
Ilova iOS App Store va Android Google Play Marketda mavjud. U smartfoningiz bilan ESP32 BLE serverini skanerlash uchun ishlatiladi.
Eslatma: Bluetooth-ni yoqishni va birinchi loyihadagi kabi ESP32-ni ulashni unutmang.
Google Play do'konida Mobil uchun nRF Connect
2 . Arduino IDE-ni oching va Fayl > Misollar > ESP32 BLE Arduino > ga o‘ting.
BLE_server .
Fayl > Misollar > ESP32 BLE Arduino > BLE_server
Quyidagi kod yuklangan yangi oyna ochilishi kerak.
#include
#include
#include
#define SERVICE_UUID "4fafc201-1fb5-459e-8fcc-c5c9c331914b"
#define CHARACTERISTIC_UUID "beb5483e-36e1-4688-b7f5-ea07361b26a8"
void setup() {
Serial.begin(115200);
Serial.println("Starting BLE work!");
BLEDevice::init("Long name works now");
BLEServer *pServer = BLEDevice::createServer();
BLEService *pService = pServer->createService(SERVICE_UUID);
BLECharacteristic *pCharacteristic = pService->createCharacteristic(
CHARACTERISTIC_UUID,
BLECharacteristic::PROPERTY_READ |
BLECharacteristic::PROPERTY_WRITE
);
pCharacteristic->setValue("Hello World says Michelle");
pService->start();
// BLEAdvertising *pAdvertising = pServer->getAdvertising(); // this still is working for backward compatibility
BLEAdvertising *pAdvertising = BLEDevice::getAdvertising();
pAdvertising->addServiceUUID(SERVICE_UUID);
pAdvertising->setScanResponse(true);
pAdvertising->setMinPreferred(0x06); // functions that help with iPhone connections issue
pAdvertising->setMinPreferred(0x12);
BLEDevice::startAdvertising();
Serial.println("Characteristic defined! Now you can read it in your phone!");
}
void loop() {
// put your main code here, to run repeatedly:
delay(2000);
}
Kod tushuntirishi: BLE imkoniyatlari uchun kerakli kutubxonalarni import qilish bilan boshlanadi. Keyin u xizmat va xarakteristikalar uchun UUIDni belgilaydi. O'rnatishda ( ) 115200 uzatish tezligida ketma-ket aloqani boshlaydi, BLE qurilmasini yaratadi va BLE qurilmasini server sifatida o'rnatadi. Shundan so'ng siz BLE serveri uchun avval belgilangan UUID bilan xizmat yaratasiz. Keyin, ushbu xizmat uchun xarakteristikani o'rnating. Shundan so'ng, uning qiymatini setValue ( ) usuli bilan o'rnating. Va nihoyat, siz xizmatni va reklamani boshlashingiz mumkin, shuning uchun boshqa BLE qurilmalari ushbu BLE qurilmasini skanerlashi va topishi mumkin.
Dostları ilə paylaş: |