Skip to content

Commit

Permalink
Merge pull request #4 from IQTLabs/egi-addition
Browse files Browse the repository at this point in the history
Add in EGI container
  • Loading branch information
luke-iqt authored Jan 22, 2021
2 parents 06b6675 + 9c1fd8e commit 17ed5cc
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 13 additions & 0 deletions egi/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
79 changes: 79 additions & 0 deletions egi/egi.py
Original file line number Diff line number Diff line change
@@ -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)
3 changes: 3 additions & 0 deletions env-example
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 17ed5cc

Please sign in to comment.