Пример #1
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 );
    }
}
Пример #3
0
/*
 * A simple result log function
 */
static void  amqp_print_status ( wiced_result_t result, const char * ok_message, const char * error_message )
{
    if ( result == WICED_SUCCESS )
    {
        if ( ok_message != NULL )
        {
            WPRINT_APP_INFO(( "OK (%s)\n\n", (ok_message)));
        }
        else
        {
            WPRINT_APP_INFO(( "OK.\n\n" ));
        }
    }
    else
    {
        if ( error_message != NULL )
        {
            WPRINT_APP_INFO(( "ERROR (%s)\n\n", (error_message)));
        }
        else
        {
            WPRINT_APP_INFO(( "ERROR.\n\n" ));
        }
    }
}
Пример #4
0
static wiced_result_t send_ping( void )
{
    const uint32_t     ping_timeout = 1000;
    uint32_t           elapsed_ms;
    wiced_result_t     status;
    wiced_ip_address_t ping_target_ip;

    wiced_ip_get_gateway_address( WICED_STA_INTERFACE, &ping_target_ip );
    status = wiced_ping( WICED_STA_INTERFACE, &ping_target_ip, ping_timeout, &elapsed_ms );

    if ( status == WICED_SUCCESS )
    {
        WPRINT_APP_INFO(( "Ping Reply %lums\r\n", elapsed_ms ));
    }
    else if ( status == WICED_TIMEOUT )
    {
        WPRINT_APP_INFO(( "Ping timeout\r\n" ));
    }
    else
    {
        WPRINT_APP_INFO(( "Ping error\r\n" ));
    }

    return WICED_SUCCESS;
}
Пример #5
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);

}
Пример #6
0
static void audio_state_handler( wiced_bt_avk_audio_state_t state, wiced_bt_bdaddr_t* device_address )
{
    switch ( state )
    {
        case WICED_BT_AVK_AUDIO_STATE_STARTED:        WPRINT_APP_INFO( ("Audio streaming started\n") );    break;
        case WICED_BT_AVK_AUDIO_STATE_REMOTE_SUSPEND: WPRINT_APP_INFO( ("Audio streaming suspended\n") );  break;
        case WICED_BT_AVK_AUDIO_STATE_STOPPED:        WPRINT_APP_INFO( ("Audio streaming stopped\n") );    break;
        default:  break;
    }
}
Пример #7
0
/*!
 ******************************************************************************
 * Prints partial details of a scan result on a single line
 *
 * @param[in] record  A pointer to the wiced_scan_result_t record
 *
 */
void print_scan_result( wiced_scan_result_t* record )
{
    WPRINT_APP_INFO( ( "%5s ", ( record->bss_type == WICED_BSS_TYPE_ADHOC ) ? "Adhoc" : "Infra" ) );
    WPRINT_APP_INFO( ( "%02X:%02X:%02X:%02X:%02X:%02X ", record->BSSID.octet[0], record->BSSID.octet[1], record->BSSID.octet[2], record->BSSID.octet[3], record->BSSID.octet[4], record->BSSID.octet[5] ) );
    WPRINT_APP_INFO( ( " %d ", record->signal_strength ) );
    if ( record->max_data_rate < 100000 )
    {
        WPRINT_APP_INFO( ( " %.1f ", (double) (record->max_data_rate / 1000.0) ) );
    }
    else
    {
        WPRINT_APP_INFO( ( "%.1f ", (double) (record->max_data_rate / 1000.0) ) );
    }
    WPRINT_APP_INFO( ( " %3d  ", record->channel ) );
    WPRINT_APP_INFO( ( "%-10s ", ( record->security == WICED_SECURITY_OPEN ) ? "Open" :
                                 ( record->security == WICED_SECURITY_WEP_PSK ) ? "WEP" :
                                 ( record->security == WICED_SECURITY_WPA_TKIP_PSK ) ? "WPA TKIP" :
                                 ( record->security == WICED_SECURITY_WPA_AES_PSK ) ? "WPA AES" :
                                 ( record->security == WICED_SECURITY_WPA2_AES_PSK ) ? "WPA2 AES" :
                                 ( record->security == WICED_SECURITY_WPA2_TKIP_PSK ) ? "WPA2 TKIP" :
                                 ( record->security == WICED_SECURITY_WPA2_MIXED_PSK ) ? "WPA2 Mixed" :
                                 "Unknown" ) );
    WPRINT_APP_INFO( ( " %-32s ", record->SSID.value ) );
    WPRINT_APP_INFO( ( "\n" ) );
}
// This function formats all of the data and prints it out ... called by the tcp_server
static void displayResult(wiced_ip_address_t peerAddress, uint16_t    peerPort, char *returnMessage)
{
    WPRINT_APP_INFO(("%d\t",nonsecureConnectionCount));

    WPRINT_APP_INFO(("%u.%u.%u.%u",
                           (uint8_t)(GET_IPV4_ADDRESS(peerAddress) >> 24),
                           (uint8_t)(GET_IPV4_ADDRESS(peerAddress) >> 16),
                           (uint8_t)(GET_IPV4_ADDRESS(peerAddress) >> 8),
                           (uint8_t)(GET_IPV4_ADDRESS(peerAddress) >> 0)
                           ));
       WPRINT_APP_INFO(("\t%d\t%s\n",peerPort,returnMessage));
}
Пример #9
0
int
rwl_write_eth_port(void* hndle, char* write_buf, unsigned long size, unsigned long *numwritten)
{
    uint16_t        available_data_length;
    wiced_packet_t* tx_packet;
    char*           tx_data;
    unsigned long temp_size = 0;
    unsigned long temp=0;

    if ( size == 0 )
     {
         return SUCCESS;
     }

    while (size > 0)
    {
    if (wiced_packet_create_tcp(&tcp_client_socket, 128, &tx_packet, (uint8_t **)&tx_data, &available_data_length) != WICED_SUCCESS)
      {
          WPRINT_APP_INFO(("TCP packet creation failed\n"));
          return WICED_ERROR;
      }
    if (size > available_data_length)
        {
        temp_size = available_data_length;
        }
    else
    {
        temp_size =size;
    }

       /*  Write the message into tx_data"*/
        memcpy(tx_data, (write_buf + temp), temp_size);

        wiced_packet_set_data_end( tx_packet, (uint8_t*)tx_data + temp_size );

        /* Send the TCP packet*/
        if ( wiced_tcp_send_packet( &tcp_client_socket, tx_packet ) != WICED_SUCCESS )
        {
            WPRINT_APP_INFO(("TCP packet send failed \n"));

             /*Delete packet, since the send failed*/
            wiced_packet_delete(tx_packet);
            return WICED_ERROR;
        }

        wiced_packet_delete(tx_packet);
        size = size - temp_size;
        temp = temp+temp_size;

     }

    return available_data_length;
}
/* This is the callback event for HTTP events */
static void event_handler( http_client_t* client, http_event_t event, http_response_t* response )
{
    static uint8_t count = 1; // Keep track of how many responses we have received

    switch( event )
    {
        case HTTP_CONNECTED:
            /* This state is never called */
            break;

        /* This is called when we are disconnected by the server */
        case HTTP_DISCONNECTED:
        {
            connected = WICED_FALSE;
            http_client_disconnect( client ); /* Need to keep client connection state synchronized with the server */
            WPRINT_APP_INFO(( "Disconnected from %s\n", SERVER_HOST ));
            break;
        }

        /* This is called when new data is received (header, or payload) */
        case HTTP_DATA_RECEIVED:
        {
            WPRINT_APP_INFO( ( "------------------ Received response: %d ------------------\n", count ) );

            /* Print Response Header */
            if(response->response_hdr != NULL)
            {
                WPRINT_APP_INFO( ( "----- Response Header: -----\n " ) );
                print_data( (char*) response->response_hdr, response->response_hdr_length );
            }

            /* Print Response Payload  */
            WPRINT_APP_INFO( ("\n----- Response Payload: -----\n" ) );
            print_data( (char*) response->payload, response->payload_data_length );

            if(response->remaining_length == 0)
            {
               WPRINT_APP_INFO( ("\n------------------ End Response %d ------------------\n", count ) );
               http_request_deinit( (http_request_t*) &(response->request) );
               wiced_rtos_set_semaphore(&httpWait); // Set semaphore that allows the next request to start
               count++;
            }
            break;
        }
        default:
        break;
    }
}
Пример #11
0
static void audio_connection_state_handler( wiced_bt_avk_connection_state_t state, wiced_bt_bdaddr_t* device_address )
{
    switch ( state )
    {
        case WICED_BT_AVK_CONNECTION_STATE_CONNECTED:
            WPRINT_APP_INFO( ("Device connected [0x%x:0x%x:0x%x:0x%x:0x%x:0x%x]\n", device_address->address[0], device_address->address[1], device_address->address[2], device_address->address[3], device_address->address[4], device_address->address[5]) );
            break;

        case WICED_BT_AVK_CONNECTION_STATE_DISCONNECTED:
            WPRINT_APP_INFO( ("Device disconnected\n") );
            break;

        default:
            break;
    }
}
Пример #12
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 );
    }
}
Пример #13
0
static void curtain_keypad_handler( uart_key_code_t code, uart_key_event_t event )
{
	//WPRINT_APP_INFO(("curtain_keypad_handler: key_code = 0x%.2x, key_event = %d\n", code, event));

    if ( event == KEY_EVENT_RELEASED )
    {
        switch ( code )
        {
            case CURTAIN_KEY_OPEN:
				curtain_open(this_dev.specific.curtain);
				break;

            case CURTAIN_KEY_CLOSE:
				curtain_close(this_dev.specific.curtain);
				break;

			case CURTAIN_KEY_STOP:
				curtain_stop(this_dev.specific.curtain);
				break;
				
            default:
                break;
        }
    }
	else if( event == KEY_EVENT_LONG_LONG_PRESSED) {
		WPRINT_APP_INFO(("KEY_EVENT_LONG_LONG_PRESSED\n"));
		if (code == CURTAIN_KEY_OPEN) {
			curtain_cali_start(this_dev.specific.curtain);
		}
	}
	return;
}
Пример #14
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++;
    }
}
Пример #15
0
void application_start( )
{

    WPRINT_APP_INFO( ( "Application stack = %u\r\n", APPLICATION_STACK_SIZE ) );

    blow_the_stack();

}
Пример #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"));
}
Пример #17
0
static void device_state_handler( wiced_bt_state_t state, wiced_result_t status )
{
    switch ( state )
    {
        case WICED_BT_STATE_ENABLED:
            WPRINT_APP_INFO( ("Bluetooth enabled\n") );
            wiced_bt_avk_init( &app_callbacks.audio_callbacks );
            break;

        case WICED_BT_STATE_DISABLED:
            WPRINT_APP_INFO( ("Bluetooth disabled\n") );
            break;

        default:
            break;
    }
}
void printStatus()
{

	linked_list_node_t* current;

	linked_list_get_front_node( &tcp_server.socket_list, &current);

	while(current)
	{
		wiced_tcp_socket_t *socket;

		wiced_tcp_server_socket_t *serverSocket;
		serverSocket = (wiced_tcp_server_socket_t *) current->data;
		socket = &serverSocket->socket;


		wiced_socket_state_t ss;
		wiced_tcp_get_socket_state( socket, &ss);

		switch(ss)
		{
		case   WICED_SOCKET_CLOSED: WPRINT_APP_INFO(("Status:closed\n")); break;
		case   WICED_SOCKET_CLOSING: WPRINT_APP_INFO(("Status:closing\n")); break;
		case   WICED_SOCKET_CONNECTING: WPRINT_APP_INFO(("Status:connecting\n")); break;
		case   WICED_SOCKET_CONNECTED: WPRINT_APP_INFO(("Status:connected\n")); break;
		case   WICED_SOCKET_DATA_PENDING: WPRINT_APP_INFO(("Status:data pending\n")); break;
		case   WICED_SOCKET_LISTEN: WPRINT_APP_INFO(("Status:listen\n")); break;
		case   WICED_SOCKET_ERROR: WPRINT_APP_INFO(("Status:error\n")); break;
		}

		current = current->next;
	}

}
Пример #19
0
int main( void )
{
    wiced_mac_t dest_mac = { {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF} };
    char* payload_ptr = 0;
    wwd_result_t result;

    NoOS_setup_timing( );

    WPRINT_APP_INFO(("\nPlatform " PLATFORM " initialised\n"));

    /* Initialise Wiced */
    WPRINT_APP_INFO(("Starting Wiced v" WICED_VERSION "\n"));
    nons_buffer_init_t pkt_buff_init = { pkt_buffer, sizeof( pkt_buffer ) };

    while ( WWD_SUCCESS != ( result = wwd_management_init( COUNTRY, &pkt_buff_init ) ) )
    {
        WPRINT_APP_INFO(("Error %d while starting WICED!\n", result));
    }

    /* Get MAC address - this needs to be done before joining a network, so that */
    /* we can check the address of any incoming packets against our MAC */
    wwd_wifi_get_mac_address( &my_mac, WWD_STA_INTERFACE );

    /* Attempt to join the Wi-Fi network */
    WPRINT_APP_INFO(("Joining : " AP_SSID "\n"));
    while ( wwd_wifi_join( &ap_ssid, AP_SEC, (uint8_t*) AP_PASS, sizeof( AP_PASS ) - 1, NULL ) != WWD_SUCCESS )
    {
        WPRINT_APP_INFO(("Failed to join  : " AP_SSID "   .. retrying\n"));
    }
    WPRINT_APP_INFO(("Successfully joined : " AP_SSID "\n"));

    if ( PKT_TARGET_IP != 0xFFFFFFFF )  /* Check if the target has a broadcast address */
    {
        /* Send an ARP request to resolve the destination IP address into a MAC address */
        resolve_dest_mac( PKT_TARGET_IP, &dest_mac );
    }

    /* Loop forever, repeatedly sending the UDP packet */
    while ( 1 )
    {
        int i;

        /* Setup the packet buffer with the canned packet contents. */
        payload_ptr = setup_canned_packet( pkt_buffer, sizeof( pkt_buffer ), my_ip_addr, &my_mac, PKT_TARGET_IP, &dest_mac, LOCAL_UDP_PORT, PKT_TARGET_UDP_PORT );

        /* Copy the payload into the packet */
        memcpy( payload_ptr, PAYLOAD, sizeof( PAYLOAD ) - 1 );

        WPRINT_APP_INFO(("Sending Hello!\n"));
        send_canned_packet( pkt_buffer, sizeof( PAYLOAD ) - 1 );

        for ( i = 0; i < 10; i++ )
        {
            host_rtos_delay_milliseconds( 100 );
            /* Poll for packets to receive (which will be dropped) - 802.11 device will run out of memory if packets are not read out of it */
            while ( wwd_thread_poll_all( ) != 0 )
            { }
        }
    }
}
/******************************************************
 *               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;
            }
        }
/* Helper function to print data in the response to the UART */
static void print_data( char* data, uint32_t length )
{
    uint32_t a;

    for ( a = 0; a < length; a++ )
    {
        WPRINT_APP_INFO( ( "%c", data[a] ) );
    }
}
Пример #22
0
static wiced_result_t tcp_server_process(  tcp_server_handle_t* server, wiced_packet_t* rx_packet )
{
    char*           request;
    uint16_t        request_length;
    uint16_t        available_data_length;
    wiced_packet_t* tx_packet;
    char*           tx_data;

    wiced_packet_get_data( rx_packet, 0, (uint8_t**) &request, &request_length, &available_data_length );

    /* Null terminate the received string */
    request[request_length] = '\x0';
    WPRINT_APP_INFO(("Received data: %s \n", request));

    /* Send echo back */
    if (wiced_packet_create_tcp(&server->socket, TCP_PACKET_MAX_DATA_LENGTH, &tx_packet, (uint8_t**)&tx_data, &available_data_length) != WICED_SUCCESS)
    {
        WPRINT_APP_INFO(("TCP packet creation failed\n"));
        return WICED_ERROR;
    }

    /* Write the message into tx_data"  */
    tx_data[request_length] = '\x0';
    memcpy(tx_data, request, request_length);

    /* Set the end of the data portion */
    wiced_packet_set_data_end(tx_packet, (uint8_t*)tx_data + request_length);

    /* Send the TCP packet */
    if (wiced_tcp_send_packet(&server->socket, tx_packet) != WICED_SUCCESS)
    {
        WPRINT_APP_INFO(("TCP packet send failed\n"));

        /* Delete packet, since the send failed */
        wiced_packet_delete(tx_packet);

        server->quit=WICED_TRUE;
        return WICED_ERROR;
    }
    WPRINT_APP_INFO(("Echo data: %s\n", tx_data));

    return WICED_SUCCESS;
}
Пример #23
0
void messageArrived( MessageData* md )
{
    MQTTMessage* message = md->message;
    WPRINT_APP_INFO ( ("Message Subscribed %d \r\n", message->payloadlen));WPRINT_APP_INFO ( ("Message dup %x \r\n", message->dup));WPRINT_APP_INFO ( ("Message id %x \r\n", message->id));WPRINT_APP_INFO ( ("Message qos %x \r\n", message->qos));WPRINT_APP_INFO ( ("Message retained %x \r\n", message->retained));

    WPRINT_APP_INFO( ( "Topic Name ==> %.*s\t", md->topicName->lenstring.len, md->topicName->lenstring.data ) );WPRINT_APP_INFO( ( "Message ==> %.*s\n", (int)message->payloadlen, (char*)message->payload ) );

    if ( strstr( (char*) message->payload, "ON" ) )
    {
        printf( "Turn ON LED\n" );
        wiced_gpio_output_high( WICED_LED1 );
    }
    else
    {
        if ( strstr( (char*) message->payload, "OFF" ) )
        {
            printf( "Turn OFF LED\n" );
            wiced_gpio_output_low( WICED_LED1 );
        }
    }
}
Пример #24
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;
            }
        }
    }
}
static void publish_callback( void* arg )
{
    if ( button_pressed == 0 )
    {
        smart_control = button_pressed = 1;
    }
    else
    {
        smart_control = button_pressed = 0;
    }

    WPRINT_APP_INFO (( "button_pressed %d\n", button_pressed ));
}
Пример #26
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" ) );
    }
}
Пример #27
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;
}
Пример #28
0
/*
 * Call back function to handle connection events.
 */
static wiced_result_t wiced_amqp_connection_event_cb( wiced_amqp_event_t event, void *args, wiced_amqp_connection_t *conn )
{
    switch( event )
    {
        case AMQP_EVENT_CONNECTION_RECV_OPEN_OK:
        case AMQP_EVENT_CONNECTION_RECV_CLOSE_OK:
        {
            expected_event = event;
            wiced_rtos_set_semaphore( &semaphore );
        }
        break;
        case AMQP_EVENT_CONNECTION_ERROR:
        {
            WPRINT_APP_INFO(("[AMQP] ERROR LOST CONNECTION\n\n"));
        }
        break;
        case AMQP_EVENT_PROTOCOL_RECV_HEADER:
        {
            WPRINT_APP_INFO(("[AMQP] ERROR RECEIVED PROTOCOL HEADER.\n"));
            WPRINT_APP_INFO(("[AMQP] Broker should support AMQP0.9-1.\n\n"));
        }
        break;
        case AMQP_EVENT_CONNECTION_RECV_CLOSE:
        {
            wiced_amqp_connection_close_arg_t   *close_args = ( wiced_amqp_connection_close_arg_t* )args;
            /* Data is sent as short string */
            memcpy( str, close_args->reply_text.str, close_args->reply_text.len );
            str[ close_args->reply_text.len ] = '\0';
            WPRINT_APP_INFO(("[AMQP] ERROR RECEIVED BROKER CLOSE REQUEST.\n"));
            WPRINT_APP_INFO(("[AMQP] REPLY TEXT: %s.\n\n",str));
        }
        break;
        default:
        break;
    }
    return WICED_SUCCESS;
}
Пример #29
0
static wiced_result_t device_init()
{
	smart_home_app_dct_t* dct_app;
	wiced_result_t res;
	
	if(	wiced_dct_read_lock( (void**) &dct_app, WICED_TRUE, DCT_APP_SECTION, 0, sizeof( *dct_app ) ) != WICED_SUCCESS)
	{
        return WICED_ERROR;
    }
	this_dev.configured = dct_app->device_configured;
	this_dev.dev_type = dct_app->dev_type;
	this_dev.dev_index = dct_app->dev_index;
	strncpy(this_dev.dev_name, dct_app->dev_name, sizeof(this_dev.dev_name));
	WPRINT_APP_INFO(("this_dev.dev_name is %s\n", this_dev.dev_name));
	wiced_dct_read_unlock( dct_app, WICED_TRUE );

	if(this_dev.configured == WICED_FALSE) {
		return WICED_ERROR;
	}		

	if(this_dev.dev_type == DEV_TYPE_MASTER) {
		this_dev.parse_socket_msg_fun = master_parse_socket_msg;
		uart_receive_enable(master_process_uart_msg);
		user_receive_enable();
	}else if(this_dev.dev_type == DEV_TYPE_LIGHT || this_dev.dev_type == DEV_TYPE_CURTAIN) {
		if(this_dev.dev_type == DEV_TYPE_LIGHT) {
			res = light_dev_init(&this_dev.specific.light_dev, WICED_HARDWARE_IO_WORKER_THREAD, report_light_status);
			if(res != WICED_SUCCESS) {
				return WICED_ERROR;
			}
			this_dev.parse_socket_msg_fun = light_parse_socket_msg;
			//this_dev.device_keypad_handler = light_keypad_handler;
			uart_keypad_enable( &device_keypad, WICED_HARDWARE_IO_WORKER_THREAD, light_keypad_handler, 3000);
		} else if(this_dev.dev_type == DEV_TYPE_CURTAIN) {
			res = curtain_init(&this_dev.specific.curtain, WICED_HARDWARE_IO_WORKER_THREAD, report_curtain_pos);
			if( res != WICED_SUCCESS) {
				return WICED_ERROR;
			}
			this_dev.parse_socket_msg_fun = curtain_parse_socket_msg;
			//this_dev.device_keypad_handler = curtain_keypad_handler;
			uart_keypad_enable( &device_keypad, WICED_HARDWARE_IO_WORKER_THREAD, curtain_keypad_handler, 3000);
		}
		pre_receive_enable();
	}
	next_receive_enable();
	return WICED_SUCCESS;
}
Пример #30
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" ) );
    }
}