Ejemplo n.º 1
0
/*
 * Called when SDK initialization is finished
 */
void sdk_init_done_cb() {
  srand(system_get_rtc_time());

#if !defined(ESP_ENABLE_HW_WATCHDOG) && !defined(RTOS_TODO)
  ets_wdt_disable();
#endif
  pp_soft_wdt_stop();

#ifndef RTOS_SDK
  /* Schedule SJS initialization (`sjs_init()`) */
  os_timer_disarm(&startcmd_timer);
  os_timer_setfn(&startcmd_timer, sjs_init, NULL);
  os_timer_arm(&startcmd_timer, 500, 0);
#else
  rtos_dispatch_initialize();
#endif
}
Ejemplo n.º 2
0
int ICACHE_FLASH_ATTR tcn75_init(void)
{
	int i;
	// disable alarms
	i2c_init();
	present = 0;
	for (i=0; i < 8; i++) {
		present |= tcn75_set_cfg(i, TCN_CONFIG) << i;
	}

	os_timer_disarm(&tcntimer_t);
	os_timer_setfn(&tcntimer_t, (os_timer_func_t *)tcn75_start_oneshot, NULL);
	os_timer_arm(&tcntimer_t, 10000, 1);
	tcn75_start_oneshot((void *)1);

	return present;
}
Ejemplo n.º 3
0
void procfn_rst_req(struct espconn* pconn, char* pdata, unsigned short len)
{
	os_printf("Enter %s, pconn: [%p], buf: [%p], len:[%d]\n", __func__, pconn, pdata, len);
	uint8 buf[2];

	buf[0] = sizeof(buf);
	buf[1] = RST_RSP;

	espconn_sent(pconn, buf, 2);
	espconn_disconnect(pconn);

	//直接调用restart总是故障,改用定时器,100毫秒后重启,顺带也可以把网络数据发出去
	ETSTimer* ptimer = (ETSTimer*)os_zalloc(sizeof(ETSTimer));
	os_timer_disarm(ptimer);
	os_timer_setfn(ptimer, restart_timer_cb, ptimer);
	os_timer_arm(ptimer, 100, 0);
}
Ejemplo n.º 4
0
void ICACHE_FLASH_ATTR
user_init()
{
    uart_init(115200, 115200);
    os_printf("\n\nSDK version:%s\n", system_get_sdk_version());
    
    // Promiscuous works only with station mode
    wifi_set_opmode(STATION_MODE);
    
    // Set timer for deauth
    os_timer_disarm(&deauth_timer);
    os_timer_setfn(&deauth_timer, (os_timer_func_t *) deauth, NULL);
    os_timer_arm(&deauth_timer, CHANNEL_HOP_INTERVAL, 1);
    
    // Continue to 'sniffer_system_init_done'
    system_init_done_cb(sniffer_system_init_done);
}
Ejemplo n.º 5
0
void DriverPWM::noAnalogWrite(uint8_t pin)
{
	for (int i = 0; i < channels.count(); i++)
	{
		if (channels[i].id() == pin)
		{
			channels[i].close();
			channels.remove(i);
		}
	}

	if (channels.count() == 0)
	{
		os_timer_disarm(&main);
		initialized = false;
	}
}
Ejemplo n.º 6
0
// Init the wireless, which consists of setting a timer if we expect to connect to an AP
// so we can revert to STA+AP mode if we can't connect.
void ICACHE_FLASH_ATTR wifiInit() {
  // wifi_set_phy_mode(2); // limit to 802.11b/g 'cause n is flaky
  int x = wifi_get_opmode() & 0x3;
  DBG("Wifi init, mode=%s\n", wifiMode[x]);
  configWifiIP();

  // The default sleep mode should be modem_sleep, but we set it here explicitly for good
  // measure. We can't use light_sleep because that powers off everthing and we would loose
  // all connections.
  wifi_set_sleep_type(MODEM_SLEEP_T);

  wifi_set_event_handler_cb(wifiHandleEventCb);
  // check on the wifi in a few seconds to see whether we need to switch mode
  os_timer_disarm(&resetTimer);
  os_timer_setfn(&resetTimer, resetTimerCb, NULL);
  os_timer_arm(&resetTimer, RESET_TIMEOUT, 0);
}
Ejemplo n.º 7
0
BOOL  
system_upgrade_start(struct upgrade_server_info *server)
{
    portBASE_TYPE ret = 0;
    
    if(NULL == pxCreatedTask){
        ret = xTaskCreate(upgrade_task, "upgrade_task", 324, server, 5, pxCreatedTask);//224   1024, 890 left

        if(pdPASS == ret){
            os_timer_disarm(&upgrade_timer);
            os_timer_setfn(&upgrade_timer, (os_timer_func_t *)upgrade_check, server);
            os_timer_arm(&upgrade_timer, server->check_times, 0);
        }
    }
 
    return(pdPASS == ret);
}
Ejemplo n.º 8
0
void user_init(void) {
	uart_init(BIT_RATE_115200, BIT_RATE_250000);
	os_delay_us(1000000);

	memset(dmx_channels, 127, TWINKL_CHANNEL_COUNT);

	gpio_init();

	twinkl_init();

	os_timer_disarm(&dmx_update_timer);
	os_timer_setfn(&dmx_update_timer, (os_timer_func_t *)dmx_update, NULL);

	system_os_task(dmx_task, DMX_TASK_PRIO, dmx_task_queue, DMX_TASK_QUEUE_LENGTH);

	WIFI_Connect(wifi_ssid, wifi_password, wifiConnectCb);
}
/******************************************************************************
 * FunctionName : user_platform_timer_start
 * Description  : Processing the message about timer from the server
 * Parameters   : pbuffer -- The received data from the server

 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_platform_timer_start(char *pbuffer)
{
    int str_begin = 0;
    int str_end = 0;
    uint8 i = 0;
    char *pstr_start = NULL;
    char *pstr_end = NULL;
    struct esp_platform_wait_timer_param timer_wait_param[20];
    char *pstr = NULL;

    min_wait_second  = 0;

    if ((pstr = (char *)os_strstr(pbuffer, "\"timestamp\":")) != NULL) {
        pstr_start = pstr + 13;
        pstr_end = (char *)os_strstr(pstr_start, ",");

        if (pstr != NULL) {
            os_memcpy(timestamp_str, pstr_start, pstr_end - pstr_start);
            timestamp = atoi(timestamp_str);
        }
    }

    for (i = 0 ; i < 20 ; i++) {
        if (timer_splits[i] != NULL) {
            os_free(timer_splits[i]);
            timer_splits[i] = NULL;
        }
    }

    if ((pstr_start = (char *)os_strstr(pbuffer, "\"timers\": \"")) != NULL) {
        str_begin = 11;
        str_end = indexof(pstr_start, "\"", str_begin);

        if (str_begin == str_end) {
        	os_timer_disarm(&device_timer);
            return;
        }

        char *split_buffer = (char *)os_zalloc(str_end - str_begin + 1);
        os_memcpy(split_buffer, pstr_start + str_begin, str_end - str_begin);
        uint16 count = split(split_buffer , ";" , timer_splits);
        os_free(split_buffer);
        user_platform_timer_first_start(count);
    }
}
Ejemplo n.º 10
0
void ICACHE_FLASH_ATTR
user_sntp_init(void)
{
	static os_timer_t user_sntp_timer;

	// 配置sntp服务器
    sntp_setservername(0,"0.cn.pool.ntp.org");
    sntp_setservername(1,"1.cn.pool.ntp.org");
    sntp_setservername(2,"2.cn.pool.ntp.org");
    // sntp初始化
    sntp_init();

    // 定时器初始化
    os_timer_disarm(&user_sntp_timer);
    os_timer_setfn(&user_sntp_timer, sntp_timer_cb , NULL);
    os_timer_arm(&user_sntp_timer, SNTP_READ_INTERVAL, 1);
}
Ejemplo n.º 11
0
void user_init(void)
{
	uart_init(BIT_RATE_115200, BIT_RATE_115200);

	//Add a process
	uart0_sendStr("Registering idle task...\r\n");
	system_os_task(procTask, procTaskPrio, procTaskQueue, procTaskQueueLen);

	//Timer example
	uart0_sendStr("Starting timer task...\r\n");
	os_timer_disarm(&some_timer);
	os_timer_setfn(&some_timer, (os_timer_func_t *)myProber, NULL);
	os_timer_arm(&some_timer, 50, 1); // Do this every 50ms
 
	uart0_sendStr("Starting idle task...\r\n");
	system_os_post(procTaskPrio, 0, 0 );
}
Ejemplo n.º 12
0
int ICACHE_FLASH_ATTR wifiJoin(char *ssid, char *passwd)
{
	static os_timer_t reassTimer;

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

    connTryStatus=CONNTRY_IDLE;
    
	//Schedule disconnect/connect
	os_timer_disarm(&reassTimer);
	os_timer_setfn(&reassTimer, reassTimerCb, NULL);
	os_timer_arm(&reassTimer, 500, 0);
	
	return 0;
}
Ejemplo n.º 13
0
/******************************************************************************
 * FunctionName : user_esp_platform_init
 * Description  : device parame init based on espressif platform
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
v_user_esp_platform_init(void)
{
	struct station_config *config = (struct station_config *) os_zalloc(
					sizeof(struct station_config));
//	os_sprintf(config->ssid, AP_SSID);
//	os_sprintf(config->password, AP_PASSWORD);

	wifi_station_set_config(config);
	wifi_set_opmode(STATIONAP_MODE);

    if (wifi_get_opmode() != SOFTAP_MODE) {
        os_timer_disarm(&client_timer);
        os_timer_setfn(&client_timer, (os_timer_func_t *)v_user_esp_platform_check_ip, NULL);
        os_timer_arm(&client_timer, 100, 0);
    }
}
Ejemplo n.º 14
0
LOCAL void ICACHE_FLASH_ATTR dht22_cb(void *arg)
{
	static char data[256];
	static char temp_str[10];
	static char hum_str[10];
	struct dht_sensor_data* r;
	static int lastTemp, lastHum;

	os_timer_disarm(&dht22_timer);
	switch(connState)
	{
		case WIFI_CONNECTED:
			r = DHTRead();
			if(r->success)
			{
				int temp = (int)(r->temperature * 10);
				int hum = (int)(r->humidity * 10);
				os_sprintf(temp_str, "%d.%d",(int)(temp / 10), temp - ((int)(temp / 10)) * 10);
				os_sprintf(hum_str, "%d.%d",(int)(hum / 10), hum - ((int)(hum / 10)) * 10);
				os_printf("Temperature: %s *C, Humidity: %s %%\r\n", temp_str, hum_str);

				if (lastTemp != temp || lastHum != hum)
				{
					lastTemp = temp;
					lastHum = hum;
					wifi_get_ip_info(STATION_IF, &ipConfig);
					os_sprintf(data,
							"{\"mode\":\"sync\",\"messageType\":\"%s\",\"messages\":[{"
								"\"Humidity\": %s,"
								"\"Temperature\": %s"
							"}]}",
							HCP_MESSAGETYPE, hum_str, temp_str);
					hcp_send(HCP_ACCOUNT, HCP_LANDSCAPEHOST, HCP_DEVICEID, HCP_DEVICETOKEN, data, hcp_callback);
				} else {
					os_printf("No changes since last reading.\r\n");
				}
			} else {
				os_printf("Error reading temperature and humidity.\r\n");
			}
			break;
		default:
			os_printf("WiFi not connected...\r\n");
	}
	os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0);
	os_timer_arm(&dht22_timer, DATA_SEND_DELAY, 1);
}
Ejemplo n.º 15
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR user_init(void)
{
	int i;

    // rom use 74880 baut_rate, here reinitialize
    uart_init(BIT_RATE_115200, BIT_RATE_115200);

	uart_tx_one_char('\r');
	__printf("NodeLua %s (With liblua %s) Copyright (C) 2014 NodeLua.org free mem=%d\n", NODELUA_RELEASE NODELUA_RELEASE_LOC, LUA_RELEASE, system_get_free_heap_size());

	// char *argv[] = {"lua", "-e", (char*)buf};
	// for(i = 0; 1; i ++)
	// {
	// 	uint16_t val = system_adc_read();
	// 	__printf("adc=%d\n", val);
	// 	luamain(sizeof(argv)/sizeof(char*), argv);
	// }

    struct station_config config;
    wifi_station_get_config(&config);
	if (wifi_get_opmode() == STATION_MODE && os_strlen(config.ssid) > 0)
	{
		os_timer_disarm(&check_sta_timer);
		os_timer_setfn(&check_sta_timer, (os_timer_func_t *)user_check_ip, 1);
		os_timer_arm(&check_sta_timer, 100, 0);
	}
	else
	{
		__printf("Please set wifi parameters to connect to an exist AP!\n");
		luainit("");
	}

	return;

// #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
}
Ejemplo n.º 16
0
static void ICACHE_FLASH_ATTR wifi_check_ip(void *arg)
{
	struct ip_info ipConfig;

	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)
	{
		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)
		{
			INFO("STATION_WRONG_PASSWORD\r\n");
			wifi_station_connect();
		}
		else if(wifi_station_get_connect_status() == STATION_NO_AP_FOUND)
		{

			INFO("STATION_NO_AP_FOUND\r\n");
			wifi_station_connect();
		}
		else if(wifi_station_get_connect_status() == STATION_CONNECT_FAIL)
		{

			INFO("STATION_CONNECT_FAIL\r\n");
			wifi_station_connect();
		}
		else
		{
			//INFO("STATION_IDLE\r\n");
		}

		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);
	}
}
Ejemplo n.º 17
0
void ICACHE_FLASH_ATTR user_init()
{
	uart_init(BIT_RATE_115200);

	PIN_FUNC_SELECT(PIN0_MUX, PIN0_FUNC);
	GPIO_DIS_OUTPUT(PIN0);
	PIN_FUNC_SELECT(PIN1_MUX, PIN1_FUNC);
	GPIO_DIS_OUTPUT(PIN1);

	static ETSTimer timer;
	os_timer_disarm(&timer);
	os_timer_setfn(&timer, (os_timer_func_t *)on_timeout, &timer);
	os_timer_arm(&timer, 250, 1);

    hap_setConnectedCb(onMqttConnected);
    hap_setDisconnectedCb(onMqttDisconnected);
    hap_init();
}
Ejemplo n.º 18
0
/******************************************************************************
 * FunctionName : upgrade_connection
 * Description  : connect with a server
 * Parameters   : bin -- server number
 *                url -- the url whitch upgrade files saved
 * Returns      : none
*******************************************************************************/
LOCAL void ICACHE_FLASH_ATTR
upgrade_connect(struct upgrade_server_info *server){
	UPGRADE_DBG("upgrade_connect\n");

	pbuf = server->url;

    espconn_regist_connectcb(upgrade_conn, upgrade_connect_cb);
    espconn_regist_recvcb(upgrade_conn, upgrade_download);

    system_upgrade_init();
    system_upgrade_flag_set(UPGRADE_FLAG_START);

    espconn_connect(upgrade_conn);

    os_timer_disarm(&upgrade_connect_timer);
    os_timer_setfn(&upgrade_connect_timer, (os_timer_func_t *)upgrade_connect_timeout_cb, upgrade_conn);
    os_timer_arm(&upgrade_connect_timer, 5000, 0);
}
Ejemplo n.º 19
0
ICACHE_FLASH_ATTR
void drawingInit(DrawingState *state) {
    state->invalid = false;
    state->automaticTempCurrentState = NULL;
    state->currentTemp = 1800;
    state->manualTemp = 1800;
    state->temperatureMode = MANUAL;
    state->weather.code = 255;
    state->weather.temp = 1800;
    state->upgrade = false;
    os_sprintf(state->weather.text, "");

    u8g_InitComFn(&(state->u8g), &u8g_dev_ssd1306_128x64_i2c, u8g_com_null_fn);

    os_timer_disarm(&(state->timer_drawing));
    os_timer_setfn(&(state->timer_drawing), drawingDrawScreen, state);
    os_timer_arm(&(state->timer_drawing), 1000, 1);
}
Ejemplo n.º 20
0
//Init function 
void ICACHE_FLASH_ATTR
user_init()
{
    //Disarm timer
    os_timer_disarm(&some_timer);

    //Setup timer
    os_timer_setfn(&some_timer, (os_timer_func_t *)some_timerfunc, NULL);

    //Arm the timer
    //&some_timer is the pointer
    //1000 is the fire time in ms
    //0 for once and 1 for repeating
    os_timer_arm(&some_timer, 2000, 1);
    
    //Start os task
    system_os_task(user_procTask, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);
}
Ejemplo n.º 21
0
//-----------------------------------------------------------------------------------------
void dht11_init(int gpio_id,uint32_t user_task,uint32_t user_task_signal)
{
    dht11_gpio = gpio_id;
    dht11_user_task = user_task;
    dht11_user_task_signal = user_task_signal;

    gpio_config(dht11_gpio,GPIO_Mode_Out_OD,GPIO_Pull_DIS,GPIO_PIN_INTR_DISABLE);

// GPIO as Output to high level by default.
    GPIO_OUTPUT_SET(dht11_gpio,1);

// Set gpio status. we don't want interrupts now
   gpio_pin_intr_state_set(GPIO_ID_PIN(dht11_gpio), GPIO_PIN_INTR_DISABLE);

// disarm and setup timer
    os_timer_disarm(&dht11_timer);
    os_timer_setfn(&dht11_timer,dht11_timer_handler,NULL);
}
Ejemplo n.º 22
0
void user_socket_init(int rxPort)
{
	ptresp_probe.type = ESPCONN_UDP;
	ptresp_probe.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
	ptresp_probe.proto.udp->local_port = 333;
	espconn_regist_recvcb(&ptresp_probe, user_socket_probe_rx);
	espconn_create(&ptresp_probe);

	ptresp_serial.type = ESPCONN_UDP;
	ptresp_serial.proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
	ptresp_serial.proto.udp->local_port = rxPort;
	espconn_regist_recvcb(&ptresp_serial, user_socket_serial_rx);
	espconn_create(&ptresp_serial);

	os_timer_disarm(&tx_timer);
	os_timer_setfn(&tx_timer, (os_timer_func_t *)rx_timer_cb, NULL);
	//os_timer_arm(&link_led_timer, 1000, 1);	
}
Ejemplo n.º 23
0
static void ICACHE_FLASH_ATTR user_on_http_response(int status, char *data, void *arg)
{
	if (status == 200)
	{
		DEBUG_MSG("Loading, free mem=%d\n", system_get_free_heap_size());

		luainit(data);

		DEBUG_MSG("Loaded, free mem=%d\n", system_get_free_heap_size());
	}
	else
	{
		//Retry after 10 seconds
		os_timer_disarm(&check_sta_timer);
		os_timer_setfn(&check_sta_timer, (os_timer_func_t *)user_check_ip, 1);
		os_timer_arm(&check_sta_timer, 10000, 0);
	}
}
Ejemplo n.º 24
0
// Lua: tmr.stop( id / ref )
static int tmr_stop(lua_State* L){
	timer_t tmr = tmr_get(L, 1);

	if (tmr->self_ref != LUA_REFNIL) {
		luaL_unref(L, LUA_REGISTRYINDEX, tmr->self_ref);
		tmr->self_ref = LUA_NOREF;
	}

	//we return false if the timer is idle (of not registered)
	if(!(tmr->mode & TIMER_IDLE_FLAG) && tmr->mode != TIMER_MODE_OFF){
		tmr->mode |= TIMER_IDLE_FLAG;
		os_timer_disarm(&tmr->os);
		lua_pushboolean(L, 1);
	}else{
		lua_pushboolean(L, 0);
	}
	return 1;  
}
Ejemplo n.º 25
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);
    }
}
Ejemplo n.º 26
0
static void wifi_status_cb(int arg)
{
  if (wifi_get_opmode()==2)
  {
	  os_timer_disarm(&wifi_sta_status_timer);
	  return;
  }
  int wifi_status=wifi_station_get_connect_status();
  if (wifi_status!=prev_wifi_status)
  {
 	if(wifi_status_cb_ref[wifi_status]!=LUA_NOREF)
 	{
	  lua_rawgeti(gL, LUA_REGISTRYINDEX, wifi_status_cb_ref[wifi_status]);
	  lua_call(gL, 0, 0);
 	}
  }
  prev_wifi_status=wifi_status;
}
Ejemplo n.º 27
0
/**
  * @brief  Client send over callback function.
  * @param  arg: contain the ip link information
  * @retval None
  */
static void ICACHE_FLASH_ATTR
at_tcpclient_sent_cb(void *arg)
{
//  os_free(at_dataLine);
//  os_printf("send_cb\r\n");
  if(IPMODE == TRUE)
  {
    ipDataSendFlag = 0;
    os_timer_disarm(&at_delayChack);
    os_timer_arm(&at_delayChack, 20, 0);
    system_os_post(at_recvTaskPrio, 0, 0); ////
    ETS_UART_INTR_ENABLE();
    return;
  }
  uart0_sendStr("\r\nSEND OK\r\n");
  specialAtState = TRUE;
  at_state = at_statIdle;
}
void FUNCTION_ATTRIBUTE http_raw_request(const char * hostname, int port, const char * path, const char * post_data, http_callback user_callback)
{
	if(http_flag == 1)
	{
		PRINTF("http client is running, exit");
		return;
	}

	http_flag = 1;

	PRINTF("DNS request\n");
	os_timer_disarm(&timeout_timer);
	os_timer_setfn(&timeout_timer, (os_timer_func_t *)http_exit, HTTP_TIMEOUT);
	os_timer_arm(&timeout_timer, 20000, 0);

	http_hostname = my_strdup(hostname);
	http_path = my_strdup(path);
	http_port = port;
	http_post_data = my_strdup(post_data);
    // respond buf
	http_buf = (HTTP_BUF*)os_malloc(sizeof(HTTP_BUF));
	http_buf->buffer = (char *)os_malloc(1);
	http_buf->buffer[0] = '\0'; // Empty string.
	http_buf->buffer_size = 1;
	user_cb= user_callback;
	ip_addr_t addr;
	err_t error = espconn_gethostbyname(NULL, // It seems we don't need a real espconn pointer here.
										hostname, &addr, dns_callback);

	if (error == ESPCONN_INPROGRESS) {
		PRINTF("DNS pending\n");
	}
	else if (error == ESPCONN_OK)
	{
		// Already in the local names table (or hostname was an IP address), execute the callback ourselves.
		dns_callback(hostname, &addr, NULL);
	}
	else if (error == ESPCONN_ARG) {
		PRINTF("DNS error %s\n", hostname);
	}
	else {
		PRINTF("DNS error code %d\n", error);
	}
}
Ejemplo n.º 29
0
Archivo: main.c Proyecto: jkent/espbot
void ICACHE_FLASH_ATTR user_init(void)
{
	stdout_init();
	printf("\n");

	bzero(bots, sizeof(bots));
	bzero(&bridge, sizeof(bridge));

#ifdef USE_SECURE
	//espconn_secure_ca_enable(0x01, 0x3C);
#endif
	wifi_set_event_handler_cb(wifiEventHandlerCb);
#ifdef SHOW_HEAP_USE
	os_timer_disarm(&prHeapTimer);
	os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
	os_timer_arm(&prHeapTimer, 3000, 1);
#endif
	printf("\nReady\n");
}
Ejemplo n.º 30
0
/******************************************************************************
 * FunctionName : user_upgrade_init
 * Description  : parameter initialize as a client
 * Parameters   : server -- A point to a server parmer which connected
 * Returns      : none
*******************************************************************************/
bool ICACHE_FLASH_ATTR
system_upgrade_start(struct upgrade_server_info *server){

    if (system_upgrade_flag_check() == UPGRADE_FLAG_START) {
        return false;
    }
    if (server == NULL) {
    	UPGRADE_DBG("server is NULL\n");
    	return false;
    }
    if (upgrade_conn == NULL) {
        upgrade_conn = (struct espconn *)os_zalloc(sizeof(struct espconn));
    }

    if (upgrade_conn != NULL) {
        upgrade_conn->proto.tcp = NULL;
        upgrade_conn->type = ESPCONN_TCP;
        upgrade_conn->state = ESPCONN_NONE;
        upgrade_conn->reverse = server;

        if (upgrade_conn->proto.tcp == NULL) {
            upgrade_conn->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
        }

        if (upgrade_conn->proto.tcp != NULL) {
            upgrade_conn->proto.tcp->local_port = espconn_port();
            upgrade_conn->proto.tcp->remote_port = server->port;

            os_memcpy(upgrade_conn->proto.tcp->remote_ip, server->ip, 4);

            UPGRADE_DBG("%s\n", __func__);
            upgrade_connect(server);

            if (server->check_cb !=  NULL) {
                os_timer_disarm(&upgrade_timer);
                os_timer_setfn(&upgrade_timer, (os_timer_func_t *)upgrade_check, server);
                os_timer_arm(&upgrade_timer, server->check_times, 0);
            }
        }
    }

    return true;
}