10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

BLEモジュールの BL600 を使って、 Eddystone 対応のビーコンを作ってみる

Last updated at Posted at 2015-07-29

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 

動作させると、公式のサンプルアプリには、このように見えます。

Screenshot_20150729-142043.png

10
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?