-
Notifications
You must be signed in to change notification settings - Fork 0
/
mqtt2sms.py
executable file
·61 lines (46 loc) · 1.7 KB
/
mqtt2sms.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/python
# -*- coding: utf-8 -*-
# vim tabstop=4 expandtab shiftwidth=4 softtabstop=4
#
# sms-bridge
# Sends sms messages
#
# todo also monitor google voice for sms messages and voice mails
# download them and keep an active count of unread
# publish the count to a topic and provide a way to retreive/play them
#
__author__ = "Dennis Sell"
__copyright__ = "Copyright (C) Dennis Sell"
APPNAME = "mqtt2sms"
VERSION = "0.10"
WATCHTOPIC = "/raw/" + APPNAME + "/command"
from googlevoice import Voice
from daemon import Daemon
from mqttcore import MQTTClientCore
from mqttcore import main
class MyMQTTClientCore(MQTTClientCore):
def __init__(self, appname, clienttype):
MQTTClientCore.__init__(self, appname, clienttype)
self.clientversion = VERSION
self.watchtopic = WATCHTOPIC
self.voicec = Voice()
def on_connect(self, mself, obj, rc):
MQTTClientCore.on_connect(self, mself, obj, rc)
self.mqttc.subscribe(self.watchtopic, qos=2)
def on_message(self, mself, obj, msg):
MQTTClientCore.on_message(self, mself, obj, msg)
if (msg.topic == self.watchtopic):
if ((msg.topic == self.watchtopic + "/message") and
(msg.payload != "")):
self.voicec.login()
sms_msg = msg.payload.split(':')
print "Sending SMS to: ", sms_msg[0]
print "Message: ", sms_msg[1]
self.voicec.send_sms(sms_msg[0], sms_msg[1])
class MyDaemon(Daemon):
def run(self):
mqttcore = MyMQTTClientCore(APPNAME, clienttype="single")
mqttcore.main_loop()
if __name__ == "__main__":
daemon = MyDaemon('/tmp/' + APPNAME + '.pid')
main(daemon)