Android Bluetooth connection parameter - bluetooth

I very long Looking for but not found a answer, hot to change bluetooth connection parameter (Connection Interval, Slave Latency, Supervision Timeout) on Android (master) device. Must importent for me is Supervision Timeout becouse on android by defaut is 20 seconds and i need lessen, i find CONNECTION_PRIORITY_BALANCED, CONNECTION_PRIORITY_HIGH and CONNECTION_PRIORITY_LOW_POWER but they dont change Supervision Timeout time,
or impossible to change connection parameter from Android (master)?
Please help me.
Thanks in advence.

Unfortunately, you are only allowed to do whatever API allows you. In most cases, mobile OS APIs do not allow you to do low level settings for the purpose of user friendly experience. Imagine you developed an app which uses connection parameters that drains battery... Then the user of your application would most probably complain about the OS provider or the OEM. This is not wanted and should be prevented. However, if you want to do low level changes for experimental reasons (research etc.), I would recommend you to download the Android API source code, do the changes and insert the custom ANdroid API to your phone (you need to root your phone).
Here is the related part from the source code in BluetoothGatt.class related to your request:
public boolean requestConnectionPriority(int connectionPriority) {
if (connectionPriority < CONNECTION_PRIORITY_BALANCED ||
connectionPriority > CONNECTION_PRIORITY_LOW_POWER) {
throw new IllegalArgumentException("connectionPriority not within valid range");
}
if (DBG) Log.d(TAG, "requestConnectionPriority() - params: " + connectionPriority);
if (mService == null || mClientIf == 0) return false;
try {
mService.connectionParameterUpdate(mClientIf, mDevice.getAddress(), connectionPriority);
} catch (RemoteException e) {
Log.e(TAG,"",e);
return false;
}
return true;
}
I would look for the implementation of BluetoothGattService#connectionParameterUpdate.

Related

Clean way to real, always working, auto-reconnect

I hope to open a question that is useful for the users of this shield.
Incipit: WiFi.setAutoReconnect(true); seems that not prevent 100% of disconnections.
I've tested a lot of shields (ESP12F, ESP01) and in some case i noted that the auto-reconnect does not work properly.
Fact:
I was unable to reproduce when the shield is connect to pc/debugger.
When did it happen, i try to execute a task depending on a botton press, eg:
loop(){
if (digitalRead... == HIGH) do_something()
}
And the shield... do something! So, the shield was not frozen.
I try to reset (BOTH via HW and SW) and the shield immediately reconnect.
I read some other source and this behavior is often described (es. https://randomnerdtutorials.com/solved-reconnect-esp32-to-wifi/ ). Brief: try WiFi.reconnect(), if it does not work try ESP.restart().
Then, the question:
Why does this happen? Is there a problem with the arduino libraries, or with the native expressif interface? Or is a well-known hardware problem unsolvable via SW?
If indeed so, what techniques do you use to prevent disconnection? I have set a ticker every 30 minutes, which if it sees the card disconnected for more than a certain time, it restarts it. Eg.
void checkWifi() {
if (lastPing + DELTA < millis()) ESP.restart();
}
ticker.attach(checkWifi, ...)
void loop() {
if WiFi.isConnect() {
lastPing = millis();
...
}
}
If there is nothing to do, what do you think of the restart technique? Is it risky to restart frequently, can it reduce the life of the device?
Thanks to anyone who wants to contribute or exchange impressions!

Can I trigger the Hololens Calibration sequence from inside my application?

I have a hololens app I am creating that requires the best accuracy possible for hologram placement. This application will be used by numerous individuals. Whenever I try to show the application progress, I have to have the user go through the calibration process, otherwise the holograms appear to have way too much drift.
I would like to be able to call the hololens calibration process automatically when the application opens. Later, after I set up user authentication and id management, I will call the calibration process when a new user is found.
https://learn.microsoft.com/en-us/windows/mixed-reality/calibration
I have looked into the calibration (via the above documentation and elsewhere) and it seems that all it is setting is IPD. However the alternative solutions I have found that allow for dynamic ipd adjustment appear to be invalid for UWP Store apps. This makes them unusable for me.
I am looking for any help or direction, or if this is even possible. Thank you.
Yes, it is possible to to this, you need to use the LaunchUriAsync protocol to launch the following URI: ms-hololenssetup://EyeTracking
Here is an example implementation, obtained from the LaunchUri example in MRTK
public void LaunchEyeTracking()
{
#if WINDOWS_UWP
UnityEngine.WSA.Application.InvokeOnUIThread(async () =>
{
bool result = await global::Windows.System.Launcher.LaunchUriAsync(new System.Uri("ms-hololenssetup://EyeTracking"));
if (!result)
{
Debug.LogError("Launching URI failed to launch.");
}
}, false);
#else
Debug.LogError("Launching eye tracking not supported Windows UWP");
#endif
}

DirectXTK make_unique<AudioEngine>(flags) fails

I am just about ready to release my first little game with my game engine. However, through having some people test it, we found that the call to acquire the pointer to the AudioEngine interface fails for one of my testers.
The call works fine for me on both my desktop and my laptop, and it works fine on tester 2's computer. However, tester 1's computer will not succeed on the call.
By "fails" I mean it throws an exception which I am handling with a try/catch block. The "what" of the exception just tells me "AudioEngine" so no help there. He has a heavily customized computer which utilizes two graphics cards which are not linked and handle separate tasks. He uses the same Virtual Audio Cable set up that I have on my Desktop (used to separate voice sources for easier video editing re: streaming/game recording).
If anyone has any clue what might cause this call to fail, we would greatly appreciate the information. Please let me know if you require any additional information. Code for initialization is below:
//aud engine declaration is in the header for the class
unique_ptr<AudioEngine> audEngine;
//function being called
bool AudioEngineClass::InitializeAudioEngine()
{
//Call this to create the DXTK Audio Engine
//Setup flags:
AUDIO_ENGINE_FLAGS eflags = AudioEngine_Default;
eflags = eflags | AudioEngine_EnvironmentalReverb | //Enables environmental reverb for 3D (required for 3D audio)
AudioEngine_ReverbUseFilters | //Enables additional features for 3D positional audio reverb
AudioEngine_UseMasteringLimiter; //Enables a mastering volume limiter to avoid distortion and clipping with 3D audio.
//MessageBox(NULL, "Attempting to assign AudioEngine Pointer", "AudioEngine.InitializeAudioEngine", MB_OK);
try
{
audEngine = make_unique<AudioEngine>(eflags);
}
catch(exception& e)
{
//Tester 1 falls into this
string exceptionStr = e.what();
string outputStr = "Failed to Initialize Audio Engine. Exception: \n";
outputStr += exceptionStr;
MessageBox(NULL, outputStr.c_str(), "AudioEngine.InitializeAudioEngine", MB_OK);
}
//MessageBox(NULL, "Got past AudioEngine Pointer Assignment", "AudioEngine.InitializeAudioEngine", MB_OK);
if (!audEngine)
{
//failed to create audio engine.
initialized = false;
}
else
{
initialized = true;
}
return initialized;
}
UPDATE: Been trying stuff all day with no luck so far.
-Had Tester download the June 2010 DirectX DLLs and install them and restart their computer.
-Had them update all of their drivers.
-Had them check their System folder (all XAudio2_#.dll files are present).
-They have Windows 10

How to prevent the screen from locking on UWP 10

I want to prevent the phone to lock if the user didnt interact with the phone for some time.
In win8 phone development i used the PhoneApplicationService.UserIdleDetectionMode Property. Unfortunately i cannot find anything alike for win 10 universal app.
Any suggestions?
Simple Answer
DisplayRequest class
var displayRequest = new DisplayRequest();
displayRequest.RequestActive(); //to request keep display on
displayRequest.RequestRelease(); //to release request of keep display on
Detailed Answer
Using display requests to keep the display on consumes a lot of power. Use these guidelines for best app behavior when using display requests.
Use display requests only when required, that is, times when no user input is expected but the display should remain on. For example, during full screen presentations or when the user is reading an e-book.
Release each display request as soon as it is no longer required.
Release all display requests when the app is suspended. If the display is still required to remain on, the app can create a new display request when it is reactivated.
To Request keep display on
private void Activate_Click(object sender, RoutedEventArgs e)
{
if (g_DisplayRequest == null)
{
g_DisplayRequest = new DisplayRequest();
}
if (g_DisplayRequest != null)
{
// This call activates a display-required request. If successful,
// the screen is guaranteed not to turn off automatically due to user inactivity.
g_DisplayRequest.RequestActive();
drCount += 1;
}
}
To release request of keep display on
private void Release_Click(object sender, RoutedEventArgs e)
{
// This call de-activates the display-required request. If successful, the screen
// might be turned off automatically due to a user inactivity, depending on the
// power policy settings of the system. The requestRelease method throws an exception
// if it is called before a successful requestActive call on this object.
if (g_DisplayRequest != null)
{
g_DisplayRequest.RequestRelease();
drCount -= 1;
}
}
References - Prevent the screen from locking on Universal Windows Platform
Hope it help someone!!
You want the DisplayRequest class in Windows 10.

What is the best architecture we can use for a Netty Client Application?

I need to develop a netty based Client, that accepts messages from a Notification Server, and places these messages as Http Requests to another Server in real time.
I have already coded a working application which does this, but I need to add multi-threading to this.
At this point, I am getting confused on how to handle Netty Channels inside a multi-threaded program, as I am all loaded with the conventional approach of sockets and threads.
When I tried to separate the Netty requesting part into a method, It complains about the Channels not being closed.
Can anyone guide me how to handle this?
I would like to use ExecutionHandler and OrderedMemoryAwareThreadPoolExecutor, but I am really new into this.
Help with some examples would be a real favour at this time.
Thanks in advance.
Just add an ExecutionHandler to the ChannelPipeline. This will make sure that every ChannelUpstreamHandler which is added behind the ExecutionHandler will get executed in an extra thread and so does not block the worker-thread.
Have you looked at the example code on the Netty site? The TelnetServer looks to do what you are talking about. The factory creates new handlers whenever it gets a connection. Threads from the Executors will be used whenever there is a new connection. You could use any thread pool and executor there I suspect:
// Configure the server.
ServerBootstrap bootstrap = new ServerBootstrap(
new NioServerSocketChannelFactory(
Executors.newCachedThreadPool(), << change
Executors.newCachedThreadPool())); << change
// Configure the pipeline factory.
bootstrap.setPipelineFactory(new TelnetServerPipelineFactory());
// Bind and start to accept incoming connections.
bootstrap.bind(new InetSocketAddress(8080));
The TelnetServerHandler then handles the individual results.
#Override
public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) {
// Cast to a String first.
// We know it is a String because we put some codec in TelnetPipelineFactory.
String request = (String) e.getMessage();
// Generate and write a response.
String response;
boolean close = false;
if (request.length() == 0) {
response = "Please type something.\r\n";
When the telnet is ready to close the connection it does this:
ChannelFuture future = e.getChannel().write(response);
if (close) {
future.addListener(ChannelFutureListener.CLOSE);
}

Resources