README install
This commit is contained in:
@@ -56,33 +56,56 @@ https://github.com/termux/termux-app
|
|||||||
- Termux: API
|
- Termux: API
|
||||||
- Termux: Widget
|
- Termux: Widget
|
||||||
|
|
||||||
|
<<<<<<< Upstream, based on origin/main
|
||||||
#### MQTT client installing:
|
#### MQTT client installing:
|
||||||
|
=======
|
||||||
|
|
||||||
|
#### Installing the mqtt client:
|
||||||
|
>>>>>>> 5d3172f README install
|
||||||
|
|
||||||
The following python packages will be installed:
|
The following python packages will be installed:
|
||||||
|
|
||||||
- termux-sms-gateway
|
- termux-sms-gateway
|
||||||
- paho-mqtt
|
- paho-mqtt
|
||||||
- supervisor
|
- supervisor
|
||||||
|
<<<<<<< Upstream, based on origin/main
|
||||||
|
=======
|
||||||
|
- supervisor is a process control system
|
||||||
|
- because Android do not support hard links, it will be necessary to patch http.py from library
|
||||||
|
>>>>>>> 5d3172f README install
|
||||||
- rsa >> https://stuvel.eu/python-rsa-doc/
|
- rsa >> https://stuvel.eu/python-rsa-doc/
|
||||||
|
|
||||||
|
|
||||||
### Installation procedure
|
### Installation procedure
|
||||||
|
|
||||||
After installing termux on the laptop, launch Termux
|
After installing termux on the smartphone, launch Termux
|
||||||
|
|
||||||
- Copy and paste the following command in the termux terminal
|
- Copy and paste the following command in the termux terminal
|
||||||
|
|
||||||
export PACKAGE="TermuxSmsGateway"&&export VERSION="1.0"&&mkdir -p $HOME/.termux/tasks&&
|
export PACKAGE="TermuxSmsGateway"&&
|
||||||
apt install termux-api git -y&&rm -rf termux-sms-gateway&&
|
export VERSION="1.0"&&
|
||||||
git clone &&
|
mkdir -p $HOME/.termux/tasks&&
|
||||||
cp -f $PACKAGE/smsquitto-st* $HOME/.termux/tasks/&&cp -f $PACKAGE/smsquitto/smsquitto-conf.yaml $HOME/.termux/&&
|
apt install python git termux-api -y&&
|
||||||
pip install $PACKAGE/dist/smsquitto-$VERSION.tar.gz
|
rm -rf TermuxSmsGateway&&
|
||||||
|
git clone https://github.com/deunix-educ/TermuxSmsGateway.git&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/smsquitto-st* $HOME/.termux/tasks/&&
|
||||||
|
cp -f $PACKAGE/smsquitto/smsquitto-conf.yaml $HOME/.termux/&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/supervisord $HOME/.termux/boot/&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/supervisord.conf $PREFIX/etc/&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/smsquitto.conf $PREFIX/etc/supervisor.d/&&
|
||||||
|
pip install $PACKAGE/dist/smsquitto-$VERSION.tar.gz&&
|
||||||
|
cd $PREFIX/lib/python3.9/site-packages/supervisor&&
|
||||||
|
patch < $PACKAGE/smsquitto-install/supervisor/patch/http.py.patch
|
||||||
|
|
||||||
- Enter to start installation
|
- Enter to start installation
|
||||||
|
|
||||||
### Installation parameters
|
### Installation parameters
|
||||||
|
|
||||||
|
<<<<<<< Upstream, based on origin/main
|
||||||
- Installation parameters are in ~/.termux/smsquitto-conf.yaml
|
- Installation parameters are in ~/.termux/smsquitto-conf.yaml
|
||||||
|
=======
|
||||||
|
- smsquitto server parameters are in ~/.termux/smsquitto-conf.yaml
|
||||||
|
>>>>>>> 5d3172f README install
|
||||||
- host: ip or domain of the MQTT server
|
- host: ip or domain of the MQTT server
|
||||||
- port: 1883 or 8883
|
- port: 1883 or 8883
|
||||||
- keepalive: 60
|
- keepalive: 60
|
||||||
@@ -96,11 +119,9 @@ After installing termux on the laptop, launch Termux
|
|||||||
- ex: SQTT010203040506079
|
- ex: SQTT010203040506079
|
||||||
|
|
||||||
- Copy and paste the following command in the terminal
|
- Copy and paste the following command in the terminal
|
||||||
|
|
||||||
nano $HOME/.termux/smsquitto-conf.yaml
|
nano $HOME/.termux/smsquitto-conf.yaml
|
||||||
|
|
||||||
- Install services (start, stop, status)
|
- Install services (start, stop, status)
|
||||||
|
|
||||||
- Install the Tremux widget:Widget on the phone's desktop by keeping your finger on the screen
|
- Install the Tremux widget:Widget on the phone's desktop by keeping your finger on the screen
|
||||||
- Choose shortcut
|
- Choose shortcut
|
||||||
- Change the icon and the name if you want
|
- Change the icon and the name if you want
|
||||||
@@ -134,10 +155,12 @@ After installing termux on the laptop, launch Termux
|
|||||||
|
|
||||||
- Notification
|
- Notification
|
||||||
- script://notify.sh #FIELD1 #FIELD2 #FIELD3 #FIELD4 #TO #MESSAGE --tls or nothing
|
- script://notify.sh #FIELD1 #FIELD2 #FIELD3 #FIELD4 #TO #MESSAGE --tls or nothing
|
||||||
|
- command
|
||||||
- /usr/bin/python3 /home/pi/domoticz/scripts/notify.py --method=notify --host=$1 --port=$2 --user=$3 --password=$4 --apikey=$5 --text="$6" $7
|
- /usr/bin/python3 /home/pi/domoticz/scripts/notify.py --method=notify --host=$1 --port=$2 --user=$3 --password=$4 --apikey=$5 --text="$6" $7
|
||||||
|
|
||||||
- SMS
|
- SMS
|
||||||
- script://notify.sh #FIELD1 #FIELD2 #FIELD3 #FIELD4 #TO #MESSAGE "00330645953706,0033791246318" --tls or nothing
|
- script://notify.sh #FIELD1 #FIELD2 #FIELD3 #FIELD4 #TO #MESSAGE "00330645953706,0033791246318" --tls or nothing
|
||||||
|
- command
|
||||||
- /usr/bin/python3 /home/pi/domoticz/scripts/smsquitto.py --method=sms --host=$1 --port=$2 --user=$3 --password=$4 --apikey=$5 --text="$6" --phone="$7" $8
|
- /usr/bin/python3 /home/pi/domoticz/scripts/smsquitto.py --method=sms --host=$1 --port=$2 --user=$3 --password=$4 --apikey=$5 --text="$6" --phone="$7" $8
|
||||||
|
|
||||||
- SSL certification
|
- SSL certification
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
settings:
|
||||||
|
host: broker.emqx.io
|
||||||
|
port: 1883
|
||||||
|
keepalive: 60
|
||||||
|
username: emqx
|
||||||
|
password: public
|
||||||
|
useSSL: False
|
||||||
|
ca_cert: None
|
||||||
|
apikey: SQTT0192837495867
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
#
|
||||||
|
# encoding: utf-8
|
||||||
|
import atexit
|
||||||
|
import sys, os
|
||||||
|
import datetime
|
||||||
|
import json
|
||||||
|
import ssl
|
||||||
|
import subprocess
|
||||||
|
import paho.mqtt.client as mqtt
|
||||||
|
import yaml
|
||||||
|
|
||||||
|
def yaml_load(f):
|
||||||
|
with open(f, 'r') as stream:
|
||||||
|
return yaml.load(stream, Loader=yaml.FullLoader)
|
||||||
|
return {}
|
||||||
|
|
||||||
|
class ClientMQTTBase(mqtt.Client):
|
||||||
|
def __init__(self,
|
||||||
|
host='localhost',
|
||||||
|
port=1883,
|
||||||
|
keepalive=60,
|
||||||
|
username=None,
|
||||||
|
password=None,
|
||||||
|
useSSL=False,
|
||||||
|
ca_cert=None,
|
||||||
|
apikey='0192837495867'
|
||||||
|
):
|
||||||
|
|
||||||
|
super(ClientMQTTBase, self).__init__()
|
||||||
|
self.host = host
|
||||||
|
self.port = port
|
||||||
|
self.keepalive = keepalive
|
||||||
|
if username:
|
||||||
|
self.username_pw_set(username, password)
|
||||||
|
|
||||||
|
if useSSL and ca_cert:
|
||||||
|
self.tls_set(ca_certs=ca_cert, tls_version=ssl.PROTOCOL_TLSv1_2)
|
||||||
|
#self.tls_insecure_set(True)
|
||||||
|
|
||||||
|
self.topic = '%s/emit/' % apikey
|
||||||
|
self.subscriptions = [['%s/pub/#' % apikey, 0],]
|
||||||
|
|
||||||
|
def now(self):
|
||||||
|
return int(datetime.datetime.now().timestamp())
|
||||||
|
|
||||||
|
def sub(self):
|
||||||
|
subs = [(topic, qos) for topic, qos in self.subscriptions]
|
||||||
|
return subs
|
||||||
|
|
||||||
|
def unsub(self):
|
||||||
|
return [topic for topic, _ in self.subscriptions ]
|
||||||
|
|
||||||
|
def startMQTT(self):
|
||||||
|
self.connect(self.host, self.port, self.keepalive)
|
||||||
|
self.subscribe(self.sub())
|
||||||
|
|
||||||
|
def stopMQTT(self):
|
||||||
|
self.unsubscribe(self.unsub())
|
||||||
|
self.disconnect()
|
||||||
|
self.exit()
|
||||||
|
|
||||||
|
def publish_message(self, topic, **payload):
|
||||||
|
try:
|
||||||
|
qos = payload.pop('qos', 0)
|
||||||
|
retain = payload.pop('retain', False)
|
||||||
|
message = json.dumps(payload)
|
||||||
|
self.publish(topic, payload=message.encode('utf_8'), qos=qos, retain=retain)
|
||||||
|
except Exception as e:
|
||||||
|
print("ClientMQTTBase::publish_message error:", e, flush=True)
|
||||||
|
|
||||||
|
def on_connect(self, mqttc, obj, flags, rc): # @UnusedVariable
|
||||||
|
#print("ClientMQTTBase on_connect ")
|
||||||
|
pass
|
||||||
|
|
||||||
|
def on_message(self, mqttc, obj, msg):
|
||||||
|
#print("ClientMQTTBase on_message:", msg.topic, msg.qos, msg.payload)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def on_publish(self, mqttc, obj, mid):
|
||||||
|
#print("on_publish:", mid, obj)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def on_subscribe(self, mqttc, obj, mid, granted_qos): # @UnusedVariable
|
||||||
|
#print("ClientMQTTBase on_subscribe:", mid, granted_qos)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def on_unsubscribe(self, mqttc, userdata, mid): # @UnusedVariable
|
||||||
|
#print("ClientMQTTBase on_unsubscribe:", mid, userdata)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def on_disconnect(self, mqttc, userdata, mid): # @UnusedVariable
|
||||||
|
#print("ClientMQTTBase on_disconnect:", mqttc)
|
||||||
|
pass
|
||||||
|
|
||||||
|
def on_log(self, mqttc, obj, level, string): # @UnusedVariable
|
||||||
|
#print("onlog:", level, string)
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class SmsQuitto(ClientMQTTBase):
|
||||||
|
|
||||||
|
def __init__(self, **mosquitto):
|
||||||
|
super(SmsQuitto, self).__init__(**mosquitto)
|
||||||
|
|
||||||
|
def exit(self):
|
||||||
|
self.gw_publish('stop', msg='SmsQuitto service stop!')
|
||||||
|
|
||||||
|
def fetchSMS(self, mtype='inbox'):
|
||||||
|
p = subprocess.Popen(["termux-sms-list", "-t", mtype], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
msg = p.stdout.read()
|
||||||
|
payload = json.loads(msg.decode("utf-8"))
|
||||||
|
for p in payload:
|
||||||
|
evt = p.pop('type')
|
||||||
|
dte = p.pop('received')
|
||||||
|
time = datetime.datetime.strptime(dte, '%Y-%m-%d %H:%M').timestamp()
|
||||||
|
self.publish_message(self.topic + evt, time=time, **p)
|
||||||
|
|
||||||
|
def fetchLocation(self):
|
||||||
|
p = subprocess.Popen("termux-location", stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
||||||
|
p.wait()
|
||||||
|
msg = p.stdout.read()
|
||||||
|
payload = json.loads(msg.decode("utf-8"))
|
||||||
|
self.publish_message(self.topic + 'location', time=self.now(), **payload)
|
||||||
|
|
||||||
|
def notification(self, title, msg):
|
||||||
|
subprocess.run(["termux-notification", "--sound", '--title', title, '--content', msg])
|
||||||
|
#print("SmsQuitto::notification", title, msg, flush=True)
|
||||||
|
|
||||||
|
def sendSMS(self, mobile, text):
|
||||||
|
subprocess.run(["termux-sms-send", "-n", mobile, text])
|
||||||
|
print("SmsQuitto::sendSMS", mobile, text, flush=True)
|
||||||
|
|
||||||
|
def gw_publish(self, evt, **payload):
|
||||||
|
self.publish_message(self.topic + evt, time=self.now(), **payload)
|
||||||
|
#print("SmsQuitto::gw_publish topic: %s payload: %s"% (self.topic+evt, payload), flush=True)
|
||||||
|
|
||||||
|
def on_connect(self, mqttc, obj, flags, rc): # @UnusedVariable
|
||||||
|
self.gw_publish('start', msg='SmsQuitto service started!')
|
||||||
|
self.notification('SmsQuitto', 'Service started!')
|
||||||
|
#print("SmsQuitto::on_connect SmsQuitto service started!", flush=True)
|
||||||
|
|
||||||
|
def on_disconnect(self, mqttc, obj, flags, rc): # @UnusedVariable
|
||||||
|
self.gw_publish('off', msg='SmsQuitto disconnected!')
|
||||||
|
self.notification('SmsQuitto', 'Service disconnected!')
|
||||||
|
#print("SmsQuitto::on_connect SmsQuitto service disconnected!", flush=True)
|
||||||
|
|
||||||
|
def on_message(self, mqttc, obj, msg): # @UnusedVariable
|
||||||
|
try:
|
||||||
|
topic = msg.topic
|
||||||
|
evt = topic.rsplit('/', 1)[1]
|
||||||
|
payload = json.loads(msg.payload.decode("utf-8"))
|
||||||
|
if evt == 'sms':
|
||||||
|
mobile = payload.get('mobile', None)
|
||||||
|
text = '%s\n%s' % (payload.get('subject', ''), payload.get('msg', ''))
|
||||||
|
if mobile:
|
||||||
|
if not isinstance(mobile, list):
|
||||||
|
mobile = [mobile]
|
||||||
|
for mob in mobile:
|
||||||
|
self.sendSMS(mob, text)
|
||||||
|
|
||||||
|
elif evt == 'location':
|
||||||
|
self.fetchLocation()
|
||||||
|
|
||||||
|
elif evt in ['all','inbox','sent','draft','outbox']:
|
||||||
|
self.fetchSMS(evt)
|
||||||
|
|
||||||
|
elif evt == 'notify':
|
||||||
|
title = payload.get('subject', '')
|
||||||
|
text = payload.get('msg', '')
|
||||||
|
self.notification(title, text)
|
||||||
|
|
||||||
|
elif evt == 'kill-service':
|
||||||
|
self.stopMQTT()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.gw_publish('error', msg=str(e))
|
||||||
|
print("SmsQuitto::on_message error:", e)
|
||||||
|
|
||||||
|
def main(path):
|
||||||
|
try:
|
||||||
|
pf = path[0] if path else os.path.dirname(os.path.abspath(__file__))
|
||||||
|
config = yaml_load(os.path.join(pf, 'smsquitto-conf.yaml'))
|
||||||
|
settings = dict(config.get('settings'))
|
||||||
|
|
||||||
|
daemon = SmsQuitto(**settings)
|
||||||
|
atexit.register(daemon.stopMQTT)
|
||||||
|
daemon.startMQTT()
|
||||||
|
daemon.loop_forever()
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print("smsquitto.main error", e)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main(sys.argv[1:])
|
||||||
|
|
||||||
|
#
|
||||||
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
@@ -0,0 +1,49 @@
|
|||||||
|
'''
|
||||||
|
Created on 30 mars 2021
|
||||||
|
|
||||||
|
@author: denis
|
||||||
|
'''
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
import pathlib
|
||||||
|
|
||||||
|
here = pathlib.Path(__file__).parent.resolve()
|
||||||
|
|
||||||
|
long_description = (here / 'README.md').read_text(encoding='utf-8')
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name = 'smsquitto',
|
||||||
|
version = '1.0',
|
||||||
|
description = 'SMS gateway using an Android phone',
|
||||||
|
long_description = long_description,
|
||||||
|
long_description_content_type = 'text/markdown',
|
||||||
|
author = 'Deunix from e-educ',
|
||||||
|
author_email = 'deunix@e-educ.fr',
|
||||||
|
#url='https://github.com/pypa/termux-smsquitto',
|
||||||
|
classifiers = [
|
||||||
|
# How mature is this project? Common values are
|
||||||
|
# 3 - Alpha
|
||||||
|
# 4 - Beta
|
||||||
|
# 5 - Production/Stable
|
||||||
|
'Development Status :: 4 - Beta',
|
||||||
|
'Intended Audience :: Any public',
|
||||||
|
'Topic :: Software Development :: Sms Tools',
|
||||||
|
'License :: OSI Approved :: MIT License',
|
||||||
|
'Programming Language :: Python :: 3.7',
|
||||||
|
'Programming Language :: Python :: 3 :: Only',
|
||||||
|
],
|
||||||
|
keywords = 'Termux, sms, Android, notification, mqtt',
|
||||||
|
|
||||||
|
package = ['smsquitto'],
|
||||||
|
package_data = {'smsquitto': ['*.yaml'] },
|
||||||
|
package_dir = {'smsquitto': './smsquitto' },
|
||||||
|
packages=find_packages(where='.'),
|
||||||
|
|
||||||
|
python_requires = '>=3.7',
|
||||||
|
install_requires=['paho-mqtt', 'rsa', 'PyYAML', 'supervisor'],
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/data/data/com.termux/files/usr/bin/bash
|
||||||
|
|
||||||
|
export PACKAGE="TermuxSmsGateway"&&export VERSION="1.0"&&mkdir -p $HOME/.termux/tasks&& \
|
||||||
|
apt install termux-api git -y&&rm -rf TermuxSmsGateway&& \
|
||||||
|
git clone https://github.com/deunix-educ/TermuxSmsGateway.git&& \
|
||||||
|
cp -f $PACKAGE/smsquitto-install/smsquitto-st* $HOME/.termux/tasks/&&cp -f $PACKAGE/smsquitto/smsquitto-conf.yaml $HOME/.termux/&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/supervisord.conf $PREFIX/etc/ \
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/smsquitto.conf $PREFIX/etc/supervisor.d/ \
|
||||||
|
pip install $PACKAGE/dist/smsquitto-$VERSION.tar.gz \
|
||||||
|
cd $PREFIX/lib/python3.9/site-packages/supervisor \
|
||||||
|
patch < $PACKAGE/smsquitto-install/supervisor/patch/http.py.patch \
|
||||||
|
|
||||||
@@ -1,2 +1,4 @@
|
|||||||
#
|
#!/data/data/com.termux/files/usr/bin/bash
|
||||||
/data/data/com.termux/files/usr/bin/python3 -m smsquitto.smsquittod $HOME/.termux/ &>/dev/null
|
#/data/data/com.termux/files/usr/bin/python3 -m smsquitto.smsquittod $HOME/.termux/ &>/dev/null
|
||||||
|
|
||||||
|
data/data/com.termux/files/usr/bin/supervisorctl stop termux_workers:smsquitto
|
||||||
@@ -1,3 +1,3 @@
|
|||||||
#!/data/data/com.termux/files/usr/bin/bash
|
#!/data/data/com.termux/files/usr/bin/bash
|
||||||
ps -aux | grep smsquittod | grep -v grep | awk '{print $2}' | xargs kill -9
|
#ps -aux | grep smsquittod | grep -v grep | awk '{print $2}' | xargs kill -9
|
||||||
|
data/data/com.termux/files/usr/bin/supervisorctl stop termux_workers:smsquitto
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
--- http-origine.py 2021-04-15 23:41:09.333691030 +0200
|
||||||
|
+++ http.py 2021-04-15 23:40:49.734284135 +0200
|
||||||
|
@@ -575,7 +575,7 @@
|
||||||
|
os.chmod(tempname, sockchmod)
|
||||||
|
try:
|
||||||
|
# hard link
|
||||||
|
- os.link(tempname, socketname)
|
||||||
|
+ os.symlink(tempname, socketname)
|
||||||
|
except OSError:
|
||||||
|
# Lock contention, or stale socket.
|
||||||
|
used = self.checkused(socketname)
|
||||||
Executable
+3
@@ -0,0 +1,3 @@
|
|||||||
|
#!/data/data/com.termux/files/usr/bin/sh
|
||||||
|
termux-wake-lock
|
||||||
|
/data/data/com.termux/files/usr/bin/supervisord
|
||||||
@@ -0,0 +1,197 @@
|
|||||||
|
Metadata-Version: 2.1
|
||||||
|
Name: smsquitto
|
||||||
|
Version: 1.0
|
||||||
|
Summary: SMS gateway using an Android phone
|
||||||
|
Home-page: UNKNOWN
|
||||||
|
Author: Deunix from e-educ
|
||||||
|
Author-email: deunix@e-educ.fr
|
||||||
|
License: UNKNOWN
|
||||||
|
Description: # Termux Sms Gateway
|
||||||
|
SMS and notification gateway using Android smartphone
|
||||||
|
|
||||||
|
#### Goal:
|
||||||
|
|
||||||
|
Make any laptop with an Internet connection a SMS gateway
|
||||||
|
Send SMS from his desktop using a web interface or other.
|
||||||
|
Receive SMS on his desk in order to use the content.
|
||||||
|
|
||||||
|
#### Method used
|
||||||
|
|
||||||
|
- SMS sending
|
||||||
|
|
||||||
|
- SMS are created on one machine (1 or more) on the network.
|
||||||
|
- They are then published to a public or private MQTT server
|
||||||
|
- The messages are received on an MQTT client installed on the laptop (1 or more).
|
||||||
|
- The messages are then sent to the recipients.
|
||||||
|
|
||||||
|
#### SMS reception
|
||||||
|
|
||||||
|
- The SMS are received on the smartphone and published to the MQTT server
|
||||||
|
- The messages are received on a MQTT client installed on the subscribed machine (1 or more)
|
||||||
|
|
||||||
|
#### Non-exhaustive use
|
||||||
|
|
||||||
|
- Email message usage
|
||||||
|
- Receive and process alert messages (IOT or other)
|
||||||
|
- etc ...
|
||||||
|
|
||||||
|
#### Conditions for receiving or sending
|
||||||
|
- Take a public or private MQTT server to relay messages
|
||||||
|
- Subscribe MQTT customers to the same topics
|
||||||
|
|
||||||
|
> You can install your own mosquitto server
|
||||||
|
>> https://mosquitto.org/download/
|
||||||
|
>
|
||||||
|
> More information on MQTT: https://fr.wikipedia.org/wiki/MQTT
|
||||||
|
|
||||||
|
- Security of data transmitted
|
||||||
|
> We may need to encrypt the content for security reasons.
|
||||||
|
>> Use encryption with public key / private key on clients
|
||||||
|
|
||||||
|
### Smartphone installation
|
||||||
|
|
||||||
|
https://github.com/termux/termux-app
|
||||||
|
|
||||||
|
#### Installation of termux
|
||||||
|
- Termux application obtained by F-Droid:
|
||||||
|
- https://www.f-droid.org/fr/
|
||||||
|
|
||||||
|
- Or by google store:
|
||||||
|
- https://play.google.com/
|
||||||
|
|
||||||
|
> IMPORTANT: We will choose either one or the other.
|
||||||
|
|
||||||
|
- Install
|
||||||
|
- Termux
|
||||||
|
- Termux: API
|
||||||
|
- Termux: Widget
|
||||||
|
|
||||||
|
|
||||||
|
#### Installing the mqtt client:
|
||||||
|
|
||||||
|
The following python packages will be installed:
|
||||||
|
|
||||||
|
- termux-sms-gateway
|
||||||
|
- paho-mqtt
|
||||||
|
- supervisor
|
||||||
|
- supervisor is a process control system
|
||||||
|
- because Android do not support hard links, it will be necessary to patch http.py from library
|
||||||
|
- rsa >> https://stuvel.eu/python-rsa-doc/
|
||||||
|
|
||||||
|
### Installation procedure
|
||||||
|
|
||||||
|
After installing termux on the smartphone, launch Termux
|
||||||
|
|
||||||
|
- Copy and paste the following command in the terminal
|
||||||
|
|
||||||
|
export PACKAGE="TermuxSmsGateway"&&
|
||||||
|
export VERSION="1.0"&&
|
||||||
|
mkdir -p $HOME/.termux/tasks&&
|
||||||
|
apt install python git termux-api -y&&
|
||||||
|
rm -rf TermuxSmsGateway&&
|
||||||
|
git clone https://github.com/deunix-educ/TermuxSmsGateway.git&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/smsquitto-st* $HOME/.termux/tasks/&&
|
||||||
|
cp -f $PACKAGE/smsquitto/smsquitto-conf.yaml $HOME/.termux/&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/supervisord $HOME/.termux/boot/&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/supervisord.conf $PREFIX/etc/&&
|
||||||
|
cp -f $PACKAGE/smsquitto-install/supervisor/smsquitto.conf $PREFIX/etc/supervisor.d/&&
|
||||||
|
pip install $PACKAGE/dist/smsquitto-$VERSION.tar.gz&&
|
||||||
|
cd $PREFIX/lib/python3.9/site-packages/supervisor&&
|
||||||
|
patch < $PACKAGE/smsquitto-install/supervisor/patch/http.py.patch
|
||||||
|
|
||||||
|
- Enter to start the installation
|
||||||
|
|
||||||
|
### Installation parameters
|
||||||
|
|
||||||
|
- smsquitto server parameters are in ~/.termux/smsquitto-conf.yaml
|
||||||
|
- host: ip or domain of the MQTT server
|
||||||
|
- port: 1883 or 8883
|
||||||
|
- keepalive: 60
|
||||||
|
- username: login
|
||||||
|
- password: password
|
||||||
|
- useSSL: False or True
|
||||||
|
- ca_cert: path/to/file/ca.cert
|
||||||
|
- apikey: *string*
|
||||||
|
|
||||||
|
- ** IMPORTANT **: This key is used to synchronize the topics with the subscriptions
|
||||||
|
- ex: SQTT010203040506079
|
||||||
|
|
||||||
|
- Copy and paste the following command in the terminal
|
||||||
|
nano $HOME/.termux/smsquitto-conf.yaml
|
||||||
|
|
||||||
|
- Install services (start, stop, status)
|
||||||
|
- Install the Tremux widget:Widget on the phone's desktop by keeping your finger on the screen
|
||||||
|
- Choose shortcut
|
||||||
|
- Change the icon and the name if you want
|
||||||
|
- Start, Stop, or Status service by clicking the icon
|
||||||
|
|
||||||
|
### Uses
|
||||||
|
|
||||||
|
- A MQTT client is required to operate the phone.
|
||||||
|
- The smsquittod.py module gives an example of a client written in python.
|
||||||
|
- Library is the Eclipse foundation paho-mqtt
|
||||||
|
- Simply implemente ClientMQTTBase class
|
||||||
|
|
||||||
|
- The sms-client.html file is another example but in websocket mode.
|
||||||
|
- Directly modify the sms-client.html file
|
||||||
|
- Launch it directly in a browser
|
||||||
|
- by drag and drop
|
||||||
|
- by an address of this type
|
||||||
|
- file: ///path/to/file/sms-client.html
|
||||||
|
|
||||||
|
- demonstration
|
||||||
|
|
||||||
|
- sms-client.html is fully functional
|
||||||
|
- You just have to update the apikey in this file and in the configuration file on the smartphone
|
||||||
|
- Set up some mobile numbers to do the tests
|
||||||
|
|
||||||
|
### Domotiz
|
||||||
|
|
||||||
|
- https://www.domoticz.com/wiki/Getting_started
|
||||||
|
|
||||||
|
- Send notification from custom HTTP/Action
|
||||||
|
|
||||||
|
- Notification
|
||||||
|
- script://notify.sh #FIELD1 #FIELD2 #FIELD3 #FIELD4 #TO #MESSAGE --tls or nothing
|
||||||
|
- command
|
||||||
|
- /usr/bin/python3 /home/pi/domoticz/scripts/notify.py --method=notify --host=$1 --port=$2 --user=$3 --password=$4 --apikey=$5 --text="$6" $7
|
||||||
|
|
||||||
|
- SMS
|
||||||
|
- script://notify.sh #FIELD1 #FIELD2 #FIELD3 #FIELD4 #TO #MESSAGE "00330645953706,0033791246318" --tls or nothing
|
||||||
|
- command
|
||||||
|
- /usr/bin/python3 /home/pi/domoticz/scripts/smsquitto.py --method=sms --host=$1 --port=$2 --user=$3 --password=$4 --apikey=$5 --text="$6" --phone="$7" $8
|
||||||
|
|
||||||
|
- SSL certification
|
||||||
|
- argument --tls, in $7 or $8.
|
||||||
|
- the certification key is in domoticz/scripts/smsquitto.py.
|
||||||
|
|
||||||
|
- You must install python3 paho-mqtt library: pip3 install paho-mqtt
|
||||||
|
|
||||||
|
### API methods
|
||||||
|
|
||||||
|
Message sent and received format:
|
||||||
|
|
||||||
|
- (topic, payload)
|
||||||
|
- topic: is a string that starts with apikey see above
|
||||||
|
- apikey/pub/sms
|
||||||
|
- apikey/emit/inbox
|
||||||
|
- payload: is a Json string
|
||||||
|
- {mobile: [mobile1, mobile2, etc ...], subject: "the subject", msg: "the message"}
|
||||||
|
- {time: time, payload: payload}
|
||||||
|
- topics
|
||||||
|
- apikey/pub/sms send SMS
|
||||||
|
- apikey/pub/notify send notification
|
||||||
|
- apikey/pub/location request for Geographic positioning
|
||||||
|
- apikey/pub/inbox or all or sent or draft or outbox Read SMS message
|
||||||
|
- apikey/pub/kill-service stop the service
|
||||||
|
|
||||||
|
Keywords: Termux,sms,Android,notification,mqtt
|
||||||
|
Platform: UNKNOWN
|
||||||
|
Classifier: Development Status :: 4 - Beta
|
||||||
|
Classifier: Intended Audience :: Any public
|
||||||
|
Classifier: Topic :: Software Development :: Sms Tools
|
||||||
|
Classifier: License :: OSI Approved :: MIT License
|
||||||
|
Classifier: Programming Language :: Python :: 3.7
|
||||||
|
Classifier: Programming Language :: Python :: 3 :: Only
|
||||||
|
Requires-Python: >=3.7
|
||||||
|
Description-Content-Type: text/markdown
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
LICENSE
|
||||||
|
README.md
|
||||||
|
setup.cfg
|
||||||
|
setup.py
|
||||||
|
./smsquitto/__init__.py
|
||||||
|
./smsquitto/smsquitto-conf.yaml
|
||||||
|
./smsquitto/smsquittod.py
|
||||||
|
smsquitto.egg-info/PKG-INFO
|
||||||
|
smsquitto.egg-info/SOURCES.txt
|
||||||
|
smsquitto.egg-info/dependency_links.txt
|
||||||
|
smsquitto.egg-info/requires.txt
|
||||||
|
smsquitto.egg-info/top_level.txt
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
paho-mqtt
|
||||||
|
rsa
|
||||||
|
PyYAML
|
||||||
|
supervisor
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
smsquitto
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
[build-system]
|
||||||
|
requires = ["setuptools", "wheel"]
|
||||||
|
build-backend = "setuptools.build_meta"
|
||||||
Reference in New Issue
Block a user