-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_sending_to_mqtt.py
executable file
·37 lines (29 loc) · 1.18 KB
/
test_sending_to_mqtt.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# APRS_to_MQTT.py
# A simple Python script by G7UHN to publish an MQTT message when
# given text is received by a RTL/BeagleBone APRS receiver
# pip3 install paho-mqtt
import sys
from subprocess import Popen, PIPE
import paho.mqtt.client as mqtt
import datetime
username_pw_set(username="africube",password="AE@m0squtt0")
client = mqtt.Client("RTL-APR-VHF")
client.connect("iot.giga.co.za")
client.loop_start()
# General guidance from
# https://stackoverflow.com/questions/2804543/read-subprocess-stdout-line-by-line
# http://www.steves-internet-guide.com/into-mqtt-python-client/
#proc = Popen('rtl_fm -p 50 -f 144.80M - | direwolf -c sdr.conf -r 24000 -t 0 -D 1 -', stdout=PIPE, shell=True)
#while True:
# line = proc.stdout.readline()
# if line != '':
# # Print each line received by Python to stdout
# print ("Decoded:", line.rstrip())
# Look for a given text string...
# if "MQTT switch on" in line:
# Send an MQTT message to the APRS topic
client.publish("APRS","Turn the switch on")
# if "MQTT switch off" in line:
# # Send an MQTT message to the APRS topic
# client.publish("APRS","Turn the switch off")
# else: break