How to scan iBeacon in ionic 3? - ionic-framework

I have a project that scans a iBeacon, and i had also learned this plugin
I have also googled so many projects for that but can't get expected result.
Here i had some code that I write for scan a beacon
listenToBeaconEvents() {
this.events.subscribe("didRangeBeaconsInRegion", data => {
// update the UI with the beacon list
this.zone.run(() => {
let json = data.region;
console.log("-------Beacons-------" + JSON.stringify(json));
this.beacons.push({
uuid: JSON.stringify(json.uuid),
identifier: JSON.stringify(json.identifier),
typename: JSON.stringify(json.typeName)
});
});
}
But my question is if i don't have an UUID of particular beacon then how i can search the beacon?
Please Help me. Thanks.

On iOS you cannot find beacons without a particular UUID -- the platform simply does not allow you to do this. Android has no such restriction.
See this related question for a more detailed explanation:
iOS iBeacon: How to get all of proximityUUID programmatically?

Related

flutter_reactive_ble scanned devices not including device UUIDs

_scanStream = flutterReactiveBle
.scanForDevices(withServices: <Uuid>[]).listen((device) {
_foundBleUARTDevices.add(device);
for (var element in _foundBleUARTDevices) {
print(
"${element.serviceUuids}---${element.name}---${element.id}---${element.serviceData}---${element.rssi}");
}
I am using the above code snippet to scan for BLE devices and on discovering and printing them out, the UUID is an empty list, and when I try to scan with a specific UUID no device is found. I am using ESP32 as the BLE device and android as the platform to run/debug the app
after waiting for hours, I got no answer from anyone and I had to keep trying, and what I find out is that I can actually connect to the BLE device without the Service UUID but just the id which is the BLE device mac address I think.
I used the below snippet to establish the connection:
void _connectToDevice() {
// We're done scanning, we can cancel it
// _scanStream.cancel();
// Let's listen to our connection so we can make updates on a state change
Stream<ConnectionStateUpdate> _currentConnectionStream = flutterReactiveBle
.connectToAdvertisingDevice(
id: _ubiqueDevice.id,
prescanDuration: const Duration(seconds: 3),
withServices: <Uuid>[]);
_currentConnectionStream.listen((event) {
print(":::::::: ${event.connectionState.name}");
});
}
so I will now proceed to see how I can read and write to the characteristics, i hope someone find this helpful

Flutter - flutter_blue is there a way to call read/write when the characteristics known

I try to implement a flutter code that will control NIR Spectrometer via BLE.
I have a very long protocol of service and characteristic uuid pair, and I actually did the same in ionic by just using the uuid pairs and it worked fine...
Is there a way in flutter to call read/write/notify with out do all the:
List<BluetoothService> services = await device.discoverServices();
services.forEach((service) {
// do something with service
for(BluetoothCharacteristic c in characteristics) {
// save the characteristic for latter usage if needed
}
});
something like:
c = BluetoothCharacteristic(device, service_uuid, characteristic_uuid); // why there is no constructor!!
It's going to make life more easy for me!
I finally gave up, also some services that I need don't do advertisement.. So I started to use the plugin flutter_reactive_ble which gives me this option

Flutter and Adafruit Feather nRF52: Could not locate CCCD descriptor

I'm trying to set up notify so that my BLE with sensor can send data to my android phone. My embedded code is based off of the example for Custom HRM on Adafruit's site (https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/custom-hrm ) and the code for flutter is based off flutter blue's example
for (final BluetoothService service in services) {
if(service.uuid == widget.serviceID){
for (final BluetoothCharacteristic characteristic in service.characteristics) {
if(characteristic.uuid == widget.charID) {
await characteristic.setNotifyValue(true);
characteristic.value.listen((value) {
print(value);
});
}
}
I keep getting this error:
Unhandled Exception: PlatformException(set_notification_error, could not locate CCCD descriptor for characteristic: 00002a24-0000-1000-8000-00805f9b34fb, null, null)
I tested my flutter code for every available characteristic in case my ID is wrong (it's not though). I also tried printing out all descriptors for that characteristic and found out there's none.
In the example adafruit code, we don't need to add any descriptors, we only need to do
characteristic.setProperties(CHR_PROPS_NOTIFY);
characteristic.setPermission(SECMODE_OPEN, SECMODE_NO_ACCESS);
Am I missing something? How can I fix this?
Solved: It was a hardware issue. Service and characteristic UUIDs weren't setting correctly. Tested on a new Feather nRF52 and everything is good.

How to get heading accuracy of mobile devices?

I offer a service which needs the correct location and heading of the mobile device the user is accessing my service with. It was relatively easy to get the information but now I am stuck at finding out how accurate the heading I received is.
Since I'm not using any framework for this or develop in Android/iOS, where there are solutions for that problem, I'd need a solution only depending on javascript (+ 3rd party libraries).
I've found the Generic Sensor API from W3C but couldn't find any sensor which hold that information. Neither the Accelerometer-, nor the AbsoluteOrientationSensor held the needed information.
My current code looks like that..
let accelerometer = null;
try {
accelerometer = new Accelerometer({ frequency: 60 });
accelerometer.addEventListener('error', event => {
// Handle runtime errors.
if (event.error.name === 'NotAllowedError') {
console.log('Permission to access sensor was denied.');
} else if (event.error.name === 'NotReadableError') {
console.log('Cannot connect to the sensor.');
}
});
accelerometer.addEventListener('reading', (event) => {
console.log(accelerometer);
console.log(event);
});
accelerometer.start();
.. but since the problem if more of a 'finding the right tool to do the job'-type, it won't help much in better depicting my problems. Further, Google uses kind of the same functionality I'm aiming for in Google Maps, so theoretically there must be a way to get the heading accuracy.
So, in conclusion, is there any way to retrieve the heading accuracy in a simple javascript environment?
Thanks!

How to get current location in google maps using "nativescript-google-maps-sdk"?

I am building an app on nativescript+Angular2. I have downloaded the "nativescript-google-maps-sdk" plugin from npm. If I enable setMyLocationEnabled(true), I get the "my-location" button on the upper right corner of the screen and clicking it takes me to my actual location.
What I would like to do is to get these coordinates programmaticaly, because I will need them for other operations (markers, proximity values etc.).
Ran through their code, but couldn't find how they are getting this current location. gMap.getMyLocation() is deprecated, so I can't use that, based on what's written here: https://developers.google.com/android/reference/com/google/android/gms/maps/GoogleMap
We should be using FusedLocationProviderApi. If this plugin isn't using it, then how does it acquire current location?
Can anyone shed some light?
mapReady(args) {
console.log("Map Ready");
var gMap = args.gMap;
gMap.setMyLocationEnabled(true);
// gMap.getMyLocation(); deprecated
// need to get current location coordinates, somehow...
}
The nativescript-google-maps-sdk plugin doesn't support getting your location from the device.
You need to get the location from nativescript-geolocation ( you are already doing that) and then pass that to the google-map.
If you check the google-maps plugin's AndroidManifest.xml, it doesn't have the permission to access the device's location.
So, as it turns out, you can get your location from your device in 2 ways:
with built in android LocationManager
with google play services location module, which uses FusedLocationProviderApi which is built on default android LocationManager
The difference, from what I've read, is that the googles' version is more advanced - it switches from different location modes (gps, wifi) automatically and saves up your battery.
So, in order to use the googles' way, we need to:
Import google play services location module (+ means newest version):
dependencies {
compile 'com.google.android.gms:play-services-location:+'
}
Then initialise the play services API:
declare var com: any;
GoogleApiClient = com.google.android.gms.common.api.GoogleApiClient;
LocationServices = com.google.android.gms.location.LocationServices;
var dis = this; // writing in typescript, so this is reference to our current component where this code will lay
// Create an instance of GoogleAPIClient.
if (this.googleApiClient == null) {
this.googleApiClient = new dis.GoogleApiClient.Builder(application.android.context)
.addConnectionCallbacks(new dis.GoogleApiClient.ConnectionCallbacks({
onConnected: function() {
console.log("GoogleApiClient: CONNECTED");
}.bind(this),
onConnectionSuspended: function() {
console.log("GoogleApiClient: SUSPENDED");
}.bind(this)
}))
.addOnConnectionFailedListener(new dis.GoogleApiClient.OnConnectionFailedListener({
onConnectionFailed: function() {
console.log("GoogleApiClient: CONNECTION ERROR");
}.bind(this)
}))
.addApi(dis.LocationServices.API)
.build();
}
this.googleApiClient.connect();