From 2afebeccf2179ef9aee5f42f1323040d7c017f31 Mon Sep 17 00:00:00 2001 From: Jan-Piet Mens Date: Thu, 10 Sep 2015 21:10:58 +0200 Subject: [PATCH] supporting ot-ping.py utility --- contrib/ot-ping.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100755 contrib/ot-ping.py diff --git a/contrib/ot-ping.py b/contrib/ot-ping.py new file mode 100755 index 0000000..5178389 --- /dev/null +++ b/contrib/ot-ping.py @@ -0,0 +1,60 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# ot-ping.py +# send a "pingping" to the OwnTracks Recorder via MQTT + +import paho.mqtt.publish as mqtt # pip install paho-mqtt +import json +import time +import os + +__author__ = 'Jan-Piet Mens ' +__copyright__ = 'Copyright 2015 Jan-Piet Mens' + +hostname = 'localhost' +port = 1883 +username = None +password = None +tls = None +qos = 0 +retain = 0 + +def pingping(): + + params = { + 'hostname' : hostname, + 'port' : port, + 'qos' : qos, + 'retain' : retain, + 'client_id' : "ot-recorder-ping-ping-%s" % os.getpid(), + } + auth = None + + if username is not None: + auth = { + 'username' : username, + 'password' : password + } + + topic = "owntracks/ping/ping" + + location = { + "_type" : "location", + "tid" : "pp", + "lat" : 51.47879, + "lon" : -0.010677, + "tst" : int(time.time()), + } + + topic = "nop/ping/ping" + payload = json.dumps(location) + + mqtt.single(topic, payload, + auth=auth, + tls=tls, + **params) + + +if __name__ == '__main__': + pingping()