Пример #1
0
void setupwebpage_init(void)
{
int reset_count = 0;

while (!GPIO_INPUT_GET(LED_GPIO_4)) // Check to see if web page setup button is held low on powerup
	{
	INFO("*");
	++reset_count;
	os_delay_us(500000); // Half second tick
	if (reset_count > 6)
		{
		for (int i = 0; i < 5; i++) { os_delay_us(100000); digitalWrite(LED_GPIO_13, 1); os_delay_us(100000); digitalWrite(LED_GPIO_13, 0);}
		break;
		}
	}


if (reset_count < 6) // OK button not held down at power up, setup MQTT etc
	{

	wifiInit(STATION_MODE); // Only connect to the local network

	if (sysCfg.enable_webpage_control)
		{
		INFO("Setting up for normal MQTT Operation\r");
		builtInUrls[0].cgiArg = "/led.tpl";
		httpdInit(builtInUrls, 80);
		}

	INFO("ESP8266 in STA mode configured.\r\n");

	// Setup a timer to initialise the mqtt system 5 seconds after a wifi connection is established
	os_timer_disarm(&MQTTlogontimer);
	os_timer_setfn(&MQTTlogontimer, MQTTLogonTimerCb, NULL);
	os_timer_arm(&MQTTlogontimer, 5000, 1);
	allow_mqtt_init = 1; // Allow the MQTT system to connect
	}
else
	{
	//struct softap_config apConfig;
	INFO("Setting up for Web Page Configuration\r");

	httpdInit(builtInUrls, 80);
	wifiInit(STATIONAP_MODE); // Connect to the local network

	//wifi_softap_get_config(&apConfig);
	}

}
Пример #2
0
void user_init(void) {
	stdoutInit();
	ioInit();
	httpdInit(builtInUrls, 80);
	dnsserver_init();
	os_printf("\nReady\n");
}
Пример #3
0
/*** Main function ***/
void ICACHE_FLASH_ATTR user_init() {
	uart_div_modify(0, UART_CLK_FREQ / BAUD);
	os_printf("Startup from %d...\r\n", system_get_rst_info()->reason);
	gpio_init();
	ap_init();

	// HTTPD
	espFsInit((void*)(webpages_espfs_start));
	httpdInit(builtInUrls, 80);

	// Set GPIO2 (DCF77 pin) to input, disable pullup
	gpio_output_set(0, 0, 0, 2);
	PIN_PULLUP_DIS(PERIPHS_IO_MUX_GPIO2_U);

	// DCF77 read timer
	os_timer_disarm(&dcf_read_timer);
	os_timer_setfn(&dcf_read_timer, (os_timer_func_t *) dcf_read_timer_cb, NULL);
	os_timer_arm(&dcf_read_timer, 5, 1);

	// Second increase timer
	os_timer_disarm(&time_inc_timer);
	os_timer_setfn(&time_inc_timer, (os_timer_func_t *) time_inc_timer_cb, NULL);
	os_timer_arm(&time_inc_timer, 1000, 1);

	// DCF77 decode timer: decide wheter 1 or 0
	dcf_decode_timer_adjust();

	os_printf(" completed!\r\n\r\n");
	system_os_task(loop, user_procTaskPrio, user_procTaskQueue, user_procTaskQueueLen);
	system_os_post(user_procTaskPrio, 0, 0);
}
Пример #4
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
  wifi_station_set_auto_connect(FALSE); 
	stdoutInit();
  CFG_Load();
	ioInit();	     
  
  MAIN_DEBUG("\nInitialise ENC stack, dhcp if requested\n");	
  stack_init();  

  /* This DNS is only for the wifi interface, as wired never acts as an 'AP' */
  captdnsInit(); 

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
  #ifdef ESPFS_POS
    espFsInit((void*)(0x40200000 + ESPFS_POS));
  #else
    espFsInit((void*)(webpages_espfs_start));
  #endif
  httpdInit(builtInUrls, 80);
  #ifdef SHOW_HEAP_USE
    os_timer_disarm(&prHeapTimer);
    os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
    os_timer_arm(&prHeapTimer, 3000, 1);
  #endif
  os_timer_disarm(&websockTimer);
  os_timer_setfn(&websockTimer, websockTimerCb, NULL);
  os_timer_arm(&websockTimer, 1000, 1);
  
  os_printf("\nReady\n");	
}
Пример #5
0
void ICACHE_FLASH_ATTR user_init(void)
{
	uart0_init(BIT_RATE_74880);

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
	espFsInit((void*)(0x40200000 + ESPFS_POS));
	httpdInit(builtInUrls, 80);
#ifdef SHOW_HEAP_USE
	os_timer_disarm(&prHeapTimer);
	os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
	os_timer_arm(&prHeapTimer, 3000, 1);
#endif

	init_relay();

	os_timer_disarm(&startup_timer);
	os_timer_setfn(&startup_timer, (os_timer_func_t *)onesec, (void *)0);
	os_timer_arm(&startup_timer, 1000, 1);

	os_timer_disarm(&delayed_start_timer);
	os_timer_setfn(&delayed_start_timer, (os_timer_func_t *)delayed_start, (void *)0);
	os_timer_arm(&delayed_start_timer, 500, 1);

	load_config();

	os_printf("running\n");

}
Пример #6
0
// Main routine, initialize some basic stuff
void ICACHE_FLASH_ATTR user_init(void)
 {
  // Init some stuff
  stdoutInit();
  batteryInit();
  configInit();
  configLoad();

  // Check if wifi mode is correct
  configCheckWifiMode();

  // Measure battery voltage
  batteryMeasureVoltage();
  if(!batteryCheckVoltage())
   {
    // Voltage too low, go to sleep mode!
    sleepmode();
   }

  // 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
  // where image is written in flash that is defined in Makefile.
  espFsInit((void*)(0x40200000 + ESPFS_POS));
  httpdInit(builtInUrls, 80);

  // Register callback
  system_init_done_cb(init_done);

  os_printf("Ready\n");
 }
Пример #7
0
void initWebserver() {
  
  httpdInit(builtInUrls, 80);
  
  //os_timer_disarm(&websockTimer);
  //os_timer_setfn(&websockTimer, websockTimerCb, NULL);
  //os_timer_arm(&websockTimer, 1000, 1);
  os_printf("Webserver init ready\n");  
}
Пример #8
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*");
  // 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");
    
  // Init SNTP service
  cgiServicesSNTPInit();
#ifdef MQTT
  NOTICE("initializing MQTT");
  mqtt_client_init();
#endif
  NOTICE("initializing user application");
  app_init();
  NOTICE("Waiting for work to do...");
}
Пример #9
0
/************************************************
*	name:			user_init
*	parameters:		none
*	return value:	none
*	purpose:		main logic
************************************************/
void user_init(void)
{	
	/* initialization */
	struct softap_config 	tWifiSettings = { 0 };
	uint8 					puMacAddress[6] = { 0 };

	os_memset((void *)&tWifiSettings, 0, sizeof(tWifiSettings));

	wifi_softap_get_config(&tWifiSettings);
	
	/* retrieve mac address */
	wifi_get_macaddr(1, puMacAddress);
	
	/* append to ssid name */
	memcpy(tWifiSettings.ssid, HOTSPOT_SSID_STRING, sizeof(HOTSPOT_SSID_STRING));

	os_sprintf(tWifiSettings.ssid + sizeof(HOTSPOT_SSID_STRING) - 1, "%x%x%x%x%x%x", puMacAddress[0],
							  												  	 	 puMacAddress[1],
							  												  	 	 puMacAddress[2],
							  												  	 	 puMacAddress[3],
							  												  	 	 puMacAddress[4],
							  												  	 	 puMacAddress[5]);
	/* set password */
	memcpy(tWifiSettings.password, HOTSPOT_PASSWORD_STRING, os_strlen(HOTSPOT_PASSWORD_STRING));
	
	/* update other settings */
	tWifiSettings.authmode = AUTH_WPA_WPA2_PSK;
	tWifiSettings.ssid_len = 0;
	tWifiSettings.channel = 6;
	tWifiSettings.max_connection = 4;
	
	/* update wifi configuration */
	wifi_softap_set_config(&tWifiSettings);
	
	/* initialize stdout */
	stdoutInit();
	
	/* initialize IOs */
	ioInit();
	
	/* initialize server */
	httpdInit(g_ptSupportedUrls, 80);
	
#ifdef USER_MAIN_DEBUG
	os_printf("user_init: ready; partition %d\n", system_upgrade_userbin_check());
#endif
}
Пример #10
0
//Main routine. Initialize stdout, the I/O and the webserver and we're done.
void user_init(void) {
// HTTPD
	stdoutInit();
	ioInit();
	httpdInit(builtInUrls, 80);
//MQTT
	uart_init(115200, 115200);
	CFG_Load();
	sleepms(1000);

	MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL);
	//MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0);
	MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1);
	//MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1);

//	MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0);
	MQTT_OnConnected(&mqttClient, mqttConnectedCb);
	MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
	MQTT_OnPublished(&mqttClient, mqttPublishedCb);
	MQTT_OnData(&mqttClient, mqttDataCb);

	INFO("device_ID:%s\r\n",sysCfg.device_id);
	INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host);
//DS18B20 timers
	os_timer_disarm(&ds18b20_timer);
	os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0);
	os_timer_arm(&ds18b20_timer, DELAY, 1);

//NTP timers
		ntp_get_time();
		os_timer_disarm(&NTP_timer);
		os_timer_setfn(&NTP_timer, (os_timer_func_t *)ntp_get_time, (void *)0);
		os_timer_arm(&NTP_timer, NTPDELAY, 1);

// initialize GPIO2
	PIN_FUNC_SELECT(PIN_GPIO2_MUX, PIN_GPIO2_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO2, 0);
	INFO("GPIO2 set to OFF\r\n");

	WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb);

	os_printf("\nReady\n");
}
Пример #11
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");
}
Пример #12
0
void user_init(void) {
	stdout_init();
	io_init();
	dht_init(SENSORTYPE, POOLTIME);

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS
	espFsInit((void*)(0x40200000 + ESPFS_POS));
#else
	espFsInit((void*)(webpages_espfs_start));
#endif
	httpdInit(builtInUrls, 80);

        wifi_init();
	config_init();	
        action_init();
	os_printf("\nESP Ready\n");
}
Пример #13
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");
}
Пример #14
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
	stdoutInit();
	ioInit();
	captdnsInit();

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS
	espFsInit((void*)(0x40200000 + ESPFS_POS));
#else
	espFsInit((void*)(webpages_espfs_start));
#endif
	httpdInit(builtInUrls, 80);
#ifdef SHOW_HEAP_USE
	os_timer_disarm(&prHeapTimer);
	os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL);
	os_timer_arm(&prHeapTimer, 3000, 1);
#endif
	os_printf("\nReady\n");
}
Пример #15
0
//Main routine. Initialize stdout, the I/O, filesystem and the webserver and we're done.
void user_init(void) {
	mmInit(mmData);
	//Redirect stdout to websocket
	os_install_putc1((void *)stdoutPutcharWs);
	ioInit();
	captdnsInit();
	telnetInit(333);

	// 0x40200000 is the base address for spi flash memory mapping, ESPFS_POS is the position
	// where image is written in flash that is defined in Makefile.
#ifdef ESPFS_POS
	espFsInit((void*)(0x40200000 + ESPFS_POS));
#else
	espFsInit((void*)(webpages_espfs_start));
#endif
	httpdInit(builtInUrls, 80);
	os_timer_disarm(&websockTimer);
	os_timer_setfn(&websockTimer, websockTimerCb, NULL);
	os_timer_arm(&websockTimer, 1000, 1);
	os_printf("\nReady\n");
	wifi_set_sleep_type(LIGHT_SLEEP_T);
}
Пример #16
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    // NODE_DBG("SDK version:%s\n", system_get_sdk_version());
    // system_print_meminfo();
    // os_printf("Heap size::%d.\n",system_get_free_heap_size());
    // os_delay_us(50*1000);   // delay 50ms before init uart

//#ifdef DEVELOP_VERSION
//    uart_init(BIT_RATE_74880, BIT_RATE_74880);
//#else
    uart_init(BIT_RATE_9600, BIT_RATE_9600);
//#endif
    // uart_init(BIT_RATE_115200, BIT_RATE_115200);
    
    #ifndef NODE_DEBUG
    system_set_os_print(0);
    #endif
    
    //espconn_tcp_set_max_con(2);
    httpdInit(80);
    system_init_done_cb(nodemcu_init);
}
Пример #17
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));
}
Пример #18
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...");
}
Пример #19
0
//Main routine
void ICACHE_FLASH_ATTR user_init(void) {

	stdoutInit();	
	os_delay_us(100000);
	CFG_Load();
	ioInit();
	
	WIFI_Connect(wifiConnectCb);
	
	httpdInit(builtInUrls, sysCfg.httpd_port);
	
	if(sysCfg.ntp_enable==1) {
		sntp_init(sysCfg.ntp_tz);	//timezone
	}
	
	if(sysCfg.mqtt_enable==1) {
		MQTT_InitConnection(&mqttClient, (uint8_t *)sysCfg.mqtt_host, sysCfg.mqtt_port, sysCfg.mqtt_use_ssl );
		MQTT_InitClient(&mqttClient, (uint8_t *)sysCfg.mqtt_devid, (uint8_t *)sysCfg.mqtt_user, (uint8_t *)sysCfg.mqtt_pass, sysCfg.mqtt_keepalive,1);
		MQTT_OnConnected(&mqttClient, mqttConnectedCb);
		MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
		MQTT_OnPublished(&mqttClient, mqttPublishedCb);		
		MQTT_OnData(&mqttClient, mqttDataCb);
		
	}
	
	if(sysCfg.sensor_dht22_enable) 
		DHTInit(SENSOR_DHT22, 30000);
		
	if(sysCfg.sensor_ds18b20_enable) 
		ds_init(30000);

	broadcastd_init();

	thermostat_init(30000);

/*
	//Netbios to set the name
	struct softap_config wiconfig;
	os_memset(netbios_name, ' ', sizeof(netbios_name)-1);
	if(wifi_softap_get_config(&wiconfig)) {
		int i;
		for(i = 0; i < sizeof(netbios_name)-1; i++) {
			if(wiconfig.ssid[i] < ' ') break;
			netbios_name[i] = wiconfig.ssid[i];
		};
	}
	else os_sprintf(netbios_name, "ESP8266");
	netbios_name[sizeof(netbios_name)-1]='\0';
	netbios_init();
*/
		
	os_printf("\nRelay Board Ready\n");	
	os_printf("Free heap size:%d\n",system_get_free_heap_size());

	
#ifdef CGIPWM_H	
	//Mind the PWM pin!! defined in pwm.h
	duty=0;
	pwm_init( 50, &duty);
	pwm_set_duty(duty, 0);
    pwm_start();
#endif
	
	//OLEDInit();
	
}
Пример #20
0
//Main routine. Initialize stdout, the I/O and the webserver and we're done.
void httpd_user_init(void) {
	httpdInit(builtInUrls, 80);
	INFO("\nReady\n");
}
Пример #21
0
/*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




}
Пример #22
0
//Main routine. Initialize stdout, the I/O and the webserver and we're done.
void user_init(void) {
// my stuff
	dBR_BOILER_SET=65; // default setting 65C boiler temperature on reboot
	dBR_TEMP_ROOM_SET=18; // default setting 18C room temperature on reboot
	dBR_HUMIDITY_SET=60; // default setting 65% humidity target on reboot
	dBR_MODE=2; // default BR MODE is AUTO
	dDEVICE_MODE=1; // This mode defines if device uses remote (MQTT) management or uses local logics - 0 for remote, 1 for local mode. DEFAULT is 0 - remote

// HTTPD
	stdoutInit();
	ioInit();
	httpdInit(builtInUrls, 80);
//MQTT
	uart_init(115200, 115200);
	CFG_Load();
	sleepms(1000);

	MQTT_InitConnection(&mqttClient, sysCfg.mqtt_host, sysCfg.mqtt_port, SEC_NONSSL);
	//MQTT_InitConnection(&mqttClient, "192.168.11.122", 1880, 0);
	MQTT_InitClient(&mqttClient, sysCfg.device_id, sysCfg.mqtt_user, sysCfg.mqtt_pass, sysCfg.mqtt_keepalive, 1);
	//MQTT_InitClient(&mqttClient, "client_id", "user", "pass", 120, 1);

//	MQTT_InitLWT(&mqttClient, "/lwt", "offline", 0, 0);
	MQTT_OnConnected(&mqttClient, mqttConnectedCb);
	MQTT_OnDisconnected(&mqttClient, mqttDisconnectedCb);
	MQTT_OnPublished(&mqttClient, mqttPublishedCb);
	MQTT_OnData(&mqttClient, mqttDataCb);

	INFO("device_ID:%s\r\n",sysCfg.device_id);
	INFO("MQTTHOST:%s\r\n",sysCfg.mqtt_host);
//DS18B20 timers
	os_timer_disarm(&ds18b20_timer);
	os_timer_setfn(&ds18b20_timer, (os_timer_func_t *)ds18b20_cb, (void *)0);
	os_timer_arm(&ds18b20_timer, DELAY, 1);
// DHT22 initialize
	DHTInit(DHT22, DELAY);
	os_timer_disarm(&dht22_timer);
	os_timer_setfn(&dht22_timer, (os_timer_func_t *)dht22_cb, (void *)0);
	os_timer_arm(&dht22_timer, DELAY, 1);
// INPUT PIN initialize
	ETS_GPIO_INTR_DISABLE(); // Disable gpio interrupts
	ETS_GPIO_INTR_ATTACH(read_input_pin, 13); // GPIO13 interrupt handler
	PIN_FUNC_SELECT(PIN_GPIO13_MUX, PIN_GPIO13_FUNC);
	gpio_output_set(0, 0, 0, BIT13); // Set GPIO13 as input
	PIN_PULLUP_EN(PIN_GPIO13_MUX); // Enable pullup
	GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, BIT(13)); // Clear GPIO12 status
	gpio_pin_intr_state_set(GPIO_ID_PIN(13), GPIO_PIN_INTR_NEGEDGE); // Interrupt on NEGATIVE GPIO13 edge
	ETS_GPIO_INTR_ENABLE(); // Enable gpio interrupts
//	INFO("Input pin INITIALIZED ! ! !");

// initialize GPIO12
	PIN_FUNC_SELECT(PIN_GPIO12_MUX, PIN_GPIO12_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO12, 0);
//	INFO("GPIO12 set to OFF\r\n");
// initialize GPIO5
	GPIO_OUTPUT_SET(PIN_GPIO5, 0);
//	INFO("GPIO5 set to OFF\r\n");
// initialize GPIO14
	PIN_FUNC_SELECT(PIN_GPIO14_MUX, PIN_GPIO14_FUNC);
	GPIO_OUTPUT_SET(PIN_GPIO14, 0);
//	INFO("GPIO14 set to OFF\r\n");
	WIFI_Connect(sysCfg.sta_ssid, sysCfg.sta_pwd, wifiConnectCb);

	os_printf("\nReady\n");
}