Skip to content

Commit

Permalink
UPDATE: transmit.py
Browse files Browse the repository at this point in the history
  • Loading branch information
junhoyeo committed Nov 21, 2018
1 parent 8106e3a commit 655c52d
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions transmit.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
import serial
import random, subprocess, json, requests

with open('./info.json', 'r') as f:
info = json.load(f)

data = round(random.uniform(1, 1.5), 2)
output = subprocess.Popen(['node', 'client/send.js', 'data', str(data)], stdout=subprocess.PIPE).communicate()[0].decode()
if output:
txhash = json.loads(output.strip())['result']
if 'Error' not in txhash:
res = requests.post(info['data_server'] + '/api/iot/add', json={
"iot" : info['device']['wallet'],
"transaction" : txhash
}).text
print(res)
if json.loads(res)['data']:
print('[*] Success')
exit(0)
print('[*] Error while executing')
ser = serial.Serial(
port=input('[*] Input port: '),
baudrate=9600,
)

while True:
if ser.readable():
res = ser.readline()
data = res.decode()[:len(res)-1]
output = subprocess.Popen(['node', 'client/send.js', 'data', str(data)], stdout=subprocess.PIPE).communicate()[0].decode()
if output:
txhash = json.loads(output.strip())['result']
if 'Error' not in txhash:
res = requests.post(info['data_server'] + '/api/iot/add', json={
"iot" : info['device']['wallet'],
"transaction" : txhash
}).text
print(res)
if json.loads(res)['data']:
print('[*] Success')
exit(0)
print('[*] Error while executing')

0 comments on commit 655c52d

Please sign in to comment.