Trying to connect multiple devices via Bluetooth LE to android device - java

The Problem
I am trying to connect multiple Bluetooth LE devices (heart rate monitors) to my android device. I am able to scan, and connect to them. They stream just fine, just that when I output the notifications it jumps between one sensor's data to another.
I basically used this GitHub source code for a majority of this project. In the project, they use ONE service (called BluetoothLeService). In my project I have created TWO services, pretty much duplicates of each other except one handles calls for one user, the other one handles for the other user.
I'm getting this output onto the console:
07-27 21:14:01.786 9062-9062/com.example.android.aware D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: true
07-27 21:14:01.786 9062-9062/com.example.android.aware D/BluetoothLeService2: Trying to use an existing mBluetoothGatt for connection. THIS ERROR IS FROM BLS2
07-27 21:14:01.796 9062-10009/com.example.android.aware D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=7 device=E3:64:43:37:D2:AA
07-27 21:14:01.796 9062-10009/com.example.android.aware I/BluetoothLeService2: Disconnected from GATT server.
07-27 21:14:01.796 9062-9062/com.example.android.aware D/BluetoothGatt: setCharacteristicNotification() - uuid: 00002a37-0000-1000-8000-00805f9b34fb enable: true
07-27 21:14:01.816 9062-9062/com.example.android.aware D/BluetoothLeService: Trying to use an existing mBluetoothGatt for connection. THIS ERROR IS FROM BLS1
07-27 21:14:01.826 9062-10009/com.example.android.aware D/BluetoothGatt: onClientConnectionState() - status=133 clientIf=6 device=00:22:D0:41:CA:B6
07-27 21:14:01.826 9062-10009/com.example.android.aware I/BluetoothLeService: Disconnected from GATT server.
Attempts
I've tried to add a new CLIENT_CHARACTERISTIC_CONFIG (called it CLIENT_CHARACTERISTIC_CONFIG2) string in the SampleGattAttributes class, this comes to play in the following code snippet (from the service classes):
BluetoothGattDescriptor descriptor = characteristic
.getDescriptor(UUID
.fromString(SampleGattAttributes.CLIENT_CHARACTERISTIC_CONFIG));
I think the problem, like the consoles says, has something to do with the variable in both Services called mBluetoothGatt (which is a BluetoothGatt type object). My thinking is like this:
If I have two services running synchronously, then if I create two different BluetoothGatt objects in each, why am I being told that the same BluetoothGatt object is being used?

I was not see the source code you referred but did you stored the different BluetoothGattCallback or return values for each connection? I mean how did you judge the two devices?
The connectGatt will return a BluetoothGattCallback instance to notify the status or you can use this instance to do further operations, e.g. know the connect status etc.

I solved this problem by outputting data based on address of the device.
So instead of just spitting out the notifications, I put a condition (is the DisplayData() method) that said, "Hey, only output here if this is the device whose output we're looking for here."
Sure, the devices were not time-synched, but when you log using the time, that helps.

Related

No peers provided by network with hyperledger app on android

With the Commercial paper tutorial, I continue to try to implement the java application to an Android emulator.
On Issue.java, when call Network network = gateway.getNetwork("mychannel"); an error occur : IllegalArgumentException: No peers provided.
Because of network argument by getChaincodeQueryPeersForOrganization(DefaultQueryHandlers.java:50), he don't give me a collection of peers and cause error on SingleQueryHandler.java:29.
I think about connection-org2.yaml file, but don't see what's wrong.
(Default Java app not work correctly)
How can I give the right network, with correct peers ?
Complete error:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: iti.paper.ch.paper_test, PID: 9568
java.lang.IllegalArgumentException: No peers provided
at org.hyperledger.fabric.gateway.impl.query.SingleQueryHandler.<init>(SingleQueryHandler.java:29)
at org.hyperledger.fabric.gateway.DefaultQueryHandlers.lambda$static$0(DefaultQueryHandlers.java:30)
at org.hyperledger.fabric.gateway.-$$Lambda$DefaultQueryHandlers$A9xv6yy6Ls07YnjWxZKkScD7PTQ.create(Unknown Source:0)
at org.hyperledger.fabric.gateway.DefaultQueryHandlers.create(DefaultQueryHandlers.java:73)
at org.hyperledger.fabric.gateway.impl.NetworkImpl.<init>(NetworkImpl.java:54)
at org.hyperledger.fabric.gateway.impl.GatewayImpl.getNetwork(GatewayImpl.java:252)
at iti.paper.ch.paper_test.Issue.main(Issue.java:56)
at iti.paper.ch.paper_test.MainActivity$1.onClick(MainActivity.java:29)
Your SDK uses the connection-org2.yaml to populate the a view of the network to a large degree on the client side. The rest is taken care of by service discovery, should there be any changes subsequently.
Having said that, you should add your channel details in your connection profile (connection-org2.yaml) and specify the roles of the peers. The error that you are seeing is related to the fact that there are no peers defined with chaincode querying roles. You do that by modiying the connection profile and including details similar to this..
channels: //name if the channel
mychannel:
peers:
peer0.org2.example.com:
endorsingPeer: false //this is a role
chaincodeQuery: true //this is a role
discover: true // this is a role
peer1.org2.example.com:
endorsingPeer: false
chaincodeQuery: true
discover: true
Try this and restart your network. Bear in mind that the default scripts will also regenate any connection profles using the template.

BMP280 ServiceSpecificException: I/O error (code 5)

I try to use AndroidThings to measure temperature with Raspberry Pi 3 and BMP280.
3,3V i have choosed because of specification of BMP280:
To power the board, give it the same power as the logic level of your microcontroller
Then i want to initialize sensor
mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1");
And by execution i receive following exeption
Error configuring sensor
com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error (code 5)
at com.google.android.things.pio.I2cDeviceImpl.readRegByte(I2cDeviceImpl.java:81)
at com.google.android.things.contrib.driver.bmx280.Bmx280.connect(Bmx280.java:215)
at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:193)
at com.google.android.things.contrib.driver.bmx280.Bmx280.<init>(Bmx280.java:180)
at com.google.android.things.contrib.driver.bmx280.Bmx280SensorDriver.<init>(Bmx280SensorDriver.java:55)
Also by 5V Power i receive the same exception.
I have found this. But i have no idea how to check, if the BMP280 is realy connected to Raspberry with adb.
By own testing the connectivity i receive by device.readRegByte(0xD0) the same exeption.
Does it mean, that BMP280 is not correctly connected?
If yes, how to correctly connect BMP280 with Raspberry?
Is some resistor needed by connection?
UPDATE
solved by soldering BMP280 with header strip.
Also to work with sensor is permission requiered that could be granded only in command line. ref
adb shell pm grant app.package com.google.android.things.permission.MANAGE_SENSOR_DRIVERS
Looking at your fritzing diagram you had SDO connected to BCM3?
From the datasheet the SDO pin is what determins the address of your sensor.
Connecting SDO to GND results in slave
address 1110110 (0x76); connection it to VDDIO results in slave address 1110111 (0x77)
Most importantly:
The SDO pin cannot be left floating; if left floating, the
I²C address will be undefined.
com.google.android.things.pio.PioException: android.os.ServiceSpecificException: I/O error (code 5)
Therefore your problem is likely an undefined i2c address.
Looking at the code you are using for the Bmx280SensorDriver, it uses the address 0x77
https://github.com/androidthings/contrib-drivers/blob/master/bmx280/src/main/java/com/google/android/things/contrib/driver/bmx280/Bmx280.java#L48
Therefore you should ensure your SDO line is connected to 5V on your raspberry pi. This will ensure your sensor has the correct address.
Or alternatively connect SDO to Ground and use this constructor:
mTemperatureSensorDriver = new Bmx280SensorDriver("I2C1", 0x76);
If you want to understand what the sensor driver is doing "under the hood" there is a great blog post and repo to see that:
http://blog.blundellapps.co.uk/tut-android-things-temperature-sensor-i2c-on-the-rainbow-hat/
https://github.com/blundell/androidthings-i2c-input/blob/master/app/src/main/java/com/blundell/tut/MainActivity.java
;-)
Thanks for informations, for right connection
bmx280 = new Bmx280("I2C1",0x76); and SDO to gnd.
But read values is strange.
myweatherstation D/statie: temp: 186.83298 pres: -296.47287
Is possible to be sensor damaged?
TNX
Cris
To read data from IoT Device, the contact should be fixed without any loose connection.
This could be only reached with soldering of BMP280 with header strip
Only then the connection could be etablished

Originate call to sip trunk via asterisk manager api java

So I am a total newbie in asterisk and managing call lines in general but I managed to install Asterisk Now 13 distro, I have connected 2 sip phones with pjsip and configured a sip trunk which works when I dial an external number with the corresponding prefix. Now I have to programmaticly originate calls and connect them to local extensions which I have no idea how to achieve and I cant seem to find much information about it on the internet after hours of searching.
I managed to connect 2 local sip phones with the asterisk manager api and OriginateAction in the following way:
originateAction = new OriginateAction();
originateAction.setChannel(ConnectionType+"/"+extCaller);
originateAction.setContext(context);
originateAction.setCallerId(idCaller);
originateAction.setExten(tDestination);
originateAction.setPriority(priority);
originateAction.setTimeout(timeoutCall);
managerConnection.login();
originateResponse = managerConnection.sendAction(originateAction, timeoutRequest);
I also tried this channel originate pjsip/201 extension number#from-ptsn and channel originate local/201#from-local extension number#trunkName .
The context of the PJSIP trunk is from-pstn,I tried using that in various ways without luck both in asterisk cli and the application.
How do I make it use the PJSIP trunk when originating the call and make a call out of the office?
EDIT: I originated an outgoing call using a number that completes with the trunk outgoing route requisites and the "from-internal" context like this:
channel originate Local/201#from-internal extension (prefix)numberToCall#from-internal
I still do not understand why this works and if it is the correct answer to my question.
So the answer is in the edit of the question. The only way to generate an outgoing call that I could find is to originate that call "internaly" (with the context "from-internal" which happens to be the same context that is used when originating internal calls) introducing a target number value that completes with the sip trunk's route pattern requirements.
Example:
I have a route configured for the sip trunk( trunk1 ) with a pattern(RegEx): [0]{1}/number/ that means that with a 0 infront of any nubmer it will be a valid value for that route and it will try to call using trunk1.
In the case of AsteriskNow CentOS installation it happens to be with the context "from-internal". Since the asterisk configuration files are owned by the FreePBX it is recomended to use the FreePBX GUI instead of configuring the .conf files of asterisk manualy.
That concludes to :
channel originate Local/201#from-internal extension (0)[numberToCall]#from-internal
Which will make the extension 201 ring first and when picked up it will try to use the sip trunk to dial that [numberToCall] because the route with the 0 is "called".
In order to send that command to asterisk using asterisk-java I wrote the following code:
ManagerConnectionFactory factory = new
ManagerConnectionFactory("serverIp", "username",
"passwd");
ManagerConnection managerConnection=factory.createManagerConnection()
OriginateAction originateAction=new OriginateAction();
final String randomUUID=java.util.UUID.randomUUID().toString();
System.out.println("ID random:_"+randomUUID);
originateAction.setChannel([connectionType]+"/"+[callerExtension]);<-- SIP or PJSIP / 201(the phone that will ring first)
originateAction.setContext("from-internal"); <-- Default FreePBX context
originateAction.setCallerId([callerId]); // what will be showed on the phone screen (in most cases your phone)
originateAction.setExten([targetExten]); //where to call.. the target extension... internal extension or the outgoing number.. the 0[nomberToCall]
originateAction.setPriority([priority]);// priority of the call
originateAction.setTimeout(timeoutCall); // the time that a pickup event will be waited for
originateAction.setVariable("UUID", randomUUID); // asigning a unique ID in order to be able to hangup the call.

Java desktop bluetooth client can not find services

I am new to bluetooth programming, so please keep that in mind.
I am trying to connect to a pulse sensor from a desktop pc, specifically the Zephyr HxM BT. I am not using any device specific drivers, the Java bluetooth library I'm using is Bluecove, and my bluetooth stack is BlueSoleil.
From my understanding, the way I proceed is
1) Scan for BT devices
public void startSearch() throws BluetoothStateException{
System.out.println("Inquiry started");
localdevice.getDiscoveryAgent().startInquiry(DiscoveryAgent.GIAC, this);
}
This works fine, it discovers my pulse belt and calls
public void deviceDiscovered(RemoteDevice arg0, DeviceClass arg1)
2) Search a device for services
Once a device has been discovered, it should be added to the DiscoveryAgent's list of cached devices, this is my first problem as the cache (and preknown devices) is always empty even though I've discovered my belt.
So the way that I do this now is to either keep my own list of devices, or simply start a service search directly from deviceDiscovered.
I am still a bit unsure if I'm using the correct parameters, but from reading the BT device manual and the javax.bluetooth documentation on DiscoveryAgent.searchServices:
public int searchServices(int[] attrSet,
UUID[] uuidSet,
RemoteDevice btDev,
DiscoveryListener discListener)
throws BluetoothStateException
My code:
public void searchServices(RemoteDevice device){
UUID[] uuidSet = new UUID[1];
uuidSet[0]=new UUID("1101",false); //Serial Port
System.out.println("Searching for services on " + device.getBluetoothAddress() );
try{
agent.searchServices(null,uuidSet, device,this);}
catch (BluetoothStateException e){
System.out.println("BluetoothStateException caught.");
}
}
I've set the attributes parameter to null, because the documentation states that this will have it search for services with the default attributes, however I've also tried to use only ServiceID (0x0003) as attribute with no luck.
This is where I'm stuck, I pass the correct BT device into the function, and it starts searching but never give me any results, it just searches forever for all I know, no exception, no calls to
public void servicesDiscovered(int arg0, ServiceRecord[] arg1)
or
public void serviceSearchCompleted(int arg0, int arg1)
So I guess my questions are:
- Am I doing something wrong? Any suggestions?
- What are the other approaches to connecting to a BT device, and what
information do I have to know about the device to do that?
Here is some information that I think is relevant from the device manual:
The following steps have to be undertaken to connect to a HxM device.
1) Activate the Bluetooth service of the device/computer wanting to connect to the HxM
2) Scan for Bluetooth devices in range
3) Pair with the HxM device found in range
4) Discover Services of Paired HxM
5) Connect to serial port of HxM device
The diagram above shows that the Bluetooth HxM typically communicates with a mobile device over the Bluetooth
link. The HxM only supports one link at a time and uses the Bluetooth SPP (Serial Port Profile) to communicate
with other devices with the following low-level protocol:
• 115,200 baud
• 8 data bits
• 1 stop bit
• No parity
Any suggestions are very much appreciated
edit: I just want to add that I'm testing the code with a console input loop, so the program is not immediately terminated after calling searchServices, it should have time to complete unless I'm misunderstanding async tasks
I just wanted to update this and say that I found the problem, it seems that I had to use a short UUID instead of a long. I should have tried both of these options before I deemed myself stuck, but I didn't think it would make any difference.

Reconnect to a device after device crashed

I have the following problem with the libusb-java and some self-made devices.
It could happen that such a device disconnects from the USB Port because it drains to much power (as an example: i have a USB-LED Light which needs sometimes more than 500mA).
In this case the USB Controller will reset the device and the device will startup normaly again.
Now i cant really detect such a problem except for trying to reinit the device on every Exception. But thats not working...
On Every Exception i call my init Method again, which looks like this:
private void initDevice() {
USB.init();
this.dev = USB.getDevice(idVendor, idProduct);
}
The Problem with that is, this runs without any problem, but the i get this error message when i want to send new data:
LibusbJava.controlMsg: error sending control message: Protocol error
How do i can reinit the device? Do i have to reset the bus or something?
You will need to call open() on the device - it is new for the system.

Categories

Resources