-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added the code which is running on the Raspi for serial communication…
… and talking to the website
- Loading branch information
1 parent
39549fc
commit ab058e3
Showing
2 changed files
with
51 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |