Example #1
0
def propagate_message(tag):

        client = Client(device_type='test_device',
                        device_name='test',
                        encrypt=False,
                        reuse_address=False,
                        iota_node="http://localhost:14700",
                        route_pow=False)

        transactions = client.get_transactions(tags=[tag], count=1)
        data = client.get_transaction_data(transactions[0])
        time = client.post_to_tangle(data=data, address_level=1)
        return client.tag, data, time
def test_mwm(number_of_transactions, mwm):

    # Create a client object
    client = Client(device_type='test_device',
                    seed='',
                    device_name='test',
                    reuse_address=False,
                    iota_node="http://localhost:14700",
                    route_pow=False)

    results = []
    for _ in range(0, number_of_transactions):
        tx_time = client.post_to_tangle(data='', mwm=mwm)
        results.append(tx_time)
    average = sum(results) / number_of_transactions
    return average
def test_setup(number_of_devices):

    # Variable to store total time
    total_time = 0

    for _ in range(0, number_of_devices):
        # Setting up a client device
        client = Client(device_type='test_device',
                        seed='',
                        device_name='test',
                        iota_node="http://localhost:14700",
                        route_pow=False)

        # Send a zero value transaction to attach address to tangle
        time = client.post_to_tangle(data='')

        # Add found time to total time
        total_time += time
    return total_time
Example #4
0
def test_latency(number_of_devices, message_size, mwm):

    total_time = 0

    client = Client(device_type='test_device',
                    device_name='test',
                    encrypt=False,
                    reuse_address=False,
                    iota_node="http://localhost:14700",
                    route_pow=False)

    data = ''.join(random.choice(string.ascii_uppercase) for _ in range(message_size))

    t = client.post_to_tangle(data=data, address_level=1, verbose=True, mwm=mwm)

    tag = client.tag

    for _ in range(0, number_of_devices):
        total_time += t
        tag, data, t = propagate_message(tag)
    return total_time
Example #5
0
def test_reuse(number_of_transactions, average_over, reuse):

    # Stores results
    results = []

    # Create a client object
    client = Client(device_type='test_device',
                    seed='',
                    device_name='test',
                    reuse_address=reuse,
                    iota_node="http://localhost:14700",
                    route_pow=False)

    # Get results
    for i in range(0, number_of_transactions):
        times = []
        for j in range(0, average_over):
            time = client.post_to_tangle(data='')
            times.append(time)
        avg = sum(times) / average_over
        results.append(avg)
    return results
def transaction_test(number_of_txs, wait):

    # List to store times
    times = []

    for _ in range(0, number_of_txs):

        client = Client(device_type='test_device',
                        seed='',
                        device_name='test',
                        iota_node="http://localhost:14700",
                        route_pow=False)

        # Send a zero value transaction to attach address to tangle
        t = client.post_to_tangle(data='')

        # Add found time to total time
        times.append(t)

        # Wait time
        time.sleep(wait)

    return times
            # Post state of device to tangle
            client.post_to_tangle(system_state, verbose=True)

            # Wait period
            client.publish(minutes=1)

        # Catches any connection errors when collecting data and restarts
        except requests.exceptions.ConnectionError:
            print("Connection error...restarting in 1 min")
            time.sleep(60)
            main(tags=tags)

        except KeyboardInterrupt:
            print("Exiting...")
            sys.exit()


# Get a device name from the user
device_list, streams = get_user_input()

# Class used to query tangle data,
client = Client(device_type='state')

# Prints client details to console
print(client)

if __name__ == '__main__':
    device_tags = client.mqtt.find_device_tags(devices=device_list, num_of_streams=streams, read_from='monitor')
    main(device_tags)
            # Posts average of data
            client.post_to_tangle(data_average, verbose=True)

            # Wait for next data collection
            client.publish(minutes=1)

    # Catches any connection errors when collecting data and restarts
    except requests.exceptions.ConnectionError:
        print("Connection error...restarting in 1 min")
        time.sleep(60)
        main(tags=tags)

    except KeyboardInterrupt:
        print("Exiting...")
        sys.exit()


device_list, streams = get_user_input()

# Create a client object with seed of device
client = Client(device_type='monitor')

# Prints client details to console
print(client)

if __name__ == '__main__':
    device_tags = client.mqtt.find_device_tags(devices=device_list,
                                               num_of_streams=streams,
                                               read_from='sensor')
    main(device_tags)
Example #9
0
            # Generates random number
            sensor_data = random.randint(0, 100)
            print("Random number: ", sensor_data)

            # Posts encrypted data to tangle
            client.post_to_tangle(sensor_data, verbose=True)

            # Wait approx 1 minute for next data collection
            client.publish(minutes=1)

    # Catches any connection errors when collecting data
    except requests.exceptions.ConnectionError:
        print("Connection error...restarting data collection in 1 min")
        time.sleep(60)
        main()

    except KeyboardInterrupt:
        print("Ending data stream....")
        sys.exit()


# Create a client object with device seed, use a seed generator to get a seed.
client = Client(device_type='sensor', reuse_address=True)

# Prints client details to console
print(client)

if __name__ == '__main__':
    main()
            # Post state of device to tangle
            client.post_to_tangle(light_state, verbose=True)

            # Wait period
            client.publish(minutes=1)

        # Catches any connection errors when collecting data and restarts
        except requests.exceptions.ConnectionError:
            print("Connection error...restarting in 1 min")
            time.sleep(60)
            main(tags=tags)

        except KeyboardInterrupt:
            print("Exiting...")
            sys.exit()


# Get a device name from the user
device_list, streams = get_user_input()

# Class used to query tangle data,
client = Client(device_type='light')

# Prints client details to console
print(client)

if __name__ == '__main__':
    device_tags = client.mqtt.find_device_tags(devices=device_list, num_of_streams=streams, read_from='state')
    main(device_tags)