Skip to content

Commit

Permalink
Added the code which is running on the Raspi for serial communication…
Browse files Browse the repository at this point in the history
… and talking to the website
  • Loading branch information
shashwatsrivastava94 committed Mar 18, 2016
1 parent 39549fc commit ab058e3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Raspberry_Pi_Code/549_demo_get.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import urllib, json

def set_method():
tagID = raw_input("Enter the tag ID")
B = raw_input("Enter the distance between two tags")
r1 = raw_input("Enter distance between anchor 1 and tag")
r2 = raw_input("Enter distance between anchor 2 and tag")
url = "https://test-server-549.herokuapp.com/testServer/set/" + tagID + "/" + B + "/" + r1 + "/" + r2
urllib.urlopen(url)

def get_method():
tagID = raw_input("Enter the tag ID")
url = 'https://test-server-549.herokuapp.com/testServer/get/' + tagID
response = urllib.urlopen(url)
data = json.loads(response.read())
print data

def read_from_cli():
while(1):
print "Enter either set or get -"
command = raw_input()
if command == "set":
set_method()
elif command == "get":
get_method()
else:
print "Your input is invalid"

read_from_cli()
22 changes: 22 additions & 0 deletions Raspberry_Pi_Code/549_serial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import serial

def main():
ser = serial.Serial(
port='/dev/ttyUSB0',
baudrate=9600
)

ser.isOpen()

print "Opened the port"

out = ""
while(1):
outChar = ser.read(1)
if(outChar == "\n"):
print out + outChar
else:
out += outChar


main()

0 comments on commit ab058e3

Please sign in to comment.