Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Egi testing #5

Merged
merged 15 commits into from
Feb 3, 2021
Prev Previous commit
Next Next commit
better logging for EGI
  • Loading branch information
luke-iqt committed Jan 22, 2021
commit b54010fc254569eba4d981a65e740903a276a3c5
2 changes: 1 addition & 1 deletion egi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ FROM debian

RUN apt update && \
apt install -y python3 python3-pip && \
pip3 install paho-mqtt
pip3 install paho-mqtt coloredlogs

RUN mkdir -p /app/
WORKDIR /app
Expand Down
26 changes: 17 additions & 9 deletions egi/egi.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,17 @@
import json
import os
import argparse
import logging
import coloredlogs

Active = True
styles = {'critical': {'bold': True, 'color': 'red'}, 'debug': {'color': 'green'}, 'error': {'color': 'red'}, 'info': {'color': 'white'}, 'notice': {'color': 'magenta'}, 'spam': {'color': 'green', 'faint': True}, 'success': {'bold': True, 'color': 'green'}, 'verbose': {'color': 'blue'}, 'warning': {'color': 'yellow'}}
level = logging.INFO
coloredlogs.install(level=level, fmt='%(asctime)s.%(msecs)03d \033[0;90m%(levelname)-8s '
''
'\033[0;36m%(filename)-18s%(lineno)3d\033[00m '
'%(message)s',
level_styles = styles)

#######################################################
## Initialize Variables ##
Expand Down Expand Up @@ -42,9 +51,9 @@
#######################################################
def on_message_local(client, userdata, message):
payload = str(message.payload.decode("utf-8"))
print('Message Received: ' + message.topic + ' | ' + payload)
logging.info('Message Received: ' + message.topic + ' | ' + payload)
#if message.topic == local_topic+"/OFF":
# print("Turning Lamp OFF")
# logging.info("Turning Lamp OFF")

def on_disconnect(client, userdata, rc):
global Active
Expand All @@ -57,24 +66,23 @@ def on_disconnect(client, userdata, rc):
broker_address=config[Unit][0]
broker_address=args.mqtt_host
local_topic= config[Unit][1]
print("connecting to MQTT broker at "+broker_address+", channel '"+local_topic+"'")
logging.info("connecting to MQTT broker at "+broker_address+", channel '"+local_topic+"'")
clientLocal = mqtt.Client("EGI-"+ID) #create new instance
clientLocal.on_message = on_message_local #attach function to callback
clientLocal.on_disconnect = on_disconnect
clientLocal.connect(broker_address) #connect to broker
clientLocal.loop_start() #start the loop
clientLocal.subscribe(local_topic+"/#") #config/#")
clientLocal.publish(local_topic+"/registration","EGI-"+ID+" Registration")
#clientLocal.subscribe(local_topic+"/#") #config/#")
#clientLocal.publish(local_topic+"/registration","EGI-"+ID+" Registration")

#############################################
## Main Loop ##
#############################################
while Active:
if timeHeartbeat < time.mktime(time.gmtime()):
timeHeartbeat = time.mktime(time.gmtime()) + 10
clientLocal.publish(local_topic+"/Heartbeat","EGI-"+ID+" Heartbeat")
#if timeHeartbeat < time.mktime(time.gmtime()):
# timeHeartbeat = time.mktime(time.gmtime()) + 10
# clientLocal.publish(local_topic+"Heartbeat","EGI-"+ID+" Heartbeat")
if timeTrigger < time.mktime(time.gmtime()):
timeTrigger = time.mktime(time.gmtime()) + 10
print("sending message: " + state)
clientLocal.publish(local_topic,state)
time.sleep(0.1)
8 changes: 6 additions & 2 deletions tracker/flighttracker.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import sys
import os
import logging
import logging
import coloredlogs
import calendar
from datetime import datetime, timedelta
Expand Down Expand Up @@ -267,7 +266,9 @@ def dict(self):


def on_message(client, userdata, message):

global camera_altitude
global camera_latitude
global camera_longitude
command = str(message.payload.decode("utf-8"))
# Assumes you will only be getting JSON on your subscribed messages
try:
Expand All @@ -284,6 +285,9 @@ def on_message(client, userdata, message):
q.put(update) #put messages on queue
elif message.topic == "/egi/":
logging.info(update)
camera_longitude = float(update["long"])
camera_latitude = float(update["lat"])
camera_altitude = float(update["alt"])
else:
logging.info("Topic not processed: " + message.topic)

Expand Down
5 changes: 0 additions & 5 deletions tracker/requirements copy.txt

This file was deleted.