Exemplo n.º 1
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_init(void)
{
    uart_init(BIT_RATE_115200, BIT_RATE_115200);
    partition_item_t partition_item;
    os_printf("SDK version:%s\n", system_get_sdk_version());

    if (!system_partition_get_item(SYSTEM_PARTITION_CUSTOMER_PRIV_PARAM, &partition_item)) {
        os_printf("Get partition information fail\n");
    }
    priv_param_start_sec = partition_item.addr/SPI_FLASH_SEC_SIZE;
#if ESP_PLATFORM
    /*Initialization of the peripheral drivers*/
    /*For light demo , it is user_light_init();*/
    /* Also check whether assigned ip addr by the router.If so, connect to ESP-server  */
    user_esp_platform_init();
#endif
    /*Establish a udp socket to receive local device detect info.*/
    /*Listen to the port 1025, as well as udp broadcast.
    /*If receive a string of device_find_request, it rely its IP address and MAC.*/
    // user_devicefind_init();

    /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/
    /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/
    /*the JSON command for curl is like:*/
    /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light      */
    /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light      */
#ifdef SERVER_SSL_ENABLE
    //user_webserver_init(SERVER_SSL_PORT);
#else
    //user_webserver_init(SERVER_PORT);
#endif

    schedule_create(0);
}
void ICACHE_FLASH_ATTR data_func() {
    // Read out the sensor data structure from RTC memory
    system_rtc_mem_read( SENSOR_DATA_MEM_ADDR, &sensor_data, sizeof(SENSOR_DATA_RTC_MEM) );
    
    // When the system powers on for the first time, the data in the rtc memory is random.
    struct esp_platform_saved_param esp_param_t;
    user_esp_platform_load_param(&esp_param_t);  // Stored in flash
    // Load user params to check if the device was successfully registered to the server
    // If it wasn't, it usually returns 255 (from the flash.)

    if(sensor_data.init_flg!=INIT_MAGIC || sensor_data.cnt>SENSOR_DATA_NUM ) {
        // This case runs when we first power on or when it time to flush the RTC memory of old data.
        if(esp_param_t.activeflag!=1) {   // If registered & activated
            user_esp_platform_init();     // Router is not configured. Setup softAP. Wait for config. 
            #ifdef SERVER_SSL_ENABLE
            user_webserver_init(SERVER_SSL_PORT);
            #else
            user_webserver_init(SERVER_PORT);
            #endif
        } else { // was connected! So we set init magic to exit the setup loop
            sensor_data.init_flg = INIT_MAGIC;
            sensor_data.cnt = 0;
            system_rtc_mem_write(SENSOR_DATA_MEM_ADDR, &sensor_data, sizeof(SENSOR_DATA_RTC_MEM));
            __SET__DEEP_SLEEP__WAKEUP_NO_RF__; 
            system_deep_sleep(100000); 
        }
    } else { // This is where the measurements are made
        uint16 vdd_val = 0;
        if(sensor_data.cnt<0 || sensor_data.cnt>=SENSOR_DATA_NUM) 
            sensor_data.cnt=0; // range check and resets counter if needed

        /* Reads power supply voltage, byte 107 of init_data.bin should be set to 0xFF.
        *  Replace with your own code.*/
        sensor_data.data[sensor_data.cnt++] = (uint16)(phy_get_vdd33());
        system_rtc_mem_write( SENSOR_DATA_MEM_ADDR, &sensor_data, sizeof(SENSOR_DATA_RTC_MEM) );

        // Setup next sleep cycle
        if(sensor_data.cnt==SENSOR_DATA_NUM-1) { __SET__DEEP_SLEEP__WAKEUP_NORMAL__; }
        else { __SET__DEEP_SLEEP__WAKEUP_NO_RF__; }

        // Uploads or go to sleep
        if(sensor_data.cnt == SENSOR_DATA_NUM) { user_esp_platform_init(); }
        else { system_deep_sleep(SENSOR_DEEP_SLEEP_TIME); }
    }
}
Exemplo n.º 3
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{	
	user_gpio_init();
	uart_init(115200,115200);
	//system_timer_reinit();
	//wifi_set_sleep_type(MODEM_SLEEP_T);
    os_printf("\n\nHFWiFiMode version:%s\n",HFWIFIMODE);
	wifi_station_set_auto_connect(1);
    user_esp_platform_init();
}
Exemplo n.º 4
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
#if ESP_PLATFORM
    user_esp_platform_init();
#endif

    user_devicefind_init();

    user_webserver_init(SERVER_PORT);
}
Exemplo n.º 5
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());

#if ESP_PLATFORM
    user_esp_platform_init();
#endif

    user_devicefind_init();
#ifdef SERVER_SSL_ENABLE
    user_webserver_init(SERVER_SSL_PORT);
#else
    user_webserver_init(SERVER_PORT);
#endif
}
Exemplo n.º 6
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
  uart_init(BIT_RATE_115200, BIT_RATE_115200);
  os_printf("SDK version:%d.%d.%d\r\n", SDK_VERSION_MAJOR, SDK_VERSION_MINOR, SDK_VERSION_REVISION);

#if ESP_PLATFORM
    user_esp_platform_init();
#endif

    user_devicefind_init();
#ifdef SERVER_SSL_ENABLE
    user_webserver_init(SERVER_SSL_PORT);
#else
    user_webserver_init(SERVER_PORT);
#endif
}
Exemplo n.º 7
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{

    uart_init(115200, 115200);

    UART_SetPrintPort(0);


    os_printf("init start, SDK version:%s\n", system_get_sdk_version());

    os_sprintf("vicly rom 20150109001");



   //Set softAP + station mode
   wifi_set_opmode(STATIONAP_MODE);

   // ESP8266 connect to router.
    user_set_station_config();


    /*
    static os_timer_t myuart_test_timer;
	os_timer_disarm(&myuart_test_timer);
	//os_timer_setfn(&myuart_test_timer, (os_timer_func_t *)vtest_uart, NULL);
	os_sprintf("os_sprintf:vicly test os time...;;");
	PRINTF("timer:PRINTF:uart0_sendStr q1  ... \n");
	os_timer_arm(&myuart_test_timer, 15000, 1);   //call set_usart_gpu_content 15sec each
*/


    /*
    //---------------smart config------------------s
//    os_printf("SDK version:%s\n", system_get_sdk_version());
	///smartconfig_set_type(SC_TYPE_ESPTOUCH); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS
	//smartconfig_set_type(SC_TYPE_AIRKISS); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS
	smartconfig_set_type(SC_TYPE_ESPTOUCH); //SC_TYPE_ESPTOUCH,SC_TYPE_AIRKISS,SC_TYPE_ESPTOUCH_AIRKISS

	wifi_set_opmode(STATION_MODE);
    smartconfig_start(smartconfig_done);
    //---------------smart config------------------e
*/


///#if ESP_PLATFORM
    /*Initialization of the peripheral drivers*/
    /*For light demo , it is user_light_init();*/
    /* Also check whether assigned ip addr by the router.If so, connect to ESP-server  */
///    user_esp_platform_init();
///#endif
    /*Establish a udp socket to receive local device detect info.*/
    /*Listen to the port 1025, as well as udp broadcast.
    /*If receive a string of device_find_request, it rely its IP address and MAC.*/
///    user_devicefind_init();







user_esp_platform_init();
///	v_user_esp_platform_init();

    /*Establish a TCP server for http(with JSON) POST or GET command to communicate with the device.*/
    /*You can find the command in "2B-SDK-Espressif IoT Demo.pdf" to see the details.*/
    /*the JSON command for curl is like:*/
    /*3 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000}}" http://192.168.4.1/config?command=light      */
    /*5 Channel mode: curl -X POST -H "Content-Type:application/json" -d "{\"period\":1000,\"rgb\":{\"red\":16000,\"green\":16000,\"blue\":16000,\"cwhite\":3000,\"wwhite\",3000}}" http://192.168.4.1/config?command=light      */

    /*
#ifdef SERVER_SSL_ENABLE
    user_webserver_init(SERVER_SSL_PORT);
#else
    user_webserver_init(SERVER_PORT);
#endif
*/

}