diff --git a/docker-compose.yml b/docker-compose.yml index 9364315..3ed4954 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -68,4 +68,16 @@ services: ports: - "9001:9001" - "1883:1883" + restart: unless-stopped + + egi: + build: ./egi + entrypoint: "/app/egi.py -m mqtt" + environment: + - LAT=${LAT} + - LONG=${LONG} + - ALT=${ALT} + - ROLL=${ROLL} + - PITCH=${PITCH} + - YAW=${YAW} restart: unless-stopped \ No newline at end of file diff --git a/egi/Dockerfile b/egi/Dockerfile new file mode 100644 index 0000000..d7a3349 --- /dev/null +++ b/egi/Dockerfile @@ -0,0 +1,13 @@ +FROM debian + +RUN apt update && \ + apt install -y python3 python3-pip && \ + pip3 install paho-mqtt + +RUN mkdir -p /app/ +WORKDIR /app +ADD *.py /app/ + +#ENTRYPOINT python3 /tmp/egi.py + +#docker run -d --restart unless-stopped --network=host -v /home/pi/:/tmp/ --name lamp docker-registry.iqt.org/mission-capabilities/rpi-stats-reporting/lamp-control diff --git a/egi/egi.py b/egi/egi.py new file mode 100644 index 0000000..2052d3d --- /dev/null +++ b/egi/egi.py @@ -0,0 +1,79 @@ +#!/usr/bin/env python3 + +import paho.mqtt.client as mqtt #import the client1 +import time +import random +import json +import os +import argparse + +Active = True + +####################################################### +## Initialize Variables ## +####################################################### +config = {} +config['Local'] = ["127.0.0.1", "/egi/", "Local MQTT Bus"] +timeTrigger = 0 +timeHeartbeat = 0 +ID = str(random.randint(1,100001)) + +LLA = [ os.environ['LAT'], os.environ['LONG'], os.environ['ALT'] ] +RPY = [ os.environ['ROLL'], os.environ['PITCH'], os.environ['YAW'] ] + +state = {} +state['lat'] = LLA[0] +state['long'] = LLA[1] +state['alt'] = LLA[2] +state['roll'] = RPY[0] +state['pitch'] = RPY[1] +state['yaw'] = RPY[2] +state=json.dumps(state) + +parser = argparse.ArgumentParser(description='An MQTT based camera controller') + +parser.add_argument('-m', '--mqtt-host', help="MQTT broker hostname", default='127.0.0.1') + +args = parser.parse_args() + + +####################################################### +## Local MQTT Callback Function ## +####################################################### +def on_message_local(client, userdata, message): + payload = str(message.payload.decode("utf-8")) + print('Message Received: ' + message.topic + ' | ' + payload) + #if message.topic == local_topic+"/OFF": + # print("Turning Lamp OFF") + +def on_disconnect(client, userdata, rc): + global Active + Active = False + +############################################# +## Initialize Local MQTT Bus ## +############################################# +Unit = 'Local' +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+"'") +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") + +############################################# +## 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 timeTrigger < time.mktime(time.gmtime()): + timeTrigger = time.mktime(time.gmtime()) + 10 + clientLocal.publish(local_topic,state) + time.sleep(0.001) \ No newline at end of file diff --git a/env-example b/env-example index 7306b39..ddc655f 100644 --- a/env-example +++ b/env-example @@ -2,6 +2,9 @@ TZ="New York" #Local timezone in "TZ database name" format. https://en.wikipedia LAT=38.890022390623265 # Latitude of the camera LONG=-77.03513244930217 # Longitude of the camera ALT=170 # Altitude of the camera, in feet above sea level +ROLL=0 # Roll Angle of Camera Mount from Inertial +PITCH=0 # Pitch Angle of Camera Mount from Inertial +YAW=0 # Yaw Angle of Camera Mount from Inertial MIN_ELEVATION=45 # The minimum elevation for the camera. FEEDER_ID=long-api-key-goes-here # Your FlightAware feeder ID (required) AXIS_USERNAME=user # The username for the Axis camera