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, "" ); }
/****************************************************** * 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; } }