I'm using FlutterBlue to find my devices... but I keep getting "old" results; if I power off my device, I still get "advertisement packets" in the phone from the device when it was on...
I'd like to say "give me only what you hear on the air" so that if the time since I last heard from the device was > 5 seconds, I'll -200 the rssi and gray it out...
But I keep getting these "cached" packets that keeps clearing my timer...
My line to start the scanner is:
await flutterBlue.startScan(allowDuplicates: true);
Related
I've hunted high and low and cannot find a solution to this problem. I am looking for a method to change the input/output devices which an AVAudioEngine will use on macOS.
When simply playing back an audio file the following works as expected:
var outputDeviceID:AudioDeviceID = xxx
let result:OSStatus = AudioUnitSetProperty(outputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Global, 0, &outputDeviceID, UInt32(MemoryLayout<AudioObjectPropertyAddress>.size))
if result != 0 {
print("error setting output device \(result)")
return
}
However if I initialize the audio input (with let input = engine.inputNode) then I get an error once I attempt to start the engine:
AVAEInternal.h:88 required condition is false: [AVAudioEngine.mm:1055:CheckCanPerformIO: (canPerformIO)]
I know that my playback code is OK since, if I avoid changing the output device then I can hear the microphone and the audio file, and if I change the output device but don't initialize the inputNode the file plays to the specified destination.
Additionally to this I have been trying to change the input device, I understood from various places that the following should do this:
let result1:OSStatus = AudioUnitSetProperty(inputUnit, kAudioOutputUnitProperty_CurrentDevice, kAudioUnitScope_Output, 0, &inputDeviceID, UInt32(MemoryLayout<AudioObjectPropertyAddress>.size))
if result1 != 0 {
print("failed with error \(result1)")
return
}
However, this doesn't work - in most cases it throws an error (10853) although if I select a sound card that has both inputs and outputs it succeeds - it appears that when I am attempting to set the output or the input node it is actually setting the device for both.
I would think that this meant that an AVAudioEngine instance can only deal with one device, however it is quite happy working with the default devices (mic and speakers/headphones) so I am confident that isn't the issue. Looking at some solutions I have seen online people simply change the default input, but this isn't a massively nice solution.
Does anyone have any ideas as to whether this is possible?
It's worth noting that kAudioOutputUnitProperty_CurrentDevice is the only property available, there is not an equivalent kAudioInputUnitProperty_CurrentDevice key, due to the fact that as I understand it both the inputNode and outputNode are classed as "Output Units" (as they both emit sound somewhere).
Any ideas would be much appreciated as this is very very frustrating!!
Thanks
So I filed a support request with apple on this and another issue and the response confirms that an AVAudioEngine can only be assigned to a single Aggregate device (that is, a device with both input and output channels) - the system default units create effectively an aggregate device internally which is why they work, although I've found an additional issue in that if the input device also has output capabilities (and you activate the inputNode) then that device has to be both the input and output device as otherwise the output appears not to work.
So answer is that I think there is no answer..
I'm interested if there is some HealthKit or other data source I can query to know if the Apple Watch was worn/in contact with the wrist at a given time interval. Currently I'm relying on HealthKit query for HeartRate and it appears that if I get no heart rate readings within a certain window, then the watch was most likely off the wrist or charging.
Is there a better way to detect if the Apple Watch was worn on the wrist?
The problem with this method is that it is not very descriptive - if the user put on the watch at the last minute and got a measurement, this logic would consider the entire period as having the watch "On". Is there something better?
// obtain heartRateSamples from HealthKit and filter them
let hrFilterStart = startDate.addingTimeInterval(startSecondsOffset)
let hrFilterEnd = hrFilterStart.addingTimeInterval(Double(30 * 60) )
let heartRateDuringTimeSlice = heartRateSamples.filter{ sample -> Bool in
let fallsBetween = (hrFilterStart ... hrFilterEnd).contains(sample.startDate)
return fallsBetween
}
if heartRateDuringTimeSlice.count == 0 {
//watch is not on the wrist - probably charging, ignore this interval
}
HealthKit does not expose any information that you can use to reliably determine whether the Apple Watch was on-wrist. Using the presence of heart rate or other automatically collected samples will work well enough for most users, but keep in mind that there are situations where heart rate samples might not be collected at a consistent frequency even when the watch is on-wrist.
Trying to come up with a list of reasons why the CMSensorRecorder would return a Nil list when calling accelerometerData(from: to:)
https://developer.apple.com/documentation/coremotion/cmsensorrecorder/1615937-accelerometerdata
1) We have noticed if the Watch is on the charger, this call will return Nil for that period of time.
2) I am speculating if the Watch is in low power mode ( < 10% battery ), it could also return Nil.
3) At times, the accelerometer does not return data in background mode. If I query the accelerometer for the same date/time range in foreground mode, I do receive data.
What are other scenarios where this situation could occur?
I am asking as our program periodically is receiving a Nil list when calling that method when the phone is not on the charger or in low power mode.
Thanks
I use a STM32F103C8T6 as a transmitter and an Arduino Uno as a receiver.
I cannot receive the value I am interested in. I have changed delay durations after each send and also CE pulse. I sometimes get it worked on spec by playing with delay durations.
To exemplify, I add a 200ms delay after TX function is executed and receiver receives very well then I disconnect the receiver and then when I connect it again, it receives nothing but zero.
Very similar situations occur when I play with CE pulse duration.
I cannot get it worked neither with auto-ack nor simple rx-tx operation.
I would like to mention that when I change roles (TX device is Arduino and RX device is STM) everything works perfectly.
I've checked STM32 by a logic analyzer to see whether the payload is filled properly or not and could not see any problem.
After I fill the payload, I check FIFO_STATUS register and everything is fine.
After I apply a pulse for a certain duration, I check STATUS register and can see that TX_DS bit is set.
I've discovered that just applying 10us pulse on CE may not be enough. It can take up to 500us.
Then decided to set CE pin high until TX_DS bit is set, but this method also did not work.
void TX_Mode(uint8_t data2send)
{
Flush_TX();
CleanInterrupts();
SetPRIM(PRIM_TX); //set as transmitter
csn_low(); //CSN=0
HAL_SPI_Transmit(&hspi2, &COMD_W_TX_PAYLOAD, 1,150); //send command to write to payload
HAL_SPI_TransmitReceive(&hspi2, &data2send, &dummy, 1, 150); // fill the payload
while(HAL_SPI_GetState(&hspi2) != HAL_SPI_STATE_READY);
csn_high();
ChipEnable_high();
while( !(TXDS_Bit_Is_Set() )); //wait until payload is sent
ChipEnable_low();
}
I'm looking for a reliable way to get the time. It can't be tampered with and it needs to work offline. So no internet time , no user time setup in settings and no BSD uptime time since last reboot. I was wondering since GPS works using atomic clock, whether I could access that information.
Thank you
This works to get the GPS time:
#import <CoreLocation/CoreLocation.h>
CLLocation* gps = [[CLLocation alloc]
initWithLatitude:(CLLocationDegrees) 0.0
longitude:(CLLocationDegrees) 0.0];
NSDate* now = gps.timestamp;
It doesn't seem to be tamper-proof though.
I tried this code on an iPhone 4 in airplane mode (iOS 6.1), and even then it gives a time all right. But unfortunately this time seems to change with the system clock. Ugh.
Funny thing that I found (still in airplane mode) is that if you tamper with the system clock (after turning to off Time & Date's Set Automatically), and then turn Set Automatically back to on, the machine restores the real (original) time without a hitch. this works even after cycling the phone's power. So it seems that there is something like a tamper-proof time the device maintains internally. But how to access this?
P.S. A discussion of this from 2010. The author of the penultimate comment tried this in a fallout shelter: so it's clear the phone is not getting the pristine time from any external source.
Addendum, July 2013
Found a few more posts (here, here and here) about another kind of time measure: system kernel boot time. It's accessed through a call something like this: sysctlbyname("kern.boottime", &boottime, &size, NULL, 0);. Unfortunately it too changes with the user-adjusted data and time, even without reboot. Another function gettimeofday() is similarly dependent on user-defined time.
NSDate and it's CF counterpart are all based on the user controllable time, and thereby aren't tamper proof.
As far as I know, there is no open API for either GPS time or carrier time directly. However, you can check the mach_absolute_time to get untampered time since last boot up, and perhaps use it to at least be aware of how much time has passed since the app has been awoken (without having the potential for that time to be tampered with while the app is running).
mach_absolute_time depends on the processor of the device. It returns ticks since the device was last rebooted (otherwise known as uptime). In order to get it in a human readable form, you have to modify it by the result from mach_timebase_info (a ratio), which will return billionth of seconds (or nanoseconds). To make this more usable I use a function like the one below:
#include <mach/mach_time.h>
int getUptimeInMilliseconds()
{
static const int64_t kOneMillion = 1000 * 1000;
static mach_timebase_info_data_t s_timebase_info;
if (s_timebase_info.denom == 0) {
(void) mach_timebase_info(&s_timebase_info);
}
// mach_absolute_time() returns billionth of seconds,
// so divide by one million to get milliseconds
return (int)((mach_absolute_time() * s_timebase_info.numer) / (kOneMillion * s_timebase_info.denom));
}
Even if you can get hold of the time from GPS you should be aware that GPS time is not quite the same as UTC. The GPS receiver in the iPhone might take care of that for you though.
This gets you the current date and time:
NSDate *now = [NSDate date];
This will be as reliable as you can get. The internal clock on the iPhone will be updated when it can get access to an NTP server. If the phone uses GPS as a time sync source it'll also be used to update the same system-wide clock which is accessible via the above method.
The CoreFoundation equivalent is something like:
CFAbsoluteTime now = CFAbsoluteTimeGetCurrent();
Which returns the CoreFoundation equivalent of the normal UNIX seconds-since-epoch timestamp.
The gold standard of timekeeping are the various government time observatories in the U.S. and worldwide. They provide Atomic time. That is used world wide. Apple should be using that. If the want to sync w/ the cell towers, there should be an Alternate internal time. If the tower or GPS system malfunctions all are left with incorrect time.