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)
{
    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);
}
Exemple #2
0
static int
linit(lua_State *L) {
	if (S)
		return luaL_error(L, "already init");
	S= schedule_create(luaL_checkinteger(L, 1));
	return 0;
}
/**
 * Create engine.
 *
 */
static engine_type*
engine_create(void)
{
    engine_type* engine;
    allocator_type* allocator = allocator_create(malloc, free);
    if (!allocator) {
        ods_log_error("[%s] unable to create engine: allocator_create() "
            "failed", engine_str);
        return NULL;
    }
    engine = (engine_type*) allocator_alloc(allocator, sizeof(engine_type));
    if (!engine) {
        ods_log_error("[%s] unable to create engine: allocator_alloc() "
            "failed", engine_str);
        allocator_cleanup(allocator);
        return NULL;
    }
    engine->allocator = allocator;
    engine->config = NULL;
    engine->workers = NULL;
    engine->drudgers = NULL;
    engine->cmdhandler = NULL;
    engine->cmdhandler_done = 0;
    engine->dnshandler = NULL;
    engine->xfrhandler = NULL;
    engine->pid = -1;
    engine->uid = -1;
    engine->gid = -1;
    engine->daemonize = 0;
    engine->need_to_exit = 0;
    engine->need_to_reload = 0;
    lock_basic_init(&engine->signal_lock);
    lock_basic_set(&engine->signal_cond);
    lock_basic_lock(&engine->signal_lock);
    engine->signal = SIGNAL_INIT;
    lock_basic_unlock(&engine->signal_lock);
    engine->zonelist = zonelist_create(engine->allocator);
    if (!engine->zonelist) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->taskq = schedule_create(engine->allocator);
    if (!engine->taskq) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->signq = fifoq_create(engine->allocator);
    if (!engine->signq) {
        engine_cleanup(engine);
        return NULL;
    }
    return engine;
}
Exemple #4
0
static void ICACHE_FLASH_ATTR led_status_center(void *arg)
{
    os_timer_arm(&status_timer, 2000, 0);
    user_wifi_output(led_status);
    led_status = (0 == led_status) ? 1 : 0;
    os_printf("get status %d \n", smart_config_get_status());

    int status = wifi_station_get_connect_status();
    int smart_status = wifi_station_get_connect_status();

    if ((E_STATUS_LINK_OVER == smart_status) &&
        (status == STATION_GOT_IP))
    {
        os_timer_disarm(&status_timer, 2000, 0);
        flash_param_set_id(CONFIG_DONE_ID);
        schedule_create(0);
    }
}
Exemple #5
0
/**
 * Create engine.
 *
 */
static engine_type*
engine_create(void)
{
    engine_type* engine;
    CHECKALLOC(engine = (engine_type*) malloc(sizeof(engine_type)));
    engine->config = NULL;
    engine->workers = NULL;
    engine->drudgers = NULL;
    engine->cmdhandler = NULL;
    engine->cmdhandler_done = 0;
    engine->dnshandler = NULL;
    engine->xfrhandler = NULL;
    engine->taskq = NULL;
    engine->signq = NULL;
    engine->pid = -1;
    engine->uid = -1;
    engine->gid = -1;
    engine->daemonize = 0;
    engine->need_to_exit = 0;
    engine->need_to_reload = 0;
    lock_basic_init(&engine->signal_lock);
    lock_basic_set(&engine->signal_cond);
    lock_basic_lock(&engine->signal_lock);
    engine->signal = SIGNAL_INIT;
    lock_basic_unlock(&engine->signal_lock);
    engine->zonelist = zonelist_create();
    if (!engine->zonelist) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->taskq = schedule_create();
    if (!engine->taskq) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->signq = fifoq_create();
    if (!engine->signq) {
        engine_cleanup(engine);
        return NULL;
    }
    return engine;
}
Exemple #6
0
/**
 * Create engine.
 *
 */
static engine_type*
engine_create(void)
{
    engine_type* engine;
    allocator_type* allocator = allocator_create(malloc, free);
    if (!allocator) {
        return NULL;
    }
    engine = (engine_type*) allocator_alloc(allocator, sizeof(engine_type));
    if (!engine) {
        allocator_cleanup(allocator);
        return NULL;
    }
    engine->allocator = allocator;
    engine->config = NULL;
    engine->workers = NULL;
    engine->drudgers = NULL;
    engine->cmdhandler = NULL;
    engine->cmdhandler_done = 0;
    engine->pid = -1;
    engine->uid = -1;
    engine->gid = -1;
    engine->daemonize = 0;
    engine->need_to_exit = 0;
    engine->need_to_reload = 0;

    engine->signal = SIGNAL_INIT;
    lock_basic_init(&engine->signal_lock);
    lock_basic_set(&engine->signal_cond);

    engine->taskq = schedule_create(engine->allocator);
    if (!engine->taskq) {
        engine_cleanup(engine);
        return NULL;
    }
    engine->signq = fifoq_create(engine->allocator);
    if (!engine->signq) {
        engine_cleanup(engine);
        return NULL;
    }
    return engine;
}
Exemple #7
0
void user_init(void)
{
    uart_init(BIT_RATE_115200, BIT_RATE_115200);
    os_printf("SDK version:%s\n", system_get_sdk_version());
    
    // rsa_api_unit_test();
    
    os_printf("================= \n");
    
    packet_test();
    
    //json_test();
    
    //aes_api_unit_test();    
    //os_printf("================= \n");
    //crypto_api_unit_test();
    
    return;

    struct station_config station_conf;
    wifi_station_get_config(&station_conf);
    os_printf(MACSTR ",%s,%s \n", MAC2STR(station_conf.bssid), station_conf.password, station_conf.ssid);


    //struct station_config {
    //    uint8 ssid[32];
    //    uint8 password[64];
    //    uint8 bssid_set;    // Note: If bssid_set is 1, station will just connect to the router
    //                        // with both ssid[] and bssid[] matched. Please check about this.
    //    uint8 bssid[6];
    //};

    // 0c:4b:54:84:9e:2d t77y2qs4
    //station_conf.bssid[0] = 0x0c;
    //station_conf.bssid[1] = 0x4b;
    //station_conf.bssid[2] = 0x54;
    //station_conf.bssid[3] = 0x84;
    //station_conf.bssid[4] = 0x9e;
    //station_conf.bssid[5] = 0x2d;
    station_conf.bssid_set = 0;
    //os_strcpy(station_conf.ssid,     "hehao");
    //os_strcpy(station_conf.password, "ziqiangbuxi");
    wifi_station_set_config(&station_conf);

    wifi_station_get_config(&station_conf);
    os_printf(MACSTR ", %s, %s %d\n", MAC2STR(station_conf.bssid), station_conf.password, station_conf.ssid, station_conf.bssid_set);

    int8 id_buf[16] = {0};
    flash_param_get_id(id_buf);
    os_printf("get id = %s \n", id_buf);

    if (0 == os_strcmp(id_buf, CONFIG_RESET_ID))
    {
        os_printf("airkiss start ... \n");
        smart_config_start();
        user_switch_init();

        os_timer_disarm(&status_timer);
        os_timer_setfn(&status_timer, (os_timer_func_t *)led_status_center, NULL);
        os_timer_arm(&status_timer, 2000, 0);

        single_key[0] = key_init_single(PLUG_KEY_0_IO_NUM,
                                        PLUG_KEY_0_IO_MUX,
                                        PLUG_KEY_0_IO_FUNC,
                                        key_long_press,
                                        key_short_press);
        keys.key_num    = PLUG_KEY_NUM;
        keys.single_key = single_key;
        key_init(&keys);

        os_timer_disarm(&sys_timer);
        os_timer_setfn(&sys_timer, (os_timer_func_t *)system_secs_center, NULL);
        os_timer_arm(&sys_timer, 1000, 1); // 0 at once, 1 restart auto.

        switch_level = 0x01;
        user_switch_output(1);
    }
    else
    {
        schedule_create(0);
    }
}