Skip to content

Example: Custom Advert Data

ozarchie edited this page Oct 22, 2016 · 1 revision

##Advertise Custom Data See "Adverts and Scans" for a description of the advertising payload.


Custom Example

Read DHT22 data every 5s and advertise it every 2s

NEW
1 AUTORUN ON
10 // "Set global varalbles"
11 DIM V(6)
12 DIM D(6)
13 D(0)=0xFF
15 PINMODE P1(1) OUTPUT
16 P1(1) = 1
17 // "Initial read"
18 GOSUB 1001
20 // "3200 = Advertise every 2 seconds"
21 T = 3200
22 BTPOKE LIM_DISC_ADV_INT_MIN, T
23 BTPOKE LIM_DISC_ADV_INT_MAX, T
24 BTPOKE GEN_DISC_ADV_INT_MIN, T
25 BTPOKE GEN_DISC_ADV_INT_MAX, T
40 // "Identify as DHT22-00n"
41 ADVERT GENERAL
42 ADVERT NAME "DHT22-001"
45 ADVERT CUSTOM D
49 ADVERT END
60 // "Read DHT Data every 5secs"
61 DELAY 5000
62 GOSUB 1001
68 // "Go back to ADVERT section to update D"
69 GOTO 41
99 RETURN
1000 // "Read DHT22, Flash LED"
1001 P1(1)=1
1002 // "Read data into V(0-5)"
1003 // "--   uses: H, Z, M"
1004 // " modifies: V, D"
1010 DIM H(83)
1015 PINMODE P0(1) OUTPUT PULLUP
1020 WIRE P0(1) OUTPUT, HIGH, LOW, WAIT 1000, INPUT, PULSE H, OUTPUT HIGH, END
1122 // "Assemble bits into V"
1124 V = 0, 0, 0, 0, 0, 0
1130 M = 128
1140 FOR Z = 4 TO 82 STEP 2
1150  IF H(Z) > 64
1160   V(Z - 4 >> 4) = V(Z - 4 >> 4) | M
1170  END
1180  M = M >> 1
1190  IF M = 0
1200   M = 128
1210  END
1220 NEXT Z
1230 // "Copy data to advert packet"
1231 FOR Z = 0 TO 4 STEP 1
1232  D(Z+1) = V(Z)
1233 NEXT Z
1240 // "Set flag byte as Mfr Data"
1241 D(0) = 0xFF
1251 P1(1)=0
1261 RETURN