Windows Store App can't find Bluetooth Arduino - windows

I'm trying to communicate with an Arduino over bluetooth using the Windows.Networking.Sockets namespace for Windows 8.1 Store apps. For some reason PeerFinder can't find the Arduino and the pairedDevices collection is empty. I manually paired the Arduino in the Settings App in Windows, so I know the problem isn't the Arduino code. If anyone can help me fix my code so I can find the Arduino it'd be much appreciated
PeerFinder.Start();
PeerFinder.AllowBluetooth = true;
PeerFinder.AlternateIdentities["Bluetooth:Paired"] = string.Empty;
var pairedDevices = await PeerFinder.FindAllPeersAsync();
int i = 0;
//Look for paired Arduino
while (i <= pairedDevices.Count)
{
if (pairedDevices[i].DisplayName == "HC-05")
{
break;
}
}

Related

Where is the list of device driver images stored in ETW?

I am trying to programatically get the list of device drives from an ETW with the great TraceProcessing Library which is used by WPA.
using ITraceProcessor processor = TraceProcessor.Create(myEtlFile, new
TraceProcessorSettings
{
AllowLostEvents = true,
AllowTimeInversion = true,
});
myProcesses = processor.UseProcesses();
foreach (var process in myProcesses.Result.Processes)
{
foreach (var dll in process.Images)
{
// get dll.Path, dll.FileVersion, dll.ProductVersion, dll.ProductName, dll.FileVersionNumber, dll.FileDescription
}
}
This works for every process except the Kernel (System(4)). Why do I have only 3 dlls in the System process? I would expect the driver files in the System process there as well. In CPU sampling the image is there so it looks like everything is right there.
This would be very useful to check for driver versions if the data is present. But so far I was not able to find it. Am I missing something here?
Happy to hear you enjoy using the TraceProcessor library!
Device drivers are logged against the "Idle (0)" process by ETW, here is an example:
using var tp = TraceProcessor.Create(#"trace.etl");
var processes = tp.UseProcesses();
tp.Process();
var idleProcess = processes.Result.Processes.FirstOrDefault(x => x.Id == 0);
foreach (var image in idleProcess?.Images)
{
Console.WriteLine(image.Path);
}

Trouble with connecting to wifi in code in Xamarin

I've been trying to connect to a specific wifi through code, but with no succcess.
This is what i've come up with:
public void ConnectToWifi(string ssid, string password)
{
WifiManager wifiManager = (WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService);
if (!wifiManager.IsWifiEnabled)
{
wifiManager.SetWifiEnabled(true);
}
string formattedSsid = $"\"{ssid}\"";
string formattedPassword = $"\"{password}\"";
WifiConfiguration wifiConfig = new WifiConfiguration
{
Ssid = formattedSsid,
PreSharedKey = formattedPassword
};
var addNetwork = wifiManager.AddNetwork(wifiConfig);
WifiConfiguration network = wifiManager.ConfiguredNetworks.FirstOrDefault(n => n.Ssid == ssid);
if (network == null)
{
Console.WriteLine($"Cannot connect to network: {ssid}");
return;
}
wifiManager.Disconnect();
bool enableNetwork = wifiManager.EnableNetwork(network.NetworkId, true);
}
I've added permissions.
When testing it does turn the wifi on atleast, so i know it works until that point. What seems not to be working is the AddNetwork part.
I appreciate any help i can get!
You are missing one key method - reconnect(). You can read more about it in the WifiManager's docs here
The important part of the documentation is:
Reconnect to the currently active access point, if we are currently disconnected.
So, what you need to do it after you have disconnected and enabled your new network, call in the end this and you will be good to go:
wifiManager.Disconnect();
wifiManager.EnableNetwork(network.NetworkId, true);
wifiManager.Reconnect(); // This is the missing method
NB: Keep in mind that most of the WifiManager's code that you are using is being obsolete starting Android 10. So, if you want to target Android 10, then you will need to write an additional code for the connectivity for devices with Android 10+.

Blocking specific USB drives on MacOS

I need to block specific USB drives on MacOS. I found two methods.
Use Disk Arbitration framework and register approval callback.(user mode)
Use MAC policy API in kernel extension and register mpo_mount_check_mount callback.(kernel mode)
In user mode, I can get a kDADiskDescriptionDeviceVendorKey which is the vender id of USB drive. I'm wondering how I can get the same information in mpo_mount_check_mount callback or some other API I don't know. The MAC policy API is undocumented and browsing the XNU source code is extremely challenging for a new MacOS developer.
This is a screenshot from IORegistryExplorer. Could I get this information from a kernel extension using MACF or other APIs? Thanks!
I can use DiskArbitration and IOKit frameworks to get vender id in user mode, but I cannot use the same code in kernel extension.
This is my code.
int GetVenderId(DADiskRef dsk, int *vid)
{
io_service_t ioService;
CFTypeRef vendorid;
ioService = DADiskCopyIOMedia(dsk);
if (0 != ioService)
{
vendorid = IORegistryEntrySearchCFProperty(ioService, kIOServicePlane, CFSTR("idVendor"), NULL, kIORegistryIterateParents | kIORegistryIterateRecursively);
if(0 != vendorid)
{
if (CFNumberGetValue(vendorid, kCFNumberIntType, vid))
{
return 0;
}
CFRelease(vendorid);
}
IOObjectRelease(ioService);
}
return 1;
}

Get iOS device ip address in xamarin

hi can you please tell me how to access iOS device ip address using xamarin. we are building iOS app in which we want to show device local ip address. I used many other solutions but they didnt work for me.
I found a post about it here: https://forums.xamarin.com/discussion/348/acquire-device-ip-addresses-monotouch-since-ios6-0
it goes as follow:
Try using System.Net.NetworkInformation.NetworkInterface:
foreach (var netInterface in NetworkInterface.GetAllNetworkInterfaces()) {
if (netInterface.NetworkInterfaceType == NetworkInterfaceType.Wireless80211 ||
netInterface.NetworkInterfaceType == NetworkInterfaceType.Ethernet) {
foreach (var addrInfo in netInterface.GetIPProperties().UnicastAddresses) {
if (addrInfo.Address.AddressFamily == AddressFamily.InterNetwork) {
var ipAddress = addrInfo.Address;
// use ipAddress as needed ...
}
}
}
}

BluetoothLEAdvertisementWatcher doesn't work

I have Windows 10 Pro, build 10586.494 on HP ZBook G2. When I go to Settings -> Devices -> Bluetooth and switch on Bluetooth, I can see nearby BLE devices (they are custom made BLE devices manufactured by my company).
I want to interact with my BLE devices in Universal Windows application (in Visual Studio 2015). I use this code (it is just a snippet of code)
BluetoothLEAdvertisementWatcher watcher;
//....
watcher = new BluetoothLEAdvertisementWatcher { ScanningMode = BluetoothLEScanningMode.Active };
watcher.Received += WatcherOnReceived;
watcher.Start();
//....
private void WatcherOnReceived(BluetoothLEAdvertisementWatcher sender, BluetoothLEAdvertisementReceivedEventArgs btAdv)
{
}
When I run this application, WatcherOnReceived is never executed (although watcher.Start was executed). Why and how to fix it?
If found a better workaround for this. (I'm using Win 10 1803.)
First, to recap the problem since the original question is not entirely clear about it:
BluetoothLEAdvertisementWatcher works if BLE device is advertising before watcher.Start()
BluetoothLEAdvertisementWatcher does not work if BLE device starts advertising after watcher.Start()
If BluetoothLEAdvertisementWatcher is not working after watcher.Start(), it will begin working when Windows 10 Bluetooth Settings is opened or closed (i.e. the opening or closing of the settings window triggers BluetoothLEAdvertisementWatcher to start working)
So, the workaround I came up with is to keep starting and stopping a second BluetoothLEAdvertisementWatcher in the background to create the same sort of trigger that the Windows Bluetooth Settings window provides.
For example, using a WinForms timer:
...
var timer = new Timer { Interval = 1000 };
timer.Tick += Timer_Tick;
timer.Start();
...
private void Timer_Tick(object sender, EventArgs e)
{
var watcher = new BluetoothLEAdvertisementWatcher();
watcher.Received += (s, a) => { };
watcher.Start();
Task.Delay(500).ContinueWith(_ => watcher.Stop());
}
I have to keep Bluetooth switched on in Settings -> Devices -> Bluetooth in order to receive advertisements in my app.

Resources