Beispiel #1
0
/*
 * Main AMQP thread.
 *
 * The thread will create a connection and then loop over the following:
 *
 * - Open a connection
 * - Open a channel
 * - Create (declare) a "WICED_QUEUE" queue
 * - Bind the queue to "amq.direct" exchange
 * - Send data through to the exchange ( using publish and send string)
 * - Receive data from the queue ( using consume and receive string )
 * - Close the channel
 * - Close the connection
 */
void application_start( void )
{
    wiced_result_t  ret = WICED_SUCCESS;

    wiced_init( );

    wiced_rtos_init_semaphore( &semaphore );

    /* Bringup the network interface */
    wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    WPRINT_APP_INFO(("[AMQP] Connecting to broker %u.%u.%u.%u ...", (uint8_t)(GET_IPV4_ADDRESS(broker_address) >> 24),
                                                          (uint8_t)(GET_IPV4_ADDRESS(broker_address) >> 16),
                                                          (uint8_t)(GET_IPV4_ADDRESS(broker_address) >> 8),
                                                          (uint8_t)(GET_IPV4_ADDRESS(broker_address) >> 0)));

    ret = amqp_connection_init( &broker_address, WICED_STA_INTERFACE, &callbacks, &connection, NULL );
    amqp_print_status( ret, NULL, NULL );

    while( ret == WICED_SUCCESS )
    {

        WPRINT_APP_INFO(("[AMQP] Opening connection..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_conn_open( &connection ), NULL, "Did you configure you broker IP address?\n" );

        WPRINT_APP_INFO(("[AMQP] Opening channel..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_open( &connection, 1 ), NULL, NULL );

        WPRINT_APP_INFO(("[AMQP] Declaring queue..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_queue_declare( &connection, 1, AMQP_RECEIVE_QUEUE_NAME ), NULL, NULL );

        WPRINT_APP_INFO(("[AMQP] Binding queue..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_queue_bind( &connection, 1, AMQP_RECEIVE_QUEUE_NAME, AMQP_ROUTING_KEY_NAME ), NULL, NULL );

        WPRINT_APP_INFO(("[AMQP] Consuming..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_consume( &connection, 1, AMQP_RECEIVE_QUEUE_NAME ), NULL, NULL );

        WPRINT_APP_INFO(("[AMQP] Publishing..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_publish( &connection, 1, AMQP_ROUTING_KEY_NAME ), NULL, NULL );

        WPRINT_APP_INFO(("[AMQP] Sending message..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_send_string( &connection, 1, AMQP_MESSAGE_STR ), AMQP_MESSAGE_STR, NULL );

        WPRINT_APP_INFO(("[AMQP] Receiving message..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_recv_string( &connection, 1 ), str, NULL );

        WPRINT_APP_INFO(("[AMQP] Closing channel..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_ch_close( &connection, 1 ), NULL, NULL);

        WPRINT_APP_INFO(("[AMQP] Closing connection..."));
        RUN_COMMAND_PRINT_STATUS_AND_BREAK_ON_ERROR( amqp_conn_close( &connection ), NULL, NULL );

        wiced_rtos_delay_milliseconds( 2000 );

    }
    WPRINT_APP_INFO(("[AMQP] Deinit connection..."));
    ret = amqp_connection_deinit( &connection );
    amqp_print_status( ret, NULL, NULL );

}
Beispiel #2
0
void application_start( )
{
    wiced_ip_address_t ip_address;
    wiced_result_t     result;

    wiced_init( );
    wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);

    /* Configure the device */
    /* wiced_configure_device( app_config ); */ /* Config bypassed in local makefile and wifi_config_dct.h */

    WPRINT_APP_INFO( ( "Resolving IP address of HTTPS server\n" ) );
    wiced_hostname_lookup("www.google.com", &ip_address, 10000);
    WPRINT_APP_INFO( ( "Server is at %u.%u.%u.%u\n",   (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 24),
                                                       (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 16),
                                                       (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 8),
                                                       (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 0) ) );

    WPRINT_APP_INFO( ( "Getting '/'...\n" ) );

    /* Initialize the root CA certificate */
    wiced_tls_init_root_ca_certificates( google_root_ca_certificate );

    result = wiced_https_get( &ip_address, SIMPLE_GET_REQUEST, buffer, BUFFER_LENGTH, "www.google.com" );
    if ( result == WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ( "Server returned\n%s", buffer ) );
    }
    else
    {
        WPRINT_APP_INFO( ( "Get failed: %u\n", result ) );
    }

    wiced_deinit();
}
Beispiel #3
0
void application_start(void)
{
    /* Initialise the device and WICED framework */
    wiced_init( );

    /* Bring up the network interface */
    wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    /* Create a TCP server socket */
    if (wiced_tcp_create_socket(&tcp_server_handle.socket, WICED_STA_INTERFACE) != WICED_SUCCESS)
    {
        WPRINT_APP_INFO(("TCP socket creation failed\n"));
    }

    if (wiced_tcp_listen( &tcp_server_handle.socket, TCP_SERVER_LISTEN_PORT ) != WICED_SUCCESS)
    {
        WPRINT_APP_INFO(("TCP server socket initialization failed\n"));
        wiced_tcp_delete_socket(&tcp_server_handle.socket);
        return;
    }

    /* Start a tcp server thread */
    WPRINT_APP_INFO(("Creating tcp server thread \n"));
    wiced_rtos_create_thread(&tcp_thread, TCP_SERVER_THREAD_PRIORITY, "Demo tcp server", tcp_server_thread_main, TCP_SERVER_STACK_SIZE, &tcp_server_handle);

}
// Main application thread which is started by the RTOS after boot
void application_start(void)
{
    wiced_init( );
    dbStart();

    WPRINT_APP_INFO(("Starting WWEP Server\n"));

    while(wiced_network_up( INTERFACE, DHCP_MODE, &ip_settings ) != WICED_SUCCESS); // Keep trying until you get hooked up

    // I created all of the server code in a separate thread to make it easier to put the server
    // and client together in one application.

    wiced_rtos_create_thread(&tcp_thread, TCP_SERVER_NONSECURE_THREAD_PRIORITY, "Server TCP Server", tcp_server_nonsecure_thread_main, TCP_SERVER_NONSECURE_STACK_SIZE, 0);
    wiced_rtos_create_thread(&ping_thread, PING_THREAD_PRIORITY, "Ping", pingAP, 1024, 0);

    // Setup Display
    WPRINT_APP_INFO(("#\t     IP\t\tPort\tMessage\n"));
    WPRINT_APP_INFO(("----------------------------------------------------------------------\n"));


    // just blink the led while the whole thing is running
    while(1)
    {
        wiced_gpio_output_low( WICED_LED1 );
        wiced_rtos_delay_milliseconds( 250 );
        wiced_gpio_output_high( WICED_LED1 );
        wiced_rtos_delay_milliseconds( 250 );
    }
}
Beispiel #5
0
/**
 *  Application start
 */
void application_start( void )
{
    /* Initialise the device */
    wiced_init();
    /* Run the main application function */
    wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);
#if TEST_TYPE == TEST_RAM
    {
        u8 m=0, n=0;
        u8 tree_num[3] = {1,2,3};
        u8 request_num[4] = {1,16,32,64};
        ramtest_titile_printf();
        //  ramtest(tree_num[0],1);

        for( m=0; m < 3; m++)
        {
            for( n=0; n < 4; n++)
            {
                ramtest_handle(tree_num[m],request_num[n]);
            }
        }
        ramtest_end_printf();
    }
#endif
#if TEST_TYPE == TEST_TIME
    performtest_all();
#endif
#if TEST_TYPE == TEST_STAB_CYCLE
    stab_test_cycle();
#endif
#if TEST_TYPE == TEST_STAB_FULLLOAD
    stab_test_fullLoad();
#endif
}
Beispiel #6
0
void application_start(void)
{
    /* Initialise the device and WICED framework */
    wiced_init( );

    /* Configure the device */
    wiced_configure_device( NULL );

    /* Bring up the network interface */
    wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    /* Enable MCU powersave. MCU powersave API can be globally DISABLED in <WICED-SDK>/include/wiced_defaults.h */
    /* WARNING: Please read the WICED Powersave API documentation before enabling MCU powersave */
    //wiced_platform_mcu_enable_powersave();

    /* Enable 802.11 powersave mode */
    wiced_wifi_enable_powersave_with_throughput( 40 );

    /* Register an event that toggles powersave every 2 seconds to
     * demonstrate power consumption with & without powersave enabled
     */
    wiced_rtos_register_timed_event( &powersave_toggle_event, WICED_HARDWARE_IO_WORKER_THREAD, &powersave_toggle, 2000, 0 );

    /* Start web-server */
    wiced_http_server_start( &http_server, 80, appliance_web_pages, WICED_STA_INTERFACE );

    /* Advertise webpage services using Gedday */
    gedday_init( WICED_STA_INTERFACE, "wiced-appliance-app" );
    gedday_add_service( "Appliance Webserver", "_http._tcp.local", 80, 300, "" );
}
Beispiel #7
0
void application_start( void )
{
    user_dct_data_t* dct;
    uint32_t sample_interval;
    uint16_t max_sockets = 10;

    wiced_init( );

    /* Configure device */
    wiced_configure_device( app_config );

    /* Initialise Xively data. Xively data is shared among multiple threads; therefore a mutex is required */
    memset( &xively_data, 0, sizeof( xively_data ) );
    wiced_rtos_init_mutex( &xively_data.mutex );

    /* Initialise temperature set point. Set point is shared among multiple threads; therefore a mutex is required */
    wiced_rtos_init_mutex( &setpoint.mutex );
    setpoint.temperature = DEFAULT_SETPOINT;
    adjust_setpoint_led_brightness( );

    /* Initialise Thermistor */
    wiced_adc_init( THERMISTOR_ADC, 5 );

    /* Initialise Set Point Control keypad and assigns it's callback function to run on hardware_io_worker_thread's context */
    gpio_keypad_enable( &setpoint_control_keypad, WICED_HARDWARE_IO_WORKER_THREAD, setpoint_control_keypad_handler, 250, 2, setpoint_control_key_list );

    /* Disable roaming to other access points */
    wiced_wifi_set_roam_trigger( -99 ); /* -99dBm ie. extremely low signal level */

    /* Bringup the network interface */
    wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    /* Timestamp is needed for sending data to Xively.
     * Start automatic time synchronisation and synchronise once every day.
     */
    sntp_start_auto_time_sync( 1 * DAYS );

    wiced_dct_read_lock( (void**) &dct, WICED_FALSE, DCT_APP_SECTION, 0, sizeof(user_dct_data_t) );
    sample_interval = dct->sample_interval;
    wiced_dct_read_unlock( dct, WICED_FALSE );

    /* Setup timed events that will take a measurement & activate Xively thread to send measurements to Xively */
    wiced_rtos_register_timed_event( &xively_timed_event,      WICED_NETWORKING_WORKER_THREAD,  send_data_to_xively,     10 * SECONDS, 0 );
    wiced_rtos_register_timed_event( &temperature_timed_event, WICED_HARDWARE_IO_WORKER_THREAD, take_temperature_reading, sample_interval, 0 );

    /* Start web server to display current temperature & setpoint */
    wiced_http_server_start( &http_server, 80, max_sockets, web_pages, WICED_STA_INTERFACE, DEFAULT_URL_PROCESSOR_STACK_SIZE );

    /* Advertise webpage services using Gedday */
    gedday_init( WICED_STA_INTERFACE, "wiced-temp-controller" );
    gedday_add_service( "temp_control web server", "_http._tcp.local", 80, 300, "" );
}
Beispiel #8
0
void application_start(void)
{
    /* Initialise the WICED device */
    wiced_init();

    /* Configure the device */
    /* wiced_configure_device( app_config ); */ /* Config bypassed in local makefile and wifi_config_dct.h */

    /* Bring up the network interface and connect to the Wi-Fi network */
    wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    sntp_start_auto_time_sync( TIME_SYNC_PERIOD );
}
// Main application thread which is started by the RTOS after boot
void application_start(void)
{

	wiced_init( );

	wiced_network_up( INTERFACE, DHCP_MODE, &ip_settings );

	// I created all of the server code in a separate thread to make it easier to put the server
	// and client together in one application.

	wiced_rtos_create_thread(&tcp_thread, TCP_SERVER_THREAD_PRIORITY, "Server TCP Server", tcp_server_thread_main, TCP_SERVER_STACK_SIZE, 0);

}
Beispiel #10
0
/**
 * Do what is needed to finalize the connection.
 * @return
 */
wlan_result_t wlan_connect_finalize()
{
    const static_ip_config_t& ip_config = *wlan_fetch_saved_ip_config();

    // enable connection from stored profiles
    wlan_result_t result = wiced_interface_up(WICED_STA_INTERFACE);
    if (!result) {
        HAL_WLAN_notify_connected();
        wiced_ip_setting_t settings;
        wiced_ip_address_t dns;

        switch (IPAddressSource(ip_config.config_mode)) {
            case STATIC_IP:
                to_wiced_ip_address(settings.ip_address, ip_config.host);
                to_wiced_ip_address(settings.netmask, ip_config.netmask);
                to_wiced_ip_address(settings.gateway, ip_config.gateway);
                result = wiced_network_up(WICED_STA_INTERFACE, WICED_USE_STATIC_IP, &settings);
                if (!result) {
                    if (to_wiced_ip_address(dns, ip_config.dns1))
                        dns_client_add_server_address(dns);
                    if (to_wiced_ip_address(dns, ip_config.dns2))
                        dns_client_add_server_address(dns);
                }
            default:
                result = wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);
                break;
        }
    }
    else
    {
        wiced_network_down(WICED_STA_INTERFACE);
    }
    // DHCP happens synchronously
    HAL_WLAN_notify_dhcp(!result);
    wiced_network_up_cancel = 0;
    return result;
}
void application_start( )
{
    Network mqtt_network;
    Client mqtt_client;
    unsigned char buf[ 100 ];
    unsigned char readbuf[ 100 ];

    wiced_ip_address_t INITIALISER_IPV4_ADDRESS( ip_address, MQTT_TARGET_IP );

    wiced_init( );

    /* Initialize MQTT */
    wiced_mqtt_init( &mqtt_network );

    wiced_mqtt_buffer_init( &mqtt_client, &mqtt_network, buf, 100, readbuf, 100 );

    mqtt_network.hostname = "broker.mqttdashboard.com";
    mqtt_network.ip_address = &ip_address;
    mqtt_network.port = MQTT_BROKER_PORT;

    /* Bring up the network interface */
    wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    if ( wiced_connectnetwork( &mqtt_network, WICED_STA_INTERFACE ) != WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ("connection failed\n") );
        return;
    }

    wiced_mqtt_connect( &mqtt_client, MQTT_CLIENT_ID, NULL, NULL );

    wiced_mqtt_subscribe( &mqtt_client, MQTT_TOPIC_NAME, messageArrived );

    while ( 1 )
    {
        wiced_subscribe( &mqtt_client );
        wiced_rtos_delay_milliseconds( 500 );
    }
}
Beispiel #12
0
wiced_result_t wiced_wlu_server_eth_start( int tcp_server_port , char** argv)
{
    wiced_result_t result;
    UNUSED_PARAMETER(argv);
    wiced_assert("wlu_server already started", (wlu_server.started == WICED_FALSE));

    wlu_server.started                  = WICED_TRUE;
    wlu_server.eth_started              = WICED_TRUE;
    wlu_server.eth_port                 = tcp_server_port;



    // WWD_WLAN_KEEP_AWAKE( );

    /* Bring up the network interface */
    result = wiced_network_up( WICED_ETHERNET_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    if ( result != WICED_SUCCESS )
    {
        WPRINT_APP_INFO(("Failed to connect to Ethernet.\n"));
    }

    /* Create a TCP socket */
    if ( wiced_tcp_create_socket( &tcp_client_socket, WICED_ETHERNET_INTERFACE ) != WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ("TCP socket creation failed\n") );
    }
    if (wiced_tcp_listen( &tcp_client_socket, tcp_server_port ) != WICED_SUCCESS)
    {
        WPRINT_APP_INFO(("TCP server socket initialization failed\n"));
        wiced_tcp_delete_socket(&tcp_client_socket);
        return WICED_ERROR;
    }

    wiced_rtos_create_thread( &wlu_server.thread, WLU_SERVER_THREAD_PRIORITY, "wlu_eth_server", wlu_server_thread, WLU_SERVER_STACK_SIZE, &wlu_server );

    return WICED_SUCCESS;
}
Beispiel #13
0
void application_start(void)
{
	WPRINT_PLATFORM_INFO( ("I2C initializing\n") );

	 //I2C_LowLevel_Init();

    /* Initialise the device */
    wiced_init();

    /* Bring up the softAP interface ------------------------------------------------------------- */
    wiced_network_up(WICED_AP_INTERFACE, WICED_USE_INTERNAL_DHCP_SERVER, &ap_ip_settings);

    /* Start a DNS redirect server to redirect wiced.com to the AP webserver database*/
    wiced_dns_redirector_start( &dns_redirector, WICED_AP_INTERFACE );
    WPRINT_PLATFORM_INFO( ("DNS Redirector initialised\n") );

    /* Start a web server on the AP interface */
    wiced_http_server_start( &ap_http_server, 80, ap_web_pages, WICED_AP_INTERFACE );
    WPRINT_PLATFORM_INFO( ("HTTP Daemon started\n") );


	//wiced_result_t result = wm8533_init(&ac);
}
void application_start( void )
{
    wiced_ip_address_t  ip_address;
    wiced_result_t      result;

    /* We need three headers - host, content type, and content length */
    http_header_field_t header[3];
    /* Header 0 is the Host header */
    header[0].field        = HTTP_HEADER_HOST;
    header[0].field_length = strlen( HTTP_HEADER_HOST );
    header[0].value        = SERVER_HOST;
    header[0].value_length = strlen( SERVER_HOST );
    /* Header 1 is the content type (JSON) */
    header[1].field        =  HTTP_HEADER_CONTENT_TYPE;
    header[1].field_length = strlen( HTTP_HEADER_CONTENT_TYPE );
    header[1].value        = "application/json";
    header[1].value_length = strlen( "application/json" );
    /* Header 2 is the content length. In this case, it is the length of the JSON message */
    sprintf(json_len,"%d", strlen(JSON_MSG)); /* Calculate the length of the JSON message and store the value as a string */
    header[2].field        = HTTP_HEADER_CONTENT_LENGTH;
    header[2].field_length = strlen( HTTP_HEADER_CONTENT_LENGTH );
    header[2].value        = json_len; // This holds the length of the JSON message as a sting containing the decimal value
    header[2].value_length = strlen( json_len ); // This is the length of the string that holds the JSON message size. For example, if the JSON is 12 characters, this would be "2" because the string "12" is 2 characters long.

    wiced_init( );

    /* This semaphore will be used to wait for one request to finish before re-initializing and starting the next one */
    wiced_rtos_init_semaphore(&httpWait);

    wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);

    WPRINT_APP_INFO( ( "Resolving IP address of %s\n", SERVER_HOST ) );
    wiced_hostname_lookup( SERVER_HOST, &ip_address, DNS_TIMEOUT_MS, WICED_STA_INTERFACE );
    WPRINT_APP_INFO( ( "%s is at %u.%u.%u.%u\n", SERVER_HOST,
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 24),
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 16),
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 8),
                                                 (uint8_t)(GET_IPV4_ADDRESS(ip_address) >> 0) ) );

    /* Initialize client */
    http_client_init( &client, WICED_STA_INTERFACE, event_handler, NULL );
    client.peer_cn = NULL; /* If you set hostname, library will make sure subject name in the server certificate is matching with host name you are trying to connect. Pass NULL if you don't want to enable this check */

    /* Connect to the server */
    if ( ( result = http_client_connect( &client, (const wiced_ip_address_t*)&ip_address, SERVER_PORT, HTTP_NO_SECURITY, CONNECT_TIMEOUT_MS ) ) == WICED_SUCCESS )
    {
        connected = WICED_TRUE;
        WPRINT_APP_INFO( ( "Connected to %s\n", SERVER_HOST ) );
    }
    else
    {
        WPRINT_APP_INFO( ( "Error: failed to connect to server: %u\n", result) );
        return; /* Connection failed - exit program */
    }

    /* Send a POST to resource /anything */
    http_request_init( &request, &client, HTTP_POST, "/post", HTTP_1_1 );
    http_request_write_header( &request, &header[0], 3 ); // We need 3 headers
    http_request_write_end_header( &request );
    http_request_write( &request, (uint8_t* ) JSON_MSG, strlen(JSON_MSG)); /* Write the content */
    http_request_flush( &request );

    wiced_rtos_get_semaphore(&httpWait, WICED_WAIT_FOREVER); /* Wait for this request to complete before going on */
    /* Disconnect from the server and deinit since we are done now */
    http_client_disconnect( &client );
    http_client_deinit( &client );
}
Beispiel #15
0
void application_start( )
{
    int i;
    wiced_result_t            status;
    wiced_mac_t               my_mac_address;
    uint32_t                  my_ip_address;
    wiced_ip_address_t        ipv4_address;
    wiced_keep_alive_packet_t keep_alive_packet_info;

    /* Initialize the device */
    wiced_init( );

    /* Bring up the network on the STA interface */
    wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL );

    /* Setup the ARP keep alive packet to copy in my MAC & IP address */
    wiced_wifi_get_mac_address( &my_mac_address );
    wiced_ip_get_ipv4_address( WICED_STA_INTERFACE, &ipv4_address );
    my_ip_address = htonl( GET_IPV4_ADDRESS(ipv4_address) );
    memcpy( &arp_packet[ 6 ], &my_mac_address, 6 );
    memcpy( &arp_packet[ 22 ], &my_mac_address, 6 );
    memcpy( &arp_packet[ 28 ], &my_ip_address, 4 );
    memcpy( &arp_packet[ 38 ], &my_ip_address, 4 );

    /* Turn off print buffers, so print output occurs immediately */
    setvbuf( stdout, NULL, _IONBF, 0 );


    /* Setup a Null function data frame keep alive */
    keep_alive_packet_info.keep_alive_id = KEEP_ALIVE_ID_NFD,
    keep_alive_packet_info.period_msec   = KEEP_ALIVE_PERIOD_NFD_MSEC,
    keep_alive_packet_info.packet_length = 0;

    status = wiced_wifi_add_keep_alive( &keep_alive_packet_info );
    switch ( status )
    {
        case WICED_SUCCESS:
        {
            WPRINT_APP_INFO( ( "\r\nAdded:\n") );
            WPRINT_APP_INFO( ( "  - Null Function Data frame with repeat period of %d milliseconds \n", KEEP_ALIVE_PERIOD_NFD_MSEC ) );
            break;
        }
        case WICED_TIMEOUT:
        {
            WPRINT_APP_INFO( ( "Timeout: Adding Null Function Data frame keep alive packet\n" ) );
            break;
        }
        default:
            WPRINT_APP_INFO( ( "Error[%d]: Adding Null Function Data frame keep alive packet\n", status ) );
            break;
    }


    /* Setup an ARP packet keep alive */
    keep_alive_packet_info.keep_alive_id = KEEP_ALIVE_ID_ARP,
    keep_alive_packet_info.period_msec   = KEEP_ALIVE_PERIOD_ARP_MSEC,
    keep_alive_packet_info.packet_length = sizeof(arp_packet)-1;
    keep_alive_packet_info.packet = (uint8_t*)arp_packet;

    status = wiced_wifi_add_keep_alive( &keep_alive_packet_info );
    switch ( status )
    {
        case WICED_SUCCESS:
        {
            WPRINT_APP_INFO( ( "  - ARP packet with repeat period of %d milliseconds\n\n", KEEP_ALIVE_PERIOD_ARP_MSEC ) );
            break;
        }
        case WICED_TIMEOUT:
        {
            WPRINT_APP_INFO( ( "Timeout: Adding ARP packet\n\n" ) );
            break;
        }
        default:
            WPRINT_APP_INFO( ( "Error[%d]: Adding ARP packet\n\n", status ) );
            break;
    }


/* Get Null Function Data Frame keep alive packet info */
keep_alive_packet_info.keep_alive_id = KEEP_ALIVE_ID_NFD;
keep_alive_packet_info.packet_length = MAX_KEEP_ALIVE_PACKET_SIZE;
keep_alive_packet_info.packet        = &keep_alive_packet_buffer[0];

    status = wiced_wifi_get_keep_alive( &keep_alive_packet_info );
    if ( status == WICED_SUCCESS )
    {
        print_keep_alive_info( &keep_alive_packet_info );
    }
    else
    {
        WPRINT_APP_INFO( ( "ERROR[%d]: Get keep alive packet failed for ID:%d\n", status, KEEP_ALIVE_ID_NFD) );
    }


    /* Get ARP keep alive packet info */
    keep_alive_packet_info.keep_alive_id = KEEP_ALIVE_ID_ARP;
    keep_alive_packet_info.packet_length = MAX_KEEP_ALIVE_PACKET_SIZE;
    keep_alive_packet_info.packet        = &keep_alive_packet_buffer[0];

    status = wiced_wifi_get_keep_alive( &keep_alive_packet_info );
    if ( status == WICED_SUCCESS )
    {
        print_keep_alive_info( &keep_alive_packet_info );
    }
    else
    {
        WPRINT_APP_INFO( ( "ERROR[%d]: Get keep alive packet failed for ID:%d\n", status, KEEP_ALIVE_ID_ARP) );
    }


    /* Wait 30 seconds, then disable all keep alive packets */
    WPRINT_APP_INFO( ( "Sending keep alive packets " ) );
    for ( i = 0; i < 30; i++ )
    {
        WPRINT_APP_INFO( ( "." ) );
        wiced_rtos_delay_milliseconds( 1000 );
    }
    WPRINT_APP_INFO( ( " done\n\n" ) );


    /* Disable Null Function Data Frame keep alive packet*/
    status = wiced_wifi_disable_keep_alive( KEEP_ALIVE_ID_NFD );
    if ( status == WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ( "Null Function data frame keep alive packet disabled\n" ) );
    }
    else
    {
        WPRINT_APP_INFO( ( "ERROR[%d]: Failed to disable NFD keep alive packet\n", status) );
    }


    /* Disable ARP keep alive packet*/
    status = wiced_wifi_disable_keep_alive( KEEP_ALIVE_ID_ARP );
    if ( status == WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ( "ARP keep alive packet disabled\n" ) );
    }
    else
    {
        WPRINT_APP_INFO( ( "ERROR[%d]: Failed to disable ARP keep alive packet\n", status) );
    }

    WPRINT_APP_INFO( ( "\r\nStop.\n") );
    while ( 1 )
    {
    }
}
int start_smartconfig(void)
{

    wiced_result_t result;
    wiced_config_ap_entry_t* dct_ap_entry;
    WPRINT_APP_INFO(("smart\n"));

    result = 1;

    /* enable protocols */
    easy_setup_enable_cooee(); /* broadcom cooee */
    easy_setup_enable_neeze(); /* broadcom neeze */
    //easy_setup_enable_akiss(); /* wechat akiss */
    //easy_setup_enable_changhong(); /* changhong */

    /* set cooee key */
    //cooee_set_key("1111111111111111");

    /* set airkiss key */
    //akiss_set_key("1111111111111111");

    /* start easy setup */
    if (easy_setup_start() != WICED_SUCCESS)
    {
        WPRINT_APP_INFO(("easy setup failed.\r\n"));
    }
    else
    {
        WPRINT_APP_INFO(("easy setup done.\r\n"));
    }

    int up_tries = 3;

    while (up_tries--) {
        result = wiced_network_up( WICED_STA_INTERFACE,\
			WICED_USE_EXTERNAL_DHCP_SERVER, NULL );
        if (result == WICED_SUCCESS) {
            break;
        } else {
            WPRINT_APP_INFO(("Network up failed, try again (%d left)\r\n", up_tries));
        }
    }
    if ( result != WICED_SUCCESS )
    {
        wiced_dct_read_lock( (void**) &dct_ap_entry, WICED_TRUE, \
			DCT_WIFI_CONFIG_SECTION, offsetof(platform_dct_wifi_config_t, stored_ap_list),\
			sizeof(wiced_config_ap_entry_t) );
		
        if (dct_ap_entry->details.security == WICED_SECURITY_WEP_PSK ) // Now try shared instead of open authentication
        {
            dct_ap_entry->details.security = WICED_SECURITY_WEP_SHARED;
            wiced_dct_write( dct_ap_entry, DCT_WIFI_CONFIG_SECTION, \
				offsetof(platform_dct_wifi_config_t, stored_ap_list),\
				sizeof(wiced_config_ap_entry_t) );
            result = wiced_network_up( WICED_STA_INTERFACE,\
				WICED_USE_EXTERNAL_DHCP_SERVER, NULL );
            if ( result != WICED_SUCCESS ) // Restore old value
            {
                //wiced_dct_read_lock( (void**) &dct_ap_entry, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, offsetof(platform_dct_wifi_config_t, stored_ap_list), sizeof(wiced_config_ap_entry_t) );
                dct_ap_entry->details.security = WICED_SECURITY_WEP_PSK;
                wiced_dct_write( dct_ap_entry, DCT_WIFI_CONFIG_SECTION, \
					offsetof(platform_dct_wifi_config_t, stored_ap_list),\
					sizeof(wiced_config_ap_entry_t) );
            }
        }
		
        wiced_dct_read_unlock( dct_ap_entry, WICED_TRUE );
    }

    if ( result != WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ("Network up failed\n") );
    }
    else
    {
        WPRINT_APP_INFO( ("Network up success\n") );
    }

    return result;
}
Beispiel #17
0
void application_start(void)
{
    const your_security_t       your_security_type = YOUR_SECURITY_WEP40_PSK;
    platform_dct_wifi_config_t* wifi_config_dct_local;

    /* Initialise the WICED device */
    wiced_init();

    /* Configure security for the device and join the AP */
    if ( set_wifi_security( your_security_type ) != WICED_SUCCESS )
    {
        WPRINT_APP_INFO( ( "Failed to update DCT with security type\r\n" ) );
        return;
    }

    /* Try join the network */
    if ( wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL ) != WICED_SUCCESS )
    {
        /* Check if we were using WEP. It is not possible to tell WEP Open from WEP Shared in a scan so we try Open first and Shared second */
        if ( your_security_type == YOUR_SECURITY_WEP40_PSK || your_security_type == YOUR_SECURITY_WEP104_PSK )
        {
            WPRINT_APP_INFO( ("WEP with open authentication failed, trying WEP with shared authentication...\r\n") );

            /* Modify the Wi-Fi config to use Shared WEP */
            wiced_dct_read_lock( (void**) &wifi_config_dct_local, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof( platform_dct_wifi_config_t ) );
            wifi_config_dct_local->stored_ap_list[0].details.security = WICED_SECURITY_WEP_SHARED;
            wiced_dct_write ( (const void*)wifi_config_dct_local, DCT_WIFI_CONFIG_SECTION, 0, sizeof (platform_dct_wifi_config_t) );
            wiced_dct_read_unlock( (void*)wifi_config_dct_local, WICED_TRUE );

            /* Try join the network again */
            if ( wiced_network_up( WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL ) != WICED_SUCCESS )
            {
                WPRINT_APP_INFO( ("WEP with Shared authentication failed as well\r\n") );

                /* Restore the Wi-Fi config back to the default Open WEP */
                wiced_dct_read_lock( (void**) &wifi_config_dct_local, WICED_TRUE, DCT_WIFI_CONFIG_SECTION, 0, sizeof( platform_dct_wifi_config_t ) );
                wifi_config_dct_local->stored_ap_list[0].details.security = WICED_SECURITY_WEP_PSK;
                wiced_dct_write ( (const void*)wifi_config_dct_local, DCT_WIFI_CONFIG_SECTION, 0, sizeof (platform_dct_wifi_config_t) );
                wiced_dct_read_unlock( (void*)wifi_config_dct_local, WICED_TRUE );

                /* Nothing more we can do.. Give up */
                WPRINT_APP_INFO(( "Unable to join AP\r\n" ));
                return;
            }
        }
        else
        {
            WPRINT_APP_INFO(( "Unable to join AP\r\n" ));
            return;
        }
    }

    while (1)
    {
        /* Send an ICMP ping to the gateway */
        send_ping( );

        /* Wait between pings */
        wiced_rtos_delay_milliseconds( PING_INTERVAL );
    }
}