How to obtain the remaining energy from BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER - android

I'm trying to get the energy consumption of my phone. I'm doing as follows but the result is 0 while I was specting any amount of nanowatts per hour.
int status2 = mBatteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER);
What is my problem?

I think BATTERY_PROPERTY_ENERGY_COUNT should be retreived using getLongIntProperty

Related

How to determine the quality of WebRTC call

Here is the stats report info that I got from the Peerconnection jingle library in Android.
I want to display an indicator on the UI to show the user the current call quality based on this report if possible.
I'm not sure how to determine if it is a good call quality or bad quality
Send video statistics
ssrc_2849248716_send
bytesSent=44487
codecImplementationName=HWEncoder
framesEncoded=30
mediaType=video
packetsLost=0
packetsSent=68
qpSum=2200
ssrc=2849248716
transportId=Channel-0-1
AdaptationChanges=0
AvgEncodeMs=0
BandwidthLimitedResolution=true
CodecName=VP8
ContentType=realtime
CpuLimitedResolution=false
EncodeUsagePercent=0
FirsReceived=0
FrameHeightInput=720
FrameHeightSent=360
FrameRateInput=30
FrameRateSent=30
FrameWidthInput=1280
FrameWidthSent=640
HasEnteredLowResolution=false
hugeFramesSent=0
NacksReceived=0
PlisReceived=0
Rtt=0
TrackId=ARDAMSv0
Receive video statistics
ssrc_1142651072_recv
bytesReceived=22760
codecImplementationName=HWDecoder
framesDecoded=21
mediaType=video
packetsLost=0
packetsReceived=31
qpSum=1684
transportId=Channel-0-1
CaptureStartNtpTimeMs=0
CodecName=VP8
ContentType=realtime
CurrentDelayMs=108
DecodeMs=14
FirsSent=0
FrameHeightReceived=360
FrameRateDecoded=34
FrameRateOutput=34
FrameRateReceived=25
FrameWidthReceived=640
InterframeDelayMax=46
JitterBufferMs=77
MaxDecodeMs=21
MinPlayoutDelayMs=0
NacksSent=0
PlisSent=0
RenderDelayMs=10
TargetDelayMs=108
TimingFrameInfo=126116936,-226,-207,-13,-13,-1,-226,-226,5772436049,5772436065,5772436217,5772436273,5772436065,0,1
TrackId=ARDAMSv0
BWE statistics = bweforvideo
ActualEncBitrate=291163
ReceiveBandwidth=0
SendBandwidth=1654217
BucketDelay=0
RetransmitBitrate=0
TargetEncBitrate=1654217
TransmitBitrate=389383
Connection statistics = Conn-0-1-0
ActiveConnection=true
bytesReceived=17759
bytesSent=31747
packetsSent=75
Readable=true
requestsSent=3
consentRequestsSent=1
responsesSent=3
requestsReceived=3
responsesReceived=3
ChannelId=Channel-0-1
localCandidateId=Cand-P/Rpk08E
LocalCandidateType=prflx
remoteCandidateId=Cand-gAVGaHs7
RemoteCandidateType=relay
Rtt=110
packetsDiscardedOnSend=0
TransportType=udp
Writable=true
onPeerConnectionStatsReady: fps = 30 target BR = 1654217 actual BR = 291163
I would recommend showing them the basic stats to the user as a first step like Packet loss %, bandwidth (upload & download), if possible the network signal strength. Calculate them for every two seconds.
Ref:
Chromes Webrtc stats: chrome://webrtc-internals
Signal strength: How to detect internet speed in JavaScript?
Packet loss: Math.round((totalPacketLost / totalPacketSent) * 1000);

Can someone please explain Android BatteryManger parameters

I am confused about the Battery Manager Parameters. can someone please explain below points:
BATTERY_PROPERTY_CHARGE_COUNTER -
Battery capacity in microampere-hours, as an integer.
Ques - Is it the remaining battery capacity or total battery Capacity.
If its total , why does it change
If its remaining( when i charged my phone 100% ) the values were somethign like 3366079 but total capcity of my phone's battery is 3300 mAh( read from power profile )
How can this be greater than 3300 mAh ?
Integer chargeCounter = mBatteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CHARGE_COUNTER);
Integer capacity = mBatteryManager.getIntProperty(BatteryManager.BATTERY_PROPERTY_CAPACITY);
Long energyCounter = mBatteryManager.getLongProperty(BatteryManager.BATTERY_PROPERTY_ENERGY_COUNTER);
long batteryCapacity = (chargeCounter/capacity) *100;
logs are as foolow :
Charge Counter: 3366079
capacity 100
Battery Capacity is :3366000
BATTERY_PROPERTY_ENERGY_COUNTER
Battery remaining energy in nanowatt-hours, as a long integer.
This parameter returns 0 ( tested on 2 devices )
Ques - Should this value be the remaining battery capacity value off 3300 mAH? or else what does this mean ?
Devices Used - LG G6 and Pixel 1
Thanks
There are a lot of physics behind these questions, for the first one,
How can this be greater than 3300 mAh ?
When manufacturers make a new battery they make them using a range, if your battery says it is 3300mAh there will be a range of error of +/- some error percentage.
Also to measure the battery they use a sensor which is prone to certain percentage of error too.
All these measures are converted from analog to digital which also conducts to another error.
I think this link could help: https://source.android.com/devices/tech/power/device
For your second question, check this post:
Android BATTERY_PROPERTY_ENERGY_COUNTER returning fixed value?

Scan period of beacons in android not working as expected

I am working with beacons in xamarin android. I want the scan to be done over 60 seconds and a period of 30 seconds to wait between the next cycle of scan.
public async void DetectAvailableBeacons()
{
_monitorNotifier = new MonitorNotifier();
_rangeNotifier = new RangeNotifier();
_tagRegion = new Region("Region",null, null, null);
_beaconManager.Bind(this);
_beaconManager.SetBackgroundScanPeriod(60000);
_beaconManager.SetForegroundScanPeriod(60000);
_beaconManager.SetBackgroundBetweenScanPeriod(30000);
_beaconManager.SetForegroundBetweenScanPeriod(30000);
_rangeNotifier.DidRangeBeaconsInRegionComplete += RangingBeaconsInRegionComplete;
}
The method RangingBeaconsInRegionComplete fills my list foundBeacons with the beacons detected.
Also, I have a method that gets all the available detected beacons as follows:
ObservableCollection<DetectedBeacon> BeaconLocator.GetAvailableBeacons()
{
return !_paused ? foundBeacons : null;
}
Now, I call the method GetAvailableBeacons() as follows:
public void PopulateBeacons() {
beaconsOnList = be.GetAvailableBeacons();
PopulateBeacons();
}
My issue is that sometimes it is missing some beacons, that is some beacons are not being detected. Also, the interval of scan does not seem to be working properly. Can someone advise what is wrong ?
In order for your scan periods to take effect right away, the easiest solution is to move the calls to set them before the call to bind so it looks like this:
_beaconManager.SetBackgroundScanPeriod(60000);
_beaconManager.SetForegroundScanPeriod(60000);
_beaconManager.SetBackgroundBetweenScanPeriod(30000);
_beaconManager.SetForegroundBetweenScanPeriod(30000);
_beaconManager.Bind(this);
By default, the scan will happen every 1.1 seconds and give you a result of all beacons seen in that period. This is probably what you are seeing happening without the code change above.
With shorter scan intervals, it is common for beacons with low advertising rates (e.g. ones that advertise only once every second) to not appear in the detection list for a single scan cycle. You can solve this by increasing the length of the scan cycle as you say you want to do, by increasing the advertising rate of the beacons, or building code logic that maintains a full list of beacons detected recently even if they weren't seen in the most recent scan cycle.
Short answer: If you increase your scan period successfully, I suspect this problem will go away.

Pic16F688 has no stable readings via buletooth

I have spent much time trying to find out where is my mistakes while Im flashing the PIC16F688. The Pic has successfully flashed using PicKit2. Im using the Pic to convert analog pressure sensor to digital output and sending the data via Bluetooth, but the Bluetooth is not receiving stable numbers of data. The data is consist of 4 character decimal number that is between 0 and 1023.
The problem is that the Bluetooth can't wait at specific number and keep reading it, instead, it is reading the 4 digits in random.
I think my mistake is within the configuration of internal oscillator.
I'm attaching my code, the code is written to configure the flexiforce sensor circuit that outputs analog voltage up to 5v, and then the pic duty is to convert it to digital as I mentioned above.
it might be my wiring is not correct, please If you could help out with this one
and what configuration "at edit project" do I need to choose for Mikro PRO software?
I used "Bluetooth terminal" app to see my data asynchronous from Bluetooth.
Thank you.
char *temp = "0000";
unsigned int adc_value;
char uart_rd; int i;
void main()
{
OSCCON = 0x77;
ANSEL = 0b00000100;
CMCON0 = 0X07;
TRISA = 0b00001100;
UART1_Init(9600);
Delay_ms(100);
while (1)
{
adc_value = ADC_Read(2);
temp[0] = adc_value/1000+48;
temp[1] = (adc_value/100)%10+48;
temp[2] = (adc_value/10)%10+48;
temp[3] = adc_value%10+48;
for (i=0;i<4; i++)
UART1_Write(temp[i]);
UART1_Write(13);
Delay_ms(1000);
}
}
You can use itoa function to convert ADC integer value to characters for sending over UART. If there is error in calculation then you wont get appropriate value. Below code snippet for your reference :
while (1)
{
adc_value = ADC_Read(2);
itoa(adc_value, temp, 10);
for (i=0;i<4; i++)
UART1_Write(temp[i]);
UART1_Write(13);
Delay_ms(1000);
}
Please check Baud Rate you have configured at both ends is same or not. If baudrate mismatches then you will get Random value at Bluetooth Terminal where you are reading values.
What i would suggest, if you have a logic analyser, hook it up. If you don't recalculate your oscillator speed with the datasheet. It could just be that the internal oscillator is not accurate enough. What also works, is to write a function in assembly that waits a known time (by copy-pasting a lot of NOPs and using this to blink a led. Then start a stopwatch and count, say, 100 blinks. This is what i used to do before i had a logic analyser. (They are quite cheep on ebay).

How to convert WiFi level (i.e. -45 , -88 ) in to percentage?

How to convert WiFi level (i.e. -45 , -88 ) in to percentage ?
I want to convert WiFi level in % . I get WiFi level using level ( in dBm format)
I try lot of google but not get proper ans
Problem with this is that is very dependent on the receiving antenna. Some antennas register no useable signal at -90 dBm, some already at -80. You will have a hard time finding 0% (100% strictly being 0dBm).
I have created a Wifi scanner application where I use -100dBm as 0% and 0dBm as 100%, in Java it turns into something like this (MIN_DBM being -100):
public int getPowerPercentage(int power) {
int i = 0;
if (power <= MIN_DBM) {
i = 0;
} else {
i = 100 + power;
}
return i;
}
This is what Microsoft does for dBm <> percent conversion:
https://stackoverflow.com/a/15798024/2096041
Basically -50 .. 0 dBm maps linear to 100 .. 0 %.
Like MS, i would prefer to sit on the safe side and not use -100 as 100% as some answers here suggest.
The WifiManager class has a function calculateSignalLevel, but as it states here, it results in an error if numLevels is greater than 45. Possible workaround could be something like this:
double percentage = WifiManager.calculateSignalLevel(int rssi, 40) * 2.5;
but of course, this will be in steps of 2.5 percents - I don't know your use case but maybe this is sufficient.
As others have stated, calculating percentages is problematic, and there's no simple precise solution for that.
You could derive the percentage from the signal-to-noise ratio, rather than the signal intensity alone, if this information is available. This is probably the desired metric.
An android.net.wifi.ScanResult does not publish the neccessary information (as of Dec 2012), but you might be able to get this information through other means.
Signal = Noise => unusable signal, so you could set 0dB SnR = 0%. Also you could set 10dB SnR to 90% (90% of the signal power is not drowned out in noise), and 100% = no noise at all. More generally,
p = 100% * (1 - 10^(SnR / (10dB)))

Categories

Resources