M5StickC로 접촉 확인 앱의 동작을 확인(버튼으로 수신 범위 전환)
                                            
                                                
                                                
                                                
                                                
                                                
                                                 16530 단어  M5StickC
                    
참고로 한 정보
M5ATOM 스케치(미쿠민 P씨 htps : // 라고 해서 r. 코 m / k 사사오 )
htps : // 기 st. 기주 b. 이 m/k 사사오/0이다 6437d3 에어 c9b2dbd675b6
M5StickC 스케치( @coppercele 씨)
https://qiita.com/coppercele/items/fef9eacee05b752ed982#m5stickc 버전
버튼 관리 정보
htps : /// g-p. 코 m/레후 렌세/우노후 헷샤 l/M5S치ckC/Cぁs/부트/
 작동 중 화면
전원 온 상태(좁은 범위에서 검지. 자신의 스마트폰 앱만 확인하고 싶은 경우는 이쪽에서.)
 
A 버튼을 눌러 수신 범위를 전환한 상태(넓은 범위에서 감지)
 
※B 버튼을 누르면 좁은 범위로 돌아갑니다.
덧붙여서, 범위의 지정은 이하와 같았습니다.
・좁은 범위:RSSI(전파 강도)가 -40보다 강하다
· 넓은 범위: RSSI가 -90보다 강하다
 스케치
sketch_jul18c.ino#include <Arduino.h>
#include <M5StickC.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 4; // スキャンする時間(秒)
BLEScan* pBLEScan;
// 接触確認アプリのUUID
const char* uuid = "0000fd6f-0000-1000-8000-00805f9b34fb";
int deviceNum = 0; // アプリの数のカウンター
int rssiNum = -40; // RSSI(Received Signal Strength Indicator)電波強度の初期値(狭いエリア)
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
       if(advertisedDevice.haveServiceUUID()){
            if(strncmp(advertisedDevice.getServiceUUID().toString().c_str(),uuid, 36) == 0){ // 検出したUUIDが接触確認アプリのUUIDと同じとき
                int rssi = advertisedDevice.getRSSI();
                Serial.print("RSSI: ");
                Serial.println(rssi);
                Serial.print("ADDR: ");
                Serial.println(advertisedDevice.getAddress().toString().c_str());
                if(rssi > rssiNum){ // rssiNum の範囲内のとき
                  Serial.println("Found!");
                  deviceNum++; // カウンターに1加算
                }
            }
        }
    }
};
void drawScreen() {
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setTextSize(2);
    M5.Lcd.setCursor(0, 0);
    M5.Lcd.setTextColor(GREEN);
    if(rssiNum < -40){ // 広いエリアを受信したとき
      M5.Lcd.print("Area:wide\n");
    } else {
      M5.Lcd.print("Area:narrow\n");
    }
    M5.Lcd.setTextSize(7);
    M5.Lcd.setTextColor(WHITE);
    M5.Lcd.printf(" %2d",deviceNum); // カウンターを表示
    M5.Lcd.setTextSize(1);
    M5.Lcd.setCursor(0, M5.Lcd.height() - 10);
    M5.Lcd.printf("Bat:%4.1fV  ", M5.Axp.GetBatVoltage());
    M5.Lcd.printf("Charge:%5.1f\n", M5.Axp.GetBatCurrent());
}
void Task1(void *pvParameters) {
  // loop()に書くとBLEスキャン中M5.update()が実行されずボタンが取れないためマルチスレッド化されている
  while(1) {
    deviceNum = 0; // カウンターを初期化
    BLEScanResults foundDevices = pBLEScan->start(scanTime, false); // 指定した時間スキャンする
    Serial.print("Devices found: ");
    Serial.println(deviceNum);
    Serial.println("Scan done!");
    pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
    drawScreen(); // 画面に表示する
  }
}
void setup() {
  M5.begin();
  Serial.begin(115200);
  Serial.println("Scanning...");
  M5.Lcd.setRotation(1);
  M5.Axp.ScreenBreath(8);
  BLEDevice::init("");             // BLEモジュールの初期化
  pBLEScan = BLEDevice::getScan(); // スキャンオブジェクトを取得
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); // コールバック関数(アドバタイジング受信)
  pBLEScan->setActiveScan(false);  // active scan uses more power, but get results faster
  pBLEScan->setInterval(5000);     // スキャン間隔5秒
  pBLEScan->setWindow(4999);       // less or equal setInterval value
  xTaskCreatePinnedToCore(         // コア指定タスク作成
    Task1,
    "Task1", 
    4096, //スタックサイズ(Byte)
    NULL, 
    3,    //作成タスクの優先順位(0:低 - 25:高)
    NULL, 
    1     //利用するCPUコア(0-1)
  );
}
void loop() {
  M5.update();
  if ( M5.BtnA.wasPressed() ) { // Aボタン1回押し
      rssiNum = -90; // 広いエリア
  }
  if ( M5.BtnB.wasPressed() ) { // Bボタン1回押し
      rssiNum = -40; // 狭いエリア
  }
}
 소감
실제로 iPhone의 앱이 작동하는지 확인할 수있었습니다. 여러가지 조사하고 있는 동안에 BLE가 조금 가까이에 느껴지게 되었습니다. 가급적 가까이 가지 않도록 해 온 C 언어에도 익숙해져 온 것 같은 생각이 듭니다. (「->」라고 뭐든지!라든지 중얼거리면서…) M5StickC의 버튼의 사용법의 공부도 되었습니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(M5StickC로 접촉 확인 앱의 동작을 확인(버튼으로 수신 범위 전환)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/tranquility/items/ab8c80f9f975b840fab7
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
전원 온 상태(좁은 범위에서 검지. 자신의 스마트폰 앱만 확인하고 싶은 경우는 이쪽에서.)

A 버튼을 눌러 수신 범위를 전환한 상태(넓은 범위에서 감지)

※B 버튼을 누르면 좁은 범위로 돌아갑니다.
덧붙여서, 범위의 지정은 이하와 같았습니다.
・좁은 범위:RSSI(전파 강도)가 -40보다 강하다
· 넓은 범위: RSSI가 -90보다 강하다
스케치
sketch_jul18c.ino#include <Arduino.h>
#include <M5StickC.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 4; // スキャンする時間(秒)
BLEScan* pBLEScan;
// 接触確認アプリのUUID
const char* uuid = "0000fd6f-0000-1000-8000-00805f9b34fb";
int deviceNum = 0; // アプリの数のカウンター
int rssiNum = -40; // RSSI(Received Signal Strength Indicator)電波強度の初期値(狭いエリア)
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
       if(advertisedDevice.haveServiceUUID()){
            if(strncmp(advertisedDevice.getServiceUUID().toString().c_str(),uuid, 36) == 0){ // 検出したUUIDが接触確認アプリのUUIDと同じとき
                int rssi = advertisedDevice.getRSSI();
                Serial.print("RSSI: ");
                Serial.println(rssi);
                Serial.print("ADDR: ");
                Serial.println(advertisedDevice.getAddress().toString().c_str());
                if(rssi > rssiNum){ // rssiNum の範囲内のとき
                  Serial.println("Found!");
                  deviceNum++; // カウンターに1加算
                }
            }
        }
    }
};
void drawScreen() {
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setTextSize(2);
    M5.Lcd.setCursor(0, 0);
    M5.Lcd.setTextColor(GREEN);
    if(rssiNum < -40){ // 広いエリアを受信したとき
      M5.Lcd.print("Area:wide\n");
    } else {
      M5.Lcd.print("Area:narrow\n");
    }
    M5.Lcd.setTextSize(7);
    M5.Lcd.setTextColor(WHITE);
    M5.Lcd.printf(" %2d",deviceNum); // カウンターを表示
    M5.Lcd.setTextSize(1);
    M5.Lcd.setCursor(0, M5.Lcd.height() - 10);
    M5.Lcd.printf("Bat:%4.1fV  ", M5.Axp.GetBatVoltage());
    M5.Lcd.printf("Charge:%5.1f\n", M5.Axp.GetBatCurrent());
}
void Task1(void *pvParameters) {
  // loop()に書くとBLEスキャン中M5.update()が実行されずボタンが取れないためマルチスレッド化されている
  while(1) {
    deviceNum = 0; // カウンターを初期化
    BLEScanResults foundDevices = pBLEScan->start(scanTime, false); // 指定した時間スキャンする
    Serial.print("Devices found: ");
    Serial.println(deviceNum);
    Serial.println("Scan done!");
    pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
    drawScreen(); // 画面に表示する
  }
}
void setup() {
  M5.begin();
  Serial.begin(115200);
  Serial.println("Scanning...");
  M5.Lcd.setRotation(1);
  M5.Axp.ScreenBreath(8);
  BLEDevice::init("");             // BLEモジュールの初期化
  pBLEScan = BLEDevice::getScan(); // スキャンオブジェクトを取得
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); // コールバック関数(アドバタイジング受信)
  pBLEScan->setActiveScan(false);  // active scan uses more power, but get results faster
  pBLEScan->setInterval(5000);     // スキャン間隔5秒
  pBLEScan->setWindow(4999);       // less or equal setInterval value
  xTaskCreatePinnedToCore(         // コア指定タスク作成
    Task1,
    "Task1", 
    4096, //スタックサイズ(Byte)
    NULL, 
    3,    //作成タスクの優先順位(0:低 - 25:高)
    NULL, 
    1     //利用するCPUコア(0-1)
  );
}
void loop() {
  M5.update();
  if ( M5.BtnA.wasPressed() ) { // Aボタン1回押し
      rssiNum = -90; // 広いエリア
  }
  if ( M5.BtnB.wasPressed() ) { // Bボタン1回押し
      rssiNum = -40; // 狭いエリア
  }
}
 소감
실제로 iPhone의 앱이 작동하는지 확인할 수있었습니다. 여러가지 조사하고 있는 동안에 BLE가 조금 가까이에 느껴지게 되었습니다. 가급적 가까이 가지 않도록 해 온 C 언어에도 익숙해져 온 것 같은 생각이 듭니다. (「->」라고 뭐든지!라든지 중얼거리면서…) M5StickC의 버튼의 사용법의 공부도 되었습니다.
                
                    
        
    
    
    
    
    
                
                
                
                
                    
                        
                            
                            
                            Reference
                            
                            이 문제에 관하여(M5StickC로 접촉 확인 앱의 동작을 확인(버튼으로 수신 범위 전환)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
                                
                                https://qiita.com/tranquility/items/ab8c80f9f975b840fab7
                            
                            
                            
                                텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                            
                            
                                
                                
                                 우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)
                            
                            
                        
                    
                
                
                
            
#include <Arduino.h>
#include <M5StickC.h>
#include <BLEDevice.h>
#include <BLEUtils.h>
#include <BLEScan.h>
#include <BLEAdvertisedDevice.h>
int scanTime = 4; // スキャンする時間(秒)
BLEScan* pBLEScan;
// 接触確認アプリのUUID
const char* uuid = "0000fd6f-0000-1000-8000-00805f9b34fb";
int deviceNum = 0; // アプリの数のカウンター
int rssiNum = -40; // RSSI(Received Signal Strength Indicator)電波強度の初期値(狭いエリア)
class MyAdvertisedDeviceCallbacks: public BLEAdvertisedDeviceCallbacks {
    void onResult(BLEAdvertisedDevice advertisedDevice) {
       if(advertisedDevice.haveServiceUUID()){
            if(strncmp(advertisedDevice.getServiceUUID().toString().c_str(),uuid, 36) == 0){ // 検出したUUIDが接触確認アプリのUUIDと同じとき
                int rssi = advertisedDevice.getRSSI();
                Serial.print("RSSI: ");
                Serial.println(rssi);
                Serial.print("ADDR: ");
                Serial.println(advertisedDevice.getAddress().toString().c_str());
                if(rssi > rssiNum){ // rssiNum の範囲内のとき
                  Serial.println("Found!");
                  deviceNum++; // カウンターに1加算
                }
            }
        }
    }
};
void drawScreen() {
    M5.Lcd.fillScreen(BLACK);
    M5.Lcd.setTextSize(2);
    M5.Lcd.setCursor(0, 0);
    M5.Lcd.setTextColor(GREEN);
    if(rssiNum < -40){ // 広いエリアを受信したとき
      M5.Lcd.print("Area:wide\n");
    } else {
      M5.Lcd.print("Area:narrow\n");
    }
    M5.Lcd.setTextSize(7);
    M5.Lcd.setTextColor(WHITE);
    M5.Lcd.printf(" %2d",deviceNum); // カウンターを表示
    M5.Lcd.setTextSize(1);
    M5.Lcd.setCursor(0, M5.Lcd.height() - 10);
    M5.Lcd.printf("Bat:%4.1fV  ", M5.Axp.GetBatVoltage());
    M5.Lcd.printf("Charge:%5.1f\n", M5.Axp.GetBatCurrent());
}
void Task1(void *pvParameters) {
  // loop()に書くとBLEスキャン中M5.update()が実行されずボタンが取れないためマルチスレッド化されている
  while(1) {
    deviceNum = 0; // カウンターを初期化
    BLEScanResults foundDevices = pBLEScan->start(scanTime, false); // 指定した時間スキャンする
    Serial.print("Devices found: ");
    Serial.println(deviceNum);
    Serial.println("Scan done!");
    pBLEScan->clearResults();   // delete results fromBLEScan buffer to release memory
    drawScreen(); // 画面に表示する
  }
}
void setup() {
  M5.begin();
  Serial.begin(115200);
  Serial.println("Scanning...");
  M5.Lcd.setRotation(1);
  M5.Axp.ScreenBreath(8);
  BLEDevice::init("");             // BLEモジュールの初期化
  pBLEScan = BLEDevice::getScan(); // スキャンオブジェクトを取得
  pBLEScan->setAdvertisedDeviceCallbacks(new MyAdvertisedDeviceCallbacks()); // コールバック関数(アドバタイジング受信)
  pBLEScan->setActiveScan(false);  // active scan uses more power, but get results faster
  pBLEScan->setInterval(5000);     // スキャン間隔5秒
  pBLEScan->setWindow(4999);       // less or equal setInterval value
  xTaskCreatePinnedToCore(         // コア指定タスク作成
    Task1,
    "Task1", 
    4096, //スタックサイズ(Byte)
    NULL, 
    3,    //作成タスクの優先順位(0:低 - 25:高)
    NULL, 
    1     //利用するCPUコア(0-1)
  );
}
void loop() {
  M5.update();
  if ( M5.BtnA.wasPressed() ) { // Aボタン1回押し
      rssiNum = -90; // 広いエリア
  }
  if ( M5.BtnB.wasPressed() ) { // Bボタン1回押し
      rssiNum = -40; // 狭いエリア
  }
}
실제로 iPhone의 앱이 작동하는지 확인할 수있었습니다. 여러가지 조사하고 있는 동안에 BLE가 조금 가까이에 느껴지게 되었습니다. 가급적 가까이 가지 않도록 해 온 C 언어에도 익숙해져 온 것 같은 생각이 듭니다. (「->」라고 뭐든지!라든지 중얼거리면서…) M5StickC의 버튼의 사용법의 공부도 되었습니다.
Reference
이 문제에 관하여(M5StickC로 접촉 확인 앱의 동작을 확인(버튼으로 수신 범위 전환)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/tranquility/items/ab8c80f9f975b840fab7텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
                                
                                
                                
                                
                                
                                우수한 개발자 콘텐츠 발견에 전념
                                (Collection and Share based on the CC Protocol.)