Ejemplo n.º 1
0
void CommandHandler::procesStatusCommand(String commandLine, CommandOutput* commandOutput)
{
	debugf("StatusCommand entered");
	char tempBuf[64];
	commandOutput->printf("System information : ESP8266 Sming Framework\r\n");
	commandOutput->printf("Sming Framework Version : %s\r\n", SMING_VERSION);
	commandOutput->printf("ESP SDK version : ");
	commandOutput->print(system_get_sdk_version());
	commandOutput->printf("\r\n");
	commandOutput->printf("Time = ");
	commandOutput->printf(SystemClock.getSystemTimeString().c_str());
	commandOutput->printf("\r\n");
	commandOutput->printf("System Start Reason : %d\r\n", system_get_rst_info()->reason);
}
Ejemplo n.º 2
0
/**
 * Dump the ESP8266 restart information.
 * This is purely for debugging.
 * When an ESP8266 crashes, before it ends, it records its exception information.
 * This function retrieves that data and logs it.
 */
static void dumpRestart() {
  struct rst_info *rstInfo = system_get_rst_info();
  os_printf("Restart info:\n");
  os_printf("  reason:   %d=%s\n", rstInfo->reason, rst_codes[rstInfo->reason]);
  os_printf("  exccause: %x\n", rstInfo->exccause);
  os_printf("  epc1:     %x\n", rstInfo->epc1);
  os_printf("  epc2:     %x\n", rstInfo->epc2);
  os_printf("  epc3:     %x\n", rstInfo->epc3);
  os_printf("  excvaddr: %x\n", rstInfo->excvaddr);
  os_printf("  depc:     %x\n", rstInfo->depc);

  uint32_t fid = spi_flash_get_id();
  os_printf("Flash map %s, manuf 0x%02lX chip 0x%04lX\n", flash_maps[system_get_flash_size_map()],
    fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
}
Ejemplo n.º 3
0
void ICACHE_FLASH_ATTR init_done_cb(void)
{
    os_printf("\nSDK Init - Ok\nCurrent 'heap' size: %d bytes\n", system_get_free_heap_size());
#ifdef USE_WEB
	web_fini(inifname);
#endif
	switch(system_get_rst_info()->reason) {
	case REASON_SOFT_RESTART:
	case REASON_DEEP_SLEEP_AWAKE:
		break;
	default:
		New_WiFi_config(WIFI_MASK_ALL);
		break;
	}
}
Ejemplo n.º 4
0
extern "C" void user_init(void) {
    struct rst_info *rtc_info_ptr = system_get_rst_info();
    memcpy((void *) &resetInfo, (void *) rtc_info_ptr, sizeof(resetInfo));

    uart_div_modify(0, UART_CLK_FREQ / (115200));

    init();

    initVariant();

    cont_init(&g_cont);

    system_os_task(loop_task,
        LOOP_TASK_PRIORITY, g_loop_queue,
        LOOP_QUEUE_SIZE);

    system_init_done_cb(&init_done);
}
Ejemplo n.º 5
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
	// init gpio pins used to reset&reprogram attached microcontrollers
	gpio_init();
	// put MCU into reset in case it interferes with serial-programming of the esp8266
	//GPIO_OUTPUT_SET(MCU_RESET, 0);
	// init UART
	uart_init(BIT_RATE_115200, BIT_RATE_115200);
	// say hello (leave some time to cause break in TX after boot loader's msg
	os_delay_us(10000L);
# define VERS_STR_STR(V) #V
# define VERS_STR(V) VERS_STR_STR(V)
	os_printf("\n\nInitializing esp-link\n" VERS_STR(VERSION) "\n");
	//configWipe();
	if (configRestore()) os_printf("Flash config restored\n");
	else os_printf("*** Flash config restore failed, using defaults ***\n");
	// Status LEDs
	statusInit();
	serledInit();
	logInit();
	// Wifi
	wifiInit();
	// init the flash filesystem with the html stuff
	EspFsInitResult res = espFsInit(&_binary_espfs_img_start);
	os_printf("espFsInit(0x%08lx) returned %d\n", (uint32_t)&_binary_espfs_img_start, res);
	// mount the http handlers
	httpdInit(builtInUrls, 80);
	// init the wifi-serial transparent bridge (port 23)
	serbridgeInit(23);
	uart_add_recv_cb(&serbridgeUartCb);
#ifdef SHOW_HEAP_USE
	os_timer_disarm(&prHeapTimer);
	os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
	os_timer_arm(&prHeapTimer, 3000, 1);
#endif

	struct rst_info *rst_info = system_get_rst_info();
	os_printf("Reset cause: %d=%s\n", rst_info->reason, rst_codes[rst_info->reason]);
	os_printf("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x\n",
			rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
			rst_info->excvaddr, rst_info->depc);

	os_printf("** esp-link ready\n");
}
Ejemplo n.º 6
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
	// get the flash config so we know how to init things
	//configWipe(); // uncomment to reset the config for testing purposes
	bool restoreOk = configRestore();
	// init gpio pin registers
	gpio_init();
	// init UART
	uart_init(flashConfig.baud_rate, 115200);
	logInit(); // must come after init of uart
	// say hello (leave some time to cause break in TX after boot loader's msg
	os_delay_us(10000L);
	os_printf("\n\n** %s\n", esp_link_version);
	os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*");
	// Status LEDs
	statusInit();
	serledInit();
	// Wifi
	wifiInit();
	// init the flash filesystem with the html stuff
	espFsInit(&_binary_espfs_img_start);
	//EspFsInitResult res = espFsInit(&_binary_espfs_img_start);
	//os_printf("espFsInit %s\n", res?"ERR":"ok");
	// mount the http handlers
	httpdInit(builtInUrls, 80);
	// init the wifi-serial transparent bridge (port 23)
	serbridgeInit(23);
	uart_add_recv_cb(&serbridgeUartCb);
#ifdef SHOW_HEAP_USE
	os_timer_disarm(&prHeapTimer);
	os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
	os_timer_arm(&prHeapTimer, 10000, 1);
#endif

	struct rst_info *rst_info = system_get_rst_info();
	os_printf("Reset cause: %d=%s\n", rst_info->reason, rst_codes[rst_info->reason]);
	os_printf("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x\n",
			rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
			rst_info->excvaddr, rst_info->depc);
	os_printf("Flash map %d, chip %08X\n", system_get_flash_size_map(), spi_flash_get_id());

	os_printf("** esp-link ready\n");
}
Ejemplo n.º 7
0
void ICACHE_FLASH_ATTR publishDeviceReset(char *version, int lastAction) {
	if (checkClient("publishDeviceReset")) {
		int idx;
		char *topic = (char *) os_zalloc(100);
		char *data = (char *) os_zalloc(200);
		if (!checkAlloc(topic, data)) return;

		os_sprintf(topic, "/Raw/%10s/reset", sysCfg.device_id);
		os_sprintf(data,
				"{\"Name\":\"%s\", \"Location\":\"%s\", \"Version\":\"%s\", \"Reason\":%d, \"LastAction\":%d}",
				sysCfg.deviceName, sysCfg.deviceLocation, version, system_get_rst_info()->reason,
				lastAction);
		if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, false))
			printMQTTstate();
		TESTP("%s=>%s\n", topic, data);
		checkMinHeap();
		os_free(topic);
		os_free(data);
	}
}
Ejemplo n.º 8
0
// Telenet info command
void EspInfoCommand(String commandLine  ,CommandOutput* commandOutput)
{
	commandOutput->printf("You entered : '");
	commandOutput->printf(commandLine.c_str());
	commandOutput->printf("'\r\n");

	Serial.println("---------------------");
#ifdef DS_18
	commandOutput->printf("\r\n********** DS18B20 *********\r\n");
#endif
#ifdef BMP_180
	commandOutput->printf("\r\n********** BMP180 **********\r\n");
#endif
#ifdef DTH_22
	commandOutput->printf("\r\n********** DHT22  **********\r\n");
#endif
	commandOutput->printf("\r\nMy IP  : ");
	commandOutput->printf("%s - %s\r\n",WifiStation.getIP().toString().c_str(),WifiStation.getMAC().c_str());
	commandOutput->printf("My gate: ");
	commandOutput->printf("%s\r\n",WifiStation.getNetworkGateway().toString().c_str());
	commandOutput->printf("My SSID: ");
	commandOutput->printf("%s\r\n\r\n",WifiStation.getSSID().c_str());
	commandOutput->printf("LastErr Keil: ");
	commandOutput->printf("%x\r\n",LastErr[0]);
	commandOutput->printf("LastErr Thing: ");
	commandOutput->printf("%x\r\n\r\n",LastErr[1]);
	commandOutput->printf("Sending counter     : ");
	commandOutput->printf("%d\r\n",sensorValue);
	commandOutput->printf("System start reason : %d\r\n", system_get_rst_info()->reason);
	commandOutput->printf("System reset time   : %s\r\n",SdateTime.toFullDateTimeString().c_str());
	commandOutput->printf("Aktual date and time: %s\r\n\r\n",SystemClock.getSystemTimeString().c_str());

	if (procTimer.isStarted())
		commandOutput->printf("Timer ON\r\n");
	else
		commandOutput->printf("Timer OFF\r\n");

	commandOutput->printf("Timer interval: %d\r\n\r\n",procTimer.getIntervalMs());


}
Ejemplo n.º 9
0
//Init function 
void ICACHE_FLASH_ATTR
user_init()
{
    struct rst_info *reset_info;

    PRINTF("wake\r\n");

    GPIO_DIS_OUTPUT(GPIO_SWITCH);
    
    reset_info = system_get_rst_info();

    PRINTF("rst reason: %d\r\n", reset_info->reason);

    if(reset_info->reason == REASON_DEEP_SLEEP_AWAKE) {
        state = STATE_LOAD_PERSIST;
    } else {
        state = STATE_INIT_PERSIST;
    }

    os_timer_disarm(&timer);
    os_timer_setfn(&timer, (os_timer_func_t *)timer_fn, NULL);
    os_timer_arm(&timer, MIN_LOOP_TIMER_MS, false);
    
/*

    // read high-frequency sensor
    // compare sensor w/ persistent value
    // if different:
    //   connect to ap
    //   notify server
    //   on success change persistent value
    //   deep sleep
    
    state = STATE_HF_READ;

    //Start os task
    system_os_task(loop, user_procTaskPrio,user_procTaskQueue, user_procTaskQueueLen);

    system_os_post(user_procTaskPrio, 0, 0 ); */
}
Ejemplo n.º 10
0
void ICACHE_FLASH_ATTR publishDeviceReset(char *version, int lastAction) {
	if (mqttIsConnected()) {
		char *topic = (char *) os_zalloc(50);
		char *data = (char *) os_zalloc(200);
		int idx;
		if (topic == NULL || data == NULL) {
			ERRORP("malloc err %s/%s\n", topic, data);
			startFlash(-1, 50, 50); // fast
			return;
		}

		os_sprintf(topic, "/Raw/%10s/reset", sysCfg.device_id);
		os_sprintf(data,
			"{\"Name\":\"%s\", \"Location\":\"%s\", \"Version\":\"%s\", \"Reason\":%d, \"LastAction\":%d}",
			sysCfg.deviceName, sysCfg.deviceLocation, version, system_get_rst_info()->reason, lastAction);
		if (!MQTT_Publish(mqttClient, topic, data, os_strlen(data), 0, false))
			printMQTTstate();
		INFOP("%s=>%s\n", topic, data);
		checkMinHeap();
		os_free(topic);
		os_free(data);
	}
}
Ejemplo n.º 11
0
// Main routine to initialize esp-link.
void ICACHE_FLASH_ATTR user_init(void) {
  // Init gpio pin registers
  gpio_init();
  gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
  // init UART
  uart_init(115200);
  // Say hello (leave some time to cause break in TX after boot loader's msg
  os_delay_us(10000L);
  NOTICE("\n\n** %s\n", esp_link_version);
  // Wifi
  wifiInit();

  // mount the http handlers
  httpdInit(builtInUrls, 80);

  struct rst_info *rst_info = system_get_rst_info();
  NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]);
  NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x",
    rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
    rst_info->excvaddr, rst_info->depc);
  uint32_t fid = spi_flash_get_id();
  NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()],
      fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
}
Ejemplo n.º 12
0
void init()
{
	//debugf("Memory info: flashID %d size: %d\n",spi_flash_get_id(),fs_size());
	
	System.setCpuFrequency(eCF_160MHz);

	Serial.systemDebugOutput(false); // Disable debug output
	Serial.print("rst_info.reason: ");
	Serial.println(system_get_rst_info()->reason);
	Serial.print("rst_info.depc ");
	Serial.println(system_get_rst_info()->depc, HEX);
	Serial.print("rst_info.epc1 ");
	Serial.println(system_get_rst_info()->epc1, HEX);
	Serial.print("rst_info.epc2 ");
	Serial.println(system_get_rst_info()->epc2, HEX);
	Serial.print("rst_info.epc3 ");
	Serial.println(system_get_rst_info()->epc3, HEX);
	Serial.print("rst_info.exccause ");
	Serial.println(system_get_rst_info()->exccause, HEX);
	Serial.print("rst_info.excvaddr ");
	Serial.println(system_get_rst_info()->excvaddr, HEX);

	//WDT.enable(false); // First (but not the best) option: fully disable watch dog timer
	system_soft_wdt_stop();

	// You can change pins:
	//Wire.pins(12, 14); // SCL, SDA
	Wire.pins(4, 5);
	Wire.begin();

	WifiStation.enable(true);
	WifiStation.config(WIFI_SSID, WIFI_PWD);
	WifiAccessPoint.enable(false);

	// Run our method when station was connected to AP
	WifiStation.waitConnection(connectOk);
}
irom void stats_generate(uint16_t size, char *dst)
{
	const struct rst_info *rst_info;
	struct station_config sc_default, sc_current;
	uint32_t system_time;

	system_time = system_get_time();
	rst_info = system_get_rst_info();

	wifi_station_get_config_default(&sc_default);
	wifi_station_get_config(&sc_current);

	snprintf(dst, size,
			"> firmware version date: %s\n"
			"> system id: %u\n"
			"> spi flash id: %u\n"
			"> cpu frequency: %u\n"
			"> flash map: %s\n"
			"> reset cause: %s\n"
			">\n"
			"> heap free: %u bytes\n"
			"> system clock: %u.%06u s\n"
			"> uptime: %u %02d:%02d:%02d\n"
			"> real time: %u %02d:%02d:%02d\n"
			"> size of config: %u\n"
			">\n"
			"> int uart rx: %u\n"
			"> int uart tx: %u\n"
			"> timer_fast fired: %u\n"
			"> timer_slow fired: %u\n"
			"> timer_second fired: %u\n"
			"> background task: %u\n"
			">\n"
			"> default ssid: %s, passwd: %s\n"
			"> current ssid: %s, passwd: %s\n"
			"> phy mode: %s\n"
			"> sleep mode: %s\n"
			"> channel: %u\n"
			"> signal strength: %d dB\n",
			__DATE__ " " __TIME__,
			system_get_chip_id(),
			spi_flash_get_id(),
			system_get_cpu_freq(),
			flash_map[system_get_flash_size_map()],
			reset_map[rst_info->reason],
			system_get_free_heap_size(),
			system_time / 1000000,
			system_time % 1000000,
			ut_days, ut_hours, ut_mins, ut_secs,
			rt_days, rt_hours, rt_mins, rt_secs,
			sizeof(config_t),
			stat_uart_rx_interrupts,
			stat_uart_tx_interrupts,
			stat_timer_fast,
			stat_timer_slow,
			stat_timer_second,
			stat_background_task,
			sc_default.ssid, sc_default.password,
			sc_current.ssid, sc_current.password,
			phy[wifi_get_phy_mode()],
			slp[wifi_get_sleep_type()],
			wifi_get_channel(),
			wifi_station_get_rssi());
}
Ejemplo n.º 14
0
STATIC mp_obj_t machine_reset_cause(void) {
    return MP_OBJ_NEW_SMALL_INT(system_get_rst_info()->reason);
}
Ejemplo n.º 15
0
// Main routine to initialize esp-link.
void user_init(void) {
  // get the flash config so we know how to init things
//  configWipe(); // uncomment to reset the config for testing purposes
  bool restoreOk = configRestore();
  // init gpio pin registers
  gpio_init();
  gpio_output_set(0, 0, 0, (1<<15)); // some people tie it to GND, gotta ensure it's disabled
  // init UART
  uart_init(flashConfig.baud_rate, 115200);
  logInit(); // must come after init of uart
  // say hello (leave some time to cause break in TX after boot loader's msg
  os_delay_us(10000L);
  os_printf("\n\n** %s\n", esp_link_version);
  os_printf("Flash config restore %s\n", restoreOk ? "ok" : "*FAILED*");

#if defined(STA_SSID) && defined(STA_PASS)
  int x = wifi_get_opmode() & 0x3;
  if (x == 2) {
    // we only force the STA settings when a full flash of the module has been made, which
    // resets the wifi settings not to have anything configured
    struct station_config stconf;
    wifi_station_get_config(&stconf);

    if (os_strlen((char*)stconf.ssid) == 0 && os_strlen((char*)stconf.password) == 0) {
      os_strncpy((char*)stconf.ssid, VERS_STR(STA_SSID), 32);
      os_strncpy((char*)stconf.password, VERS_STR(STA_PASS), 64);
#ifdef CGIWIFI_DBG
      os_printf("Wifi pre-config trying to connect to AP %s pw %s\n",
          (char*)stconf.ssid, (char*)stconf.password);
#endif
      wifi_set_opmode(3); // sta+ap, will switch to sta-only 15 secs after connecting
      stconf.bssid_set = 0;
      wifi_station_set_config(&stconf);
    }
  }
#endif

  // Status LEDs
  statusInit();
  serledInit();
  // Wifi
  wifiInit();

  // init the flash filesystem with the html stuff
  espFsInit(&_binary_espfs_img_start);
  //EspFsInitResult res = espFsInit(&_binary_espfs_img_start);
  //os_printf("espFsInit %s\n", res?"ERR":"ok");
  // mount the http handlers
  httpdInit(builtInUrls, 80);
  // init the wifi-serial transparent bridge (port 23)
  serbridgeInit(23, 2323);
  uart_add_recv_cb(&serbridgeUartCb);
#ifdef SHOW_HEAP_USE
  os_timer_disarm(&prHeapTimer);
  os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
  os_timer_arm(&prHeapTimer, 10000, 1);
#endif

  struct rst_info *rst_info = system_get_rst_info();
  NOTICE("Reset cause: %d=%s", rst_info->reason, rst_codes[rst_info->reason]);
  NOTICE("exccause=%d epc1=0x%x epc2=0x%x epc3=0x%x excvaddr=0x%x depc=0x%x",
    rst_info->exccause, rst_info->epc1, rst_info->epc2, rst_info->epc3,
    rst_info->excvaddr, rst_info->depc);
  uint32_t fid = spi_flash_get_id();
  NOTICE("Flash map %s, manuf 0x%02lX chip 0x%04lX", flash_maps[system_get_flash_size_map()],
      fid & 0xff, (fid&0xff00)|((fid>>16)&0xff));
  NOTICE("** esp-link ready");

  cgiServicesSNTPInit();

#ifdef MQTT
  NOTICE("initializing MQTT");
  mqtt_client_init();
#endif

  NOTICE("initializing user application");
  app_init();

  NOTICE("waiting for work to do...");
}
Ejemplo n.º 16
0
void user_rf_pre_init(void)
{
	reset_info = system_get_rst_info();
}
Ejemplo n.º 17
0
/******************************************************************************
 * FunctionName : user_esp_platform_init
 * Description  : device parame init based on espressif platform
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void ICACHE_FLASH_ATTR
user_esp_platform_init(void)
{

	os_sprintf(iot_version,"%s%d.%d.%dt%d(%s)",VERSION_TYPE,IOT_VERSION_MAJOR,\
	IOT_VERSION_MINOR,IOT_VERSION_REVISION,device_type,UPGRADE_FALG);
	os_printf("IOT VERSION = %s\n",iot_version);

	system_param_load(ESP_PARAM_START_SEC, 0, &esp_param, sizeof(esp_param));

	struct rst_info *rtc_info = system_get_rst_info();

	os_printf("reset reason: %x\n", rtc_info->reason);

	if (rtc_info->reason == REASON_WDT_RST ||
		rtc_info->reason == REASON_EXCEPTION_RST ||
		rtc_info->reason == REASON_SOFT_WDT_RST) {
		if (rtc_info->reason == REASON_EXCEPTION_RST) {
			os_printf("Fatal exception (%d):\n", rtc_info->exccause);
		}
		os_printf("epc1=0x%08x, epc2=0x%08x, epc3=0x%08x, excvaddr=0x%08x, depc=0x%08x\n",
				rtc_info->epc1, rtc_info->epc2, rtc_info->epc3, rtc_info->excvaddr, rtc_info->depc);
	}

	/***add by tzx for saving ip_info to avoid dhcp_client start****/
    struct dhcp_client_info dhcp_info;
    struct ip_info sta_info;
    system_rtc_mem_read(64,&dhcp_info,sizeof(struct dhcp_client_info));
	if(dhcp_info.flag == 0x01 ) {
		if (true == wifi_station_dhcpc_status())
		{
			wifi_station_dhcpc_stop();
		}
		sta_info.ip = dhcp_info.ip_addr;
		sta_info.gw = dhcp_info.gw;
		sta_info.netmask = dhcp_info.netmask;
		if ( true != wifi_set_ip_info(STATION_IF,&sta_info)) {
			os_printf("set default ip wrong\n");
		}
	}
    os_memset(&dhcp_info,0,sizeof(struct dhcp_client_info));
    system_rtc_mem_write(64,&dhcp_info,sizeof(struct rst_info));


#if AP_CACHE
    wifi_station_ap_number_set(AP_CACHE_NUMBER);
#endif

#if 0
    {
        char sofap_mac[6] = {0x16, 0x34, 0x56, 0x78, 0x90, 0xab};
        char sta_mac[6] = {0x12, 0x34, 0x56, 0x78, 0x90, 0xab};
        struct ip_info info;

        wifi_set_macaddr(SOFTAP_IF, sofap_mac);
        wifi_set_macaddr(STATION_IF, sta_mac);

        IP4_ADDR(&info.ip, 192, 168, 3, 200);
        IP4_ADDR(&info.gw, 192, 168, 3, 1);
        IP4_ADDR(&info.netmask, 255, 255, 255, 0);
        wifi_set_ip_info(STATION_IF, &info);

        IP4_ADDR(&info.ip, 10, 10, 10, 1);
        IP4_ADDR(&info.gw, 10, 10, 10, 1);
        IP4_ADDR(&info.netmask, 255, 255, 255, 0);
        wifi_set_ip_info(SOFTAP_IF, &info);
    }
#endif

    if (esp_param.activeflag != 1) {
#ifdef SOFTAP_ENCRYPT
        struct softap_config config;
        char password[33];
        char macaddr[6];

        wifi_softap_get_config(&config);
        wifi_get_macaddr(SOFTAP_IF, macaddr);

        os_memset(config.password, 0, sizeof(config.password));
        os_sprintf(password, MACSTR "_%s", MAC2STR(macaddr), PASSWORD);
        os_memcpy(config.password, password, os_strlen(password));
        config.authmode = AUTH_WPA_WPA2_PSK;

        wifi_softap_set_config(&config);
#endif
		
		wifi_station_set_hostname( HOST_NAME );
        wifi_set_opmode(STATION_MODE);
    }

#if SENSOR_DEVICE
    user_sensor_init(esp_param.activeflag);
#endif

#if 0
    if (wifi_get_opmode() != SOFTAP_MODE) {
        os_timer_disarm(&client_timer);
        os_timer_setfn(&client_timer, (os_timer_func_t *)user_esp_platform_check_ip, 1);
        os_timer_arm(&client_timer, 100, 0);
    }
	
	// 2015-12-27 
	single_key[0] = key_init_single( 12, PERIPHS_IO_MUX_MTDI_U, FUNC_GPIO12, NULL, GPIO_INTER);
	keys.key_num = 1;
	keys.single_key = single_key;
	key_init(&keys);
#endif
}
Ejemplo n.º 18
0
void ICACHE_FLASH_ATTR
supla_esp_gpio_init(void) {

	switch_cfgbtn_state_check = 0;
	switch_cfgbtn_last_state = -1;
	switch_cfgbtn_counter = 0;

	#if defined(USE_GPIO3) || defined(UART_SWAP)
		 system_uart_swap ();
	#endif

	ETS_GPIO_INTR_DISABLE();

	GPIO_PORT_INIT;

    #ifdef USE_GPIO16_INPUT
	gpio16_input_conf();
    #endif

	#ifdef USE_GPIO16_OUTPUT
	gpio16_output_conf();
	#endif


    #ifdef USE_GPIO3
	   PIN_FUNC_SELECT(PERIPHS_IO_MUX_U0RXD_U, FUNC_GPIO3);
	   PIN_PULLUP_DIS(PERIPHS_IO_MUX_U0RXD_U);
    #endif

    #ifdef BTN_PULLUP
        #if CFG_PORT == 0
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO0_U);
        #elif CFG_PORT == 2
          PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO2_U);
        #elif CFG_PORT == 4
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_GPIO4_U);
		#elif CFG_PORT == 12
	     PIN_PULLUP_EN(PERIPHS_IO_MUX_MTDI_U);
		#elif CFG_PORT == 13
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_MTCK_U);
		#elif CFG_PORT == 14
	      PIN_PULLUP_EN(PERIPHS_IO_MUX_MTMS_U);
       #endif
    #endif

    #ifdef LED_RED_PORT
      #if LED_RED_PORT != 16
	    gpio_pin_intr_state_set(GPIO_ID_PIN(LED_RED_PORT), GPIO_PIN_INTR_DISABLE);
      #endif
    #endif

    #ifdef LED_GREEN_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(LED_GREEN_PORT), GPIO_PIN_INTR_DISABLE);
    #endif

    #ifdef LED_BLUE_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(LED_BLUE_PORT), GPIO_PIN_INTR_DISABLE);
    #endif


    #ifdef RELAY1_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(RELAY1_PORT), GPIO_PIN_INTR_DISABLE);
    #endif

    #ifdef RELAY2_PORT
    gpio_pin_intr_state_set(GPIO_ID_PIN(RELAY2_PORT), GPIO_PIN_INTR_DISABLE);
    #endif

	#ifdef ZAM_INPUT1
	supla_esp_gpio_enable_input_port(ZAM_INPUT1);
	#endif

	#ifdef ZAM_INPUT2
	supla_esp_gpio_enable_input_port(ZAM_INPUT2);
	#endif

	ETS_GPIO_INTR_ENABLE();

	keys.key_num = 0;

	single_key[0] = key_init_single(CFG_PORT, supla_esg_gpio_cfg_pressed, supla_esg_gpio_manual_pressed);
	keys.key_num++;

    #if defined(BUTTON1_PORT) && defined(RELAY1_PORT)

		single_key[keys.key_num] = key_init_single(BUTTON1_PORT, NULL, supla_esg_gpio_button1_pressed);
		keys.key_num++;

    #endif

	#if defined(BUTTON1_PORT) && defined(RELAY1_PORT)

		single_key[keys.key_num] = key_init_single(BUTTON2_PORT, NULL, supla_esg_gpio_button2_pressed);
		keys.key_num++;

	#endif

	keys.single_key = single_key;
	keys.handler = supla_esp_key_intr_handler;

    #ifdef RELAY_STATE_RESTORE

		struct rst_info *rtc_info = system_get_rst_info();

		#ifdef RELAY1_PORT
			if ( rtc_info->reason == 0 ) {
				   supla_esp_gpio_relay1_hi(supla_esp_state.Relay1);
			}
		#endif

		#ifdef RELAY2_PORT
		    if ( rtc_info->reason == 0 ) {
			   supla_esp_gpio_relay2_hi(supla_esp_state.Relay2);
			}
		#endif

    #elif defined(RESET_RELAY_PORT)

		#ifdef RELAY1_PORT
		   supla_esp_gpio_relay1_hi(RELAY_INIT_VALUE);
		#endif

		#ifdef RELAY2_PORT
		   supla_esp_gpio_relay2_hi(RELAY_INIT_VALUE);
		#endif

    #endif

	key_init(&keys);


    GPIO_PORT_POST_INIT;

    supla_esp_gpio_init_time = system_get_time();

}