Skip to content

Instantly share code, notes, and snippets.

@dadecoza
Created September 20, 2024 17:26
Show Gist options
  • Save dadecoza/60b47574f44c3b08b5b9d34dd8f1a1ac to your computer and use it in GitHub Desktop.
Save dadecoza/60b47574f44c3b08b5b9d34dd8f1a1ac to your computer and use it in GitHub Desktop.
from subprocess import Popen, PIPE, STDOUT, DEVNULL
import time
import meshtastic
import meshtastic.tcp_interface
from pubsub import pub
pager_id = "0107962"
def sendmsg(msg):
payload = f"{pager_id}:{msg}".encode()
p = Popen([
"/home/pi/rpitx/pocsag",
"-f",
"151100000",
"-b",
"3",
"-r",
"512",
"-t",
"1"
],
stdin=PIPE,
stdout=DEVNULL
)
p.communicate(input=payload)
def onReceive(packet, interface): # called when a packet arrives
# print(f"Received: {packet}")
if "channel" not in packet:
return
if packet["channel"] == 1:
decoded = packet["decoded"]
if decoded["portnum"] == "TEXT_MESSAGE_APP":
payload = decoded["payload"].decode()
fromid = packet["fromId"]
msg = f"{fromid}>{payload}"
print(msg)
sendmsg(msg)
pub.subscribe(onReceive, "meshtastic.receive")
interface = meshtastic.tcp_interface.TCPInterface(hostname='192.168.3.12')
while True:
time.sleep(200)
interface.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment