Skip to content

Commit

Permalink
added logger to cometa and gps objects
Browse files Browse the repository at this point in the history
  • Loading branch information
marcoeg committed Dec 7, 2016
1 parent 06d4fc7 commit 99e6009
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions application.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ def main(argv):

# Connect to GPS
if 'gps' in config:
gps = GPS()
gps = GPS(syslog)
ret = gps.connect(config['gps']['serial'], config['gps']['speed'])
if ret:
syslog("Connected to GPS.")
Expand All @@ -72,7 +72,7 @@ def main(argv):
config['serial'] = device_id

# Instantiate a Cometa object
com = CometaClient(cometa_server, cometa_port, application_id, config['cometa']['ssl'])
com = CometaClient(cometa_server, cometa_port, application_id, config['cometa']['ssl'], syslog)
com.debug = config['app_params']['debug']
# bind the message_handler() callback
com.bind_cb(api.message_handler)
Expand Down
5 changes: 3 additions & 2 deletions cometalib.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class CometaClient(object):
"""Connect a device to the Cometa infrastructure"""
errors = {0:'ok', 1:'timeout', 2:'network error', 3:'protocol error', 4:'authorization error', 5:'wrong parameters', 9:'internal error'}

def __init__(self,server, port, application_id, use_ssl):
def __init__(self,server, port, application_id, use_ssl, logger):
"""
The Cometa instance constructor.
Expand All @@ -55,6 +55,7 @@ def __init__(self,server, port, application_id, use_ssl):
self._thbeat = None
self._hb_lock = threading.Lock()
self._reconnecting = False
self.log = logger
return

def attach(self, device_id, device_info):
Expand Down Expand Up @@ -186,7 +187,7 @@ def _heartbeat(self):
print "--- heartbeat while reconnecting"
continue
sendBuf = "1\r\n%c\r\n" % '\06'
print "sending heartbeat"
self.log("sending heartbeat")
try:
self._hb_lock.acquire()
self._sock.send(sendBuf)
Expand Down
9 changes: 5 additions & 4 deletions gpslib.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@
class GPS(object):
"""Receive data from a NMEA compatible GPS """

def __init__(self):
def __init__(self, logger):
self.port = None
self.reader = None
self.log = logger
self.readings = {}
""" Current readings accessible from the `readings` instance attribute """

Expand All @@ -38,7 +39,7 @@ def connect(self, device, speed):
try:
self.port = serial.Serial(device, speed)
except Exception as e:
print (e)
log("GPS: %s" % e)
return False

self.reader = pynmea2.NMEAStreamReader()
Expand Down Expand Up @@ -75,6 +76,6 @@ def loop(self):
self.readings['lon_dir'] = msg.lon_dir
self.readings['time'] = msg.timestamp
except Exception, e:
print e
log("GPS: %s" % e)
except Exception, e:
print e
log("GPS: %s" % e)

0 comments on commit 99e6009

Please sign in to comment.