示例#1
0
def demo_receiver(base_host, base_port, tdf_server):
    # TDF decoding state
    tdfparse = tdf3.Tdf()
    tdfparse.loadTdf(tdf_server, timeout=10.0)
    parser = tdfparse.parseTdf16

    # Baselisten connection
    listener = ListenClient.ListenClient(base_host, base_port)
    listener.connect()

    MY_DEVICE_TOKEN = '4005b6a7-e9bd-4315-9b41-5fe527d7ebec'
    my_device = tago.Device(MY_DEVICE_TOKEN)

    try:
        # Loop forever for packets from baselisten
        while True:
            try:
                packet = listener.read(timeout=None)
            except ConnectionResetError:
                print("Connection to baselisten lost...")
                return
            except NotImplementedError:
                continue

            # Loop over every payload in the serial packet
            for payload_type, route, payload in packet.iter_payloads():

                now = datetime.datetime.now()

                first_hop = route[-1]
                pkt_addr = first_hop.address_fmt
                pkt_rssi = "{:d}dBm".format(first_hop.rssi)
                print("From {:s}, {:d} bytes, RSSI {:s}".format(
                    pkt_addr, len(payload), pkt_rssi))

                # This demo is only concerned with TDF payloads
                if payload_type != PayloadType.PAYLOAD_TDF3:
                    print("\tPacket was not a TDF ({:})".format(payload_type))
                    continue

                # Payload is a TDF
                for point in parser(payload,
                                    datetime.datetime.utcnow(),
                                    debug=False,
                                    combine=True):
                    print(point)

                    if point.get('sensor') == 'LPS22HB_ALL':

                        data_to_insert = {
                            'variable': point.get('sensor'),
                            'time': now.strftime("%Y-%m-%d %H:%M:%S"),
                            'metadata': {
                                'pressure':
                                point.get('phenomena').get('pressure').get(
                                    'formatted')
                            }
                        }

                    if point.get('sensor') == '3D_POSE':

                        data_to_insert = {
                            'variable': point.get('sensor'),
                            'time': now.strftime("%Y-%m-%d %H:%M:%S"),
                            'metadata': {
                                'roll':
                                point.get('phenomena').get('roll').get(
                                    'formatted'),
                                'pitch':
                                point.get('phenomena').get('pitch').get(
                                    'formatted')
                            }
                        }

                    if point.get('sensor') == 'HEIGHT_MSL':

                        data_to_insert = {
                            'variable': point.get('sensor'),
                            'time': now.strftime("%Y-%m-%d %H:%M:%S"),
                            'metadata': {
                                'height':
                                point.get('phenomena').get('height').get(
                                    'formatted'),
                                'raw':
                                point.get('phenomena').get('height').get('raw')
                            }
                        }

                    if point.get('sensor') == 'RANGE_MM':

                        data_to_insert = {
                            'variable': point.get('sensor'),
                            'time': now.strftime("%Y-%m-%d %H:%M:%S"),
                            'metadata': {
                                'range':
                                point.get('phenomena').get('range').get(
                                    'formatted'),
                                'raw':
                                point.get('phenomena').get('range').get('raw')
                            }
                        }

                    my_device.insert(data_to_insert)

    except KeyboardInterrupt:
        pass
示例#2
0
filename = input("Please Enter A Filename: ")
action = input("Please Enter Your Activity: ")
duration = input(
    "Please Enter How Many Seconds You Want To Collect Data For: ")

dictArr = []

start = 0

aidenThingy = "EF:B9:B8:80:14:B7"
georgeThingy = "CD:B0:C1:93:02:48"
aidenBool = False
georgeBool = False
tempDictArr = np.empty(2, dtype=object)

my_device = tago.Device('013dc384-56e6-4dc2-8a86-380701c5ad4e')


def write_data():
    csv_file = f"{filename}.csv"
    csv_columns = ['Accelerometor_Data', 'Action']
    try:
        with open(csv_file, 'a', newline='') as csvfile:
            writer = csv.DictWriter(csvfile, fieldnames=csv_columns)
            for data in dictArr:
                writer.writerow(data)
    except IOError:
        print("I/O error")


def upload_to_dashboard(x, y, z, action):
示例#3
0
def demo_receiver(base_host, base_port, tdf_server, tago_token):
    # Tago setup
    tago_device = tago.Device(tago_token)

    # TDF decoding state
    tdfparse = tdf3.Tdf()
    tdfparse.loadTdf(tdf_server, timeout=10.0)
    parser = tdfparse.parseTdf16

    # Baselisten connection
    listener = ListenClient.ListenClient(base_host, base_port)
    listener.connect()

    try:
        # Loop forever for packets from baselisten
        while True:
            try:
                packet = listener.read(timeout=None)
            except ConnectionResetError:
                print("Connection to baselisten lost...")
                return
            except NotImplementedError:
                continue

            # Loop over every payload in the serial packet
            for payload_type, route, payload in packet.iter_payloads():

                first_hop = route[-1]
                pkt_addr = first_hop.address_fmt
                pkt_rssi = "{:d}dBm".format(first_hop.rssi)
                print("From {:s}, {:d} bytes, RSSI {:s}".format(
                    pkt_addr, len(payload), pkt_rssi))

                # This demo is only concerned with TDF payloads
                if payload_type != PayloadType.PAYLOAD_TDF3:
                    print("\tPacket was not a TDF ({:})".format(payload_type))
                    continue

                # Payload is a TDF
                for point in parser(payload,
                                    datetime.datetime.utcnow(),
                                    debug=False,
                                    combine=True):
                    phenomena = point['phenomena']
                    print(point['time'])
                    for key in phenomena:
                        tago_data = {
                            'variable': key,
                            'value': phenomena[key]['converted']
                        }
                        tago_device.insert(tago_data)


# data_to_insert = {
#   'variable': 'temperature',
#   'time': '2014-01-20 03:43:59',
#   'unit': 'C',
#   'value': 63
# }

    except KeyboardInterrupt:
        pass
示例#4
0
    def run(self):
        model = get_trainingmodel()
        ## Static nodes locations
        stations = list(
            np.array([[17.8, 7.8], [2.4, 7.8], [5.85, 3.0], [11.95, 0.1],
                      [6.55, 0.1], [12.75, 3.0], [9.45, 12.75], [14.2, 10],
                      [5.5, 10], [12.55, 9.2], [8.65, 9.2], [15.05, 4.8],
                      [6.95, 4.8]]))
        time1 = datetime.now()
        timestamp = datetime.timestamp(time1)
        MY_DEVICE_TOKEN = '3503290b-05e5-433d-a864-e1b8e7bfbf11'  ## Add tagoio dashboard api key here
        my_device = tago.Device(MY_DEVICE_TOKEN)
        temp1 = []
        temp2 = []
        temp3 = []
        count = 0
        while True:
            ## feed rssi to modal
            m1 = mobile1_R
            m2 = mobile2_R
            m3 = mobile3_R
            knn1 = model.predict([m1])
            knn2 = model.predict([m2])
            knn3 = model.predict([m3])
            ## get distance from rssi value
            min_list1 = sorted(
                zip(stations, m1),
                key=lambda t: t[1])[7:]  ## get the best 6 rssi signal strength
            dist1 = [rssi_dist_convert(i[1], 0) for i in min_list1]
            nodes1 = [i[0] for i in min_list1]
            min_list2 = sorted(zip(stations, m2), key=lambda t: t[1])[7:]
            dist2 = [rssi_dist_convert(i[1], 0) for i in min_list2]
            nodes2 = [i[0] for i in min_list2]
            min_list3 = sorted(zip(stations, m3), key=lambda t: t[1])[7:]
            dist3 = [rssi_dist_convert(i[1], 0) for i in min_list3]
            nodes3 = [i[0] for i in min_list3]
            ## multilateration
            multi1 = gps_solve(dist1, nodes1)
            multi2 = gps_solve(dist2, nodes2)
            multi3 = gps_solve(dist3, nodes3)
            ## kalman filter
            if count > 5:  ## takes 10 readings of knn and multilateration coordinates and perform Kalman filter
                loc1 = Kalman(temp1)
                loc2 = Kalman(temp2)
                loc3 = Kalman(temp3)
                temp = []
                temp.append(loc1)
                temp.append(loc2)
                temp.append(loc3)
                loc = [[int(i[0]) for i in temp], [int(i[1]) for i in temp]]
                self.signal.emit(loc)
                temp1 = []
                temp2 = []
                temp3 = []
                count = 0
            else:
                temp1.append(knn1[0])
                temp1.append(multi1)
                temp2.append(knn2[0])
                temp2.append(multi2)
                temp3.append(knn3[0])
                temp3.append(multi3)
                count += 1

            if (datetime.timestamp(datetime.now()) - timestamp >
                    60):  ## upload mobiles nodes location every minute
                ## uplaod loc to dashboard
                data = [{
                    'variable': 'Mobile1',
                    'value': loc1
                }, {
                    'variable': 'Mobile2',
                    'value': loc2
                }, {
                    'variable': 'Mobile3',
                    'value': loc3
                }]
                result = my_device.insert(data)
                timestamp = datetime.timestamp(datetime.now())
                if result['status']:
                    print(result['result'])
                else:
                    print(result['message'])
            time.sleep(0.1)