bluegiga - BGScript: Conversion of string into integer -


i have android app sends data ble113 module. receive data through gatt characteristic of type 'user'. able data strings. when send integers, 24, receive string '24'. there anyway can convert string number integer type?

this gatt.xml.

<characteristic uuid="xxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxx" id="configuration">     <description>config register</description>     <properties read="true" write="true"/>     <value type="user" /> </characteristic> 

this snippet android side write integer value '1'.

string str = "1";     try {       byte[] value = str.getbytes("utf-8");       chara.setvalue(value);     } catch (unsupportedencodingexception e) {       e.printstacktrace();     } . . . boolean status = mbluetoothgatt.writecharacteristic(chara); 

i want receive data integer '1' in bgscript side. doing wrong conversion? please me send integers.

has got type 'user' of gatt characteristic? if change 'hex' or 'utf-8', issue solved?

in gatt.xml file, change value type "user" "hex" , give fixed length, so:

<characteristic uuid="xxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxx" id="configuration">     <description>config register</description>     <properties read="true" write="true"/>     <value type="hex">00</value> </characteristic> 

in android project, assuming chara of type bluetoothgattcharacteristic, write characteristic like:

int newconfigregvalue = 1; chara.setvalue(newconfigregvalue, bluetoothgattcharacteristic.format_uint8, 0); boolean status = mbluetoothgatt.writecharacteristic(chara); 

then, in bgscript (i assume, didn't otherwise), in attributes_value() event, can save integer like:

dim configregister ... event attributes_value(connection, reason, handle, offset, value_len, value_data) ...     if handle = configuration         configregister = value_data(0:value_len)         end if ... end 

-ted

-begin edit-

you can too.

the characteristic in gatt.xml this:

<characteristic uuid="xxxxx-xxxx-xxxxx-xxxx-xxxxxxxxxx" id="configuration">     <description>config register</description>     <properties read="true" write="true"/>     <value type="user">0</value> </characteristic> 

then in bgscript file, need provide value when read request comes in. done in attributes_user_read_request() event. so:

event attributes_user_read_request(connection, handle, offset, maxsize)     if handle = configuration         # retreive configregister value         # if need read external eeprom or something, save 'connection' value can use in callback event         call attributes_user_read_response(connection, 0, 1, configregister(0:1))     end if end 

Popular posts from this blog

php - How should I create my API for mobile applications (Needs Authentication) -

5 Reasons to Blog Anonymously (and 5 Reasons Not To)

Google AdWords and AdSense - A Dynamic Small Business Marketing Duo