Skip to content

Instantly share code, notes, and snippets.

@moonmile
Forked from ksasao/ContactTracingAppFinder.ino
Last active August 17, 2020 03:04
Show Gist options
  • Save moonmile/cccd82c52796249fd41529030094f263 to your computer and use it in GitHub Desktop.
Save moonmile/cccd82c52796249fd41529030094f263 to your computer and use it in GitHub Desktop.
接触確認アプリが有効になっているかを調べるアプリの M5Stack 版です。取得した ServiceData(RPI)を表示させています。https://twitter.com/ksasao/status/1274385507565178885 参照。Apache 2.0ライセンスです。
#include <M5Stack.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());
M5.Lcd.setCursor(0,80,2);
M5.Lcd.println("RSSI: ");
M5.Lcd.println(rssi);
M5.Lcd.println("ADDR: ");
M5.Lcd.println(advertisedDevice.getAddress().toString().c_str());
M5.Lcd.println("Service UUID: ");
M5.Lcd.println(advertisedDevice.getServiceUUID().toString().c_str());
M5.Lcd.println("Service Data: ");
M5.Lcd.println(toRPI(advertisedDevice.getServiceData().data()));
count++;
}
}
}
char *toRPI( const char *str ) {
static char buf[32+1] ;
static char hex[] = "0123456789ABCDEF";
for ( int i=0; i<16; i++ ) {
buf[i*2] = hex[(str[i] >> 2) & 0xF];
buf[i*2+1] = hex[str[i] & 0xF];
}
buf[32] = 0x00;
return buf;
}
};
void setup() {
Serial.begin(115200);
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