자유롭게 질의 및 응답을 할 수 있는 게시판입니다. 개발자 여러분의 답변이 큰 도움이 됩니다. 
  • 제품설치/등록 오류 문의: 설치/등록 Q&A 이용 (제품 구매 고객 한정)

본 게시판은 개발자들이 자유롭게 질문과 답변을 공유하는 게시판입니다.
* 따라서 최대한 정중하게 질문을 올려 주세요.
* 질문을 상세히 작성해 주실 수록 좋은 답변이 올라 옵니다.
* 다른 분들도 참고할 수 있도록 결과 댓글 필수(또는 감사 댓글)
(결과 댓글을 달지 않는 경우 다음 질문에 대한 답변이 달리지 않는 불이익이 있을 수 있습니다.)
-----------------------------------------------------------------------------------------------
 

위험지역 경보 시스템 #1 - 비콘을 이용해 위험지역 진입 경보앱 만들기

 

위험지역 경보시스템 비콘을 이용해서 위험지역 진입시 경보음이 울리는 앱을 만들었는데

안드로이드 핸드폰에 어플을 배포하고 실행했으나

비콘 제조업체에서 제공한 어플로 비콘의 UUID를 찾았지만

만든 앱에서는 비콘이 인식되지 않는것 같습니다. 

이럴때에는 어떻게 해결해야하는거일까요?

 

unit MainForm4;

 

interface

 

uses

  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,

  FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Ani,

  FMX.Layouts, System.Beacon, System.Beacon.Components, FMX.Media,

  FMX.Objects, FMX.StdCtrls, FMX.Controls.Presentation, System.IOUtils,

  System.Bluetooth;

 

type

  TForm1 = class(TForm)

    ToolBar1: TToolBar;

    Label1: TLabel;

    Switch1: TSwitch;

    Image1: TImage;

    StatusBar1: TStatusBar;

    Label2: TLabel;

    Rectangle1: TRectangle;

    Layout1: TLayout;

    Label3: TLabel;

    lblDistance: TLabel;

    MediaPlayer1: TMediaPlayer;

    FloatAnimation1: TFloatAnimation;

    Beacon1: TBeacon;

    Timer1: TTimer;

    procedure Beacon1BeaconEnter(const Sender: TObject; const ABeacon: IBeacon;

      const CurrentBeaconList: TBeaconList);

    procedure Beacon1BeaconExit(const Sender: TObject; const ABeacon: IBeacon;

      const CurrentBeaconList: TBeaconList);

    procedure Switch1Switch(Sender: TObject);

    procedure Timer1Timer(Sender: TObject);

  private

    { Private declarations }

    FIsWarning: Boolean;

// 경고 중인가?

    FDangerAreaStaySecs,

// 위험지역에 머무른 시간(초)

    FDangerAreaOutSecs: Integer;

// 위험지역에서 벗어난 시간(초)

    FBeacon: IBeacon;

  procedure StartWarning;

// 위험지역 진입 경고 시작

  procedure StopWarning;

// 위험지역 진입 경고 중지

 

  procedure StartSiren;

// 사이렌 시작

  procedure StopSiren;

// 사이렌 중지

  public

    { Public declarations }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.fmx}

 

{ TForm1 }

 

procedure TForm1.Beacon1BeaconEnter(const Sender: TObject;

  const ABeacon: IBeacon; const CurrentBeaconList: TBeaconList);

begin

  FBeacon := ABeacon;

end;

 

procedure TForm1.Beacon1BeaconExit(const Sender: TObject;

  const ABeacon: IBeacon; const CurrentBeaconList: TBeaconList);

begin

  FBeacon := nil;

end;

 

procedure TForm1.StartSiren;

begin

  MediaPlayer1.FileName := TPath.Combine(TPath.GetDocumentsPath, 'alert.mp3');

  MediaPlayer1.Play;

end;

 

procedure TForm1.StopSiren;

begin

  MediaPlayer1.Stop;

end;

 

procedure TForm1.StartWarning;

begin

  Rectangle1.Visible := True;

  FloatAnimation1.Enabled := True;

 

  StartSiren;

end;

 

procedure TForm1.StopWarning;

begin

  Rectangle1.Visible := False;

  FloatAnimation1.Enabled := False;

 

  StopSiren;

end;

 

procedure TForm1.Switch1Switch(Sender: TObject);

begin

  Beacon1.Enabled := Switch1.IsChecked;

end;

 

procedure TForm1.Timer1Timer(Sender: TObject);

var

  InDangerArea: Boolean;

// 위험지역에 있는가?(비콘과의 거리가 1m 이내인가?)

begin

   if Assigned(FBeacon) then

  begin

    InDangerArea := FBeacon.Distance <= 1;

 

 

// 경고 중 아님

 

// 위험지역에 3초간 머무른 경우 경고 시작

    if not FIsWarning then

    begin

      if InDangerArea then

        Inc(FDangerAreaStaySecs)

      else

        FDangerAreaStaySecs := 0

      ;

 

      if FDangerAreaStaySecs >= 3 then

      begin

        FIsWarning := True;

        StartWarning;

        FDangerAreaStaySecs := 0

      end;

    end

 

// 경고 중

 

// 위험지역을 3초 이상 벗어난 경우 경고 중단

    else if FIsWarning then

    begin

      if not InDangerArea then

        Inc(FDangerAreaOutSecs)

      else

        FDangerAreaOutSecs := 0;

 

      if FDangerAreaOutSecs >= 3 then

      begin

        FIsWarning := False;

        StopWarning;

        FDangerAreaOutSecs := 0;

       end;

    end;

 

 

// 위험지역과의 거리를 표시

    lblDistance.Text := FBeacon.Distance.ToString;

    Label3.Text := '주면에 노약자와의 거리: ' + FBeacon.Distance.ToString + ' m';

  end;

end;

 

end.