How to get location in DMS on Flutter/Dart - flutter

so I use geolocator to get the place location, but it gives a decimal. But my app need the location as degrees, minutes and seconds, is there another package/lib that can do it, our a way to do that with geolocator,      tried formatting with sub string but to no avail (maybe I did it wrong).

Related

WatchFolder() Function From Autohotkey Community

This is beyond my comfort zone of Sendinput and Sleep.
Any help as to what am doing wrong, would much appreciated.
I have found this function WatchFolder() - updated on 2021-10-14 - AutoHotkey Community and using some of the examples shared on that thread I was ables to put this together:
#Persistent
#Include, <WatchFolder>
WatchFolder("C:\Temp\", "ReportFunction", false, 1 | 2 | 4 | 8 |16 | 32 | 64 | 256)
Return
ReportFunction(Directory, Changes) {
 For Each, Change In Changes {
       Action := Change.Action
       Name := Change.Name
       If (Action = 3)
         Run, Notepad
}
}
I figured out how to watch for all the other events correctly (deleted, added etc etc). I am having problems wih the file modified event. The event occurs twice.
so in the above ebove example notepad is run twice. If I set Run to open .Url it will also open twice.
I dont know why. I tried changing a bunch of things in my ReportFunction but nothing worked.
PS: Watchfolder function is saved in Documents\Autohotkey\Lib folder and I have made no changes to it, it is as I downloaded it.
As I have checked myself, it works just fine if you modify the files in the folder yourself but while using the downloads folder like your example script in the ahk forum post or using temp folder it will execute multiple times as normal. The reason is, it's keep updating and modifying the file while downloading, you can check it as well if you download a large sized file, size will change time to time. Just to try, I downloaded your example in the ahk forum and it opened 3 notepad windows while just downloading 342bytes sized file. Temp folder is just the same, files keep written and deleted there, not easy to track and execute by those folders like that. Try to set a custom folder location and check it by modifying the files by yourself. If you must use those folders maybe you can add a sleep like 5 secs after Run command but I don't know how efficient it would be.

Rest Server with Z1 Websense

Hi Stackover'followers :). I'm very much new to Stackoverflow. Let me put forward a question I have regarding Instant Contiki. Anybody who has idea on Instant Contiki, zolertia motes, REST Server, is welcomed to resolve it out.
I could successfully work on the two different motes by considering 'z1-websense.c' and 'rest-server-example.c'.
But I want to get the result of 'z1-websense.c' which is the
temperature, by executing the 'rest-server-example.c'.
So, regarding this, there is something to be done in the 'rest-server-example.c' code, may be by calling a function for z1-websense.c, which I'm unable to crack it.
Please help me out. Thanks in advance.
the rest-engine app on Contiki let's you set up resources and handlers for methods called on them.
So, if I understood, you want to tweak the resource GET handlers in er-example-server to taylor onto the z1 mote, in particular a resource for the battery sensor and a resource for the temperature one.
If you take a look at z1-websense.c the values are retrieved and simply scaled (lines 66-79).
static int
get_battery(void)
{
return battery_sensor.value(0);
}
static int
get_temp(void)
{
return temperature_sensor.value(0);
}
static float get_mybatt(void){ return (float) ((get_battery()*2.500*2)/4096);}
static float get_mytemp(void){ return (float) (((get_temp()*2.500)/4096)-0.986)*282;}
Take that code and inject it into the battery and temperature resources you can find hereenter link description here and you are done.
So in the end you will have something like
file res-battery.c, line 60
float battery = ( battery_sensor.value(0) *2.500*2) /4096 ;
You should do similarly for the temperature and you are done.
Remember to deactivate all sensors/resources you are not interested in, since they would take precious memory.
I cannot test it right now, but this should work.

Getting GPS locations and other attributes - BEGINNER

I am currently doing this tutorial to get the GPS coordinates of my present location. I need to know what these values means?
The first 2 values are the geo-coordinates, and i don't know what the other attributes are ?
From Apple's iOS Developer Library what you are seeing as a result of the description selector being sent to your CLLocation object (which represents your current location and other location-related info):
A string of the form <<latitude>, <longitude>> +/- <accuracy>m (speed
<speed> kph / heading <heading>) # <date-time>, where <latitude>,
<longitude>, <accuracy>, <speed>, and <heading> are formatted floating
point numbers and <date-time> is a formatted date string that includes
date, time, and time zone information.
What you probably want to do now is extract info from your CLLocation object by accessing its various properties (e.g. CLLocation.altitude will return the altitude only). Generally, aside from debugging purposes to the console, you would not want to print or display to the user the result of [CLLocation description] which is what you have there!

Is it possible to get the atomic clock timestamp from the iphone GPS?

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.

How can I detect whether the iphone has been rebooted since last time app started

I'd like to detect from within my app whether the iPhone has been rebooted since last time my app was started. I need to do this because my app uses the timer since last system reboot to clock a user's time and I want to detect reboot so I can invalidate the time.
Is there anywhere I could extract the information from the system console log like reboot , crashes ? The organizer in xcode can access it , maybe I can too.
If not , can you think of other ways to get this information?
This seems like it would work:
get the time since last reboot, and for this example, let's store it in a variable called 'tslr' (duration in milliseconds I guess, BTW, how do you get that?)
get the current time, store it in variable 'ct' for example
compute the last reboot time (let's call it 'lr'), we have: lr = ct - tslr
store 'lr'
Next time your application gets started, load the previous value for 'lr', compute the new one, and if they differ, you have detected a reboot (you'll probably have to tolerate a small difference there... a couple milliseconds perhaps).
I think it would be pretty tough to fool that... the user would have to tamper their phone time very precisely, and they would have to start your application at a very precise moment on top of that, exactly when the new 'lr' would be identical to the previous one... pretty tough to do, the probability of them being able to do that is very close to 0 I think. And you don't need any internet connection to do that...
The new 'lr' would be identical to the previous one in the following cases only:
phone was not rebooted, and time was not changed
time was tampered with, AND the user managed to start your application at the precise millisecond to fool your algorithm (chances of that happening more than ultraslim)
// Returns true if device has rebooted since last time
private func deviceRebootedSinceLastTime() -> Bool {
let userDefaults = NSUserDefaults.standardUserDefaults()
let systemUptime = NSProcessInfo.processInfo().systemUptime;
let timeNow = NSDate().timeIntervalSince1970
let dateOfLastReboot = NSDate(timeIntervalSince1970: timeNow-systemUptime)
var didDeviceRebootSinceLastTime = false
if let storedDateOfLastReboot:NSDate = userDefaults.objectForKey("deviceLastRebootDate") as? NSDate {
if Int(dateOfLastReboot.timeIntervalSinceDate(storedDateOfLastReboot)) < 1 { //
print("Reboot time didn't change - date: \(dateOfLastReboot)");
}
else {
print("Reboot time has changed - from: \(storedDateOfLastReboot) to \(dateOfLastReboot)");
didDeviceRebootSinceLastTime = true
}
}
else {
print("Reboot time is saved for the first time")
didDeviceRebootSinceLastTime = true // first time we save value
}
userDefaults.setObject(dateOfLastReboot, forKey: "deviceLastRebootDate")
userDefaults.synchronize() // don't forget this!!!
return didDeviceRebootSinceLastTime;
}
Zoran's answer is the right way to go; it's the closest you are going to get without a network connection. (neither the cellular subsystem, nor the syslog are accessible for security reasons)
If you are looking to prevent malicious users from generating fake time data, have some central server (or trusted local server for enterprise deployments) track time-related events for you.
Get and save the time either from the iPhone or from NIST and the current runtime from the BSD uptime function. For NIST time see How can I get the real time in iPhone, not the time set by user in Settings?
When you want to check for a reboot get new values of these, compute the elapsed time for each and compare the elapsed times. Based on the difference you should be able to determine a reboot.
Here is one I made. It takes the current time in GMT and the time since last reboot to extrapolate a date for when the device was last restarted. Then it keeps track of this date in memory using NSUserDefaults. Enjoy!
Note: Since you want to check this since last time app was started, you need to make sure you call the method anytime the app is started. The easiest way would be to call the method below in +(void)initialize { and then also whenever you need to check it manually
#define nowInSeconds CFAbsoluteTimeGetCurrent()//since Jan 1 2001 00:00:00 GMT
#define secondsSinceDeviceRestart ((int)round([[NSProcessInfo processInfo] systemUptime]))
#define storage [NSUserDefaults standardUserDefaults]
#define DISTANCE(__valueOne, __valueTwo) ((((__valueOne)-(__valueTwo))>=0)?((__valueOne)-(__valueTwo)):((__valueTwo)-(__valueOne)))
+(BOOL)didDeviceReset {
static BOOL didDeviceReset;
static dispatch_once_t onceToken;
int currentRestartDate = nowInSeconds-secondsSinceDeviceRestart;
int previousRestartDate = (int)[((NSNumber *)[storage objectForKey:#"previousRestartDate"]) integerValue];
int dateVarianceThreshold = 10;
dispatch_once(&onceToken, ^{
if (!previousRestartDate || DISTANCE(currentRestartDate, previousRestartDate) > dateVarianceThreshold) {
didDeviceReset = YES;
} else {
didDeviceReset = NO;
}
});
[storage setObject:#(currentRestartDate) forKey:#"previousRestartDate"];
[storage synchronize];
return didDeviceReset;
}