Skip to content

Commit

Permalink
Merge pull request #1243 from aaronwmorris/dev
Browse files Browse the repository at this point in the history
add MQTT image publish option
  • Loading branch information
aaronwmorris authored Apr 30, 2024
2 parents fc53b74 + 8e4d4cb commit a8b0dea
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 10 deletions.
1 change: 1 addition & 0 deletions indi_allsky/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ class IndiAllSkyConfigBase(object):
"QOS" : 0, # 0, 1, or 2
"TLS" : True,
"CERT_BYPASS" : True,
"PUBLISH_IMAGE" : True,
},
"SYNCAPI" : {
"ENABLE" : False,
Expand Down
16 changes: 9 additions & 7 deletions indi_allsky/filetransfer/paho_mqtt.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ def put(self, *args, **kwargs):
qos = kwargs['qos']
mq_data = kwargs['mq_data']
image_topic = kwargs['image_topic']
publish_image = kwargs['publish_image']

local_file_p = Path(local_file)


message_list = list()

# publish image
with io.open(local_file_p, 'rb') as f_localfile:
message_list.append({
'topic' : '/'.join((base_topic, image_topic)),
'payload' : f_localfile.read(), # this requires paho-mqtt >= v2.0.0
'qos' : qos,
'retain' : True,
})
if publish_image:
with io.open(local_file_p, 'rb') as f_localfile:
message_list.append({
'topic' : '/'.join((base_topic, image_topic)),
'payload' : f_localfile.read(), # this requires paho-mqtt >= v2.0.0
'qos' : qos,
'retain' : True,
})


for k, v in mq_data.items():
Expand Down
1 change: 1 addition & 0 deletions indi_allsky/flask/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -2598,6 +2598,7 @@ class IndiAllskyConfigForm(FlaskForm):
MQTTPUBLISH__QOS = IntegerField('MQTT QoS', validators=[MQTTPUBLISH__QOS_validator])
MQTTPUBLISH__TLS = BooleanField('Use TLS')
MQTTPUBLISH__CERT_BYPASS = BooleanField('Disable Certificate Validation')
MQTTPUBLISH__PUBLISH_IMAGE = BooleanField('Enable Image Publishing')
SYNCAPI__ENABLE = BooleanField('Enable Sync API')
SYNCAPI__BASEURL = StringField('URL', validators=[SYNCAPI__BASEURL_validator])
SYNCAPI__USERNAME = StringField('Username', validators=[SYNCAPI__USERNAME_validator], render_kw={'autocomplete' : 'new-password'})
Expand Down
22 changes: 21 additions & 1 deletion indi_allsky/flask/templates/config.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

{% block head %}
<style>
#nav-camera-tab, #nav-image-tab, #nav-processing-tab, #nav-location-tab, #nav-admin-tab, #nav-filetransfer-tab, #nav-s3-tab, #nav-syncapi-tab, #nav-youtube-tab {
#nav-camera-tab, #nav-image-tab, #nav-processing-tab, #nav-location-tab, #nav-admin-tab, #nav-filetransfer-tab, #nav-s3-tab, #nav-syncapi-tab, #nav-youtube-tab, #nav-mqtt-tab {
width: 150px;
margin-top: 10px;
margin-right: 5px;
Expand All @@ -24,6 +24,7 @@
<button class="nav-link link-info bg-dark" id="nav-location-tab" data-bs-toggle="tab" data-bs-target="#nav-location" type="button" role="tab" aria-controls="nav-location" aria-selected="false">Location</button>
<button class="nav-link link-warning bg-dark" id="nav-admin-tab" data-bs-toggle="tab" data-bs-target="#nav-admin" type="button" role="tab" aria-controls="nav-admin" aria-selected="false">Admin</button>
<button class="nav-link link-primary bg-dark" id="nav-filetransfer-tab" data-bs-toggle="tab" data-bs-target="#nav-filetransfer" type="button" role="tab" aria-controls="nav-filetransfer" aria-selected="false">File Transfer</button>
<button class="nav-link link-info bg-dark" id="nav-mqtt-tab" data-bs-toggle="tab" data-bs-target="#nav-mqtt" type="button" role="tab" aria-controls="nav-mqtt" aria-selected="false">MQTT</button>
<button class="nav-link link-danger bg-dark" id="nav-youtube-tab" data-bs-toggle="tab" data-bs-target="#nav-youtube" type="button" role="tab" aria-controls="nav-youtube" aria-selected="false">YouTube</button>
<button class="nav-link link-secondary bg-dark" id="nav-s3-tab" data-bs-toggle="tab" data-bs-target="#nav-s3" type="button" role="tab" aria-controls="nav-s3" aria-selected="false">Object Storage</button>
<button class="nav-link link-light bg-dark" id="nav-syncapi-tab" data-bs-toggle="tab" data-bs-target="#nav-syncapi" type="button" role="tab" aria-controls="nav-syncapi" aria-selected="false">SyncAPI</button>
Expand Down Expand Up @@ -3167,6 +3168,9 @@
<div class="col-sm-8">Enable Allsky EndOfNight uploads</div>
</div>

</div><!-- end filetransfer tab -->
<div class="tab-pane fade" id="nav-mqtt" role="tabpanel" aria-labelledby="nav-mqtt-tab">

<hr>

<div class="form-group row">
Expand Down Expand Up @@ -3285,6 +3289,21 @@
<div class="col-sm-8">Bypass certificate validation</div>
</div>

<hr>

<div class="form-group row">
<div class="col-sm-2">
{{ form_config.MQTTPUBLISH__PUBLISH_IMAGE.label }}
</div>
<div class="col-sm-2">
<div class="form-switch">
{{ form_config.MQTTPUBLISH__PUBLISH_IMAGE(class='form-check-input') }}
<div id="MQTTPUBLISH__PUBLISH_IMAGE-error" class="invalid-feedback text-danger" style="display: none;"></div>
</div>
</div>
<div class="col-sm-8"></div>
</div>

</div><!-- end filetransfer tab -->
<div class="tab-pane fade" id="nav-youtube" role="tabpanel" aria-labelledby="nav-youtube-tab">

Expand Down Expand Up @@ -4271,6 +4290,7 @@
'MQTTPUBLISH__ENABLE',
'MQTTPUBLISH__TLS',
'MQTTPUBLISH__CERT_BYPASS',
'MQTTPUBLISH__PUBLISH_IMAGE',
'SYNCAPI__ENABLE',
'SYNCAPI__CERT_BYPASS',
'SYNCAPI__POST_S3',
Expand Down
4 changes: 2 additions & 2 deletions indi_allsky/flask/templates/imageprocessing.html
Original file line number Diff line number Diff line change
Expand Up @@ -709,8 +709,6 @@ <h5>These options are applied to the unprocessed image automatically</h5>
'SATURATION_FACTOR',
'IMAGE_ROTATE',
'IMAGE_ROTATE_ANGLE',
'IMAGE_FLIP_V',
'IMAGE_FLIP_H',
'DETECT_MASK',
'SQM_FOV_DIV',
'SQM_ROI_X1',
Expand All @@ -737,6 +735,8 @@ <h5>These options are applied to the unprocessed image automatically</h5>
'IMAGE_STRETCH__MODE1_ENABLE',
'AUTO_WB',
'IMAGE_STACK_ALIGN',
'IMAGE_FLIP_V',
'IMAGE_FLIP_H',
//'PROCESSING_SPLIT_SCREEN',
'FISH2PANO__ENABLE',
];
Expand Down
2 changes: 2 additions & 0 deletions indi_allsky/flask/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,7 @@ def get_context(self):
'MQTTPUBLISH__QOS' : self.indi_allsky_config.get('MQTTPUBLISH', {}).get('QOS', 0),
'MQTTPUBLISH__TLS' : self.indi_allsky_config.get('MQTTPUBLISH', {}).get('TLS', True),
'MQTTPUBLISH__CERT_BYPASS' : self.indi_allsky_config.get('MQTTPUBLISH', {}).get('CERT_BYPASS', True),
'MQTTPUBLISH__PUBLISH_IMAGE' : self.indi_allsky_config.get('MQTTPUBLISH', {}).get('PUBLISH_IMAGE', True),
'SYNCAPI__ENABLE' : self.indi_allsky_config.get('SYNCAPI', {}).get('ENABLE', False),
'SYNCAPI__BASEURL' : self.indi_allsky_config.get('SYNCAPI', {}).get('BASEURL', 'https://example.com/indi-allsky'),
'SYNCAPI__USERNAME' : self.indi_allsky_config.get('SYNCAPI', {}).get('USERNAME', ''),
Expand Down Expand Up @@ -1921,6 +1922,7 @@ def dispatch_request(self):
self.indi_allsky_config['MQTTPUBLISH']['QOS'] = int(request.json['MQTTPUBLISH__QOS'])
self.indi_allsky_config['MQTTPUBLISH']['TLS'] = bool(request.json['MQTTPUBLISH__TLS'])
self.indi_allsky_config['MQTTPUBLISH']['CERT_BYPASS'] = bool(request.json['MQTTPUBLISH__CERT_BYPASS'])
self.indi_allsky_config['MQTTPUBLISH']['PUBLISH_IMAGE'] = bool(request.json['MQTTPUBLISH__PUBLISH_IMAGE'])
self.indi_allsky_config['SYNCAPI']['ENABLE'] = bool(request.json['SYNCAPI__ENABLE'])
self.indi_allsky_config['SYNCAPI']['BASEURL'] = str(request.json['SYNCAPI__BASEURL'])
self.indi_allsky_config['SYNCAPI']['USERNAME'] = str(request.json['SYNCAPI__USERNAME'])
Expand Down
1 change: 1 addition & 0 deletions indi_allsky/uploader.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ def processUpload(self, u_dict):
'base_topic' : self.config['MQTTPUBLISH']['BASE_TOPIC'],
'qos' : self.config['MQTTPUBLISH']['QOS'],
'mq_data' : metadata,
'publish_image' : self.config['MQTTPUBLISH'].get('PUBLISH_IMAGE', True),
}

try:
Expand Down

0 comments on commit a8b0dea

Please sign in to comment.