コード例 #1
0
ファイル: mqtt-object.c プロジェクト: svenbw/esp-mqtt-object
void ICACHE_FLASH_ATTR object_init_pool(const struct object_config** object_configs)
{
	struct object* object;
	const struct object_config** config;
	uint32_t cnt = 0, daemon_timeout_ms = 0;

	// Count the objects
	for(config=object_configs; *config != NULL; ++config, ++cnt);

	global_objects = (struct object*) os_zalloc(sizeof(struct object) * (cnt + 1));

	for(object=global_objects,config=object_configs; *config != NULL; ++object,++config)
	{
		object->config = *config;

		if(object->config->init != NULL)
			object->config->init(object, &daemon_timeout_ms);

		if((object->config->daemon != NULL) && (daemon_timeout_ms != 0))
		{
			os_timer_setfn(&object->daemon, object_daemon_task, object);
			os_timer_arm(&object->daemon, daemon_timeout_ms, 1);

			object_daemon_task(object);
		}
	}
}
コード例 #2
0
ファイル: cgiwifi.c プロジェクト: mroavi/esp-link
int ICACHE_FLASH_ATTR cgiWiFiConnStatus(HttpdConnData *connData) {
  char buff[1024];
  int len;

  if (connData->conn==NULL) return HTTPD_CGI_DONE; // Connection aborted. Clean up.
  jsonHeader(connData, 200);

  len = os_sprintf(buff, "{");
  len += printWifiInfo(buff+len);
  len += os_sprintf(buff+len, ", ");

  if (wifiReason != 0) {
    len += os_sprintf(buff+len, "\"reason\": \"%s\", ", wifiGetReason());
  }

#if 0
  // commented out 'cause often the client that requested the change can't get a request in to
  // find out that it succeeded. Better to just wait the std 15 seconds...
  int st=wifi_station_get_connect_status();
  if (st == STATION_GOT_IP) {
    if (wifi_get_opmode() != 1) {
      // Reset into AP-only mode sooner.
      os_timer_disarm(&resetTimer);
      os_timer_setfn(&resetTimer, resetTimerCb, NULL);
      os_timer_arm(&resetTimer, 1000, 0);
    }
  }
#endif

  len += os_sprintf(buff+len, "\"x\":0}\n");
  //DBG("  -> %s\n", buff);
  httpdSend(connData, buff, len);
  return HTTPD_CGI_DONE;
}
コード例 #3
0
ファイル: syslog.c プロジェクト: susisstrolch/ems-esp-link
static void ICACHE_FLASH_ATTR syslog_timer_arm(int delay) {
    static os_timer_t wifi_chk_timer = {};
    syslog_timer_armed = true;
    os_timer_disarm(&wifi_chk_timer);
    os_timer_setfn(&wifi_chk_timer, (os_timer_func_t *)syslog_chk_status, NULL);
    os_timer_arm(&wifi_chk_timer, delay, 0);
}
コード例 #4
0
ファイル: ntp.c プロジェクト: boyhuesd/esp8266
void ICACHE_FLASH_ATTR ntp_get_time() {

	ntp_t ntp;

	// set up the udp "connection"
	pCon = (struct espconn*)os_zalloc(sizeof(struct espconn));
	pCon->type = ESPCONN_UDP;
	pCon->state = ESPCONN_NONE;
	pCon->proto.udp = (esp_udp*)os_zalloc(sizeof(esp_udp));
	pCon->proto.udp->local_port = espconn_port();
	pCon->proto.udp->remote_port = 123;
	os_memcpy(pCon->proto.udp->remote_ip, ntp_server, 4);

	// create a really simple ntp request packet
	os_memset(&ntp, 0, sizeof(ntp_t));
	ntp.options = 0b00100011; // leap = 0, version = 4, mode = 3 (client)

	// set timeout timer
	os_timer_disarm(&ntp_timeout);
	os_timer_setfn(&ntp_timeout, (os_timer_func_t*)ntp_udp_timeout, pCon);
	os_timer_arm(&ntp_timeout, NTP_TIMEOUT_MS, 0);

	// send the ntp request
	espconn_create(pCon);
	espconn_regist_recvcb(pCon, ntp_udp_recv);
	espconn_sent(pCon, (uint8*)&ntp, sizeof(ntp_t));
}
コード例 #5
0
static void ICACHE_FLASH_ATTR wifi_check_ip(void *arg)
{
	os_timer_disarm(&WiFiLinker);
	switch(wifi_station_get_connect_status())
	{
		case STATION_GOT_IP:
			wifi_get_ip_info(STATION_IF, &ipConfig);
			if(ipConfig.ip.addr != 0) {
				connState = WIFI_CONNECTED;
				os_printf("WiFi connected\r\n");
			} else {
				connState = WIFI_CONNECTING_ERROR;
				os_printf("WiFi connected, ip.addr is null\r\n");
			}
			break;
		case STATION_WRONG_PASSWORD:
			connState = WIFI_CONNECTING_ERROR;
			os_printf("WiFi connecting error, wrong password\r\n");
			break;
		case STATION_NO_AP_FOUND:
			connState = WIFI_CONNECTING_ERROR;
			os_printf("WiFi connecting error, ap not found\r\n");
			break;
		case STATION_CONNECT_FAIL:
			connState = WIFI_CONNECTING_ERROR;
			os_printf("WiFi connecting fail\r\n");
			break;
		default:
			connState = WIFI_CONNECTING;
			os_printf("WiFi connecting...\r\n");
	}
	os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
	os_timer_arm(&WiFiLinker, 2000, 0);
}
コード例 #6
0
/*******************************************************************************
* 名称: SysTick_Handler
* 功能: 系统时钟节拍1MS
* 形参:
* 返回: 无
* 说明:
*******************************************************************************/
void ICACHE_FLASH_ATTR
SysTickStart(void)
{
	os_timer_disarm(&SystemSysTick);
	os_timer_setfn(&SystemSysTick,(os_timer_func_t*)SysTick_Handler,NULL);
	os_timer_arm(&SystemSysTick, 1, 1);
}
コード例 #7
0
ファイル: tmr.c プロジェクト: NicolSpies/nodemcu-firmware
int luaopen_tmr( lua_State *L ){
	int i;	

	luaL_rometatable(L, "tmr.timer", (void *)tmr_dyn_map);

	for(i=0; i<NUM_TMR; i++){
		alarm_timers[i].lua_ref = LUA_NOREF;
		alarm_timers[i].self_ref = LUA_REFNIL;
		alarm_timers[i].mode = TIMER_MODE_OFF;
		os_timer_disarm(&alarm_timers[i].os);
	}
	last_rtc_time=system_get_rtc_time(); // Right now is time 0
	last_rtc_time_us=0;

	os_timer_disarm(&rtc_timer);
	os_timer_setfn(&rtc_timer, rtc_callback, NULL);
	os_timer_arm(&rtc_timer, 1000, 1);

  SWTIMER_REG_CB(rtc_callback, SWTIMER_RESUME);
  //The function rtc_callback calls the a function that calibrates the SoftRTC for drift in the esp8266's clock.
  //My guess: after the duration of light_sleep there's bound to be some drift in the clock, so a calibration is due.
  SWTIMER_REG_CB(alarm_timer_common, SWTIMER_RESUME);
  //The function alarm_timer_common handles timers created by the developer via tmr.create().
  //No reason not to resume the timers, so resume em'.


	return 0;
}
コード例 #8
0
void ICACHE_FLASH_ATTR connected_cloud_cb(void* param)
{
	uint8 rcvbuf[16];
	struct espconn* conn = (struct espconn*)param;

	os_printf("connected_cloud_cb, conn: [%p]\n", conn);
	client_status = STATUS_CONNECTED;
	//注册 断开与接收、发送的回调
	espconn_regist_recvcb(conn, data_received_cb);
	espconn_regist_sentcb(conn, sent_cloud_cb);
	espconn_regist_disconcb(conn, disconnected_cloud_cb);
	//注册心跳回调
	heart_timer* pheart = (heart_timer*)os_zalloc(sizeof(heart_timer));
	ETSTimer* timer = (ETSTimer*)os_zalloc(sizeof(ETSTimer));
	pheart->timer = timer;
	pheart->conn = conn;

	conn->reverse = (void*)pheart;
	os_timer_disarm(timer);
	os_timer_setfn(timer, heart_beat_cbfn, pheart);
	os_timer_arm(timer, 120000, 1);//两分钟一个心跳包, 重复

	uint32* pchipid = (uint32*)(rcvbuf + 2);
	rcvbuf[0] = 7;
	rcvbuf[1] = 0;

	*pchipid = system_get_chip_id();
	rcvbuf[6] = 1;

	espconn_sent(conn, rcvbuf, 7);
	os_printf("DEV RP OVER\n");
}
コード例 #9
0
ファイル: cgiwifi.c プロジェクト: jkent/libesphttpd
//This cgi uses the routines above to connect to a specific access point with the
//given ESSID using the given password.
CgiStatus ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
	char essid[128];
	char passwd[128];
	static os_timer_t reassTimer;
	if (connData->isConnectionClosed) {
		//Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}

	httpdFindArg(connData->post.buff, "essid", essid, sizeof(essid));
	httpdFindArg(connData->post.buff, "passwd", passwd, sizeof(passwd));
	strncpy((char*)stconf.ssid, essid, 32);
	strncpy((char*)stconf.password, passwd, 64);

	//Schedule disconnect/connect
	os_timer_disarm(&reassTimer);
	os_timer_setfn(&reassTimer, reassTimerCb, NULL);
//Set to 0 if you want to disable the actual reconnecting bit
	connTryStatus = CONNTRY_WORKING;
#ifdef DEMO_MODE
	httpdRedirect(connData, "/wifi");
#else
	os_timer_arm(&reassTimer, 500, 0);
	httpdRedirect(connData, "connecting.html");
#endif

	return HTTPD_CGI_DONE;
}
コード例 #10
0
ファイル: user_main.c プロジェクト: Squonk42/nodelua
void ICACHE_FLASH_ATTR user_check_ip(uint8 reset_flag)
{
    struct ip_info ipconfig;

    os_timer_disarm(&check_sta_timer);

    wifi_get_ip_info(STATION_IF, &ipconfig);

    if (wifi_station_get_connect_status() == STATION_GOT_IP && ipconfig.ip.addr != 0)
	{
		fetch_code_from_cloud();
    }
	else
	{
        /* if there are wrong while connecting to some AP, then reset mode */
        if ((wifi_station_get_connect_status() == STATION_WRONG_PASSWORD ||
                wifi_station_get_connect_status() == STATION_NO_AP_FOUND ||
                wifi_station_get_connect_status() == STATION_CONNECT_FAIL))
		{
			//TODO: reconfig wifi!!!
            //user_esp_platform_reset_mode();
        } else {
            os_timer_setfn(&check_sta_timer, (os_timer_func_t *)user_check_ip, NULL);
            os_timer_arm(&check_sta_timer, 100, 0);
        }
    }
}
コード例 #11
0
void light_pwm_dh_adj_proc(void *Targ)
{
    uint8 i;
    for(i=0;i<PWM_CHANNEL;i++){ 
        
        duty_now[i] = (duty_now[i]*7 + current_duty[i])>>3;
        
        if( ABS_MINUS(duty_now[i],current_duty[i])<20 ){
            duty_now[i] = current_duty[i];
        }
        user_light_set_duty(duty_now[i],i);
    }
    //printf("duty:%u,%u,%u\r\n", duty_now[0],duty_now[1],duty_now[2] );
//    pwm_init(light_param.pwm_period, light_param.pwm_duty,PWM_CHANNEL,pwmio_info); //lujian
    
    pwm_start();	
    if(check_pwm_current_duty_diff()){
        change_finish = 0;
        os_timer_disarm(&timer_pwm_adj);
        os_timer_setfn(&timer_pwm_adj, (os_timer_func_t *)light_pwm_dh_adj_proc, NULL);
        os_timer_arm(&timer_pwm_adj, min_ms, 0);
    }
    else{
        //printf("finish\n");
        change_finish = 1;  
        //light_save_target_duty();
        os_timer_disarm(&timer_pwm_adj);
        light_pwm_smooth_adj_proc();
    }

}
コード例 #12
0
void mg_ev_mgr_init(struct mg_mgr *mgr) {
  LOG(LL_INFO, ("%p Mongoose init, tq %p", mgr, s_mg_task_queue));
  system_os_task(mg_lwip_task, MG_TASK_PRIORITY, s_mg_task_queue,
                 MG_TASK_QUEUE_LEN);
  os_timer_setfn(&s_poll_tmr, mg_poll_timer_cb, mgr);
  os_timer_arm(&s_poll_tmr, MG_POLL_INTERVAL_MS, 0 /* no repeat */);
}
コード例 #13
0
static void mg_lwip_check_rexmit(void *arg) {
  struct mg_mgr *mgr = (struct mg_mgr *) arg;
  struct mg_connection *nc;
  uint32_t now = system_get_time();
  uint32_t next_rexmit_in_micros = ~0;
  for (nc = mgr->active_connections; nc != NULL; nc = nc->next) {
    struct mg_lwip_conn_state *cs = (struct mg_lwip_conn_state *) nc->sock;
    if (nc->sock == INVALID_SOCKET || nc->flags & MG_F_UDP ||
        nc->flags & MG_F_LISTENING || cs->pcb.tcp == NULL) {
      continue;
    }
    if (cs->next_rexmit_ts_micros > 0 &&
        time_left_micros(now, cs->next_rexmit_ts_micros) == 0) {
      mg_lwip_rexmit(nc);
    }
    if (cs->next_rexmit_ts_micros > 0) {
      uint32_t time_left = time_left_micros(now, cs->next_rexmit_ts_micros);
      next_rexmit_in_micros = MIN(next_rexmit_in_micros, time_left);
    }
  }
  if (next_rexmit_in_micros != ~0U) {
    uint32_t delay_millis = 1;
    delay_millis = next_rexmit_in_micros / 1000;
    if (delay_millis == 0) delay_millis = 1;
    os_timer_disarm(&s_rexmit_tmr);
    os_timer_setfn(&s_rexmit_tmr, mg_lwip_check_rexmit, mgr);
    os_timer_arm(&s_rexmit_tmr, delay_millis, 0 /* no repeat */);
  }
}
コード例 #14
0
// initialization
void IRrecv::enableIRIn() {
	
  // initialize state machine variables
  irparams.rcvstate = STATE_IDLE;
  irparams.rawlen = 0;

  // set pin modes  
  //PIN_FUNC_SELECT(IR_IN_MUX, IR_IN_FUNC);
  GPIO_DIS_OUTPUT(irparams.recvpin);
  
  // Initialize timer
  os_timer_disarm(&timer);
  os_timer_setfn(&timer, (os_timer_func_t *)read_timeout, &timer);
  
  // ESP Attach Interrupt
  ETS_GPIO_INTR_DISABLE();
  ETS_GPIO_INTR_ATTACH(gpio_intr, NULL);
  gpio_pin_intr_state_set(GPIO_ID_PIN(irparams.recvpin), GPIO_PIN_INTR_ANYEDGE);
  ETS_GPIO_INTR_ENABLE();
  //ETS_INTR_UNLOCK();  
  
  //attachInterrupt(irparams.recvpin, readIR, CHANGE);  
  //irReadTimer.initializeUs(USECPERTICK, readIR).start();
  //os_timer_arm_us(&irReadTimer, USECPERTICK, 1);
  //ets_timer_arm_new(&irReadTimer, USECPERTICK, 1, 0);
}
コード例 #15
0
ファイル: status.c プロジェクト: alonewolfx2/esp-link
// change the wifi state
void ICACHE_FLASH_ATTR statusWifiUpdate(uint8_t state) {
	wifiState = state;
	// schedule an update (don't want to run into concurrency issues)
	os_timer_disarm(&ledTimer);
	os_timer_setfn(&ledTimer, ledTimerCb, NULL);
	os_timer_arm(&ledTimer, 500, 0);
}
コード例 #16
0
void ICACHE_FLASH_ATTR
user_sensor_deep_sleep_init(uint32 time)
{
    os_timer_disarm(&sensor_sleep_timer);
    os_timer_setfn(&sensor_sleep_timer, (os_timer_func_t *)user_sensor_deep_sleep_enter, NULL);
    os_timer_arm(&sensor_sleep_timer, time, 0);
}
コード例 #17
0
ファイル: user_main.c プロジェクト: donnaware/ESP8266
// ----------------------------------------------------------------------------
// Send data
// Parameters:  uint8* psent -- Data to send
//              uint16 length -- Length of data to send
// ----------------------------------------------------------------------------
static void create_udp(void)
{
    uint32_t ip;

    os_timer_disarm(&WiFiLinker);

    ip = ipaddr_addr(UDPSERVERIP);
    os_memcpy(ConnUDP.remote_ip, &ip, 4);

    struct ip_info ipConfig;
    wifi_get_ip_info(STATION_IF, &ipConfig);
    os_memcpy(ConnUDP.local_ip, &ipConfig.ip.addr, 4);

    ConnUDP.local_port  = UDPSERVERPORT;
    ConnUDP.remote_port = UDPSERVERPORT;

    Conn.proto.udp = &ConnUDP;
    Conn.type      = ESPCONN_UDP;
    Conn.state     = ESPCONN_NONE;

    espconn_regist_recvcb(&Conn,  recv_cb); // register a udp packet receiving callback
    espconn_regist_sentcb(&Conn,  sent_cb);

    os_printf("Start espconn_connect to   " IPSTR ":%d\n", IP2STR(Conn.proto.udp->remote_ip), Conn.proto.udp->remote_port);
    os_printf("Start espconn_connect from " IPSTR ":%d\n", IP2STR(Conn.proto.udp->local_ip), Conn.proto.udp->local_port);
    espconn_create(&Conn);   // create udp
    os_timer_setfn(&WiFiLinker, (os_timer_func_t *)wifi_check_ip, NULL);
    os_timer_arm(&WiFiLinker, 1000, 0);
}
コード例 #18
0
ファイル: cgiwifi.c プロジェクト: matigumma/esp8266
int ICACHE_FLASH_ATTR cgiWiFiConfigureBasicAuth(HttpdConnData *connData) {
	char user[64];
	char passwd[64];
	static ETSTimer resetTimer;

	if (connData->conn==NULL) {
		//Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}

	httpdFindArg(connData->postBuff, "authUser", user, sizeof(user));
	httpdFindArg(connData->postBuff, "authPasswd", passwd, sizeof(passwd));

	flash_key_value_set("user", user);
	flash_key_value_set("password", passwd);

	os_printf("Reconfigure basic auth  %s pw %s\n", user, passwd);

	os_timer_disarm(&resetTimer);
	os_timer_setfn(&resetTimer, systemRestartCb, NULL);
	os_timer_arm(&resetTimer, 4000, 0);

	httpdRedirect(connData, "/wifi");
	return HTTPD_CGI_DONE;
}
コード例 #19
0
ファイル: Timer.cpp プロジェクト: alonewolfx2/Sming_RTOS_POC
void Timer::start(bool repeating/* = true*/)
{
	this->repeating = repeating;
	stop();
	if(interval == 0 || (!callback && !delegate_func)) 
		return;

	os_timer_setfn(&timer, (os_timer_func_t *)processing, this);
/*  -> NONOS version for reference
	ets_timer_setfn(&timer, (os_timer_func_t *)processing, this);
	if (interval > 10000) 
	{
		ets_timer_arm_new(&timer, (uint32_t)(interval / 1000),
				(long_intvl_cntr_lim > 0 ? true : repeating), 1); // msec
	}
	else 
	{
		ets_timer_arm_new(&timer, (uint32_t)interval, repeating, 0); 		  // usec
	}
*/
	os_timer_arm(&timer, (uint32_t)(interval / 1000),
			(long_intvl_cntr_lim > 0 ? true : repeating)); // msec


	started = true;
}
コード例 #20
0
ファイル: user_main.c プロジェクト: whdlut/ESP8266_NONOS_SDK
void ICACHE_FLASH_ATTR user_init(void)
{
    char buf[128] = {0};
    at_customLinkMax = 5;
	sdio_slave_init();
	sdio_register_recv_cb(sdio_recv_data_callback);
    at_init();
	at_register_uart_rx_buffer_fetch_cb(at_custom_uart_rx_buffer_fetch_cb);
#ifdef ESP_AT_FW_VERSION
    if ((ESP_AT_FW_VERSION != NULL) && (os_strlen(ESP_AT_FW_VERSION) < 64)) {
        os_sprintf(buf,"compile time:%s %s\r\n"ESP_AT_FW_VERSION,__DATE__,__TIME__);
    } else {
        os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
    }
#else
    os_sprintf(buf,"compile time:%s %s",__DATE__,__TIME__);
#endif
    at_set_custom_info(buf);
	at_fake_uart_enable(TRUE,at_sdio_response);
	
    at_cmd_array_regist(&at_custom_cmd[0], sizeof(at_custom_cmd)/sizeof(at_custom_cmd[0]));

	espconn_tcp_set_wnd(4);
	at_port_print("\r\nready\r\n");

#ifdef SDIO_DEBUG
	os_timer_disarm(&at_spi_check);
	os_timer_setfn(&at_spi_check, (os_timer_func_t *)at_spi_check_cb, NULL);
	os_timer_arm(&at_spi_check, 1000, 1);
	os_printf("\r\ntimer start\r\n");
#endif
}
コード例 #21
0
void ICACHE_FLASH_ATTR
light_blinkStart(uint32 COLOR)
{
    os_timer_disarm(&light_hint_t);
    os_timer_setfn(&light_hint_t,light_blink,COLOR);
    os_timer_arm(&light_hint_t,1000,1);
}
コード例 #22
0
ファイル: cgiwifi.c プロジェクト: alonewolfx2/esp-link
// This cgi uses the routines above to connect to a specific access point with the
// given ESSID using the given password.
int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
	char essid[128];
	char passwd[128];

	if (connData->conn==NULL) {
		//Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}

	int el = httpdFindArg(connData->getArgs, "essid", essid, sizeof(essid));
	int pl = httpdFindArg(connData->getArgs, "passwd", passwd, sizeof(passwd));

	if (el > 0 && pl >= 0) {
		//Set to 0 if you want to disable the actual reconnecting bit
#ifndef DEMO_MODE
		os_strncpy((char*)stconf.ssid, essid, 32);
		os_strncpy((char*)stconf.password, passwd, 64);
		os_printf("Wifi try to connect to AP %s pw %s\n", essid, passwd);

		//Schedule disconnect/connect
		os_timer_disarm(&reassTimer);
		os_timer_setfn(&reassTimer, reassTimerCb, NULL);
		os_timer_arm(&reassTimer, 1000, 0);
#endif
		jsonHeader(connData, 200);
	} else {
		jsonHeader(connData, 400);
		httpdSend(connData, "Cannot parse ssid or password", -1);
	}
	return HTTPD_CGI_DONE;
}
コード例 #23
0
//This cgi uses the routines above to connect to a specific access point with the
//given ESSID using the given password.
int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
	char essid[128];
	char passwd[128];
	static ETSTimer reassTimer;
	
	if (connData->conn==NULL) {
		//Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}
	
	httpdFindArg(connData->post->buff, "essid", essid, sizeof(essid));
	httpdFindArg(connData->post->buff, "passwd", passwd, sizeof(passwd));

	os_strncpy((char*)stconf.ssid, essid, 32);
	os_strncpy((char*)stconf.password, passwd, 64);
	debug("Try to connect to AP %s pw %s\n", essid, passwd);

	//Schedule disconnect/connect
	os_timer_disarm(&reassTimer);
	os_timer_setfn(&reassTimer, reassTimerCb, NULL);
//Set to 0 if you want to disable the actual reconnecting bit
#ifdef DEMO_MODE
	httpdRedirect(connData, "/wifi");
#else
	os_timer_arm(&reassTimer, 500, 0);
	httpdRedirect(connData, "connecting.html");
#endif
	return HTTPD_CGI_DONE;
}
コード例 #24
0
ファイル: cgiwifi.c プロジェクト: alonewolfx2/esp-link
//This cgi changes the operating mode: STA / AP / STA+AP
int ICACHE_FLASH_ATTR cgiWiFiSetMode(HttpdConnData *connData) {
	int len;
	char buff[1024];

	if (connData->conn==NULL) {
		// Connection aborted. Clean up.
		return HTTPD_CGI_DONE;
	}

	len=httpdFindArg(connData->getArgs, "mode", buff, sizeof(buff));
	if (len!=0) {
		int m = atoi(buff);
		os_printf("Wifi switching to mode %d\n", m);
#ifndef DEMO_MODE
		wifi_set_opmode(m&3);
		if (m == 1) {
			wifi_set_sleep_type(SLEEP_MODE);
			// STA-only mode, reset into STA+AP after a timeout
			os_timer_disarm(&resetTimer);
			os_timer_setfn(&resetTimer, resetTimerCb, NULL);
			os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
		}
		jsonHeader(connData, 200);
#endif
	} else {
	  jsonHeader(connData, 400);
	}
	return HTTPD_CGI_DONE;
}
コード例 #25
0
ファイル: cgiwifi.c プロジェクト: mroavi/esp-link
// This cgi uses the routines above to connect to a specific access point with the
// given ESSID using the given password.
int ICACHE_FLASH_ATTR cgiWiFiConnect(HttpdConnData *connData) {
    int mode = wifi_get_opmode();
    if(mode == 2){
        jsonHeader(connData, 400);
        httpdSend(connData, "Can't associate to an AP en SoftAP mode", -1);
        return HTTPD_CGI_DONE;
    }
  char essid[128];
  char passwd[128];

  if (connData->conn==NULL) return HTTPD_CGI_DONE;

  int el = httpdFindArg(connData->getArgs, "essid", essid, sizeof(essid));
  int pl = httpdFindArg(connData->getArgs, "passwd", passwd, sizeof(passwd));

  if (el > 0 && pl >= 0) {
    //Set to 0 if you want to disable the actual reconnecting bit
    os_strncpy((char*)stconf.ssid, essid, 32);
    os_strncpy((char*)stconf.password, passwd, 64);
    DBG("Wifi try to connect to AP %s pw %s\n", essid, passwd);

    //Schedule disconnect/connect
    os_timer_disarm(&reassTimer);
    os_timer_setfn(&reassTimer, reassTimerCb, NULL);
    os_timer_arm(&reassTimer, 1000, 0); // 1 second for the response of this request to make it
    jsonHeader(connData, 200);
  } else {
    jsonHeader(connData, 400);
    httpdSend(connData, "Cannot parse ssid or password", -1);
  }
  return HTTPD_CGI_DONE;
}
コード例 #26
0
// init the CTRL stack
void ICACHE_FLASH_ATTR ctrl_stack_init(tCtrlCallbacks *cc)
{
	ctrlCallbacks = cc;

	os_timer_disarm(&tmrDataExpecter);
	os_timer_setfn(&tmrDataExpecter, (os_timer_func_t *)data_expecter_timeout, NULL);
}
コード例 #27
0
/******************************************************************************
 * FunctionName : mesh_StartReconnCheck
 * Description  : start a timer to check mesh status
                  called in platform(dns found) to restart mesh if can not get any response from esp-server.
*******************************************************************************/
void ICACHE_FLASH_ATTR
mesh_StartReconnCheck(uint32 t)
{
    os_timer_disarm(&mesh_user_t);
    os_timer_setfn(&mesh_user_t,mesh_ReconCheck,NULL);
    os_timer_arm(&mesh_user_t,t,0);
}
コード例 #28
0
LOCAL void ICACHE_FLASH_ATTR wifi_check_ip(void *arg) {
	struct ip_info ipConfig;
	uint8_t wifiStatus = STATION_IDLE;

	os_timer_disarm(&wiFiLinker);

	wifi_get_ip_info(STATION_IF, &ipConfig);

	wifiStatus = wifi_station_get_connect_status();

	if (wifiStatus == STATION_GOT_IP && ipConfig.ip.addr != 0) {

		DEBUG("[NETWORK] Connected to network (IP: "IPSTR")\r\n", IP2STR(&ipConfig.ip));

		os_timer_setfn(&wiFiLinker, (os_timer_func_t *) wifi_check_ip, NULL);
		os_timer_arm(&wiFiLinker, 2000, 0);

	} else {

		if (wifi_station_get_connect_status() == STATION_WRONG_PASSWORD) {
			DEBUG("[NETWORK] error: STATION_WRONG_PASSWORD\r\n");
			station_connect();
		} else if (wifi_station_get_connect_status() == STATION_NO_AP_FOUND) {
			DEBUG("[NETWORK] error: STATION_NO_AP_FOUND\r\n");
			station_connect();
		} else if (wifi_station_get_connect_status() == STATION_CONNECT_FAIL) {
			DEBUG("[NETWORK] error: STATION_CONNECT_FAIL\r\n");
			station_connect();
		} else {
			//DEBUG("[NETWORK] error: STATION_IDLE\r\n");
		}

		if(state == USER_STATION_MODE){
			os_timer_setfn(&wiFiLinker, (os_timer_func_t *) wifi_check_ip, NULL);
			os_timer_arm(&wiFiLinker, 500, 0);
		}

	}

	if (wifiStatus != lastWifiStatus) {

		lastWifiStatus = wifiStatus;
		if (wifiCb)
			wifiCb(wifiStatus);

	}
}
コード例 #29
0
ファイル: espconn_tcp.c プロジェクト: AlexShadow/esp8266web
/******************************************************************************
 * FunctionName : esponn_server_err
 * Description  : The pcb had an error and is already deallocated.
 *                The argument might still be valid (if != NULL).
 * Parameters   : arg -- Additional argument to pass to the callback function
 *                err -- Error code to indicate why the pcb has been closed
 * Returns      : none
*******************************************************************************/
static void ICACHE_FLASH_ATTR
esponn_server_err(void *arg, err_t err)
{
	espconn_msg *pserr_cb = arg;
	struct tcp_pcb *pcb = NULL;
    if (pserr_cb != NULL) {
    	os_timer_disarm(&pserr_cb->pcommon.ptimer);
    	pcb = pserr_cb->pcommon.pcb;
    	pserr_cb->pespconn->state = ESPCONN_CLOSE;

		/*remove the node from the server's active connection list*/
		espconn_list_delete(&plink_active, pserr_cb);

		if (err == ERR_ABRT) {
			switch (pcb->state) {
				case SYN_RCVD:
					if (pcb->nrtx == TCP_SYNMAXRTX) {
						pserr_cb->pcommon.err = ESPCONN_CONN;
					} else {
						pserr_cb->pcommon.err = err;
					}

					break;

				case ESTABLISHED:
					if (pcb->nrtx == TCP_MAXRTX) {
						pserr_cb->pcommon.err = ESPCONN_TIMEOUT;
					} else {
						pserr_cb->pcommon.err = err;
					}

					break;

				case CLOSE_WAIT:
					if (pcb->nrtx == TCP_MAXRTX) {
						pserr_cb->pcommon.err = ESPCONN_CLSD;
					} else {
						pserr_cb->pcommon.err = err;
					}
					break;
				case LAST_ACK:
					pserr_cb->pcommon.err = ESPCONN_CLSD;
					break;

				case CLOSED:
					pserr_cb->pcommon.err = ESPCONN_CONN;
					break;
				default :
					break;
			}
		} else {
			pserr_cb->pcommon.err = err;
		}

		os_timer_setfn(&pserr_cb->pcommon.ptimer,
				(os_timer_func_t *) espconn_tcp_reconnect, pserr_cb);
		os_timer_arm(&pserr_cb->pcommon.ptimer, 10, 0);
    }
}
コード例 #30
0
void ICACHE_FLASH_ATTR network_init() 
{
  //uart0_tx_buffer("net init",8);
  
  os_timer_disarm(&network_timer);
  os_timer_setfn(&network_timer, (os_timer_func_t *)network_check_ip, NULL);
  os_timer_arm(&network_timer, 1000, 0);
}