Using Flutter to connect and write to Bluetooth Devices - bluetooth

I'm new with Flutter and am just trying to make this work.
Am using Flutter Blue https://pub.dartlang.org/packages/flutter_blue
It connects though, just this issue when writing.
But when writing i'm receiving this message. Not sure what I am doing wrong though.
here's my code..
onPressed: () {
print("HEY write pressed");
var fff1 = new Guid("0000fff1-0000-1000-8000-00805f9b34fb");
var fffa = new Guid("0000fffa-0000-1000-8000-00805f9b34fb");
BluetoothCharacteristic characteristic = new BluetoothCharacteristic(uuid: fffa, serviceUuid: fff1, descriptors: null, properties: null);
_writeCharacteristic(characteristic);
},
PlatformException(locateCharacteristic, service could not be located on the device, null)
I've tried following this post.
Flutter Blue Read characteristic UUID
In production I would probably save the UUID as variables, but the effect should be similar..
If anyone has any guidance or tips that would be super welcome.

Your code is right but the device you want to connect to doesnt contain this service :var fff1 = new Guid("0000fff1-0000-1000-8000-00805f9b34fb");
Check which services exist in the device you want to connect to.

Related

Web Bluetooth - Show extra info on scanning dialog

I'm trying to support web-bluetooth to connect to my devices and perform a simple task (such as playing LED).
However, the device information showed on the scanning dialog when calling navigator.bluetooth.requestDevice is not so clear. It only shows the device name and a random (?) hex string.
The problem here is all my devices have the same name (AWESOME_LED), thus it's not easy for the user to select the correct LED if all scanning items show the same device name info. As far as I know, we can not custom to add more info showing on the scanning dialog.
I come up with a new solution that is changing the device name to unique for each LED with the format AWESOME_LED + [uniqueid] e.g AWESOME_LED1, AWESOME_LED2, AWESOME_LED3 so that the user can distinguish one from the others.
My question are:
Is there any alternative solution without making the device name unique?
If not, is there any problem / rejection / limitation from Apple or Google for my current app on App Store / Google Play by not using the same device name for all devices? I have been investigating it at Apple forums / Accessory Design Guidelines and looks like there are no problems, just to make sure if anyone has faced trouble from Apple / Google.
Thanks for your help.
Scanning dialog
My question are:
Is there any alternative solution without making the device name unique?
The browser prompt is not customisable yet. One solution you highlighted already is to make your LED device name unique. If you're able to control the device, why not having one AWESOME_DEVICE name and a GATT characteristic you can write to that controls individual LED colors. Maybe something like:
const device = await navigator.bluetooth.requestDevice({
filters: [{ name: "AWESOME_DEVICE" }],
});
const server = await device.gatt.connect();
const service = await server.getPrimaryService(0x1234); // Your service UUID
const characteristic = await service.getCharacteristic(0x5678); // Your characteristic UUID
// Set LED #1 to red color.
await characteristic.writeValue(
new Uint8Array(/*ledIndex=*/ 1, /*r=*/ 255, /*g=*/ 0, /*b=*/ 0)
);
If not, is there any problem / rejection / limitation from Apple or Google for my current app on App Store / Google Play by not using the
same device name for all devices? I have been investigating it at
[Apple forums][1] / [Accessory Design Guidelines][2] and looks like
there are no problems, just to make sure if anyone has faced trouble
from Apple / Google.
None that I'm aware of.

noble.state is set to "poweredOff" immediately after running the program. (Node.js Noble)

as the title suggests, I made a simple program made with Node.js and Noble to scan for devices with Bluetooth LE. My end goal here is to connect to my daydream view controller and receive information from it.
My problem is that whenever I run the file the state is set to "poweredOff" even though I set it to "poweredOn". When the state is set to "poweredOff" it stops scanning so I am never able to find devices.
Here is my code:
const noble = require('noble')
noble.on('stateChange', function(state) {
console.log("[STATE] State changed to: ", state)
if (state === 'poweredOn') {
console.log("[STATE] Powered on, now scanning")
noble.startScanning();
} else {
console.log("[STATE] Powered off, stopped scanning")
noble.stopScanning();
}
})
noble.state = "poweredOn"
// we found something
noble.on("discover", function(peripheral){
console.log(peripheral)
})
Here is the output I get after running that:
[STATE] State changed to: poweredOff
[STATE] Powered off, stopped scanning
What have I tried?
I have checked that I have all the prerequisites for Noble.
I have tried to run the examples provided by Noble. (same thing happens)
And I have tried moving noble.state = "poweredOn" above and below the noble.on('stateChange') event
I also figured out the problem is not in the daydream controller because I downloaded the LightBlue app on my phone and it detects and connects to the daydream controller just fine. I get no errors or anything at all. This is very strange to me and I hope that anyone could help me.
Thanks in advance.

Transmitting as iBeacon in XAMARIN - AltBeacon library

I have come across a problem with iBeacon transmission in AltBeacon library in XAMARIN.
In Android Studio, this code works perfect (I can detect created iBeacon on iPhone). I am using Android 5:
mBeaconTransmitter = new BeaconTransmitter(this, new BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
Beacon beacon = new Beacon.Builder()
.setId1("FDA50693-A4E2-4FB1-AFCF-C6EB07647825")
.setId2("1000")
.setId3("2000")
.setManufacturer(0x004C)
.setTxPower(-59)
.setDataFields(Arrays.asList(new Long[] {0l}))
.build();
mBeaconTransmitter.startAdvertising(beacon);
However, I have not managed to attain the same result in XAMARIN (Visual Studio). I cannot detect created iBeacon on iPhone in this case:
var iBeaconParser = new BeaconParser();
iBeaconParser.SetBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24");
BeaconTransmitter beaconTransmitter = new BeaconTransmitter(ApplicationContext, iBeaconParser);
var beacon1 = new AltBeacon.Builder().SetId1("FDA50693-A4E2-4FB1-AFCF-C6EB07647825")
.SetId2("1000").SetId3("2000").SetTxPower(-59).SetManufacturer(0x004C).Build();
beaconTransmitter.StartAdvertising(beacon1);
The transmission also works in the second case. Other Android device could detect the created iBeacon. It was unsuccessful to detect the iBeacon on iPhone.
Thank you for any advice.
Hey buddy it's been almost 3 years you have ask this question so I don't know that is it still relevant for you or not but my be this will help others.
I have seen this code this is absolutely right for the beacon broadcasting and I will suggest to check that if you have bind IBeaconconsumer with beacon manage in the initialization function Bind((IBeaconConsumer)Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity); or check that if you have use _tagRegion and this refers to right one.
Hope this will help.

socket.io - io.sockets.adapter object?

I'm experimenting with socket.io and trying to build a multi-room chat app. The guide I'm following is out of date using pre 1.0.0 socket.io.
I'm trying to find a list of connected clients in a given room. Googling around shows that I have to use the adapter. However, I cannot find the documentation for it anywhere. I searched for it in the git-hub doc but search didn't return any information on adapter. https://github.com/socketio/socket.io-client/blob/master/docs/API.md
Can someone point me in the right direction and where I can read more about adapter and associated methods on it? Also if you can provide the most up to date documentation for socket.io I'd greatly appreciate it. Thank you.
You can get a map of all rooms in the top level namespace like this:
io.nsps['/'].adapter.rooms
You can list the sockets in one of those rooms like this:
function getSocketsInRoom(room, namespace = '/') {
let room = io.nsps[namespace].adapter.rooms[room];
return room.sockets;
}
As best I can tell, this kind of stuff is simply not documented. I've only discovered things like this by examining how things are stored in the debugger. That may or may not mean it's subject to change in the future - I really have no idea.
sockets:
{ '2v8OmIS4qTGX61-YAAAC': true, '3YnScxOgpmAGhZWsAAAG': true },
length: 2 }
it gives u this output. So it basically gives you the clientId and whether it is connected or not and total number of clients connected to a specific room. When the code below is executed (in server side written in node.js) gives u the above output.There is currently two clients connected to the same room named "hello".
var clientsInRoom = io.sockets.adapter.rooms[room];
but when u write this code below and console log it
var clientsInRoom = io.sockets.adapter.rooms
when single client is connected it will console log this
{ '9mVAHSDwcwnqsF4aAAAA':
Room { sockets: { '9mVAHSDwcwnqsF4aAAAA': true }, length: 1 } }
this crazy '9mVAHSDwcwnqsF4aAAAA' literals is client id which is unique for each client

Auto focus camera without preview

I am running Win10 IoT on a pi 2. I need to be able to take pictures that are focused but cannot get the focus working. The application is a background app so I don't have a way of previewing the camera on a display. Is there any way of doing this? Currently I have
await _mediaCapture.StartPreviewAsync();
_mediaCapture.VideoDeviceController.FocusControl.Configure(new FocusSettings
{
Mode = FocusMode.Continuous,
WaitForFocus = true
});
await _mediaCapture.VideoDeviceController.FocusControl.FocusAsync();
await _mediaCapture.CapturePhotoToStreamAsync(ImageEncodingProperties.CreateJpeg(), stream);
await _mediaCapture.StopPreviewAsync();
but I am getting the error
WinRT information: Preview sink not set
when I try to focus. All of the examples I've seen online show that the preview is output to a control and I assume it wires a sink up automagically. Is there a way to do this manually through code? Possibly without the preview?
I wonder if the code may work even without FocusControl.
I propose you follow Customer Media Sink implementation example and use of StartPreviewToCustomSinkIdAsync method described at http://www.codeproject.com/Tips/772038/Custom-Media-Sink-for-Use-with-Media-Foundation-To
I didn't find a way to do this. I ended up converting the background app to a UI app with a Page containing a CaptureElement control in order to preview and focus.
Instead of adding a UI, just create a CaptureElement and set the source to the _mediaCapture before calling await _mediaCapture.StartPreviewAsync();
Something like:
_captureElement = new CaptureElement { Stretch = Stretch.Uniform };
_mediaCapture = new MediaCapture();
await _mediaCapture.InitializeAsync(...);
_captureElement.Source = _mediaCapture;
await _mediaCapture.StartPreviewAsync();

Resources