Esempio n. 1
0
    def post(self):
        api_assert(self.body['data'], 400, 'empty data')

        try:
            ap_datas = []

            router_mac = Mac.correct(self.body['apMac'])
            signal = Signal(band='2.4', channel=self.body['band'])
            created_at = Time(int(self.body['time']))

            for item in self.body['data']:
                device_mac = Mac.correct(item['clientMac'])
                rssis = {}
                if item.get('rss1') is not None:
                    rssis['1'] = RSSI(float(item['rss1']))
                if item.get('rss2') is not None:
                    rssis['2'] = RSSI(float(item['rss2']))
                if item.get('rss3') is not None:
                    rssis['3'] = RSSI(float(item['rss3']))

                if len(rssis) > 0:
                    ap_datas.append(
                        APData(router_mac=router_mac,
                               device_mac=device_mac,
                               created_at=created_at,
                               rssis=rssis,
                               signal=signal))

            for ap_data in ap_datas:
                self.ap_data_dao.save(ap_data)
        except DBException as e:
            raise APIError(500, e.message)
        return 'ok'
Esempio n. 2
0
 def from_db_object(self, db_object):
     return APData(
         router_mac=Mac(db_object['router_mac']),
         device_mac=Mac(db_object['device_mac']),
         created_at=Time(int(db_object['created_at'])),
         rssis={k: RSSI(float(v))
                for k, v in db_object['rssis'].items()},
         signal=Signal(channel=int(db_object['signal']['channel']),
                       band=db_object['signal']['band']),
         _id=db_object['_id'])
Esempio n. 3
0
    def __init__(self, db_obj, mac=None):
        self.__dict__.update({
            "data": [
                {
                    "clientMac": Mac.raw(db_obj["device_mac"] if mac is None else mac)
                }
            ],
            "apMac": Mac.raw(db_obj["router_mac"]),
            "time": db_obj["created_at"],
            "band": db_obj["signal"]["channel"]
        })

        for n, v in db_obj["rssis"].items():
            self.__dict__["data"][0]["rss" + n] = v
Esempio n. 4
0
 def from_db_object(self, db_object):
     return Position(mac=Mac(db_object['mac']),
                     location=Location(x=db_object['location']['x'],
                                       y=db_object['location']['y'],
                                       z=db_object['location']['z']),
                     created_at=Time(int(db_object['created_at'])),
                     _id=db_object['_id'])
Esempio n. 5
0
 def from_db_object(self, db_object):
     return SampleStamp(mac=Mac(db_object['mac']),
                        location=Location(x=db_object['location']['x'],
                                          y=db_object['location']['y'],
                                          z=db_object['location']['z']),
                        start_time=Time(int(db_object['start_time'])),
                        end_time=Time(int(db_object['end_time'])))
Esempio n. 6
0
 def post(self):
     try:
         sample = PathStamp(mac=Mac(self.body['mac']),
                            name=self.body["name"])
         self.path_service.set_path_stamp(sample)
     except SampleException as e:
         raise APIError(400, e.message)
     return 'ok'
Esempio n. 7
0
def check_mac():
    devices = Device()
    mac = Mac()
    macs = []
    data_list = devices.get(page='all')
    for data in data_list:
        macs.append(data['mac'])
    while True:
        wifi_connected = utils.check_wifi_connected()
        if not wifi_connected:
            utils.connect_wifi()
        for ip in range(155):
            if ip not in [0, 1, 2, 5, 255]:
                network = utils.check_arp(ip)
                if network:
                    # app.logger.info(network)
                    if network['mac'] not in macs:
                        macs.append(network['mac'])
                        devices.new_post({'mac': network['mac']})
                    mac.post(network)
        time.sleep(5)
Esempio n. 8
0
    def post(self):
        try:
            sample = SampleStamp(mac=Mac(self.body['mac']),
                                 location=Location(
                                     x=self.body['location']['x'],
                                     y=self.body['location']['y'],
                                     z=self.body['location']['z']))

            self.set_stamp(sample)
        except SampleException as e:
            raise APIError(400, e.message)
        return 'ok'
Esempio n. 9
0
 def locate(self):
     start = time.perf_counter()
     measures = self.fetch_measures()
     end = time.perf_counter()
     print("{} measures fetched in {}s".format(len(measures), end - start))
     for device_mac, measure in measures.items():
         if len(measure) >= 3:
             start = time.perf_counter()
             res = self.engine.locate(measure)
             end = time.perf_counter()
             print("engine localised {} in {}s".format(
                 device_mac, end - start))
             self.publisher.publish({
                 "mac": device_mac,
                 "location": res.to_db_object()
             })
             self.position_dao.save(Position(Mac(device_mac), res))