From 02fe4a91a58dfa059bd22add3037e6ba18078781 Mon Sep 17 00:00:00 2001 From: Jauhar Arifin <jauhararifin10@gmail.com> Date: Fri, 24 Nov 2017 16:09:32 +0700 Subject: [PATCH] add python listener for connection with server --- earthquake/earthquake.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 earthquake/earthquake.py diff --git a/earthquake/earthquake.py b/earthquake/earthquake.py new file mode 100644 index 0000000..4028cc3 --- /dev/null +++ b/earthquake/earthquake.py @@ -0,0 +1,27 @@ +#!/bin/python3 + +import serial +import requests +import time + +if len(sys.argv) < 2: + exit("Usage: earthquake.py [device]") + +ser = serial.Serial(sys.argv[1], 115600) +last = -1000000 + +while True: + line = ser.readline() + if line.startswith("gempa"): + strength = float(line.split(' ')[1]) + if time.time() - last >= 36000: + + data = { + "lat": -6.892004, + "long": 107.599828, + "strength": strength, + "date": "2017-12-06 PM 22:03:36.000Z" + } + + request.post('jauhararifin.cf:8888/api/earchquake', data) + last = time.time() \ No newline at end of file -- GitLab