Created
September 20, 2024 17:26
-
-
Save dadecoza/60b47574f44c3b08b5b9d34dd8f1a1ac to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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