Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to create characteristics with uint8 value respond #28

Open
0xFACE opened this issue Aug 13, 2016 · 4 comments
Open

How to create characteristics with uint8 value respond #28

0xFACE opened this issue Aug 13, 2016 · 4 comments

Comments

@0xFACE
Copy link

0xFACE commented Aug 13, 2016

BlueBasic is using 32-bit variables. When I create characteristic for reading, the response value is 32bit long. Is it possible to respond with uint8 values ?

According to the specification: alert level characteristic is uint8:
https://www.bluetooth.com/specifications/gatt/viewer?attributeXmlFile=org.bluetooth.characteristic.alert_level.xml&u=org.bluetooth.characteristic.alert_level.xml

32bit response gives invalid value :

screenshot_20160813-105457

@kscheff
Copy link

kscheff commented Dec 6, 2016

As far as I can see, it is always fixed to 4 bytes, big endian.
When using a array variable you can have different number of bytes, e.g. use DIM A(1) for a 1 byte characteristic.

@0xFACE
Copy link
Author

0xFACE commented Dec 7, 2016

I tried to use arrays:
GATT READ DIM A(1) ONREAD GOSUB 300

But can't run the code, it exits with Error
Syntax seems to be incorrect.

@kscheff
Copy link

kscheff commented Dec 8, 2016

@0xFACE try to using the below code. Your syntax is indeed wrong, you cannot use DIM A(1) inside the GATT command. DIM A(1) must be outside.

A running idle loop keeps the DIM A(1) alive. If the basic program terminates, it falls back to Int32 type and you get the 4 bytes by reading. You can also not declare DIM A(1) in the GOSUB area, since this would hide the instance variable which gets accessed by GATT.

Another thing I observed is, that the DIM variable gets lost for GATT when you use a DELAY instruction during GATT access in the GOSUB section. Sometimes an "DELAY 1" is required in interactive sessions, to give control back to the BLE stack in order not to loose the console connection. But this is only the case when you execute longer tasks in the BASIC program. For GATT access I try to avoid this, by e.g. using a TIMER to shift some processing outside the GATT access (see e.g. line 400 below).

-Kai

NEW
10 DIM A(1)

// setup advertsing
20 ADVERT GENERAL 
30 ADVERT "105a84de-40bd-428b-bf06-698e5e422cd9"
40 ADVERT END 
50 SCAN NAME "oneByteDemo"
60 SCAN END

// setup GATT profile

100 GATT SERVICE "105a84de-40bd-428b-bf06-698e5e422cd9" ONCONNECT GOSUB 400
110 GATT CHARACTERISTIC "00d8a2c6-65f3-40c2-a342-b4e5126f45f0" "sec"
120 GATT READ WRITE A ONREAD GOSUB 300
130 GATT END 

150 TIMER 0, 1000 REPEAT GOSUB 1000

// Idle loop keeping DIM A(1) alive
200 DELAY 10000
210 GOTO 200

// GATT read A
300 A(0) = T % 60
310 RETURN

// GATT Service on connect
400 TIMER 1, 2000 GOSUB 500
410 RETURN 

// welcome
500 PRINT "Hello World!"
510 RETURN 

// time tick
1000 T = T + 1
1010 RETURN


// this last return seems to be required
65529 RETURN

AUTORUN ON
END
REBOOT

oneByte.bbasic.zip

@0xFACE
Copy link
Author

0xFACE commented Dec 9, 2016

Wow, great.
Idle loop did the trick.
Thanks a lot ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants