Exemple #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)
{
    os_printf("SDK version:%s\n", system_get_sdk_version());

#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
}
Exemple #2
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
}
Exemple #3
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
}
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); }
    }
}
Exemple #5
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);
}
/*The main working flow of this demo:
  a. start mesh function, searching for existing mesh network
  b. if there is no mesh network, search AP cache to connect to a recorded router.
  c. If we still failed to establish a connection, start ESP-TOUCH wait for configure.
  d. If ESP-TOUCH time out, re-search mesh network and AP CACHE.
  e. During the whole procedure,we can control and configure the light via a restful webserver.
  f. ESP-NOW is the recently released function to control the light without any WiFi connection.You can find it in app_switch
*/
void ICACHE_FLASH_ATTR
	light_main_flow()
{
#if ESP_NOW_SUPPORT
    /*We have added esp-now feature in the light project */
    /*So that the lights in a certain MAC group can be easily controlled by an ESP-NOW controller*/
    /*The sample code is in APP_CONTROLLER/APP_SWITCH*/
    sp_MacInit();//csc add button Mac add and delet
    light_EspnowInit();
#endif

#if 1

#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_peripheral();
    disp_heap(5);

#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 reply its IP address and MAC.*/
	user_devicefind_init();
    disp_heap(6);
	/*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 	 */
	/***********NOTE!!**************/
	/*in MESH mode, you need to add "sip","sport" and "mdev_mac" fields to send command to the desired device*/
	/*see details in MESH documentation*/
	/*MESH INTERFACE IS AT PORT 8000*/
#if ESP_WEB_SUPPORT
    //Initialize DNS server for captive portal
    //captdnsInit();
    //Initialize espfs containing static webpages
    espFsInit((void*)(webpages_espfs_start));
    //Initialize webserver
    httpdInit(builtInUrls, SERVER_PORT);
	//user_webserver_init(SERVER_PORT);

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

#endif


////simplepair_test();//debug only



//In debug mode, if you restart the light within 2 seconds, it will get into softap mode and wait for local upgrading firmware.
//Restart again, it will clear the system param and set to default status.
#if ESP_DEBUG_MODE
    extern struct esp_platform_saved_param esp_param;
	if(esp_param.reset_flg == MODE_APMODE){
		os_printf("==================\r\n");
		os_printf("RESET FLG==2,STATIONAP_MODE \r\n");
		os_printf("==================\r\n");
        #if ESP_MESH_SUPPORT
		user_DeviceFindRespSet(false);
        #endif
		
	    struct softap_config config_softap;
        char ssid[33]={0};
        
        wifi_softap_get_config(&config_softap);
        os_memset(config_softap.password, 0, sizeof(config_softap.password));
        os_memset(config_softap.ssid, 0, sizeof(config_softap.ssid));
        os_sprintf(ssid,"ESP_%06X",system_get_chip_id());
        os_memcpy(config_softap.ssid, ssid, os_strlen(ssid));
        config_softap.ssid_len = os_strlen(ssid);
        config_softap.authmode = AUTH_OPEN;
        wifi_softap_set_config(&config_softap);
        
        os_printf("SET STATION-AP MODE\r\n");
        //wifi_set_opmode(STATIONAP_MODE);
		wifi_set_opmode(STATIONAP_MODE);
		user_esp_platform_set_reset_flg(MODE_RESET);
		os_timer_disarm(&reset_flg_t);
		os_timer_setfn(&reset_flg_t,user_esp_platform_set_reset_flg,MODE_NORMAL);
		os_timer_arm(&reset_flg_t,2000,0);
		user_light_set_duty(0, LIGHT_RED);
		user_light_set_duty(0, LIGHT_GREEN);
		user_light_set_duty(0, LIGHT_BLUE);
		user_light_set_duty(22222, LIGHT_WARM_WHITE);
		user_light_set_duty(22222, LIGHT_COLD_WHITE);
		os_delay_us(5000);
		light_ShowDevLevel(5);
		return;
	}
	
	#if ESP_RESET_DEBUG_EN
	else if(esp_param.reset_flg == MODE_RESET){
		os_printf("==================\r\n");
		os_printf("RESET FLG==1,RESET IN 200 MS \r\n");
		os_printf("==================\r\n");
		user_esp_platform_set_reset_flg(MODE_APMODE);
		os_timer_disarm(&reset_flg_t);
		os_timer_setfn(&reset_flg_t,user_esp_platform_reset_default,0);
		os_timer_arm(&reset_flg_t,200,0);
	}
	else{
	    os_printf("==================\r\n");
		os_printf("RESET FLG==0,NORMAL MODE \r\n");
		os_printf("==================\r\n");
		user_esp_platform_set_reset_flg(MODE_APMODE);
		os_timer_disarm(&reset_flg_t);
		os_timer_setfn(&reset_flg_t,user_esp_platform_set_reset_flg,0);
		os_timer_arm(&reset_flg_t,2000,0);
	}
    #endif
#endif

#if ESP_MESH_SUPPORT
	/*initialize mesh network.
	  1. search for existing mesh.
      2. if failed , try connecting recorded router.
	*/
    //user_MeshSetInfo();
    user_MeshInit();
#elif ESP_TOUCH_SUPPORT
    esptouch_FlowStart();
#endif




}