Skip to content
Snippets Groups Projects
Commit b00dd160 authored by Jauhar Arifin's avatar Jauhar Arifin
Browse files

update earthquake sender python

parent c70e1b61
No related merge requests found
......@@ -3,6 +3,8 @@
import serial
import requests
import time
import sys
import re
if len(sys.argv) < 2:
exit("Usage: earthquake.py [device]")
......@@ -11,17 +13,20 @@ 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:
line = ser.readline().decode("utf-8")[:-2]
print(line)
if re.match("[0-9\\.]+", line):
strength = float(line)
if strength > 1.3 and strength < 10 and time.time() - last >= 36000:
data = {
"lat": -6.892004,
"long": 107.599828,
"strength": strength,
"date": "2017-12-06 PM 22:03:36.000Z"
"date": time.strftime("%Y-%m-%d %p %H:%M:%S.000Z")
}
request.post('jauhararifin.cf:8888/api/earchquake', data)
last = time.time()
\ No newline at end of file
print("send requests ", data)
resp = requests.post('http://jauhararifin.cf:8888/api/earthquakes', data)
print(resp)
last = time.time()
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment