Skip to content
Snippets Groups Projects
Commit ad630b31 authored by Server (Shared Users)'s avatar Server (Shared Users)
Browse files

aaa

parent ff0214e4
Branches
Tags
No related merge requests found
...@@ -18,7 +18,7 @@ from coapthon.utils import parse_uri ...@@ -18,7 +18,7 @@ from coapthon.utils import parse_uri
__author__ = 'Giacomo Tanganelli' __author__ = 'Giacomo Tanganelli'
class CoapClient(): class CoapClient():
def __init__(self): # 문제없음. def __init__(self): # complete
self.ip = "shmd01.iptime.org" self.ip = "shmd01.iptime.org"
self.myMAC = ':'.join(re.findall('..', '%012x' % uuid.getnode())) self.myMAC = ':'.join(re.findall('..', '%012x' % uuid.getnode()))
self.clearMyData() self.clearMyData()
...@@ -27,7 +27,7 @@ class CoapClient(): ...@@ -27,7 +27,7 @@ class CoapClient():
self._beacon = BeaconEmit() self._beacon = BeaconEmit()
self.advertiseMe() self.advertiseMe()
def clearMyData(self): #문제없음. def clearMyData(self): # complete
path = "/rpNodeInfoPath" path = "/rpNodeInfoPath"
path = "coap://" + self.ip + path path = "coap://" + self.ip + path
...@@ -54,7 +54,7 @@ class CoapClient(): ...@@ -54,7 +54,7 @@ class CoapClient():
client.stop() client.stop()
def obtainMyID(self): # 문제없음. def obtainMyID(self): # complete
path = "/rpNodeInfoPath" path = "/rpNodeInfoPath"
path = "coap://" + self.ip + path path = "coap://" + self.ip + path
...@@ -83,7 +83,7 @@ class CoapClient(): ...@@ -83,7 +83,7 @@ class CoapClient():
client.stop() client.stop()
return string, json.loads(response.payload)['operate'] return string, json.loads(response.payload)['operate']
def advertiseMe(self): #문제없음. def advertiseMe(self): # complete
seq = self.myuuid seq = self.myuuid
length = 3 length = 3
string ="" string =""
...@@ -93,7 +93,7 @@ class CoapClient(): ...@@ -93,7 +93,7 @@ class CoapClient():
print(map(''.join, zip(*[iter(seq)]*length))) print(map(''.join, zip(*[iter(seq)]*length)))
self._beacon.beacon_Start(string) self._beacon.beacon_Start(string)
def calculateNodePositionAtServer(self): #문제없음. def calculateNodePositionAtServer(self): # complete
path = "/rpNodeInfoPath" path = "/rpNodeInfoPath"
path = "coap://" + self.ip + path path = "coap://" + self.ip + path
...@@ -124,7 +124,7 @@ class CoapClient(): ...@@ -124,7 +124,7 @@ class CoapClient():
client.stop() client.stop()
client.stop() client.stop()
def putBLEInfo(self): # 문제 없음. def putBLEInfo(self): # complete
dev_id = 0 dev_id = 0
try: try:
self.sock = bluez.hci_open_dev(dev_id) self.sock = bluez.hci_open_dev(dev_id)
...@@ -165,7 +165,7 @@ class CoapClient(): ...@@ -165,7 +165,7 @@ class CoapClient():
response = client.put(path, json.dumps(payload)) response = client.put(path, json.dumps(payload))
print((response.pretty_print())) print((response.pretty_print()))
time.sleep(1) time.sleep(0.05)
except KeyboardInterrupt: except KeyboardInterrupt:
print("PutBLEInfo Stop") print("PutBLEInfo Stop")
...@@ -173,8 +173,8 @@ class CoapClient(): ...@@ -173,8 +173,8 @@ class CoapClient():
client.stop() client.stop()
def mkJsonbeaconInfo(self, info): #문제 없음. def mkJsonbeaconInfo(self, info): # complete
n = 2.2 n = 4
distance = math.pow(10, (float(info[4]) - float(info[5])) / (10 * n)) distance = math.pow(10, (float(info[4]) - float(info[5])) / (10 * n))
payload = { payload = {
'rpuuid' : self.myuuid, 'rpuuid' : self.myuuid,
...@@ -184,7 +184,7 @@ class CoapClient(): ...@@ -184,7 +184,7 @@ class CoapClient():
} }
return payload return payload
def regiRelWithNewPi(self, info): #문제 없음 def regiRelWithNewPi(self, info): # complete
#새로운 rasbPi를 찾은 경우 새로운 rasbPi를 위치측정기로 사용하기 위해서 server에 관련 정보를 저장하는 method #새로운 rasbPi를 찾은 경우 새로운 rasbPi를 위치측정기로 사용하기 위해서 server에 관련 정보를 저장하는 method
path = "/rpGraphInfoPath" path = "/rpGraphInfoPath"
...@@ -207,8 +207,8 @@ class CoapClient(): ...@@ -207,8 +207,8 @@ class CoapClient():
client.stop() client.stop()
client.stop() client.stop()
def mkJsonRpgraphInfo(self, info): #문제 없음 def mkJsonRpgraphInfo(self, info): # complete
n = 3 n = 2.2
print(info) print(info)
distance = math.pow(10, ((float(info[4]) - float(info[5])) / (10 * n))) distance = math.pow(10, ((float(info[4]) - float(info[5])) / (10 * n)))
payload = { payload = {
......
...@@ -12,7 +12,7 @@ from exampleresources import BleInfoResource, RpNodeInfoResource, RpGraphInfoRes ...@@ -12,7 +12,7 @@ from exampleresources import BleInfoResource, RpNodeInfoResource, RpGraphInfoRes
from pymongo import MongoClient from pymongo import MongoClient
class CoAPServer(CoAP): class CoAPServer(CoAP):
def __init__(self, host, port, multicast=False): #문제 없음. def __init__(self, host, port, multicast=False): # complete
CoAP.__init__(self, (host, port), multicast) CoAP.__init__(self, (host, port), multicast)
self.add_resource('bleInfoPath/', BleInfoResource()) self.add_resource('bleInfoPath/', BleInfoResource())
self.add_resource('rpNodeInfoPath/', RpNodeInfoResource()) self.add_resource('rpNodeInfoPath/', RpNodeInfoResource())
...@@ -28,28 +28,29 @@ class CoAPServer(CoAP): ...@@ -28,28 +28,29 @@ class CoAPServer(CoAP):
self.userNodeCollection = self.db.UserNodeData self.userNodeCollection = self.db.UserNodeData
self.trackingCollection = self.db.TrackingData self.trackingCollection = self.db.TrackingData
self.usersCollection = self.db.users self.usersCollection = self.db.users
self.updatePeriod = 1.5
self.limitDistance = 40
except: except:
print("Could not connect to MongoDB") print("Could not connect to MongoDB")
def updateUserLocation(self): def updateUserLocation(self): # complete
try: try:
while True: while True:
cursor = self.usersCollection.find() cursor = self.usersCollection.find()
for c in cursor: for c in cursor:
print(c['uuid'])
positionCalculationThread = threading.Thread(target = self.positionCalculation, args=([c['uuid']])) positionCalculationThread = threading.Thread(target = self.positionCalculation, args=([c['uuid']]))
positionCalculationThread.start() positionCalculationThread.start()
time.sleep(10.1) time.sleep(self.updatePeriod + 0.1)
currentTime = time.time() currentTime = time.time()
trackingCursor = self.trackingCollection.remove({'updateTime': {'lte' : currentTime - 10}}) trackingCursor = self.trackingCollection.remove({'updateTime': {'$lte' : currentTime - self.updatePeriod}})
except KeyboardInterrupt: except KeyboardInterrupt:
print("existing updateUserLocation") print("existing updateUserLocation")
def positionCalculation(self, useruuid): def positionCalculation(self, useruuid): # complete but need to check triangulation.py
print(useruuid) print(useruuid)
currentTime = time.time() currentTime = time.time()
trackingCursor = self.trackingCollection.find({'$and':[{'useruuid': useruuid}, trackingCursor = self.trackingCollection.find({'$and':[{'useruuid': useruuid},
{'updateTime':{'$gt' : currentTime - 10}}]}) {'updateTime':{'$gt' : currentTime - self.updatePeriod}},{'distance': {'$lt' : self.limitDistance}}]})
#trackingCursor = self.trackingCollection.find({'$and':[{'useruuid':{'$eq' : useruuid}}]}) #trackingCursor = self.trackingCollection.find({'$and':[{'useruuid':{'$eq' : useruuid}}]})
userLocationData =[] userLocationData =[]
......
from pymongo import MongoClient
class MyMongoDB():
def __init__(self): #문제 없음.
try:
self.conn = MongoClient('mongodb://iotuser:iotsystem@localhost/IoT_System', 27017)
self.db = self.conn.IoT_System
self.piNodeCollection = self.db.RpNodeData
self.piGraphCollection = self.db.RpGraphData
self.userNodeCollection = self.db.UserNodeData
self.trackingCollection = self.db.TrackingData
self.usersCollection = self.db.users
except:
print("Could not connect to MongoDB")
def clear(self):
self.piNodeCollection.remove()
self.piGraphCollection.remove()
self.userNodeCollection.remove()
self.trackingCollection.remove()
db = MyMongoDB()
db.clear()
\ No newline at end of file
...@@ -6,7 +6,7 @@ from pymongo import MongoClient ...@@ -6,7 +6,7 @@ from pymongo import MongoClient
from coapthon import defines from coapthon import defines
from coapthon.resources.resource import Resource from coapthon.resources.resource import Resource
class RpNodeInfoResource(Resource): #문제 없음. class RpNodeInfoResource(Resource):
def __init__(self, name="RpNodeInfo"): def __init__(self, name="RpNodeInfo"):
super(RpNodeInfoResource, self).__init__(name) super(RpNodeInfoResource, self).__init__(name)
self.payload = "RpNodeInfo resource" self.payload = "RpNodeInfo resource"
...@@ -41,20 +41,21 @@ class RpNodeInfoResource(Resource): #문제 없음. ...@@ -41,20 +41,21 @@ class RpNodeInfoResource(Resource): #문제 없음.
elif self.payload['option'] == 1: elif self.payload['option'] == 1:
#coapclient.py에서 calculateNodePositionAtServer()이 호출된 경우 #coapclient.py에서 calculateNodePositionAtServer()이 호출된 경우
response.payload = self.calculateNodePosition(self.payload) response.payload = self.calculateNodePosition(self.payload)
else :# coapclient.py 에서 obtainMyID()가 호출된 경우 else :
# coapclient.py 에서 obtainMyID()가 호출된 경우
response.payload = self.postRpNodeInfoInDB(self.payload) response.payload = self.postRpNodeInfoInDB(self.payload)
response.code = defines.Codes.CHANGED.number response.code = defines.Codes.CHANGED.number
return self, response return self, response
def deleteNodeData(self, info): #문제 없음 def deleteNodeData(self, info): # complete
info = info['rpMAC'] info = info['rpMAC']
graphColletion = self.db.RpGraphData graphColletion = self.db.RpGraphData
if self.collection.find({'rpMAC' : info}).count() != 0: if self.collection.find({'rpMAC' : info}).count() != 0:
rpuuid = self.collection.find({'rpMAC' : info})[0]['rpuuid'] rpuuid = self.collection.find({'rpMAC' : info})[0]['rpuuid']
graphColletion.delete_many({'v2' : rpuuid}) graphColletion.remove({'v2' : rpuuid})
self.collection.delete_many({'rpMAC' : info}) self.collection.remove({'rpMAC' : info})
def postRpNodeInfoInDB(self, info): #문제 없음 def postRpNodeInfoInDB(self, info): # complete
info = info['rpMAC'] info = info['rpMAC']
rpuuid = "52528282"+str(uuid.uuid4())[8:] rpuuid = "52528282"+str(uuid.uuid4())[8:]
rpuuid = rpuuid.replace("-","") rpuuid = rpuuid.replace("-","")
...@@ -82,7 +83,7 @@ class RpNodeInfoResource(Resource): #문제 없음. ...@@ -82,7 +83,7 @@ class RpNodeInfoResource(Resource): #문제 없음.
}) })
return response return response
def calculateNodePosition(self, info): # 문제 없음. def calculateNodePosition(self, info): # complete , need to check 4-th case.
print("Start calculateNodePosition") print("Start calculateNodePosition")
info = info['rpuuid'] info = info['rpuuid']
graphColletion = self.db.RpGraphData graphColletion = self.db.RpGraphData
...@@ -103,21 +104,27 @@ class RpNodeInfoResource(Resource): #문제 없음. ...@@ -103,21 +104,27 @@ class RpNodeInfoResource(Resource): #문제 없음.
tempdoc = self.collection.find({'rpuuid': doc['v1']}) tempdoc = self.collection.find({'rpuuid': doc['v1']})
if tempdoc[0]['x'] == 0 and tempdoc[0]['y'] == 0: # 첫번째 RpNode 즉, (0,0) if tempdoc[0]['x'] == 0 and tempdoc[0]['y'] == 0: # 첫번째 RpNode 즉, (0,0)
vertexA = tempdoc[0]# 첫번째 RpNode를 vertexA라 한다. vertexA = tempdoc[0]# 첫번째 RpNode를 vertexA라 한다.
vertexB = tempdoc[1] elif tempdoc[0]['y'] == 0:
vertexB = tempdoc[0]#두번째 RpNode를 vertexB라 한다. vertexB = tempdoc[0]#두번째 RpNode를 vertexB라 한다.
vertexA = tempdoc[1]
dis = { dis = {
'a': graphColletion.find({'v1': vertexB['rpuuid'], 'v2': info})[0]['distance'], 'a': graphColletion.find({'v1': vertexB['rpuuid'], 'v2': info})[0]['distance'],
'b': graphColletion.find({'v1': vertexA['rpuuid'], 'v2': info})[0]['distance'], 'b': graphColletion.find({'v1': vertexA['rpuuid'], 'v2': info})[0]['distance'],
'c': vertexB['x'] 'c': vertexB['x']
} }
if ((dis['a'] + dis['b']) <= dis['c']) or dis['a'] == 0 or dis['b'] == 0: if ((dis['a'] + dis['b']) <= dis['c']) or dis['a'] == 0 or dis['b'] == 0 or dis['c'] == 0:
# 3번째 rpNode를 만들 수 없는 경우 # 3번째 rpNode를 만들 수 없는 경우
print("3번째 rpNode를 만들 수 없습니다.") print("3번째 rpNode를 만들 수 없습니다.")
response['operate'] = 0 response['operate'] = 0
return json.dumps(response) return json.dumps(response)
cosA = (math.pow(dis['b'], 2) + math.pow(dis['c'], 2) - math.pow(dis['a'], 2)) / (2 * dis['b'] * dis['c']) cosA = (math.pow(dis['b'], 2) + math.pow(dis['c'], 2) - math.pow(dis['a'], 2)) / (2 * dis['b'] * dis['c'])
if cosA >= 1 or cosA <= 0 :
# 3번째 rpNode를 만들 수 없는 경우
print("3번째 rpNode를 만들 수 없습니다.")
response['operate'] = 0
return json.dumps(response)
sinA = math.sqrt((1 - math.pow(cosA,2))) sinA = math.sqrt((1 - math.pow(cosA,2)))
x = dis['b'] * cosA x = dis['b'] * cosA
y = dis['b'] * sinA y = dis['b'] * sinA
...@@ -166,7 +173,7 @@ class RpNodeInfoResource(Resource): #문제 없음. ...@@ -166,7 +173,7 @@ class RpNodeInfoResource(Resource): #문제 없음.
response['operate'] = 0 response['operate'] = 0
return json.dumps(response) return json.dumps(response)
class RpGraphInfoResource(Resource): #문제 없음 class RpGraphInfoResource(Resource): # complete
def __init__(self, name="RpGraphInfo"): def __init__(self, name="RpGraphInfo"):
super(RpGraphInfoResource, self).__init__(name) super(RpGraphInfoResource, self).__init__(name)
self.payload = "RpGraphInfo resource" self.payload = "RpGraphInfo resource"
...@@ -204,9 +211,9 @@ class RpGraphInfoResource(Resource): #문제 없음 ...@@ -204,9 +211,9 @@ class RpGraphInfoResource(Resource): #문제 없음
response.code = defines.Codes.DELETED.number response.code = defines.Codes.DELETED.number
return True, response return True, response
def postRpGraphInfoInDB(self, info): #문제 없음. def postRpGraphInfoInDB(self, info): # complete
info = json.loads(info) info = json.loads(info)
mydoc = self.collection.find({'v1':info['v1'], 'v2':info['v2']}) mydoc = self.collection.find({'v1':info['v1'], 'v2':info['v2'], 'distance': {'$lte' : 40}})
if mydoc.count() > 0: if mydoc.count() > 0:
distance = (mydoc[0]['sum']+info['distance']) / (mydoc[0]['count'] + 1) distance = (mydoc[0]['sum']+info['distance']) / (mydoc[0]['count'] + 1)
...@@ -227,7 +234,7 @@ class RpGraphInfoResource(Resource): #문제 없음 ...@@ -227,7 +234,7 @@ class RpGraphInfoResource(Resource): #문제 없음
'count': 1 'count': 1
}, upsert=True) }, upsert=True)
class BleInfoResource(Resource): #문제없음. class BleInfoResource(Resource): # complete
def __init__(self, name="BleInfo"): def __init__(self, name="BleInfo"):
super(BleInfoResource, self).__init__(name) super(BleInfoResource, self).__init__(name)
self.payload = "BleInfo resource" self.payload = "BleInfo resource"
......
...@@ -21,7 +21,7 @@ var options = { ...@@ -21,7 +21,7 @@ var options = {
yAxes: [ yAxes: [
{ {
ticks: { ticks: {
max:30,
beginAtZero: true beginAtZero: true
} }
} }
...@@ -29,7 +29,7 @@ var options = { ...@@ -29,7 +29,7 @@ var options = {
xAxes: [ xAxes: [
{ {
ticks: { ticks: {
max:20,
beginAtZero: true beginAtZero: true
} }
} }
......
...@@ -111,7 +111,9 @@ router.get('/findUserByUUID/:id', function(req, res, next) { ...@@ -111,7 +111,9 @@ router.get('/findUserByUUID/:id', function(req, res, next) {
for(i in temp){ for(i in temp){
console.log(i, temp[i].rpuuid) console.log(i, temp[i].rpuuid)
await rpNode.find({'rpuuid': temp[i].rpuuid},(err,output)=>{ await rpNode.find({'rpuuid': temp[i].rpuuid},(err,output)=>{
//console.log(temp[i].distance) console.log(output)
if(output.length == 0)
break;
rpNodeData.push({ rpNodeData.push({
rpuuid : temp[i].rpuuid, rpuuid : temp[i].rpuuid,
x: output[0].x, x: output[0].x,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment