Unable to set target temperature to Nest Thermostat from Android SDK - android

I am writing an Android application to control a Nest thermostat. I was able to connect to it just fine and I can read the correct target temperature (turning the nob on the thermostat updates my TextView).
However, when I try to write the target temperature like this, nothing happens:
String thermostatID = mThermostat.getDeviceId();
mNest.thermostats.setTargetTemperatureF(thermostatID, 70);
I tried setting the HVAC mode first, in case I needed that, but this didn't work either:
String thermostatID = mThermostat.getDeviceId();
mNest.thermostats.setHVACMode(thermostatID, "cool");
mNest.thermostats.setTargetTemperatureF(thermostatID, 70);
The Textview flashes 70 for a brief second, but then shoots back up to 77 which is the target temperature that was set by the actual thermostat. Is this an issue with the SDK code for setTargetTemperatureF, or am I missing something simple here?

The permissions for the Nest thermostat are set on the Nest website. Visit https://developer.nest.com/products and sign in. You will be given a list of your products, all you need to do is select one and scroll down to permissions.
Note that after you change permissions, your mobile (or various platform) application will need to rerun authentication for this change to take place.

Try to modify your code as following, then you can set the target temperature.
mNest.setTargetTemperatureF(thermostatID, 70L, null);

Related

Issue with float.Parse in Unity Android App

I develop an Android app. If I call
float.Parse("51.552058")
in Editor or App on my Mac Book (Language Setting English), it works fine. After publishing to Android (Language Setting German) the result of the Parse operation is not "51.552058" anymore but "5,155211E+09". I understand that this might be related to the device's language but I still don't really understand what is happening and why.
I also tried following with no success:
float.Parse("51.552058", System.Globalization.NumberStyles.Any)
float.Parse("51.552058", System.Globalization.NumberStyles.AllowDecimalPoint)
Did anyone stumble over this before?
float.Parse is culture dependent.
See e.g. from NumberFormatInfo
// '1,034,562.91' --> 1034562.91 (en-US)
// '1,034,562.91': FormatException (fr-FR)
// '1,034,562.91' --> 1034562.91 (Invariant)
Reason here is that in EU cultures the , is usually the decimal separator while the . is used as the group separator. So from the example above the correct format for fr-FR would be 1.034.562,91
You probably rather want to use CultureInfo.InvariantCulture like
float.Parse("51.552058", CultureInfo.InvariantCulture);
or directly NumberFormatInfo.InvariantInfo
float.Parse("51.552058", NumberFormatInfo.InvariantInfo);
which simply has defined
NumberDecimalSeparator .
NumberGroupSeparator ,

Set no-touch option to Chrome OS emulator

Good morning. I need to test my application in Chrome OS, but without the "touch screen"
I used this guide to run a emulation of Chrome OS:
https://www.groovypost.com/howto/chrome-os-android-studio/
Ok, I succeeded to run it, I activated the debugging mode and I activated the adb debugging....finally everything is working and I can run my application on it.
The problem is, I want to test it without touchscreen.
I found the hw.screen property inside
~/.android/avd/<machine-name>.avd/hardware-qemu.ini
that was set to hw.screen = multi-touch.
WOW, exactly what I want, let's change it to no-touch.
Inside ~/Android/Sdk/emulator/lib/hardware-properties.ini you can see
# Touch screen type
name = hw.screen
type = string
enum = touch, multi-touch, no-touch
default = multi-touch
abstract = Touch screen type
description = Defines type of the screen.
so, no-touch is a valid option.
The problem is, even if I change it, every time I restart the emulator, it is set back to multi-touch.
I also tried to change the option directly in ~/Android/Sdk/emulator/lib/hardware-properties.ini, that should contain the default option, but no luck...
Someone can tell me who is overwriting this property each time I start the emulation?
How can I remove the touch screen in the emulation?
Launch the emulator from the command line and use the flag -screen no-touch. This is because the emulator overrides the config in the .ini file. That gives no touch screen but the mouse wasn't usable, at least on Windows.
See the docs for more details

PrintAttributes not working. not able to create custom page size

I am struggling with google printing interface in tablet. I want a print of fixed page size. PrintAttributes.Builder is not modifying the page and margin settings. How can i create a new custom/fixed page dimension for print. Now It shows ISO_A4 by default for HP printer.
My code is below:
PrintAttributes.Builder builder = new PrintAttributes.Builder();
PrintAttributes.MediaSize custom = new PrintAttributes.MediaSize("VISIT_K" , "VISIT_K", 86000,139860);
custom.asPortrait();
builder.setMediaSize( custom );
printJob = printManager.print(jobName, adapter,
builder.build());
Which Android version are you testing on? See this answer concerning a bug pre- Android 7
Regardless, the attributes here serve only as "hints", from the Android documentation:
You can use this parameter to provide hints to the printing framework
and pre-set options based on the previous printing cycle, thereby
improving the user experience. You may also use this parameter to set
options that are more appropriate to the content being printed, such
as setting the orientation to landscape when printing a photo that is
in that orientation.
I think if it conflicts with what the printer is reporting as supported/default, the printer's attributes may take precedence. This could be a feature/bug report to Android if it is not otherwise working.

How to take off a PX4 autopilot using mavlink message?

I follow the following link's sample code
http://android.dronekit.io/first_app.html
and when I set API VehicleApi.getApi(this.drone).arm(true);
vehicleState.isFlying() automatically becomes true.
Can anybody tell me what this problem is?
What I need is:
1. take off, land
I read from some website that the dronekit-android does not support the mode changing. If so, how should I send the mavlink message to take off and land?
So far, I can sucessfully send the mavlink message to the PX4 board.
Thanks for replying.
Thank you for replying.
BR
SeanH
If you trace though some of the code in dronekit-android, you can see that isFlying is set here with the code below.
boolean isFlying = systemStatus == MAV_STATE.MAV_STATE_ACTIVE || ...;
MAV_STATE_ACTIVE, defined here states
System is active and might be already airborne. Motors are engaged.
So isFlying doesn't mean it's airborne but just that the motors are turned on. That occurs when you call VehicleApi.getApi(this.drone).arm(true); because you are literally arming the vehicle at that point.
For takeoff, you want to use the ControlApi. ControlApi.getApi(drone).takeOff(desired_altitude, listener) and for land you need to use VehicleApi.getApi(drone).setVehicleMode(VehicleMode.COPTER_LAND, listener)
The sample code you're looking at is very old. I suggest you follow the sample app from github.
I have not tried android-dronekit before and I noticed that the src folder have not been updated for more than two years on github.
I advice you to use python-dronekit because there is a powerful library called pymavlink in python and used in python-dronekit. You can build hyper application if you want but first try to takeoff and land in python.

Samsung Galaxy S5; Changing ISO-speed settings with camera API

I'm trying to set the ISO for the Samsung Galaxy S5 using the Camera API.
The parameters which includes the ISO tag in the Camera Parameters (retreived using camera.getParameters.flatten();) are:
exif_iso=0;
iso=auto;
iso-values=auto,ISO_HJR,100,200,400,800,1600;
I quess that the exif_iso parameter has something to do with the Meta file, so i don't need that. The iso setting is what i need, and i can choose all the values stated under iso-values. If i set one of these parameters, the parameters are accepted (no exception is getting thrown). If i use a parameters which isn't stated under the values, an exception is thrown. So the value of iso are set!
But... the strange thing is that when you take a picture, the iso setting seems to be ignored. Settings like white balance and resolution work like a charm, but i can't get the iso to change. On another phone (galaxy S2) the iso setting does work.
In the official camera app from samsung, the iso value is editable, so somewhere in the api it should be possible! I have tried some camera apps from the play store (including open camera 1.20) but the same thing; you can change the value but it gets ignored.
Has anyone any idea why the value is ignored? is there maybe another parameter which enables or disables this kind of settings?
Thanks a lot :)
Update:
I'am a little bit further. It seems to be caused by OpenCV which i also use in my app. Specifically the class CameraBridgeViewBase seems to cause the iso setting problem. Even i disable the view before taking the picture, the iso settings are getting ignored. I've build a little camera app without the use of OpenCV and the iso is set just like it should.
If an app with CameraBridgeViewBase been running (even if you clear the memory after that) my camera test app iso settings are ignored again. I also tried the app 'open camera', the iso settings are simply ignored again. If i start the official samsung camera app, it seems like it resets the whole camera; My camera test app and 'open camera' iso setting work again after that.
The weird thing of all is that this problem doesn't occur at all on my Samsung Galaxy S2. It only occurs on the Samsung Galaxy S5...
CameraBridgeViewBase: OpenCV class which is used to capture (video)frames from the camera, show it and implements a 'onFrameListener' function.
Parameters =
phase-af-values
focallength-value-denominator=100
brightness-step=1
zoom=0
redeye-reduction-values=enable,disable
exif_iso=0
max-num-detected-faces-hw=10
scene-detect-values=off,on
qc-camera-features=542
face-detection-values=off,on
dynamic-range-control-values=
whitebalance=auto
max-sharpness=36
focallength-value-numerator=480
preview-format-values=yuv420sp,yuv420p
jpeg-thumbnail-quality=85
preview-format=yuv420sp
face-detection=off
auto-exposure-values=matrix,center,spot
iso=auto
fast-fps-mode=0
mce-values=enable,disable
flash-mode-values=off,auto,on,torch
preview-frame-rate=30
jpeg-thumbnail-width=512
video-size=1920x1080
scene-mode-values=auto,hdr
redeye-reduction=disable
preview-fps-range-values=(10000,30000)
histogram=disable
face-recognition=off
camera-mode=0
preview-size-values=1920x1080,1440x1080,1280x720,1056x864,960x720,800x480,720x480,640x480,352x288,320x240,176x144
maxaperture-value-denominator=100
saturation-step=1
touch-af-aec=touch-off
smart-screen-exposure-values=vision-ae-normal,vision-ac-backlight
preview-fps-range=10000,30000
auto-whitebalance-lock=false
min-exposure-compensation=-4
llv_mode=0
antibanding=auto
max-num-focus-areas=1
face-recognition-values=off,on
vertical-view-angle=38
video-stabilization-supported=false
sce-factor-step=10
maxaperture-value-numerator=228
qc-max-num-requested-faces=10
min-saturation=0
max-saturation=10
contrast-step=1
raw-size=5328x3000
max-brightness=6
supported-live-snapshot-sizes=5312x2988,4128x2322,4000x3000,3264x2448,3264x1836,3200x2400,2592x1944,2048x1536,2048x1152,1920x1080,1600x1200,1440x1080,1280x768,1280x720,1024x768,800x600,800x480,800x450,720x480,640x480,352x288,320x240,176x144
max-contrast=10
min-sce-factor=-100
picture-format-values=jpeg,bayer-qcom-10gbrg,bayer-qcom-10grbg,bayer-qcom-10rggb,bayer-qcom-10bggr,bayer-mipi-10gbrg,bayer-mipi-10grbg,bayer-mipi-10rggb,bayer-mipi-10bggr,yuv422sp
video-hfr=off
supported-shot-modes=normal-shot,panorama-burst
exposure-compensation-step=0.5
scene-detect=off
fnumber-value-numerator=220
picture-size=1920x1080
saturation=5
whitebalance-values=auto,incandescent,fluorescent,daylight,cloudy-daylight
picture-format=jpeg
zsl=off
lensshade-values=enable,disable
selectable-zone-af=auto
video-hfr-values=60,90,150
iso-values=auto,ISO_HJR,100,200,400,800,1600
selectable-zone-af-values=
lensshade=enable
preferred-preview-size-for-video=1920x1080
anti-shake=0
min-sharpness=0
intelligent-mode=0
mce=enable
hfr-size-values=2664x1500,1328x748,824x496
snapshot-picture-flip=off
zoom-supported=true
metering=center
denoise-values=denoise-off,denoise-on
zsl-values=off,on
sharpness=36
phase-af=off
contrast=5
scene-mode=auto
jpeg-quality=96
dynamic-range-control=off
histogram-values=enable,disable
exif_exptime=0
metering-areas=(0,0,0,0,0)
min-contrast=0
video-size-values=1920x1080,1440x1080,1280x720,800x450,800x480,720x480,640x480,352x288,320x240,176x144
skinToneEnhancement=0
rt-hdr=off
preview-size=1920x1080
focal-length=4.80
ae-bracket-hdr-values=Off,AE-Bracket
denoise=denoise-on
video-flip=off
max-sce-factor=100
preview-frame-rate-values=15,24,30
max-num-metering-areas=10
preview-flip=off
focus-mode-values=auto,infinity,macro,continuous-video,continuous-picture
vtmode=0
jpeg-thumbnail-size-values=512x288,480x288,256x154,432x288,512x384,352x288,320x240,176x144,0x0
zoom-ratios=100,104,109,114,119,125,129,134,139,144,150,154,159,164,169,175,179,184,189,194,200,204,209,214,219,225,229,234,239,244,250,254,259,264,269,275,279,284,289,294,300,304,309,314,319,325,329,334,339,344,350,354,359,364,369,375,379,384,389,394,400,404,409,414
dis-values=enable,disable
dual_mode=0
picture-size-values=5312x2988,3984x2988,3264x2448,3264x1836,2560x1920,2048x1152,1920x1080,1280x960,1280x720,800x480,640x480
touch-af-aec-values=touch-off,touch-on
smart-screen-exposure=0
luma-adaptation=3
min-brightness=0
horizontal-view-angle=62
firmware-mode=none
imageuniqueid-value=F16QLHF01GB

Categories

Resources