34 lines
1 KiB
Python
34 lines
1 KiB
Python
|
import time
|
||
|
import meshtastic
|
||
|
import meshtastic.tcp_interface
|
||
|
from pubsub import pub
|
||
|
|
||
|
def onReceive(packet, interface):
|
||
|
# called when a packet arrives
|
||
|
if 'decoded' in packet:
|
||
|
print('decoded')
|
||
|
decoded = packet['decoded']
|
||
|
|
||
|
if 'TEXT_MESSAGE_APP' in packet['decoded']:
|
||
|
print('TEXT_MESSAGE_APP')
|
||
|
|
||
|
if 'TELEMTRY_APP' in packet['decoded']:
|
||
|
print('Telementy found. Ignore')
|
||
|
|
||
|
if 'decoded' in packet and 'text' in packet['decoded']:
|
||
|
print(f"text message here: {packet['decoded']['text']}")
|
||
|
else:
|
||
|
print('Not the text message')
|
||
|
|
||
|
# print(f"Received: {packet}")
|
||
|
|
||
|
def onConnection(interface, topic=pub.AUTO_TOPIC): # called when we (re)connect to the radio
|
||
|
# defaults to broadcast, specify a destination ID if you wish
|
||
|
interface.sendText("hello mesh")
|
||
|
|
||
|
pub.subscribe(onReceive, "meshtastic.receive")
|
||
|
# pub.subscribe(onConnection, "meshtastic.connection.established")
|
||
|
interface = meshtastic.tcp_interface.TCPInterface(hostname='192.168.1.102')
|
||
|
while True:
|
||
|
time.sleep(1000)
|
||
|
interface.close()
|