I am currently trying to get Advertisement Packets from Bluetooth LE in Windows 10.
I am developing an Universal Windows Application, thus I am using JavaScript with the following code:
// Create and initialize a new watcher instance.
var watcher = new Windows.Devices.Bluetooth.Advertisement.BluetoothLEAdvertisementWatcher();
watcher.signalStrengthFilter.inRangeThresholdInDBm = -126;
watcher.signalStrengthFilter.outOfRangeThresholdInDBm = -126;
watcher.signalStrengthFilter.outOfRangeTimeout = 60000;
watcher.signalStrengthFilter.samplingInterval = 0;
watcher.scanningMode = 1;
watcher.addEventListener("received", onAdvertisementReceived, false);
These are my settings to get the most BLE ADV Packets.
In my scenario I have a BLE transponder sending an ADV packet every second, which I can verify on a linux-machine with WireShark.
Strangely I don't get all of these ADV packets with the Windows application.
I will get like 15-20 packets and then there is a 30-60s pause before getting other packets.
All devices (windows-machine, linux-machine and ble-transponder) are within a 1m radius. So I think I should get the same packets on the windows-machine like on the linux-machine, but I don't. Why is that? Are my settings wrong or is there a better way of getting ADV packets?
Thank you in advance.
See my answer at BLE Scan Interval Windows 10.
Basically, Windows instructs the BLE controller to scan for 18.125 ms and then to sleep for 100 ms. That's why you don't get all packets.
Related
Problem: How can I detect when the audio UAC1 gadget is used from a host device?
Background: I created a USB audio gadget using USB Audio Class 1 (UAC1) to send/receive audio over USB from a Linux device to/from a Windows host. The gadget is already working and Windows detects the device as an audio in and output. I am also able to send and receive audio over the gadget using alsa and jack.
Detailed Problem: I'm trying to connect two different audio devices with Jack to route an incoming signal from audio-device-1 to the output of audio-device-2. To do this, I'm working with the virtual wiring of Jack. This works already fine, but I run into the problem that if the gadget device is not actively selected as audio in and output in a DAW or other program on the host computer (e.g. Windows), Jack gets a "poll time out" error and the virtual wiring has to be restarted.
$ jackd -r --name default -d alsa --device hw:2 -r 48000 -p 64 -n 2
jackdmp 1.9.17
....
creating alsa driver ... hw:2|hw:2|64|2|48000|0|0|nomon|swmeter|-|32bit
configuring for 48000Hz, period = 64 frames (1.3 ms), buffer = 2 periods
ALSA: final selected sample format for capture: 24bit little-endian in 3bytes format
ALSA: use 4 periods for capture
ALSA: final selected sample format for playback: 24bit little-endian in 3bytes format
ALSA: use 4 periods for playback
ALSA: poll time out, polled for 2000981 usecs, Retrying with a recovery, retry cnt = 1
ALSA: poll time out, polled for 2000979 usecs, Retrying with a recovery, retry cnt = 2
ALSA: poll time out, polled for 2000982 usecs, Retrying with a recovery, retry cnt = 3
ALSA: poll time out, polled for 2000979 usecs, Retrying with a recovery, retry cnt = 4
ALSA: poll time out, polled for 2000988 usecs, Retrying with a recovery, retry cnt = 5
ALSA: poll time out, polled for 2000989 usecs, Reached max retry cnt = 5, Exiting
JackAudioDriver::ProcessAsync: read error, stopping...
I would like to solve this automatically e.g. via a shell script that detects when the gadget driver is requested by the host and I then start the virtual cabling with Jack.
For this it is necessary to be able to read whether the gadget driver is in use or not.
Is there any directory / file where I can detect, if the audio gadget device is in use?
I'm writing a kind of wrapper over wlanapi. When receiving notifications via WlanRegisterNotification I'm getting unexpected media-specific module (MSM) notification with code 59 (which is 0x3B in hex). WLAN_NOTIFICATION_MSM MSDN page does not contain any helpful information. My wlanapi.h does not contain such value as well, in fact this enumeration is zero-based and contain only 18 values - from 0 to 17.
Does anybody knows the meaning of such notification, and why it is not documented at all?
Here is what I have so far.
Looks like this notification is a part of regular connection process. That is, I'm getting it when connecting to a wireless network - regardless of previous connection state. Here is the notification sequence which happens each time when I connect to a network:
wlan_notification_msm_associating
wlan_notification_msm_associated
wlan_notification_msm_authenticating
59 (0x3B)
wlan_notification_msm_signal_quality_change
wlan_notification_msm_associated and wlan_notification_msm_authenticating fires in the same moment of time, and then immediately (in 10-20 milliseconds) fires notification with code 59 (0x3F).
This notification has 16-bytes payload. Data structure does not look familiar to me, posting this in case if it looks familiar to someone (10 events):
80805E08 009B0000 F1F10800 C400D634 <-- Switching between two networks here and below in random order
D0D049FA 009B0000 A6A60800 01542A00
80805E08 009B0000 696902FF 00FF4C6F
80805E08 00C40000 04040E00 000093DF
80805E08 009B0000 04040900 6F009361 <-- Diconnect and connect to the same network
80805E08 009B0000 04000700 00009340 <-- Diconnect and connect to the same network
64640000 00450002 0400114D 00009363 <-- Disconnect and connect to another network
80805E08 009B0000 04040511 005B93E8 <-- Diconnect and connect to the same network
58580000 00450002 04000904 3D4293A1 <-- Connect to another network (i. e. switch)
80805E08 009B0000 04040100 10919316 <-- Connect to another network (i. e. switch)
Useful links
[Wlanapi] WLAN_NOTIFICATION_MSM NotificationCode 59 (Microsoft Q&A)
[Wlanapi] WLAN_NOTIFICATION_MSM NotificationCode 59 (c++ forums)
Will appreciate any help!
Update 1
Notifications sequence is the same when connecting via official sample:
HandleAcmNotification(type = ConnectionStart)
HandleMsmNotification(type = Associating)
HandleMsmNotification(type = Associated)
HandleMsmNotification(type = Authenticating)
HandleMsmNotification(type = Code59)
HandleMsmNotification(type = SignalQualityChange)
HandleMsmNotification(type = Connected)
HandleAcmNotification(type = ConnectionComplete)
Update 2
I've created a minimal test project on GitHub for this purpose - https://github.com/alexbereznikov/wlanapi-notification-code59-test.
Binary x64 release is located here - https://github.com/alexbereznikov/wlanapi-notification-code59-test/releases.
I'm getting the following output after successful connection to a wireless network:
This is by design.
The 0n59 notification code is a private notification code that is processed by the OS when the wireless network may be undergoing a network speed change.
For the end developer, this should be ignored by the end developer as it is not documented and subject to change in the future since it is a private notification handled by underlying OS.
Note:This will only be sent on newer OS now (Windows 10) when disabling and re-enabling the wireless network. This notification is not sent for older OS (example, Windows 7, Windows 8.1)
I have a Realtek Gigabit ethernet adapter connected to my PC's PCI port and my OS is Windows 7 x64. I have a device in my LAN which brodcasts data via UDP every 100 ms (source port: 0, dest. port: 5100) and I can see all incoming data via Wireshark. The problem is I can't receive data via the application I developed and total received bytes is always zero in Windows:
I can't even receive data via NetCat. What's the problem? How it is possible that Wireshark is able to receive UDP packets although Windows says total number of received bytes is zero? I can't ping or respond to ping from other computers that are present in my LAN.
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
string ip = "192.168.0.1";
int port = 5100;
socket.Bind(new IPEndPoint(IPAddress.Parse(ip), port));
var buffer = new byte[1024];
int numBytesReceived = socket.Receive(buffer);
Using Andrew Rapp's XBee-API, how can I sample I/O data via a coordinator from more than two endpoints?
I have 17 Series 1 XBees. I have programmed one to be a coordinator (API mode = 2) and the rest to be endpoints. Using XBee-API I am sending a Force I/O Sample ("IS") remote AT command, unicast to each endpoint. This works perfectly well when there are up to two endpoints, but as soon as a third is added, one of the three always becomes non-responsive (times out with XBeeTimeoutException). It's not always the same physical unit that stops responding, but it is always the third one (for example, if I send Force I/O Sample to Device1, Device2, and Device3, Device3 will time out, and if I change the order to Device3, Device1, Device2, Device2 will time out.
If I set up more than three XBees, about 1 out of 3 will time out - but not every third one.
I've verified that the XBees themselves are fine. I've searched the Internet and Stack Overflow in particular to no avail. I've tried using a simple ZNetRemoteAtRequest. I've tried opening and closing the XBee coordinator serial connection once for all three devices, once per device, and once per program run. I've tried varying the distance between the coordinator and endpoints (never more than five feet apart). I've tried different coordinator configuration parameters (from the Digi documentation). I've tried changing out the XBee for the coordinator.
This is the code I'm using to send the Force I/O Sample request to each endpoint and read the response:
xbee = new XBee(); // Coordinator
xbee.open("/dev/ttyUSB0, 115200)); // Happens before any of the endpoints are contacted
... // Loop through known endpoint addresses
XBeeRequest request = new ZBForceSampleRequest(new XBeeAddress64(endpointAddress));
ZNetRemoteAtResponse response = null;
response = (ZNetRemoteAtResponse) xbee.sendSynchronous(request, remoteXBeeTimeout);
if (response.isOk()) {
// Process response payload
}
... // End loop and finally close coordinator connection
What might help polling I/O samples from more than two endpoints?
EDIT: I found that Andrew Rapp's XBee-API library fakes multithreaded behavior, which causes the synchronization issues described in this question. I wrote a replacement library that is actually multithreaded and correctly maps responses from multiple XBee endpoints: https://github.com/steveperkins/xbee-api-for-java-1-4. When I wrote it Java 1.4 was necessary for use on the BeagleBone, Plug, and Zotac single-board PCs but it's an easy conversion to 1.7+.
Are you using hardware flow control on your serial port? Is it possible that you're sending requests out when the local XBee has deasserted CTS (e.g., asking you to stop sending)? I assume you're running at 115200 bps, so the XBee serial port can keep up with the network data rate.
Can you turn on debugging information, or connect some port monitoring hardware/software to display the data going over the serial port to the local XBee?
My program puts a file into a remote host using HTTP. For some unavoidable
reasons, the remote hosts needs some time to acknowledge the final packet of
the data transmission. More time than the default timeout, which according
to my experience is around 30 seconds.
Therefore I wanted to increase the timeout to 5 minutes, using this code:
DWORD dwTimeout= 300000; // 5 minutes
pFtpConnection->SetOption( // KB176420: this has no effect on some
INTERNET_OPTION_SEND_TIMEOUT, dwTimeout); // old versions of IE.
pFtpConnection->SetOption(
INTERNET_OPTION_RECEIVE_TIMEOUT, dwTimeout);
pFtpConnection->SetOption( // NB: Docs say these 2 are not implemented.
INTERNET_OPTION_DATA_SEND_TIMEOUT, dwTimeout);
pFtpConnection->SetOption( // our own tests show that they are!
INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, dwTimeout);
This is MFC code which boils down to calling
InternetOption(hConnection, INTERNET_XXX, &dwTimeout, sizeof(dwTimeout))
The problem is that this code apparently fails to modify the timeout on a
non negligeable proportion of computers where the program is used.
How can I reliably set the data connection timeout?
TIA,
Serge Wautier.
It looks like this WinInet isue can'tbe solved reliably.
I eventually switched from WinInet to Ultimate TCP/IP.