Bluno General Arduino

Trouble with cross-platform app to communicate with bluno m0

userHead s.achterop 2019-11-12 21:47:51 5883 Views1 Replies
Hello List,
I try to create an app using PyQt5/QML software to talk to the Bluno m0.
It has to work on Linux, Android en iOS, so the existing apps cannot be used.
The current state of the app can be found on https://github.com/SietseAchterop/Bluno_pyqt5

Most of it works, but there are no responses from the Bluno.
I know that the characteristic DFB1 is missing the 0x2902 Descriptor, but that should not
be a problem. The BlunoBasicDemo works on Android and I created a Python program blunoTerminal.py
that works on Linux and uses the bluepy library. Its included in the repository.

The sketch on the Bluno m0, test3.ino in the repository, is a simple program that responds to incoming messages with a reply, e.g. when 'i\r' is send, the response is 'XXInfo, 0, 0\r'.

But I need to use PyQt5 for my app. The app is derived from the lowenergyscanner from qtconnectivity.
I first ported the c++ version to PyQt5, and then added the functionality to communicate with the DBF1 (Serial)
characteristic from the Bluno.

After the connecting and retrieving the services and characteristic I try to communicate with DBF1.
I can write to it, and date is seen on the bluno. Also data is send back, but reading the characteristic only yields the string that was send, not the response.

Here some code snippets from main.py:
Code: Select all
        self.currentService.characteristicWritten.connect(self.writtenToBluno)
        self.currentService.error.connect(self.errorBluno)
        self.currentService.characteristicChanged.connect(self.charChanged)
        self.currentService.characteristicRead.connect(self.charRead)        
Here the callbacks are set for reading, writing and changing the characteristic.
When pushing the "Send" button a command is created and the next function is called to write to DBF1:
Code: Select all
    def sendtoBluno(self, charinfo):
        c = self.currentCharacteristic.getCharacteristic()
        self.currentService.writeCharacteristic(c, charinfo.encode(), QtBt.QLowEnergyService.WriteMode.WriteWithResponse)
And finally the callbacks:
Code: Select all
    @pyqtSlot(QtBt.QLowEnergyCharacteristic, QByteArray)
    def writtenToBluno(self, c, result):
        print(f'Written callback {c.uuid()}   {result}')

    @pyqtSlot(QtBt.QLowEnergyCharacteristic, QByteArray)
    def charChanged(self, c, result):
        print(f'Changed callback {c}   {result}')

    @pyqtSlot(QtBt.QLowEnergyCharacteristic, QByteArray)
    def charRead(self, c, result):
        print(f'Read callback {c}   {result}')
        self.blresult = result
        self.characChanged.emit()
        
    @pyqtSlot(QtBt.QLowEnergyService.ServiceError)
    def errorBluno(self, e):
        print(f'errorBluno {e}')
When, in the app, the command hello is entered and send to the bluno, the following is shown.
Code: Select all
   setCommand to hello
   Written callback PyQt5.QtCore.QUuid('{0000dfb1-0000-1000-8000-00805f9b34fb}')   b'hello\r'
The '\r' is added in the code.
When I later push the "Read" button, the following function is called to read DBF1
Code: Select all
  @pyqtSlot()
    def dddd(self):
        c = self.currentCharacteristic.getCharacteristic()
        self.currentService.readCharacteristic(c)
 
The response then is:
Code: Select all
   Read callback <PyQt5.QtBluetooth.QLowEnergyCharacteristic object at 0x7f62277fb798>   b'h'
The writtenToBluno callback shows the data that was send. Ok, but not very useful.
The charRead callback ONLY shows the first character of the string, also when the Read button is called more often.
I would have expected the response 'ack', with is what the bluno did send.

The question is, why does the read not yield the data send from the Bluno.
The basic assumption is that when I do a writeCharacteristic that, when the bluno sends something back, that data should be retrievable by using readCharacteristic.

Or does the Android app do it differently? I can't find it.

I really would like to make the Bluno a useful device, so I hope that someone can give
me a pointer, or try the code. I will also ask this on the PyQt5 list.

Thanks in advance,
Sietse
2019-12-31 17:04:55
s.achterop wrote:
Tue Nov 12, 2019 1:47 pm
Hello List,
I try to create an app using PyQt5/QML software to talk to the Bluno m0.
It has to work on Linux, Android en iOS, so the existing apps cannot be used.
The current state of the app can be found on https://github.com/SietseAchterop/Bluno_pyqt5

Most of it works, but there are no responses from the Bluno.
I know that the characteristic DFB1 is missing the 0x2902 Descriptor, but that should not
be a problem. The BlunoBasicDemo works on Android and I created a Python program blunoTerminal.py
that works on Linux and uses the bluepy library. Its included in the repository.

The sketch on the Bluno m0, test3.ino in the repository, is a simple program that responds to incoming messages with a reply, e.g. when 'i\r' is send, the response is 'XXInfo, 0, 0\r'.

But I need to use PyQt5 for my app. The app is derived from the lowenergyscanner from qtconnectivity.
I first ported the c++ version to PyQt5, and then added the functionality to communicate with the DBF1 (Serial)
characteristic from the Bluno.

After the connecting and retrieving the services and characteristic I try to communicate with DBF1.
I can write to it, and date is seen on ac market app bluno. Also data is send back, but reading the characteristic only yields the string that was send, not the response.

Here some code snippets from main.py:
Code: Select all
        self.currentService.characteristicWritten.connect(self.writtenToBluno)
        self.currentService.error.connect(self.errorBluno)
        self.currentService.characteristicChanged.connect(self.charChanged)
        self.currentService.characteristicRead.connect(self.charRead)        
Here the callbacks are set for reading, writing and changing the characteristic.
When pushing the "Send" button a command is created and the next function is called to write to DBF1:
Code: Select all
    def sendtoBluno(self, charinfo):
        c = self.currentCharacteristic.getCharacteristic()
        self.currentService.writeCharacteristic(c, charinfo.encode(), QtBt.QLowEnergyService.WriteMode.WriteWithResponse)
And finally the callbacks:
Code: Select all
    @pyqtSlot(QtBt.QLowEnergyCharacteristic, QByteArray)
    def writtenToBluno(self, c, result):
        print(f'Written callback {c.uuid()}   {result}')

    @pyqtSlot(QtBt.QLowEnergyCharacteristic, QByteArray)
    def charChanged(self, c, result):
        print(f'Changed callback {c}   {result}')

    @pyqtSlot(QtBt.QLowEnergyCharacteristic, QByteArray)
    def charRead(self, c, result):
        print(f'Read callback {c}   {result}')
        self.blresult = result
        self.characChanged.emit()
        
    @pyqtSlot(QtBt.QLowEnergyService.ServiceError)
    def errorBluno(self, e):
        print(f'errorBluno {e}')
When, in the app, the command hello is entered and send to the bluno, the following is shown.
Code: Select all
   setCommand to hello
   Written callback PyQt5.QtCore.QUuid('{0000dfb1-0000-1000-8000-00805f9b34fb}')   b'hello\r'
The '\r' is added in the code.
When I later push the "Read" button, the following function is called to read DBF1
Code: Select all
  @pyqtSlot()
    def dddd(self):
        c = self.currentCharacteristic.getCharacteristic()
        self.currentService.readCharacteristic(c)
 
The response then is:
Code: Select all
   Read callback <PyQt5.QtBluetooth.QLowEnergyCharacteristic object at 0x7f62277fb798>   b'h'
The writtenToBluno callback shows the data that was send. Ok, but not very useful.
The charRead callback ONLY shows the first character of the string, also when the Read button is called more often.
I would have expected the response 'ack', with is what the bluno did send.

The question is, why does the read not yield the data send from the Bluno.
The basic assumption is that when I do a writeCharacteristic that, when the bluno sends something back, that data should be retrievable by using readCharacteristic.

Or does the Android app do it differently? I can't find it.

I really would like to make the Bluno a useful device, so I hope that someone can give
me a pointer, or try the code. I will also ask this on the PyQt5 list.

Thanks in advance,
Sietse
I appreciate your work man. Amazing
userHeadPic acmarketonl