Connecting blend micro with bluepy on raspberry pi


#1

Hello,

I am working on connecting the blend micro to a python script running on a raspberry pi.
As of now I am able to ‘connect’ them, but I am not able to send and receive data.

The Code for the micro is the HelloWorld Example. I just added this line ble_set_name("My BLE");

For the raspberry i use the bluepy modul: http://ianharvey.github.io/bluepy-doc/index.html#
Code for raspberry is:


def getCompleteLocalName(dev):
	data = dict([(desc, value) for (adtype, desc, value) in dev.getScanData()])
	return data.get("Complete Local Name")
	

class ScanDelegate(DefaultDelegate):
    def __init__(self):
        DefaultDelegate.__init__(self)

    def handleDiscovery(self, dev, isNewDev, isNewData):
	if isNewDev and getCompleteLocalName(dev) == "My BLE":
		print "DISCOVERED MY BLE"
        if isNewData and getCompleteLocalName(dev) == "My BLE":
            print "Received new data from", dev.addr


class PeriDelegate(DefaultDelegate):
	def __init__(self):
        	DefaultDelegate.__init__(self)
		print "init peri"

	def handleNotification(self, cHandle, data):
		print data



scanner = Scanner().withDelegate(ScanDelegate())
devices = scanner.scan(5.0)

if __name__ == "__main__":

	for dev in devices:
		if getCompleteLocalName(dev) == "My BLE":
			print "Creating Peripheral"
			peri = Peripheral(dev)
			peri.setDelegate(PeriDelegate())

	while True:
    		if peri.waitForNotifications(1.0):
			print "There is something"
        		# handleNotification() was called
        		continue

    		print "waiting"

Output from the python program is:

Received new data from db:b6:4d:4e:d6:0b
Creating Peripheral
init peri
waiting
waiting
[...]

And the output from my arduino serial monitor:

Evt Connected
Evt Pipe Status

So it looks like that there is a connection, but no communication.
How can i see the data in my script?

Thanks in advance.
Pascal


#2

Hi @paszin, I’m not expert on python script, but I can tell that this script seams that it is waiting for notification. In this case, the BlendMicro should send data actively using the ble_write() or ble_write_bytes() APIs.


#3

Hi guohui,
i use ble_write() in the arduino script. I think I need some support for my python code.