Example #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 );

}
Example #2
0
void application_start( )
{
    uint8_t      led_state = 0;
    wiced_bool_t button_pressed;

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

    // The RGB and setup button are initialized in platform.c

    WPRINT_APP_INFO( ( "The RGB are flashing R-G-B alternately. Holding the setup button will force it flashing white.\n" ) );

    while ( 1 )
    {
        /* Read the state of setup button */
        button_pressed = wiced_gpio_input_get( SETUP_BUTTON ) ? WICED_FALSE : WICED_TRUE;  /* The button has inverse logic */

        if ( button_pressed == WICED_TRUE )
        {
            /* Flashing white */
            if( (led_state%2) == 0 )
            {
                wiced_gpio_output_low( RGB_R );
                wiced_gpio_output_low( RGB_G );
                wiced_gpio_output_low( RGB_B );
            }
            else
            {
                wiced_gpio_output_high( RGB_R );
                wiced_gpio_output_high( RGB_G );
                wiced_gpio_output_high( RGB_B );
            }
        }
        else
        {
            /* Flashing R-G-B alternately */
            if ( (led_state%3) == 0 )
            {
                wiced_gpio_output_low( RGB_R );
                wiced_gpio_output_high( RGB_G );
                wiced_gpio_output_high( RGB_B );
            }
            else if ( (led_state%3) == 1 )
            {
                wiced_gpio_output_high( RGB_R );
                wiced_gpio_output_low( RGB_G );
                wiced_gpio_output_high( RGB_B );
            }
            else
            {
                wiced_gpio_output_high( RGB_R );
                wiced_gpio_output_high( RGB_G );
                wiced_gpio_output_low( RGB_B );
            }
        }

        wiced_rtos_delay_milliseconds( 300 );
        led_state++;
    }
}
Example #3
0
void application_start( )
{
    /* Initialise the WICED device */
    wiced_init();

    WPRINT_APP_INFO( ( "The color of the RGB is changing every second.\n" ) );

    RGB_Init( D0 );

    while ( 1 )
    {
        RGB_Show(0xFF, 0x00, 0x00);
        wiced_rtos_delay_milliseconds( 500 );

        RGB_Show(0x00, 0xFF, 0x00);
        wiced_rtos_delay_milliseconds( 500 );

        RGB_Show(0x00, 0x00, 0xFF);
        wiced_rtos_delay_milliseconds( 500 );

        RGB_Show(0xFF, 0x00, 0xFF);
        wiced_rtos_delay_milliseconds( 500 );

        RGB_Show(0xFF, 0xFF, 0x00);
        wiced_rtos_delay_milliseconds( 500 );

        RGB_Show(0x00, 0xFF, 0xFF);
        wiced_rtos_delay_milliseconds( 500 );
    }
}
Example #4
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);

}
Example #5
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();
}
// 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 );
    }
}
Example #7
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, "" );
}
Example #8
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
}
Example #9
0
void application_start( void )
{
    /* Initialise the WICED device */
    wiced_init();

    /* Initialise SPI slave device */
    spi_slave_init( &spi_slave_device, &spi_slave_device_config );
}
void application_start( )
{
	wiced_init();	/* Initialize the WICED device */

	/* Initialize and start a new thread */
    wiced_rtos_create_thread(&ledThreadHandle, THREAD_PRIORITY, "ledThread", ledThread, THREAD_STACK_SIZE, NULL);

    /* No while(1) here since everything is done by the new thread. */
}
Example #11
0
void application_start( )
{
    float temp  = 100;
    float duty = 100;
    float cnt = 0;
    wiced_bool_t rise = WICED_FALSE;

    /* Initialise the WICED device */
    wiced_init();
	
    // The RGB and setup button are initialized in platform.c

    WPRINT_APP_INFO( ( "The RGB is breathing green.\n" ) );

    while ( 1 )
    {
        wiced_pwm_init( RGB_G_PWM, 1000, duty );
        wiced_pwm_start( RGB_G_PWM );

        wiced_rtos_delay_milliseconds( 10 );

        if(rise)
        {
            temp += cnt;
            cnt -= 0.005;
            if(temp >= 100.0)
            {
                duty = 100;
                cnt = 0;
                rise = WICED_FALSE;
            }
            else
            {
                duty = temp;
            }
        }
        else
        {
            cnt += 0.005;
            temp -= cnt;
            if(temp <= 0.0)
            {
                duty = 0;
                rise = WICED_TRUE;
            }
            else
            {
                duty = temp;
            }
        }
    }
}
Example #12
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, "" );
}
Example #13
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);

}
Example #15
0
/******************************************************
 *               Function Definitions
 ******************************************************/
void application_start( )
{
   wiced_init( );

   /* Disable WIFI sleeping */
   wwd_wifi_set_iovar_value( IOVAR_STR_MPC, 0, WWD_STA_INTERFACE );

#ifdef MFG_TEST_ENABLE_ETHERNET_SUPPORT
   wiced_wlu_server_eth_start( ETHERNET_PORT, 0);
#else
   wiced_wlu_server_serial_start( STDIO_UART );
#endif
}
Example #16
0
/******************************************************
 *               Function Definitions
 ******************************************************/
void application_start( )
{
    /* Initialise the device */
    wiced_init( );

	//WPRINT_APP_INFO(("Version data & time 2015/09/06 10:00\n"));

	/* Configure the device */
    configure_device();

	if(device_init() != WICED_SUCCESS){
		WPRINT_APP_INFO(("device_init failed\n"));
		return;
	}
	
	WPRINT_APP_INFO(("end ...\n"));
}
Example #17
0
void application_start( )
{
    wiced_result_t result;

    wiced_init( );

    platform_init_audio( );

    WPRINT_APP_INFO ( ("Starting Bluetooth...\n") );

    /* Initialize BT stack and profiles */
    result = wiced_bt_init( &app_callbacks.device_manager_callbacks, &audio_preferences );
    if ( result != WICED_SUCCESS )
    {
        WPRINT_APP_ERROR( ( "Failed to initialize Bluetooth\n" ) );
    }
}
/******************************************************
 *               Function Definitions
 ******************************************************/
wiced_result_t aws_app_init( aws_app_info_t *app_info )
{
    wiced_result_t ret = WICED_SUCCESS;
    aws_config_dct_t *aws_app_dct = NULL;

    aws_app_info = app_info;

    wiced_init( );

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

    WPRINT_APP_INFO((" Please wait, connecting to network...\n"));
    WPRINT_APP_INFO(("(To return to SSID console screen, hold USER switch for 5 seconds during RESET to clear DCT configuration)\n"));
    wiced_rtos_delay_milliseconds( 1000 );

    for ( int i = 0; i < 25; i++ )
    {
        wiced_gpio_output_high( WICED_LED2 );
        wiced_rtos_delay_milliseconds( 100 );
        wiced_gpio_output_low( WICED_LED2 );
        wiced_rtos_delay_milliseconds( 100 );

        if ( !wiced_gpio_input_get( WICED_BUTTON1 ) )
        {
            wiced_rtos_delay_milliseconds( 5000 );

            if ( !wiced_gpio_input_get( WICED_BUTTON1 ) )
            {
                aws_config_dct_t aws_dct =
                {
                    .is_configured = WICED_FALSE,
                    .thing_name = AWS_DEFAULT_THING_NAME
                };

                wiced_gpio_output_high( WICED_LED1 );
                WPRINT_APP_INFO(( "DCT clearing start\n" ));
                wiced_dct_write( &aws_dct, DCT_APP_SECTION, 0, sizeof( aws_config_dct_t ) );
                wiced_rtos_delay_milliseconds( 1000 );
                wiced_gpio_output_low( WICED_LED1 );
                WPRINT_APP_INFO(( "DCT clearing end\n" ));

                break;
            }
        }
/* Main application */
void application_start( )
{
	char    receiveChar;
    uint32_t expected_data_size = 1;

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

    /* Configure and start the UART. */
    /* Note that WICED_DISABLE_STDIO must be defined in the make file for this to work */
	#define RX_BUFFER_SIZE (5)
	wiced_ring_buffer_t rx_buffer;
    uint8_t             rx_data[RX_BUFFER_SIZE];
	ring_buffer_init(&rx_buffer, rx_data, RX_BUFFER_SIZE ); /* Initialize ring buffer to hold receive data */
    wiced_uart_config_t uart_config =
    {
        .baud_rate    = 9600,
        .data_width   = DATA_WIDTH_8BIT,
        .parity       = NO_PARITY,
        .stop_bits    = STOP_BITS_1,
        .flow_control = FLOW_CONTROL_DISABLED,
    };
    wiced_uart_init( STDIO_UART, &uart_config, &rx_buffer); /* Setup UART */

    while ( 1 )
    {
        if ( wiced_uart_receive_bytes( STDIO_UART, &receiveChar, &expected_data_size, WICED_NEVER_TIMEOUT ) == WICED_SUCCESS )
        {
            /* If we get here then a character has been received */
        	if(receiveChar == '0') /* LED OFF for the shield (LED ON if using the baseboard by itself) */
        	{
        		wiced_gpio_output_low( WICED_LED1 );
        	}
        	if(receiveChar == '1') /* LED ON for the shield (LED OFF if using the baseboard by itself) */
        	{
        		wiced_gpio_output_high( WICED_LED1 );
        	}
        }

    }
}
Example #20
0
void application_start(void)
{
    wiced_interface_t interface;
    wiced_result_t result;
	int fail = 0;
    wiced_init( );
	command_console_init(STDIO_UART, 300, cmdline, 10, history, " ");
	console_add_cmd_table(commands);
	memset(write_buffer, 0, BUFFER_SIZE);
	ws2812_init();
	write_ws2812(0, 3, init_data);
	wiced_network_register_link_callback(link_cb_up, link_cb_down, WICED_STA_INTERFACE);
    result = wiced_network_up_default( &interface, NULL);
//	result = wiced_network_up(WICED_STA_INTERFACE, WICED_USE_EXTERNAL_DHCP_SERVER, NULL);

    if( result != WICED_SUCCESS ) {
        printf("Bringing up network interface failed !\r\n");
		fail = 1;
    }

    /* Create UDP socket */
    if (wiced_udp_create_socket(&udp_socket, PORTNUM, interface) != WICED_SUCCESS) {
        WPRINT_APP_INFO( ("UDP socket creation failed\n") );
		fail = 1;
    } else {
	//	wiced_udp_register_callbacks(&udp_socket, udp_cb, &udp_socket);
		wiced_rtos_register_timed_event( &process_udp_rx_event, WICED_NETWORKING_WORKER_THREAD, &process_received_udp_packet, (1*SECONDS)/50, 0 );
	}
	if(!fail){
		init_data[0] = 0x10;
		init_data[1] = 0x00;
		init_data[2] = 0x00;
	} else {
		init_data[0] = 0x00;
		init_data[1] = 0x10;
		init_data[2] = 0x00;
	}
	write_ws2812(0, 3, init_data);
}
Example #21
0
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 );
    }
}
Example #22
0
void application_start( )
{
    /* Initialise the WICED device */
    wiced_init();

    while ( 1 )
    {
        WPRINT_APP_INFO( ( "Analog input voltage measurement:\n" ) );
		
        for(uint8_t i=0; i<8; i++)
        {
            wiced_adc_init( analog_channel[i], 480 );
            // This function only takes sample for the channel that selected by the last time invoking wiced_adc_init().
            // So if you change to take sample for another channel, you need to invoke wiced_adc_init() to select this channel first.
            wiced_adc_take_sample( analog_channel[i], &analog_value[i] );
            WPRINT_APP_INFO( ( "Channel %d input voltage: %d\n", i, analog_value[i] ) );
    	}

        wiced_rtos_delay_milliseconds( 3000 );
        WPRINT_APP_INFO( ( "\n\n" ) );
    }
}
Example #23
0
void application_start( )
{
    int i =0;
    char c;
    char name[20];

    memset( name, 0, sizeof( name ) );

    wiced_init();

    /* Remove buffering from all std streams */
    setvbuf( stdin,  NULL, _IONBF, 0 );
    setvbuf( stdout, NULL, _IONBF, 0 );
    setvbuf( stderr, NULL, _IONBF, 0 );


    /* Read the users name from standard input */
    printf( "\n" );
    printf( PROMPT1 );
    do
    {
       name[i] = getchar();
    }
    while( ( i < sizeof(name) ) && ( name[i++] != 0x0d ) );

    /* Set the line terminator */
    if ( i != 0 )
    {
        name[--i] = 0x00;
    }

    printf( "Hello %s, "
            "welcome to WICED.\n", name );
    printf( "Ok %s, "PROMPT2, name );
    c = getchar();
    printf( "Your number is %d\n", c - 0x30 );
    printf( "Goodbye\n" );
}
Example #24
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);
}
Example #25
0
static void downloading_init_func( uint32_t arg )
{
    wiced_init( );
    WICED_END_OF_CURRENT_THREAD_NO_LEAK_CHECK( );
}
Example #26
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 )
    {
    }
}
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 );
}
Example #28
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 );
    }
}