Example #1
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...");
}
Example #2
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");
}
Example #3
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");
}
Example #4
0
// Cgi to change choice of pin assignments
int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) {
  if (connData->conn==NULL) {
    return HTTPD_CGI_DONE; // Connection aborted
  }

  int8_t ok = 0;
  int8_t reset, isp, conn, ser;
  bool swap, rxpup;
  ok |= getInt8Arg(connData, "reset", &reset);
  ok |= getInt8Arg(connData, "isp", &isp);
  ok |= getInt8Arg(connData, "conn", &conn);
  ok |= getInt8Arg(connData, "ser", &ser);
  ok |= getBoolArg(connData, "swap", &swap);
  ok |= getBoolArg(connData, "rxpup", &rxpup);
  if (ok < 0) return HTTPD_CGI_DONE;

  char *coll;
  if (ok > 0) {
    // check whether two pins collide
    uint16_t pins = 0;
    if (reset >= 0) pins = 1 << reset;
    if (isp >= 0) {
      if (pins & (1<<isp)) { coll = "ISP/Flash"; goto collision; }
      pins |= 1 << isp;
    }
    if (conn >= 0) {
      if (pins & (1<<conn)) { coll = "Conn LED"; goto collision; }
      pins |= 1 << conn;
    }
    if (ser >= 0) {
      if (pins & (1<<ser)) { coll = "Serial LED"; goto collision; }
      pins |= 1 << ser;
    }
    if (swap) {
      if (pins & (1<<15)) { coll = "Uart TX"; goto collision; }
      if (pins & (1<<13)) { coll = "Uart RX"; goto collision; }
    } else {
      if (pins & (1<<1)) { coll = "Uart TX"; goto collision; }
      if (pins & (1<<3)) { coll = "Uart RX"; goto collision; }
    }

    // we're good, set flashconfig
    flashConfig.reset_pin = reset;
    flashConfig.isp_pin = isp;
    flashConfig.conn_led_pin = conn;
    flashConfig.ser_led_pin = ser;
    flashConfig.swap_uart = swap;
    flashConfig.rx_pullup = rxpup;
    os_printf("Pins changed: reset=%d isp=%d conn=%d ser=%d swap=%d rx-pup=%d\n",
	reset, isp, conn, ser, swap, rxpup);

    // apply the changes
    serbridgeInitPins();
    serledInit();
    statusInit();

    // save to flash
    if (configSave()) {
      httpdStartResponse(connData, 204);
      httpdEndHeaders(connData);
    } else {
      httpdStartResponse(connData, 500);
      httpdEndHeaders(connData);
      httpdSend(connData, "Failed to save config", -1);
    }
  }
  return HTTPD_CGI_DONE;

collision: {
    char buff[128];
    os_sprintf(buff, "Pin assignment for %s collides with another assignment", coll);
    errorResponse(connData, 400, buff);
    return HTTPD_CGI_DONE;
  }
}
Example #5
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...");
}