BLE 모듈 BL600을 사용하여 Eddystone 호환 비콘을 만들어보십시오.

Laird Technology 사제의 BLE 모듈 BL600-SA를 탑재한 「FRISK 케이스에 들어가는 BL600 기판 REBL600FR」를 사용해, Eddystone 대응의 비콘을 만들어 보았다.

본 샘플 프로그램은 Eddystone UID, URL, TLM의 3개의 신호를 교대로 송신하는 프로그램으로 되어 있습니다.

이 모듈은 SmartBASIC으로 작성할 수 있으며 UART를 통해 모듈로 프로그램을 전송할 수 있으므로 약간의 실험에 적합합니다.

\$autorun$.eddystone.Firmware.sb
' BL600用 Eddystoneサンプルアプリ
' Programed by Kazuyuki Eguchi

 DIM rc AS INTEGER
 DIM txpower AS INTEGER : txpower = 4

 DIM addr$ : addr$="" 
 DIM advRpt$
 DIM scnRpt$ : scnRpt$=""  
 DIM adElmnt$ : adElmnt$="\aa\fe"
 DIM devname$ : devname$=""

 DIM flag AS INTEGER : flag = 0
 DIM adv AS INTEGER : adv = 0
 DIM tim AS INTEGER : tim = 0

 FUNCTION HandlerTimer0()
    IF flag == 0 THEN
        IF BleAdvertStop()==0 THEN
        ENDIF

        // Eddystone UID
        DIM adElmnt1$ : adElmnt1$="\aa\fe\00\00\00\01\02\03\04\05\06\07\08\09\0a\0b\0c\0d\0e\0f"

        DIM power1 AS INTEGER : power1 = SYSINFO(2008)

        IF power1 < 0 THEN
            power1 = 256 + power1
        ENDIF

        rc = StrSetChr(adElmnt1$,power1 & 0xff,3)

        rc = BleAdvRptInit(advRpt$, 2, 0, 0) 
        rc = BleAdvRptAppendAD(advRpt$,0x03,adElmnt$)
        rc = BleAdvRptAppendAD(advRpt$,0x16,adElmnt1$)
        rc = BleScanRptInit(scnRpt$)
        rc = BleAdvRptAppendAD(scnRpt$,0x09,devname$)
        rc = BleAdvRptsCommit(advRpt$,scnRpt$)

        IF BleAdvertStart(3,addr$,500,0,0)==0 THEN
        ELSE
        ENDIF

    ELSEIF flag == 2 THEN
        IF BleAdvertStop()==0 THEN
        ENDIF

        // Eddystone URL
        DIM adElmnt2$ : adElmnt2$="\aa\fe\10\00\02eguchi.jp"

        DIM power2 AS INTEGER : power2 = SYSINFO(2008)

        IF power2 < 0 THEN
            power2 = 256 + power2
        ENDIF

        rc = StrSetChr(adElmnt2$,power2 & 0xff,3)

        rc = BleAdvRptInit(advRpt$, 2, 0, 0) 
        rc = BleAdvRptAppendAD(advRpt$,0x03,adElmnt$)
        rc = BleAdvRptAppendAD(advRpt$,0x16,adElmnt2$)
        rc = BleScanRptInit(scnRpt$)
        rc = BleAdvRptAppendAD(scnRpt$,0x09,devname$)
        rc = BleAdvRptsCommit(advRpt$,scnRpt$)

        IF BleAdvertStart(3,addr$,500,0,0)==0 THEN
        ELSE
        ENDIF

    ELSEIF flag == 5 THEN
        IF BleAdvertStop()==0 THEN
        ENDIF

        // Eddystone TLM
        adv = adv + 10
        tim = tim + 50

        DIM adElmnt3$ : adElmnt3$="\aa\fe\20\00\01\00\02\00\00\00\00\00\00\00\00\00"
        DIM temp : temp = 0
        DIM vol : vol = 3000 // mv

        rc = StrSetChr(adElmnt3$,(vol & 0xff),5)
        rc = StrSetChr(adElmnt3$,((vol >> 8) & 0xff),4)

        rc = StrSetChr(adElmnt3$,(temp & 0xff),7)
        rc = StrSetChr(adElmnt3$,((temp >> 8) & 0xff),6)

        rc = StrSetChr(adElmnt3$,(adv & 0xff),11)
        rc = StrSetChr(adElmnt3$,((adv >> 8) & 0xff),10)
        rc = StrSetChr(adElmnt3$,((adv >> 16) & 0xff),9)
        rc = StrSetChr(adElmnt3$,((adv >> 24) & 0xff),8)

        rc = StrSetChr(adElmnt3$,(tim & 0xff),15)
        rc = StrSetChr(adElmnt3$,((tim >> 8) & 0xff),14)
        rc = StrSetChr(adElmnt3$,((tim >> 16) & 0xff),13)
        rc = StrSetChr(adElmnt3$,((tim >> 24) & 0xff),12)

        rc = BleAdvRptInit(advRpt$, 2, 0, 0) 
        rc = BleAdvRptAppendAD(advRpt$,0x03,adElmnt$)
        rc = BleAdvRptAppendAD(advRpt$,0x16,adElmnt3$)
        rc = BleScanRptInit(scnRpt$)
        rc = BleAdvRptAppendAD(scnRpt$,0x09,devname$)
        rc = BleAdvRptsCommit(advRpt$,scnRpt$)

        IF BleAdvertStart(3,addr$,500,0,0)==0 THEN
        ELSE
        ENDIF

    ENDIF

    flag = flag + 1

    IF flag > 5 THEN
        flag = 0
    ENDIF
 ENDFUNC 1 

 ONEVENT    EVTMR0  CALL    HandlerTimer0 

 rc = BleTxPowerSet(txpower)

 TimerStart(0,1000,1)

 PRINT "\nWaiting for Timer 0\n" 

 WAITEVENT 

작동하면 공식 샘플 앱은 다음과 같이 보입니다.

좋은 웹페이지 즐겨찾기