def get_gps_time_sensor(self): """ Calculates GPS time using a TPV response from GPSd, and returns as a sensor dict This time is not high accuracy. """ self.log.trace("Polling GPS time results from GPSD") with GPSDIface() as gps_iface: response_mode = 0 # Read responses from GPSD until we get a non-trivial mode while response_mode <= 0: gps_info = gps_iface.get_gps_info(resp_class='tpv', timeout=15) self.log.trace("GPS info: {}".format(gps_info)) response_mode = gps_info.get("mode", 0) time_str = gps_info.get("time", "") self.log.trace("GPS time string: {}".format(time_str)) time_dt = datetime.datetime.strptime(time_str, "%Y-%m-%dT%H:%M:%S.%fZ") self.log.trace("GPS datetime: {}".format(time_dt)) epoch_dt = datetime.datetime(1970, 1, 1) gps_time = int((time_dt - epoch_dt).total_seconds()) return { 'name': 'gps_time', 'type': 'INTEGER', 'unit': 'seconds', 'value': str(gps_time), }
def get_gps_sky_sensor(self): """ Get a SKY response from GPSd as a sensor dict """ self.log.trace("Polling GPS SKY results from GPSD") with GPSDIface() as gps_iface: # Just get the first SKY result gps_info = gps_iface.get_gps_info(resp_class='sky', timeout=15) # Return the JSON'd results gps_sky = json.dumps(gps_info) return { 'name': 'gps_sky', 'type': 'STRING', 'unit': '', 'value': gps_sky, }
def get_gps_tpv_sensor(self): """ Get a TPV response from GPSd as a sensor dict """ self.log.trace("Polling GPS TPV results from GPSD") with GPSDIface() as gps_iface: response_mode = 0 # Read responses from GPSD until we get a non-trivial mode while response_mode <= 0: gps_info = gps_iface.get_gps_info(resp_class='tpv', timeout=15) self.log.trace("GPS info: {}".format(gps_info)) response_mode = gps_info.get("mode", 0) # Return the JSON'd results gps_tpv = json.dumps(gps_info) return { 'name': 'gps_tpv', 'type': 'STRING', 'unit': '', 'value': gps_tpv, }