Exemplo n.º 1
0
/**
 * Use a connection, checking that it is good
 * Checks via doing an NTP transaction
 */
static void use_connection(OnboardCellularInterface *driver)
{
    const char *ip_address = driver->get_ip_address();
    const char *net_mask = driver->get_netmask();
    const char *gateway = driver->get_gateway();

    TEST_ASSERT(driver->is_connected());

    TEST_ASSERT(ip_address != NULL);
    tr_debug("IP address %s.", ip_address);
    TEST_ASSERT(net_mask != NULL);
    tr_debug("Net mask %s.", net_mask);
    TEST_ASSERT(gateway != NULL);
    tr_debug("Gateway %s.", gateway);

    UDPSocket sock;
    SocketAddress host_address;

    TEST_ASSERT(driver->gethostbyname(MBED_CONF_APP_ECHO_SERVER, &host_address) == 0);
    host_address.set_port(MBED_CONF_APP_ECHO_UDP_PORT);

    tr_debug("UDP: Server %s address: %s on port %d.",
             MBED_CONF_APP_ECHO_SERVER, host_address.get_ip_address(),
             host_address.get_port());

    TEST_ASSERT(sock.open(driver) == 0)

    sock.set_timeout(10000);
    do_udp_echo(&sock, &host_address, 1);

    sock.close();
}
Exemplo n.º 2
0
/**
 * Test with credentials preset
 */
void test_connect_preset_credentials()
{
    driver.disconnect();
    driver.set_sim_pin(MBED_CONF_APP_DEFAULT_PIN);
    driver.set_credentials(MBED_CONF_APP_APN, MBED_CONF_APP_USERNAME,
                           MBED_CONF_APP_PASSWORD);
    int num_retries = 0;
    nsapi_error_t err = NSAPI_ERROR_OK;
    while (!driver.is_connected()) {
        err = driver.connect();
        if (err == NSAPI_ERROR_OK || num_retries > MBED_CONF_APP_MAX_RETRIES) {
            break;
        }
    }

    TEST_ASSERT(err == 0);
    use_connection(&driver);
    drop_connection(&driver);
}
Exemplo n.º 3
0
/**
 * Drop a connection and check that it has dropped
 */
static void drop_connection(OnboardCellularInterface *driver)
{
    TEST_ASSERT(driver->disconnect() == 0);
    TEST_ASSERT(!driver->is_connected());
}