Coder Social home page Coder Social logo

Comments (4)

kscheff avatar kscheff commented on July 20, 2024

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.

from bluebasic.

0xFACE avatar 0xFACE commented on July 20, 2024

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.

from bluebasic.

kscheff avatar kscheff commented on July 20, 2024

@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

from bluebasic.

0xFACE avatar 0xFACE commented on July 20, 2024

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

from bluebasic.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.