jrowberg / bglib Goto Github PK
View Code? Open in Web Editor NEWBGLib implementation for Bluegiga BLE Bluetooth Smart modules
License: Other
BGLib implementation for Bluegiga BLE Bluetooth Smart modules
License: Other
Hi, I need to create a simple application using BLE112.
I need to create a simple script that:
Discovery Mode -> Accept connection from another device -> Read a file and send datas read to a device which made a connection
I don't know where can I found the API doc to use your library.
I want to run this script on my raspberry pi, thanks for the help.
Hi, I was going through this instruction ==> "http://docs-europe.electrocomponents.com/webdocs/12eb/0900766b812eb651.pdf" and then when I'm trying to run python code to scan other BLE devices it cannot detect any while there so many around it. Basically, I'm seeing something like this, can someone help me with this?
The last time I used this library about two years ago, the gatt.xml only had 2 gatt characteristics for the the data transceiver service, and the slave stub sketch reflects that. The gatt.xml has since been updated to have 4 gatt characteristics, but with no attributes.txt file, it's impossible to know what the gatt handles are for these characteristics without reflashing the firmware.
The commit that removed them has the hash: e0f1dbe
The commit adding the new characteristics is: ea3e918
Do you happen to have the attributes.txt file handy? Thanks.
Hi,
I'm trying to implement a BLE master to read data from a custom BLE device, and am trying to run the BGLIB_scanner demo to scan for the device.
I notice that after scan response from the device of a few packets, I see a "system boot" message, which indicates that the ble112 device restarted?
I have tried the scanner with a TI Sensor Tag and it can read scan responses all day long.
The only difference I see with this device is that the address type is "1" (random) (whereas the TI Sensor Tag has an address type of "0" (public) ).
I'm wondering if there is anything different in the code path in the device/library for address type of "1", where there might be a bug or issue?
Output from BGLib_scanner demo is shown below:
Thanks,
Sridhar
������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������BLE112 BGAPI Scanner Demo
Operations Menu:
0) Reset BLE112 module
1) Say hello to the BLE112 and wait for response
2) Toggle scanning for advertising BLE devices
Command?
--> system_hello
<-- system_hello
--> system_reset: { boot_in_dfu: 0 }
### system_boot: { major: 1, minor: 4, patch: 2, build: 82, ll_version: 3, protocol_version: 1, hw: 1 }
--> system_reset: { boot_in_dfu: 0 }
### system_boot: { major: 1, minor: 4, patch: 2, build: 82, ll_version: 3, protocol_version: 1, hw: 1 }
--> gap_set_scan_parameters: { scan_interval: 0xC8, scan_window: 0xC8, active: 1 }
<-- gap_set_scan_parameters: { result: 0 }
--> gap_discover: { mode: 2 (GENERIC) }
<-- gap_discover: { result: 0 }
### gap_scan_response: { rssi: -49, packet_type: 0, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 0201050D09536D617274204D6F64756C65 }
### gap_scan_response: { rssi: -49, packet_type: 4, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 110700000000000000B00040510421AA00F0 }
### gap_scan_response: { rssi: -49, packet_type: 0, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 0201050D09536D617274204D6F64756C65 }
.....
### gap_scan_response: { rssi: -48, packet_type: 0, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 0201050D09536D617274204D6F64756C65 }
### gap_scan_response: { rssi: -49, packet_type: 4, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 110700000000000000B00040510421AA00F0 }
### gap_scan_response: { rssi: -49, packet_type: 0, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 0201050D09536D617274204D6F64756C65 }
### gap_scan_response: { rssi: -49, packet_type: 4, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 110700000000000000B00040510421AA00F0 }
### gap_scan_response: { rssi: -48, packet_type: 0, sender: 3C1F4932ACF7, address_type: 1, bond: FF, data: 0201050D09536D617274204D6F6475801C }
### system_boot: { major: 6, minor: D0, patch: 1F3C, build: 3249, ll_version: F7AC, protocol_version: 1, hw: FF }
The interesting thing is that the system_boot message at the end shows a different major/minor versions than the initial message.
Hi,
I was trying to have the arduino connected to ble112 as master. I started with the BGLib_scanner example, and modified it to connect to the address it found.
I used the BGLib_U1A1P_38400_noflow_wake16 firmware on the BLE112. I'm also using an Arduino Pro Mini at 3.3v, so there would be no 5v-3.3v issues.
What I see is that it scans and gets the address successfully, but then hangs on ble_cmd_gap_connect_direct (I put a Serial.println right before and right after, and I don't see the println right after).
Any clues as to whether I'm doing something wrong, or what the problem might be?
Here is the modified version:
void my_evt_gap_scan_response(const ble_msg_gap_scan_response_evt_t msg) {
Serial.print("###\tgap_scan_response: { ");
Serial.print("rssi: "); Serial.print(msg -> rssi);
Serial.print(", packet_type: "); Serial.print((uint8_t)msg -> packet_type, HEX);
Serial.print(", sender: ");
// this is a "bd_addr" data type, which is a 6-byte uint8_t array
for (uint8_t i = 0; i < 6; i++) {
if (msg -> sender.addr[i] < 16) Serial.write('0');
Serial.print(msg -> sender.addr[i], HEX);
}
Serial.print(", address_type: "); Serial.print(msg -> address_type, HEX);
Serial.print(", bond: "); Serial.print(msg -> bond, HEX);
Serial.print(", data: ");
// this is a "uint8array" data type, which is a length byte and a uint8_t pointer
for (uint8_t i = 0; i < msg -> data.len; i++) {
if (msg -> data.data[i] < 16) Serial.write('0');
Serial.print(msg -> data.data[i], HEX);
}
Serial.println(" }");
if (msg->address_type == 0 && ble_state < BLE_STATE_CONNECTING) {
// save this device
memcpy(connect_addr.addr, msg -> sender.addr, sizeof(bd_addr));
Serial.print("-->\tgap_connect_direct: {");
Serial.print("address: ");
// this is a "bd_addr" data type, which is a 6-byte uint8_t array
for (uint8_t i = 0; i < 6; i++) {
if (msg -> sender.addr[i] < 16) Serial.write('0');
Serial.print(msg -> sender.addr[i], HEX);
}
Serial.println(" }");
uint8_t status;
Serial.println("Before connect_direct");
//ble112.ble_cmd_gap_connect_direct(connect_addr, msg->address_type, 0x20, 0x30, 0x100, 0);
ble112.ble_cmd_gap_connect_direct(connect_addr, msg->address_type, 0x06, 0x0c, 0x200, 0);
Serial.println("After connect_direct"); /// <<<<<<<<<<<<<<<<<--- NEVER GETS PRINTED
// while ((status = ble112.checkActivity(1000)));
ble_state = BLE_STATE_CONNECTING;
Serial.println("Connecting...");
}
}
Thanks,
Sridhar
This:
if (BLEEventSMPasskeyDisplay != null) { BLEEventSMPasskeyDisplay(this, new Bluegiga.BLE.Events.SM.PasskeyDisplayEventArgs( bgapiRXBuffer[4], (UInt16)(bgapiRXBuffer[5] + (bgapiRXBuffer[6] << 8) + (bgapiRXBuffer[6] << 16) + (bgapiRXBuffer[6] << 24)) )); }
Should be:
if (BLEEventSMPasskeyDisplay != null) { BLEEventSMPasskeyDisplay(this, new Bluegiga.BLE.Events.SM.PasskeyDisplayEventArgs( bgapiRXBuffer[4], (uint)(bgapiRXBuffer[5] + (bgapiRXBuffer[6] << 8) + (bgapiRXBuffer[7] << 16) + (bgapiRXBuffer[8] << 24)) )); }
Hello,
I have a Arduino Due based board with the BLE113 on board. The bluetooth sketches I've found for testing connectivity have an #include <SoftwareSerial.h> at the beginning of the sketch which does not get used in Due, which I understand is because of the 3 other available hardware serial ports. (Serial1, Serial2 and Serial3)
So my question is how can I use a Due with the BGLib_scanner.ino without calling for the #include SoftwareSerial.h library, just to ensure the BLE113 is functioning properly? Thank you very much, and happy new year!
the xrange is not defined in python 3, you need to use range instead. Since the division gives a float output, need to cast it into an int
Line 387 to 395 :
if this_field[0] == 0x02 or this_field[0] == 0x03: # partial or complete list of 16-bit UUIDs
for i in range(int((len(this_field) - 1) / 2)):
ad_services.append(this_field[-1 - i*2 : -3 - i*2 : -1])
if this_field[0] == 0x04 or this_field[0] == 0x05: # partial or complete list of 32-bit UUIDs
for i in range(int((len(this_field) - 1) / 4)):
ad_services.append(this_field[-1 - i*4 : -5 - i*4 : -1])
if this_field[0] == 0x06 or this_field[0] == 0x07: # partial or complete list of 128-bit UUIDs
for i in range(int((len(this_field) - 1) / 16)):
ad_services.append(this_field[-1 - i*16 : -17 - i*16 : -1])
Hi,
I wish to use the BLE113 Breakout with a large button for disabled children, that would send a to iOS (HID Keyboard). Any chance I could contract with you to write that?
RJ :)
Can any one help me or provide more documentation on bglib.SendCommand().
This command works fine:
result = bglib.SendCommand(serialAPI, bglib.BLECommandSystemHello());
But not this:
result = bglib.SendCommand(serialAPI, bglib.BLECommandGAPConnectDirect(new byte[] { 46, 180, 169, 89, 178, 246 }, (byte)AddressType.Public, CONN_INT_MIN, CONN_INT_MAX, TIMEOUT, LATENCY));
or
result = bglib.SendCommand(serialAPI, bglib.BLECommandConnectionDisconnect(0));
Hello,
Can you provide an example to advertise the packets using your c# library?.
I have replicated the code from c to your c#. But it doesn't work.
Thanks
Sahil
In hardware.xml it has flow="false" for the property. According to the developer guide this should always be true when mode="uart" which you left the default value of uart. This could be the source of your flow control problems. Also shouldn't the sleeposc should be set to true according to the developer guide.
Hi,
Is it possible for BLED 112, to act as a peripheral (iBeacon) and scan for the beacons at the same time or advertise for certain period and then scan for certain minutes? An example would be really great.
Thanks!
I tried using the Arduino Scanner Example with my BLE112 that was flashed with the BGLib_U1A1P_38400_noflow firmware but couldn't get a response from the BLE112 (timeout would occur). It was, however, able to function correctly with the BGLib_U1A1P_38400_noflow_wake16 firmware so I don't think it's an issue with my setup.
I want to use your BGLib library in my opensource arduino related project.
Particularly BGLib.cpp, BGLib.h, BGLibConfig.h .
But haven't found any information related to licensing.
I expect it :) to be something like MIT License, but how do you think?
I am able to write and read BLE request and response via NRF BLE app for an embedded device. But while using this library for the same purpose, I am only able to send successful request but the indication(read) is not working.
Pls Note: The scanner function and send function(for write) works fine and I have specified proper UUID as well as read/write characteristic in the code as well as cross verified in the mobile app.
Hi, I got one BLED112 and working with that, I'm kind of new to that dongle and BLE, I want to know how can I adjust transmission power via your code to my USB BLE? is there any way to set it in the lowest possible number like -27?
@jrowberg @rkravchik
Where can I look up the meaning of status codes for Bluegiga.BLE.Events.Connection.DisconnectedEventArgs.reason? I was seeing 0x208 as the DisconnectedEventArgs.reason.
I see 0x208 defined as connection timeout in https://www.silabs.com/documents/login/reference-manuals/Bluetooth_Smart_Software-BLE-1.6-API-RM.pdf in section 5.11.1 “BGAPI errors”, but I'm not sure the documentation applies to DisconnectedEventArgs.reason.
When trying to run (a slightly modified copy of) bglib_test_scanner.py with python3 using the Python3/bglib.py, the following error occurs:
$ python3 bglib_test_scanner.py
Traceback (most recent call last):
File "bglib_test_scanner.py", line 117, in <module>
main()
File "bglib_test_scanner.py", line 90, in main
ble.send_command(ser, ble.ble_cmd_connection_disconnect(0))
File "/home/alvaro/code/bglib/Python3/Examples/bglib.py", line 618, in send_command
if self.packet_mode: packet = chr(len(packet) & 0xFF) + packet
TypeError: Can't convert 'bytes' object to str implicitly
How do i retrieve the tx power using the bglib?
I am able to write and read BLE request and response via NRF BLE app for an embedded device. But while using this library for the same purpose, I am only able to send successful request but the indication is not working.
Pls Note: The scanner function and send function(for write) works fine and I have decided proper UUID as well as read write characteristic in the code as well as cross verified in the mobile app.
When I call:
handle=15
value='01'
ble.send_command(ser, ble.ble_cmd_attributes_write(handle, 0, value))
ble.check_activity(ser, 1)
I get the following error:
Traceback (most recent call last):
File "test.py", line 14, in <module>
machine.groups[0].startBrewing()
File "/Users/ben/Github/bt4prototype/MockEspresso/Group.py", line 86, in startBrewing
listener.didStartBrewing(self.id)
File "/Users/ben/Github/bt4prototype/MockEspresso/EspressoMachine.py", line 32, in didStartBrewing
self.bluetooth.write_attribute(24,'01')
File "/Users/ben/Github/bt4prototype/MockEspresso/Bluetooth.py", line 55, in write_attribute
self.ble.send_command(self.ser, self.ble.ble_cmd_attributes_write(handle, 0, value))
File "/Users/ben/Github/bt4prototype/bglib.py", line 172, in ble_cmd_attributes_write
return struct.pack('<4BHBB' + str(len(value)) + 's', 0, 4 + len(value), 2, 0, handle, offset, len(value), b''.join(chr(i) for i in value))
File "/Users/ben/Github/bt4prototype/bglib.py", line 172, in <genexpr>
return struct.pack('<4BHBB' + str(len(value)) + 's', 0, 4 + len(value), 2, 0, handle, offset, len(value), b''.join(chr(i) for i in value))
TypeError: an integer is required
I think the problem line is Line 172 in bglib.py
It reads:
return struct.pack('<4BHBB' + str(len(value)) + 's', 0, 4 + len(value), 2, 0, handle, offset, len(value), b''.join(chr(i) for i in value))
When I change it to:
return struct.pack('<4BHBB' + str(len(value)) + 's', 0, 4 + len(value), 2, 0, handle, offset, len(value), b''.join(i for i in value))
I am able to successfully write attributes.
Am I overlooking something?
Hi,
Thanks for the code! I came here actually from myo-raw project. Since, my question involves low level access to the dongle, I would like to know how to differ between 2 dongles of the same type? Is it also possible to connect multiple devices from the same dongle at the same time?
Thanks a lot!
return sendCommand(4 + value_len + value_len, 2, 0, d);
This seems to be sending value_len + value_len + 4 bytes, when it should be value_len + 4 bytes.
I found this on the logic analyser, the command gets sent too long. For some reason only seems to cause problems with very long (~44 bytes) attributes.
Looks like ble_cmd_flash_write_words just above might have the same problem, but I'm not using this command so not certain.
Toby
Hi there, not sure if this is the right place to put this, but here goes.
I'm developing a simple sketch for a TinyDuino with the BLE rev2 board based on the BGLib_stub_slave found here:
http://tiny-circuits.com/learn/using-the-bluetooth-low-energy-tinyshield/
I've adjusted the adv_data to be 30 bytes long, however, when I call
ble112.ble_cmd_gap_set_adv_data(0, 0x1e, adv_data);
none of my devices detect BLE packets from the device. Only when I lower it from 0x1e to 0x1c does the data get (mostly) advertised; obviously, 0x1c cuts off the last two bytes of my data. I'm a mobile app dev by trade, so I'm not familiar with BlueGiga or C++ (which is what it looks like the BGLib is written in), but looking at the code it appears a byte or three are added to the front of the payload to account for length, or some sort of BLE command. Since advertising packets are limited to 31 bytes, I believe that's what's cutting off my packet... how can I fix this issue? I was considering adjusting the BGLib::ble_cmd_gap_set_adv_data or BGLib::sendCommand methods in some way, but I have no idea what I'm doing, so it'd just be trial and error. Am I doing something wrong? Is this use case not supported? How can I get this working?
hi, is there a minimal example on how to connect to a ble beacon and turn on a notification? I am new to ble stuff and even though I can get the scanner example to work fine and print the nearby beacons, connecting to a beacon and turning on a notification is taking me quite a bit of time. I am trying to extract just the pieces needed for me to achieve the connection and notification but haven't had much success yet. Appreciate any pointers or links to an example that does this
Working on a BLE121LR project, I got user feedback of very rare occasions of corrupted data. After analysis I came to the conclusion that it must be bit flip errors in the transmission.
I understand BTLE does not have FEC. But I see that a CRC is included in each packet.
By which mechanism can the CRC be accessed?
When receiving the packet, how do I know whether it passed CRC?
I have been trying to figure out to import and use this library. Any help or advice is acceptable.
I would like to know if this API could be used for the BLE121.
https://www.bluegiga.com/en-US/products/ble121lr-bluetooth-smart-long/
Hi,
I set my bled112 to start advertising packets with specific UUID and other features via blegiga SDK, now I wanted to change that in raspberry pi via my command terminal, I found your python code for advertising ibeacon packets when I run this code, it won't change the default advertising settings and bled112 is still sending packets with old configs. What can I do about this?
if you don't change packet_mode to False in bglib_test_scanner.py (and others) then it will send a packet that causes the BLED112B USB dongle to reset itself (which you can see happening in /var/log/syslog - it reattaches itself to USB) and you get the following error message
$python bglib_test_scanner.py
Traceback (most recent call last):
File "bglib_test_scanner.py", line 117, in
main()
File "bglib_test_scanner.py", line 94, in main
ble.send_command(ser, ble.ble_cmd_gap_set_mode(0, 0))
File "/home/alan/Projects/rfid/bglib/Python/Examples/bglib.py", line 642, in send_command
ser.write(packet)
File "/usr/lib/python2.7/dist-packages/serial/serialposix.py", line 489, in write
raise SerialException('write failed: %s' % (v,))
serial.serialutil.SerialException: write failed: [Errno 5] Input/output error
it would be good if this could be trapped in bglib and raise a more informative error message pointing to the packet mode flag as a possible cause.
Hi all,
I am using the .NET version of this library. I have tried to run the examples but do not understand how they get the UUID for thermometer and heart monitor. So I have a bluetooth ble calliper and bluegiga bluetooth dongle and I am trying to establish connection between the calliper and dongle so that I can retrieve data from the calliper.
Please help.
Thanks.
Unable to find whether or not this is possible. Can i connect at least two modules simultaneously to the dingle?
Cheers
The Current example for Arduino BGLib_scanner.ino uses BLE112.
A setup instruction or code example for BLE121LR would be very much needed.
Hello, I would like to know if your library could be used for the BGM121.
Thank you
Hi. I'm using your great bglib library (c#) to create a react native module for windows wpf/uwp.
I'm starting to implement notification and indication. Notifications are working perfectly but I'm unable to work with indication. This is my piece of code:
[ReactMethod()]
public async void monitorCharacteristicForService(JObject device, string serviceIdentifier, string characteristicUUID, IPromise promise)
{
Device dev = device.ToObject<Device>();
TaskCompletionSource<byte[]> task = new TaskCompletionSource<byte[]>();
ushort? notify_chrhandle, chrhandle;
// get notify chrhandle (0x29, 0x02)
notify_chrhandle = dev.GetCharacteristicHandle(serviceIdentifier, "2902");
if (notify_chrhandle == null)
{
promise.Reject(new NotSupportedException("The requested service is not notificable."));
return;
}
// get characteristic chrhandle
chrhandle = dev.GetCharacteristicHandle(serviceIdentifier, characteristicUUID);
if (chrhandle == null)
{
promise.Reject(new KeyNotFoundException("Service or characteristic not found for this device."));
return;
}
//Byte[] cmdNotify = bglib.BLECommandATTClientAttributeWrite(dev.connectionHandle.Value, notify_chrhandle.Value, new Byte[] { 0x01, 0x00 });
Byte[] cmdIndicate = bglib.BLECommandATTClientAttributeWrite(dev.connectionHandle.Value, notify_chrhandle.Value, new Byte[] { 0x02, 0x00 });
Bluegiga.BLE.Events.ATTClient.AttributeValueEventHandler avEventHandler = new Bluegiga.BLE.Events.ATTClient.AttributeValueEventHandler((sender, e) => {
if (e.connection == dev.connectionHandle && e.atthandle == chrhandle)
{
task.TrySetResult(e.value);
}
});
bglib.BLEEventATTClientAttributeValue += avEventHandler;
//bglib.SendCommand(serialAPI, cmdNotify);
bglib.SendCommand(serialAPI, cmdIndicate);
await task.Task;
bglib.BLEEventATTClientAttributeValue -= avEventHandler;
promise.Resolve(task.Task.Result);
}
But the AttributeValueEvent is never fired.
Am I missing something?
Hi, I've noticed that maybe there are some performance issue using BgLib for C#.
In particular, I'm reading data from a BLED112, and I've noticed that the BytesToRead property of the SerialPort starts increasing a lot before BgLib is able to finish parsing the previous data.
Looking ad the DataReceivedHandler method:
private void DataReceivedHandler(object sender, SerialDataReceivedEventArgs e){
var sp = (SerialPort)sender;
var bytesToRead = sp.BytesToRead;
var inData = new byte[bytesToRead];
// read all available bytes from serial port in one chunk
sp.Read(inData, 0, bytesToRead);
// parse all bytes read through BGLib parser
foreach (var t in inData)
{
_bglib.Parse(t);
}
}
Printing bytesToRead property reveals that the value is for example 9, then 2000, then 12000 and so on, so I'm seeing the data with an increasing delay!
Anyone has noticed this? Are there any workaround?
My data has a frequency of 64hz.
Thanks!
I've copied the enums from cmd_def.h and C#-styled them.
Helps with code clarity quite a bit.
Hope it helps someone else too! :)
I was able to run the slave example (BGLib_stub_slave.ino) on my TinyDuino. But it only shows how to handle a writable characteristics. Can any anybody help me with readable characteristics? Which callback should I define for a readable characteristics?
Thanks for making the library available.
Hi Jeff
First thanks a million for the python library. I am trying to get the bglib_test_crp_collector.py example to work with Processing3 in python mode using the Arduino101 board and having only partial success.
It gets through reading the advertising packet and discovering the service but never connects to the Arduino101. I tested example in python and of course it works like a charm. I also tested the scanner example under processing/python mode and it works fine.
Don't know of anyone trying this with the BLED112 dongle so any help would be appreciated. I am attaching the files for reference.
BLEPython.zip
Here is how far it gets. It never gets the the 05 packet to trigger the event.
Baudrate: 115200
=>[ 00 01 03 00 00 ]
<=[ 00 03 03 00 00 86 01 ]
=>[ 00 02 06 01 00 00 ]
<=[ 00 02 06 01 00 00 ]
=>[ 00 00 06 04 ]
<=[ 00 02 06 04 00 00 ]
=>[ 00 05 06 07 C8 00 C8 00 01 ]
<=[ 00 02 06 07 00 00 ]
Scanning for BLE peripherals...
=>[ 00 01 06 02 01 ]
<=[ 00 02 06 02 00 00 ]
Thanks
Mike
Great lib btw. I ran into one major issue so far though. I can get everything working except terminating a scan in BGLib_scanner.ino (your included demo). It scans fine, etc. but pressing 2 a second time just seems to die (the call seems to go out, but no return) The scan keeps going, but there seems to be no way to stop it.
The only mod I made was changing the BLE_WAKEUP_PIN to match my wiring, and setting Serial to 38400 (I'm running on a 8mhz chip)
I was able to get the peripheral setup 100% working, paired to another BLE device, etc.
I've been bit by this, or at least I think so: not having onBusy
and onIdle
callbacks seems to cause things to fail (i.e. my bluetooth module never turns out). I'm using code based on the stub slave module. I'm not 100% sure about this, but perhaps this'll save someone the time.
I am using a rev 2 TinyDuino BLE shield. I am trying to run the scanner example (BGLib_scaner.ino). I have modified the line 59:
SoftwareSerial bleSerialPort(3, 4); // RX, TX
to account for the fact that the serial ports are connected to pin 3 and 4 according to the official tutorial.
But it is not working as expected. From my iPhone I am running BLE explorer in peripheral mode to advertise alert notification service. But when I enter '2' from the serial monitor of the TinyDuino, I just get the output - --> gap_set_scan_parameters: { scan_interval: 0xC8, scan_window: 0xC8, active: 1 }
, but no actual advertising data.
I am not sure if I am doing anything wrong. Any help would be appreciated!
Thanks for making this library available.
Would anyone have pointers on getting a wireless serial connection working between two BLE113 modules? the closest I could find was a BGScript only implementation, ...though I'm not sure how it translates to BGLib equivalent calls. This is what im trying to translate: https://bluegiga.zendesk.com/entries/27615486-Tested-cable-replacement-sample-for-ble113-
struct.unpack() returns a tuple even if it contains a single item according to the docs. Thus for responses like ble_rsp_attributes_write, result is of the form (0,) instead of just 0. The fix is simply to set result to the first element of struct.unpack for single item responses/events.
First, congratulations for your work with BGLib for Arduino and your breakout board for BLE112 (I have one)
I'm not sure, but after a lot of test, I can't make it work using Serial instead SerialSoftware.
Using SerialSoftware all works like a charm, but using Serial (without DEBUG defined of course) ble_cmd_attributes_write command fails and my iOS app don't receives anything.
The rest like ble_cmd_gap_set_adv_parameters, ble_cmd_gap_set_mode and event handlers works.
Have you tried the same? Any ideas?
When the program starts up, it connects to a BLE module. But when I close and restart the program, it cannot connect are read from the devices, as the dongle hasn't terminated the connections. I can manually go through Bluegiga's BLE Graphical User Interface tool to disconnect each device, but the program doesn't seem to be able to disconnect them on startup
Using this library i have been able to only connect to one module to my dongle. Whenever i try to connect a second, it interferes with the incoming data checking from the first dongle. Is it possible to support more than one connection with this library. If so, how?
There is a bug in your C# and Python when parsing very long packets. I ran across it in my fork. Nobody has probably seen it before because seldom are there packets larger than 256 bytes. Here's the fixes in a diff:
diff --git a/MSVCSharp/BGLib.cs b/MSVCSharp/BGLib.cs
index 55aac3c..8e42338 100644
--- a/MSVCSharp/BGLib.cs
+++ b/MSVCSharp/BGLib.cs
@@ -1816,7 +1816,7 @@ namespace Bluegiga {
bgapiRXBuffer[bgapiRXBufferPos++] = ch;
if (bgapiRXBufferPos == 2) {
// just received "Length Low" byte, so store expected packet length
bgapiRXDataLen = ch + ((bgapiRXBuffer[0] & 0x03) << 8);
bgapiRXDataLen = ch + ((bgapiRXBuffer[0] & 0x07) << 8);
} else if (bgapiRXBufferPos == bgapiRXDataLen + 4) {
// just received last expected byte
/*#ifdef DEBUG
self.bgapi_rx_expected_length = 4 + (self.bgapi_rx_buffer[0] & 0x07) + self.bgapi_rx_buffer[1]
self.bgapi_rx_expected_length = 4 + (self.bgapi_rx_buffer[0] & 0x07)*256 + self.bgapi_rx_buffer[1]
elif len(self.bgapi_rx_buffer) > 1:
self.bgapi_rx_buffer.append(b)
Hi,
To start let me inform you the I'm using BGLib in Python 2.5. It was a straight forward conversion, so I don't expect a problem there.
The Issue:
I don't seem to be able to dispose of the BGLib object and run again. The result is that the first attempt will find a list of nearby devices. The second attempt will timeout and return an empty list having never serviced the ble_evt_gap_scan_response event.
Sorry about the formatting, I can't seem to find the way to show code correctly
import bglib,serial,time
gap_scan_response handler
def evt_find_device(sender, args):
print "evt_find_device"
global devices
id = ''
data = args["data"]
if (len(data) >= 1):
index = 0
while index < len(data):
dLen = data[index]
index+=1
dType = data[index]
index+=1
val = ''.join(['%c' % b for b in args["data"][index:index+dLen-1]]).strip('\0x00')
mac = ''.join(['%02X' % b for b in args["sender"]]).strip('\0x00')
index = index+dLen-1
if dType == 0x08 or dType == 0x09:
id = val.strip('\0x00')
devices[mac] = id
if (not devices.has_key(mac)):
devices[mac] = id
if name == 'main':
timeout = 10
bg = bglib.BGLib()
ser = serial.Serial(port="COM6",baudrate=256000)
global devices
# disconnect if we are connected already
bg.send_command(ser, bg.ble_cmd_connection_disconnect(0))
bg.check_activity(ser, 1)
# stop advertising if we are advertising already
bg.send_command(ser, bg.ble_cmd_gap_set_mode(0, 0))
bg.check_activity(ser, 1)
# stop scanning if we are scanning already
bg.send_command(ser, bg.ble_cmd_gap_end_procedure())
bg.check_activity(ser, 1)
bg.send_command(ser, bg.ble_cmd_gap_set_scan_parameters(0xC8, 0xC8, 1))
bg.check_activity(ser, 1)
devices = {}
bg.ble_evt_gap_scan_response += evt_find_device
# start scanning now
bg.send_command(ser, bg.ble_cmd_gap_discover(1))
tStart = time.time()
while (time.time() - tStart < timeout):
# check for all incoming data (no timeout, non-blocking)
bg.check_activity(ser)
# don't burden the CPU
time.sleep(0.01)
print devices
#shutdown procedure
# disconnect if we are connected already
bg.send_command(ser, bg.ble_cmd_connection_disconnect(0))
bg.check_activity(ser, 1)
# stop advertising if we are advertising already
bg.send_command(ser, bg.ble_cmd_gap_set_mode(0, 0))
bg.check_activity(ser, 1)
# stop scanning if we are scanning already
bg.send_command(ser, bg.ble_cmd_gap_end_procedure())
bg.check_activity(ser, 1)
#reconnect
#attempt number 2
bg = bglib.BGLib()
# disconnect if we are connected already
bg.send_command(ser, bg.ble_cmd_connection_disconnect(0))
bg.check_activity(ser, 1)
# stop advertising if we are advertising already
bg.send_command(ser, bg.ble_cmd_gap_set_mode(0, 0))
bg.check_activity(ser, 1)
# stop scanning if we are scanning already
bg.send_command(ser, bg.ble_cmd_gap_end_procedure())
bg.check_activity(ser, 1)
bg.send_command(ser, bg.ble_cmd_gap_set_scan_parameters(0xC8, 0xC8, 1))
bg.check_activity(ser, 1)
devices = {}
bg.ble_evt_gap_scan_response += evt_find_device
# start scanning now
bg.send_command(ser, bg.ble_cmd_gap_discover(1))
tStart = time.time()
while (time.time() - tStart < timeout):
# check for all incoming data (no timeout, non-blocking)
bg.check_activity(ser)
# don't burden the CPU
time.sleep(0.01)
print devices
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.