maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Maemo 5 / Fremantle (https://talk.maemo.org/forumdisplay.php?f=40)
-   -   [Python script] Syncing datetime with GPS time (https://talk.maemo.org/showthread.php?t=94637)

int_ua 2015-02-19 18:21

[Python script] Syncing datetime with GPS time
 
Main python script, gps_date.py:
Code:

#!/usr/bin/python
import location
import gobject
from sys import stderr


def on_error(control, error, data):
    stderr.write("location error: %d... quitting" % error)
    data.quit()


def on_changed(device, data):
    if not device:
        return

    if device.fix:
        if device.fix[1] & location.GPS_DEVICE_TIME_SET:
            timestamp, accuracy = device.fix[2:4]
            if accuracy == 0:
                print "%d" % timestamp
                data.stop()


def on_stop(control, data):
    data.quit()


def start_location(data):
    data.start()
    return False


method = location.METHOD_USER_SELECTED

loop = gobject.MainLoop()
control = location.GPSDControl.get_default()
device = location.GPSDevice()
control.set_properties(preferred_method=method,
                      preferred_interval=location.INTERVAL_DEFAULT)

control.connect("error-verbose", on_error, loop)
device.connect("changed", on_changed, control)
control.connect("gpsd-stopped", on_stop, loop)

gobject.idle_add(start_location, control)

loop.run()

Bash wrapper, must be executed with su privileges:
Code:

#!/bin/bash
/usr/bin/gnu/date --set "@$(python gps_date.py)"
hwclock -r
hwclock -w
hwclock -r


nokiabot 2015-02-19 19:20

Re: [Python script] Syncing datetime with GPS time
 
great been looking for something like this and can you make one which does via wifi ?
as i am tired of putting date on my other n900

peterleinchen 2015-02-19 19:27

Re: [Python script] Syncing datetime with GPS time
 
@nokiabot
package: ntpd

@int_ua
nice one. :)
(for me gpsrecorder does that, but now I can do script based:D)

JohnHughes 2015-02-22 16:17

Re: [Python script] Syncing datetime with GPS time
 
Would it be easier if ntpd could use the GPS as a clock source?

pichlo 2015-02-22 19:34

Re: [Python script] Syncing datetime with GPS time
 
It does! Albeit indirectly. It uses NTP, utilizing GPS as one of the clock sources. Read about the strata in the linked article.

JohnHughes 2015-02-28 12:45

Re: [Python script] Syncing datetime with GPS time
 
Quote:

Originally Posted by pichlo (Post 1461706)
It does! Albeit indirectly. It uses NTP, utilizing GPS as one of the clock sources. Read about the strata in the linked article.

Yes, I know that. What I meant is wouldn't it be easier if the ntpd on the n900 used the n900's GPS as a clock source.

Could ntpd clock driver type 20 (127.127.20.x) "Generic NMEA GPS Receiver" talk to the n900's GPS?


All times are GMT. The time now is 02:27.

vBulletin® Version 3.8.8