Update for new Meshtastic version
This commit is contained in:
parent
7a053a51fe
commit
4baa80657c
20
main.py
20
main.py
|
@ -31,19 +31,19 @@ def int_to_mesh_id(num):
|
||||||
# example: -697240346 to !d670f4e6
|
# example: -697240346 to !d670f4e6
|
||||||
|
|
||||||
hex_str = hex(num & 0xFFFFFFFF)
|
hex_str = hex(num & 0xFFFFFFFF)
|
||||||
return '!' + hex_str[2:]
|
return '!' + hex_str[2:].zfill(8)
|
||||||
|
|
||||||
async def process_text(data):
|
async def process_text(data):
|
||||||
msg_to = data.get('to', None)
|
msg_to = data.get('to', None)
|
||||||
|
|
||||||
if msg_to != -1:
|
if msg_to not in [-1, 4294967295]:
|
||||||
logging.debug('Message not for channel: %s', str(data))
|
logging.debug('Message not for channel: %s', str(data))
|
||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
msg_text = data['payload']['text']
|
msg_text = data['payload']['text']
|
||||||
sender = data['from']
|
sender = data['from']
|
||||||
except KeyError:
|
except (KeyError, TypeError):
|
||||||
logging.info('Invalid payload: %s', str(data))
|
logging.info('Invalid payload: %s', str(data))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -51,20 +51,20 @@ async def process_text(data):
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from_name = storage['nodes'][sender_id]['long_name']
|
from_name = storage['nodes'][sender_id]['long_name']
|
||||||
except KeyError:
|
except (KeyError, TypeError):
|
||||||
from_name = 'Unknown sender'
|
from_name = sender_id
|
||||||
|
|
||||||
logging.info('Channel message from %s: %s', from_name, msg_text)
|
logging.info('Channel message from %s: %s', from_name, msg_text)
|
||||||
|
|
||||||
msg = from_name + ': ' + msg_text
|
msg = from_name + ': ' + msg_text
|
||||||
await bot.send_message(settings.CHAT_ID, msg)
|
await bot.send_message(settings.CHAT_ID, msg, link_preview=False)
|
||||||
|
|
||||||
async def process_info(data):
|
async def process_info(data):
|
||||||
try:
|
try:
|
||||||
node_id = data['payload']['id']
|
node_id = data['payload']['id']
|
||||||
long_name = data['payload']['longname']
|
long_name = data['payload']['longname']
|
||||||
short_name = data['payload']['shortname']
|
short_name = data['payload']['shortname']
|
||||||
except KeyError:
|
except (KeyError, TypeError):
|
||||||
logging.info('Invalid payload: %s', str(data))
|
logging.info('Invalid payload: %s', str(data))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -102,7 +102,7 @@ async def process_mqtt(message):
|
||||||
|
|
||||||
if msg_type == 'text':
|
if msg_type == 'text':
|
||||||
await process_text(data)
|
await process_text(data)
|
||||||
if msg_type == 'nodeinfo':
|
elif msg_type == 'nodeinfo':
|
||||||
await process_info(data)
|
await process_info(data)
|
||||||
else:
|
else:
|
||||||
logging.debug('Ignored message type %s: %s', msg_type, text)
|
logging.debug('Ignored message type %s: %s', msg_type, text)
|
||||||
|
@ -110,8 +110,8 @@ async def process_mqtt(message):
|
||||||
|
|
||||||
async def fetch_mqtt():
|
async def fetch_mqtt():
|
||||||
async with Client('localhost') as client:
|
async with Client('localhost') as client:
|
||||||
async with client.filtered_messages('msh/+/json/#') as messages:
|
async with client.filtered_messages('msh/+/+/json/#') as messages:
|
||||||
await client.subscribe('msh/+/json/#')
|
await client.subscribe('msh/+/+/json/#')
|
||||||
async for message in messages:
|
async for message in messages:
|
||||||
await process_mqtt(message)
|
await process_mqtt(message)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user