-
-
Save YamadaKyohei/8df9f3f29f7bb047f1ea99595ac932fd to your computer and use it in GitHub Desktop.
@ksasaoさんのスケッチをM5StickC用に変更したもの。付近のCOCOAユーザ数をLCDに表示します。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <M5StickC.h> | |
#include <BLEDevice.h> | |
// Contact Tracing Bluetooth Specification (Apple/Google) | |
// https://blog.google/documents/58/Contact_Tracing_-_Bluetooth_Specification_v1.1_RYGZbKW.pdf | |
const char* uuid = "0000fd6f-0000-1000-8000-00805f9b34fb"; | |
unsigned int count = 0; | |
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks { | |
void onResult(BLEAdvertisedDevice advertisedDevice) { | |
if(advertisedDevice.haveServiceUUID()){ | |
if(strncmp(advertisedDevice.getServiceUUID().toString().c_str(),uuid, 36) == 0){ | |
int rssi = advertisedDevice.getRSSI(); | |
Serial.print("RSSI: "); | |
Serial.println(rssi); | |
Serial.print("ADDR: "); | |
Serial.println(advertisedDevice.getAddress().toString().c_str()); | |
count++; | |
} | |
} | |
} | |
}; | |
void setup() { | |
M5.begin(); | |
M5.Lcd.setRotation(1); | |
BLEDevice::init(""); | |
} | |
void loop(){ | |
count = 0; | |
BLEScan* pBLEScan = BLEDevice::getScan(); | |
pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); | |
pBLEScan->setActiveScan(true); | |
pBLEScan->start(1, false); | |
M5.Lcd.fillScreen(TFT_BLACK); | |
M5.Lcd.setCursor(20,12,6); | |
M5.Lcd.println(count); | |
M5.Lcd.setCursor(40,60,2); | |
M5.Lcd.println("COCOA users here"); | |
delay(2000); | |
M5.update(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment