add more MQTT stuff

This commit is contained in:
KF7EEL 2022-03-07 19:08:55 -08:00
parent 866cbba362
commit 0d49fba100
5 changed files with 97 additions and 22 deletions

View File

@ -457,7 +457,6 @@ def download_config(CONFIG_FILE, cli_file):
try:
req = requests.post(user_man_url, data=json_object, headers={'Content-Type': 'application/json'})
resp = json.loads(req.text)
print(resp)
iterate_config = resp['peers'].copy()
corrected_config = resp['config'].copy()
corrected_config['SYSTEMS'] = {}
@ -885,18 +884,18 @@ def process_sms(_rf_src, sms, call_type, system_name):
elif '#' == parse_sms[0][0:1]:
## print(mqtt_services.keys())
if parse_sms[0][1:] in mqtt_services.keys():
mqtt_send_msg(str(parse_sms[0])[1:], parse_sms[1], int_id(_rf_src), ' '.join(parse_sms[2:]))
else:
# Add error message
pass
## if parse_sms[0][1:] in mqtt_services.keys():
mqtt_send_msg(str(parse_sms[0])[1:], parse_sms[1], int_id(_rf_src), ' '.join(parse_sms[2:]))
## else:
## # Add error message
## pass
elif '!' == parse_sms[0][0:1]:
## print(mqtt_services.keys())
if parse_sms[0][1:] in mqtt_services.keys():
mqtt_send_app(str(parse_sms[0])[1:], str(int_id(_rf_src)), ' '.join(parse_sms[1:]))
else:
# Add error message
pass
## if parse_sms[0][1:] in mqtt_services.keys():
mqtt_send_app(str(parse_sms[0])[1:], str(int_id(_rf_src)), ' '.join(parse_sms[1:]))
## else:
## # Add error message
## pass
elif '@' in parse_sms[0][0:1] and ' ' in sms: #'M-' not in parse_sms[1][0:2] or '@' not in parse_sms[0][1:]:
#Example SMS text: @ARMDS This is a test.
@ -1761,7 +1760,9 @@ def data_received(self, _peer_id, _rf_src, _dst_id, _seq, _slot, _call_type, _fr
for i in ars_snd:
print(ahex(bptc_decode(i)))
## systems[UNIT_MAP[_rf_src][0]].send_system(i)
systems[UNIT_MAP[_rf_src][0]].send_system(i)
@ -2073,6 +2074,8 @@ if __name__ == '__main__':
user_ssid = CONFIG['DATA_CONFIG']['USER_APRS_SSID']
aprs_comment = CONFIG['DATA_CONFIG']['USER_APRS_COMMENT']
aprs_filter = CONFIG['DATA_CONFIG']['APRS_FILTER']
## # User APRS settings
@ -2146,10 +2149,12 @@ if __name__ == '__main__':
rule_timer.addErrback(loopingErrHandle)
# Experimental MQTT for external applications, etc.
print(CONFIG['DATA_CONFIG']['MQTT_SERVER'])
mqtt_thread = threading.Thread(target=mqtt_main, args=(CONFIG['DATA_CONFIG']['MQTT_SERVER'],int(CONFIG['DATA_CONFIG']['MQTT_PORT']),))
mqtt_thread.daemon = True
mqtt_thread.start()
if CONFIG['DATA_CONFIG']['GATEWAY_CALLSIGN'] == 'n0call'.upper():
logger.info('MQTT disabled. External applications and networks will not be available.')
else:
mqtt_thread = threading.Thread(target=mqtt_main, args=(CONFIG['DATA_CONFIG']['MQTT_SERVER'],int(CONFIG['DATA_CONFIG']['MQTT_PORT']),))
mqtt_thread.daemon = True
mqtt_thread.start()
# Used for misc timing events
ten_loop_task = task.LoopingCall(ten_loop_func)

View File

@ -201,9 +201,10 @@ def build_config(_config_file):
## 'DASHBOARD_URL': config.get(section, 'DASHBOARD_URL'),
## 'SERVER_NAME': config.get(section, 'SERVER_NAME'),
## 'RULES_PATH': config.get(section, 'RULES_PATH'),
'GATEWAY_CALLSIGN': config.get(section, 'GATEWAY_CALLSIGN'),
'URL': config.get(section, 'URL'),
'DESCRIPTION': config.get(section, 'DESCRIPTION'),
## 'URL': config.get(section, 'URL'),
## 'DESCRIPTION': config.get(section, 'DESCRIPTION'),
'MQTT_SERVER': config.get(section, 'MQTT_SERVER'),
'MQTT_PORT': config.get(section, 'MQTT_PORT'),

View File

@ -54,7 +54,7 @@ import os, ast
from cryptography.fernet import Fernet
peer_locations = {}
hbnet_version = 'HWS 0.0.1-pre_pre_alpha'
hbnet_version = 'HWS 0.0.1-pre_pre_alpha/MQTT'
# Query radioid.net for list of IDs
def get_ids(callsign):
@ -4654,7 +4654,7 @@ Name: <strong>''' + p.name + '''</strong>&nbsp; -&nbsp; Port: <strong>''' + str(
## s = ServerList.query.filter_by(name=request.args.get('add_data_options')).first()
print(request.form)
print(request.form.get('user_settings'))
add_data_options(request.args.get('add_data_options'), 'DATA_GATEWAY:data_id=' + request.form.get('data_id') + ':call_type=' + request.form.get('call_type') + ':aprs_login_call=' + request.form.get('aprs_login_call') + ':aprs_login_passcode=' + request.form.get('aprs_login_passcode') + ':aprs_server=' + request.form.get('aprs_server') + ':aprs_port=' + request.form.get('aprs_port') + ':default_ssid=' + request.form.get('default_ssid') + ':default_comment=' + request.form.get('default_comment') + ':aprs_filter=' + request.form.get('aprs_filter') + ':user_settings=' + request.form.get('user_settings') + ':igate_time=' + request.form.get('igate_time') + ':igate_icon=' + request.form.get('igate_icon') + ':igate_comment=' + request.form.get('igate_comment') + ':igate_lat=' + request.form.get('igate_lat') + ':igate_lon=' + request.form.get('igate_lon') + '')
add_data_options(request.args.get('add_data_options'), 'DATA_GATEWAY:data_id=' + request.form.get('data_id') + ':call_type=' + request.form.get('call_type') + ':aprs_login_call=' + request.form.get('aprs_login_call') + ':aprs_login_passcode=' + request.form.get('aprs_login_passcode') + ':aprs_server=' + request.form.get('aprs_server') + ':aprs_port=' + request.form.get('aprs_port') + ':default_ssid=' + request.form.get('default_ssid') + ':default_comment=' + request.form.get('default_comment') + ':aprs_filter=' + request.form.get('aprs_filter') + ':user_settings=' + request.form.get('user_settings') + ':igate_time=' + request.form.get('igate_time') + ':igate_icon=' + request.form.get('igate_icon') + ':igate_comment=' + request.form.get('igate_comment') + ':igate_lat=' + request.form.get('igate_lat') + ':igate_lon=' + request.form.get('igate_lon') + ';MQTT:gateway_callsign=' + request.form.get('gateway_call') + ':server=' + request.form.get('mqtt_server') + ':port=' + request.form.get('mqtt_port') + ':username=' + request.form.get('mqtt_user') + ':password=' + request.form.get('mqtt_password') + ':url=' + request.form.get('url') + ':description=' + request.form.get('description'))
content = '''<h3 style="text-align: center;">Added data gateway options.</h3>
<p style="text-align: center;">Redirecting in 3 seconds.</p>
@ -7081,7 +7081,7 @@ Name: <strong>''' + p.name + '''</strong>&nbsp; -&nbsp; Port: <strong>''' + str(
</tr>
'''
web_output = '''
<h4 style="text-align: center;">External Services for: ''' + i.name + '''</h4>
<h4 style="text-align: center;">External Services for discovered: ''' + i.name + '''</h4>
<table data-toggle="table" data-pagination="true" data-search="true">
<thead>
<tr>

View File

@ -60,6 +60,34 @@
</tbody>
</table>
<p>&nbsp;</p>
<h2 style="text-align: center;"><strong>External Applications</strong></h2>
<p>If configured, this gateway can send and receive SMS messages from other networks and applications. An external application may be a type of gateway, such as an email gateway, or some other information service. See the <a href="/external_services" rel="nofollow">External Services</a> page to see what is available.</p>
<h4 style="text-align: center;">Social Status Commands</h4>
<table data-toggle="table" data-pagination="false">
<thead>
<tr>
<th>Command</th>
<th>Description</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>![SHORTCUT] [MESSAGE]</strong></td>
<td>Send a message to an external application.</td>
<td><em><code>!TST test</code></em></td>
</tr>
<tr>
<td><strong>#[SHORTCUT] [DMR ID] [MESSAGE]</strong></td>
<td>Send an SMS to another user on a different network.</td>
<td><em><code>#DMRNET 1234567 Are you there?</code></em></td>
</tr>
</tbody>
</table>
<p>&nbsp;</p>
<h2 style="text-align: center;"><strong>Tiny Pages</strong></h2>
<p>Tiny Pages are statically retrievable pieces of information. A tiny page can be created and changed by a user in the web service. A tiny page can be retrieved via SMS with a simple command. Potential uses include help messages, net schedule messages, or whatever you can think of.</p>
@ -121,7 +149,7 @@
<tbody>
<tr>
<td><strong>*SS</strong></td>
<td>Post a message to social status..</td>
<td>Post a message to social status.</td>
<td><em><code>*SS testing 123</code></em></td>
</tr>
<tr>

View File

@ -5,10 +5,13 @@
<br />
<strong>Note: </strong> Setting the APRS Login Call to <strong>N0CALL</strong> will disable APRS features. You will still be able to see station positions on the map though.
<strong>Note: </strong> Setting the APRS Login Call to <strong>N0CALL</strong> will disable APRS and MQTT (external application/network) features. You will still be able to see station positions on the map though.
<strong>Note: </strong> Setting iGate Time to 0 will disable beaconing of iGate packets.
<strong>Note: </strong> Leave MQTT Username and Password to use with servers that don't require authentication.
<br />
<br />
@ -106,6 +109,44 @@
<input type="text" id="igate_lon" name="igate_lon" class="form-control" aria-describedby="basic-addon1" value="00000.00W">
</div>
<br />
<br />
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">MQTT Callsign</span>
<input type="text" id="gateway_call" name="gateway_call" class="form-control" aria-describedby="basic-addon1" value="N0CALL">
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">URL</span>
<input type="text" id="url" name="url" class="form-control" aria-describedby="basic-addon1" value="www.example.org">
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">Description</span>
<input type="text" id="description" name="description" class="form-control" aria-describedby="basic-addon1" value="This is a network powered by HBNet.">
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">MQTT Server</span>
<input type="text" id="mqtt_server" name="mqtt_server" class="form-control" aria-describedby="basic-addon1" value="mqtt.hbnet.xyz">
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">MQTT Port</span>
<input type="text" id="mqtt_port" name="mqtt_port" class="form-control" aria-describedby="basic-addon1" value="1883">
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">MQTT Username</span>
<input type="text" id="mqtt_user" name="mqtt_user" class="form-control" aria-describedby="basic-addon1" value="">
</div>
<div class="input-group mb-3">
<span class="input-group-text" id="basic-addon1">MQTT Password</span>
<input type="text" id="mqtt_password" name="mqtt_password" class="form-control" aria-describedby="basic-addon1" value="">
</div>
<br />
<p style="text-align: center;"><input class="btn btn-primary" type="submit" value="Save" /></form></p>