Ganglion/Simblee streaming Bluetooth to Android Studio Project?

2»

Comments

  • NaughtiusMaximusNaughtiusMaximus San Diego, California
    Hi Florian,

    I am working with the code now:

    I noticed in BluetoothLeService.java that there were line/comments such as this:
    mBluetoothAdapter.startLeScan(mLeScanCallback); ///yes this is deprecated, but there isn't a decent enough example for the replacement to emulate

    I found online that 'BluetoothAdapter' should be replaced with 'BluetoothLeScanner' :
        private BluetoothLeScanner mBluetoothScanner; // *** DEPRECATED *** private BluetoothAdapter mBluetoothAdapter;

    So now there is:
    mBluetoothScanner.startScan(mLeScanCallback);
    mBluetoothScanner.stopScan(mLeScanCallback);

    And the callback needs to change too:

        // Device scan callback.
        private ScanCallback mLeScanCallback = new ScanCallback() {

                @Override
                public void onScanResult(int callbackType, ScanResult result)
                {
                    final BluetoothDevice device = result.getDevice();

                    if(device.getName()!=null) {
                        mIsDeviceGanglion = device.getName().toUpperCase().contains(SampleGattAttributes.DEVICE_NAME_GANGLION);
                    }
                    else{//device name is not available
                        mIsDeviceGanglion= false;
                    }

                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {

                            Log.v(TAG,"Found LE Device "+ device.getName());
                            mLeDeviceListAdapter.addDevice(device);
                            mLeDeviceListAdapter.notifyDataSetChanged();
                        }
                    });
                }


                @Override
                public void onBatchScanResults(List<ScanResult> results) {
                    Log.w( "ScanCallback", "onBatchScanResults");
                    super.onBatchScanResults(results);
                }


                @Override
                public void onScanFailed(int errorCode) {
                    Log.w("ScanCallback", "onScanFailed");
                    super.onScanFailed(errorCode);
                }

            };

        static class ViewHolder {
            TextView deviceName;
            TextView deviceAddress;
        }

    I'd be happy to email the complete file or post somewhere.

    Best regards,
    Max
  • wjcroftwjcroft Mount Shasta, CA
    Can there be a public "sample app" / demo app? That, for example, displays the live 4 channel graph? The same screen might also display a numeric counter that accumulates any packet number sequencing errors. This could give a rough estimate of the connection quality. So that if you increased distance between the mobile and the Ganglion past a certain threshold, you may see this start to climb.

    Max, do you use Github? If so you could just issue a pull request to Florian on your mods.
  • NaughtiusMaximusNaughtiusMaximus San Diego, California
    Hi William,

    I was thinking of the very same thing!  I am learning Florian's code to see how to at least keep a running count of dropped packets.

    I have used MPAndroidChart (https://github.com/PhilJay/MPAndroidChart) in another application, for showing a live channel.  This could be integrated into Florian's application.

    Yes, I use GitHub. 

    Best regards,
    Max
  • @NaughtiusMaximus ;

    Good find, would you mind to either make a pull request or send me the updated file?


    It is already a demo app, but it doesn't have a graph implemented. 

    The functionality to keep track of any dropped packets is already in there - updatePacketsCount() is called every time new data is available and compares the packet ids to see how many packets have been lost. 
    The method getPacketLoss() calculates the packet loss in % of total packets.

  • wjcroftwjcroft Mount Shasta, CA
    Florian, cool. I have not run your demo app. What does it display / any user interface? Does it just display a percentage packet loss? I believe you said earlier that there was a substantial loss during startup phase, but none after that. How would the display make this more clear? A percentage figure does not make obvious the current packet loss. Does the app also display the current count of lost packets? So that one can see new packets lost when that increments?

    Regards,

  • NaughtiusMaximusNaughtiusMaximus San Diego, California
    Hi William and Florian,

    I added the following to 'BluetoothLeService.java':

    public static int getTotalPackets() { return totalPackets; }

    public static int getLostPackets() { return lostPackets; }

    public static double getPacketLossPercent()
    {
    int packetNumber = lostPackets + totalPackets;
    double packetLoss = (double)lostPackets*100/packetNumber;
    return packetLoss;
    }

    I then added the following to 'DeviceControlActivity.java' to see current packet statistics on the screen:

    TextView stats = findViewById(R.id.packetStatisticsTextView);
    stats.setText("Total pkts: " + BluetoothLeService.getTotalPackets() + ", lost pkts: " + BluetoothLeService.getLostPackets() + ", % loss: " + BluetoothLeService.getPacketLossPercent() );

    Looks good: so far no packet loss!

    Max

  • NaughtiusMaximusNaughtiusMaximus San Diego, California
    Hi Florian and William,

    Is there a way to poll the Ganglion for the battery level?  I don't see a way to do this in either the code or the documentation.

    Thanks,
    Max
  • wjcroftwjcroft Mount Shasta, CA
    edited October 2018
    It's not built in. But the Simblee has some spare analog to digital converter pins. You could rig up a (resistor) voltage divider and monitor the battery level on one of the spare aux channels.

    This thread is not exactly what you want, but discusses the aux channels.

  • NaughtiusMaximusNaughtiusMaximus San Diego, California
    Hi William,

    Good to know.  The battery level is not too important now, but a nice-to-have feature at some point.

    Thanks,
    Max
  • NaughtiusMaximusNaughtiusMaximus San Diego, California
    Hi Florian and William,

    Great news: I ran
    the Ganglion connected to my Amazon (Android) tablet for 10 hours with
    NO lost packets!  I used a modified version of the demo app:

    I added plotting for channel #1 and also persisted the channel #1 data and the packet index number.  All works great!  Thanks!

    Best regards,
    Max
  • wjcroftwjcroft Mount Shasta, CA
    Max, Florian, that's fantastic!

    Max, what is your Github link with the complete source including the plots? Upload a photo or screenshot to Google Drive and leave the link.

    This would make a great post on the OpenBCI Community announcement page,


    Even the next newsletter.


    Best regards,

    William

Sign In or Register to comment.