Exemplo n.º 1
0
static char * ICACHE_FLASH_ATTR readRx(RcvMsgBuff *rxBfr) {
	static int idx = 0;
	static char bfr[400];
	char c;

	ETS_UART_INTR_DISABLE();
	while (rxBfr->count > 0) {
		c = *(rxBfr->pReadPos);
		rxBfr->count--;
		rxBfr->pReadPos++;
        if (rxBfr->pReadPos == (rxBfr->pRcvMsgBuff + RX_BUFF_SIZE)) {
        	rxBfr->pReadPos = rxBfr->pRcvMsgBuff ;
        }
		if (c == '\r' || c == '\n') {
			if (idx > 0) { // Otherwise ignore blank line
				bfr[idx] = 0;
				idx = 0;
				ETS_UART_INTR_ENABLE();
				return bfr;
			}
		} else {
			if (idx < sizeof(bfr)-3) {
				bfr[idx++] = c;
			} else {
				ERRORP("Bfr overflow\n");
			}
		}
	}
    ETS_UART_INTR_ENABLE();
	return NULL;
}
Exemplo n.º 2
0
/**
  * @brief  Setup commad of set wifi mode.
  * @param  id: commad id number
  * @param  pPara: AT input param
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_setupCmdCwmode(uint8_t id, char *pPara)
{
  uint8_t mode;
  char temp[32];

  pPara++;
  mode = atoi(pPara);
  if(mode == at_wifiMode)
  {
    uart0_sendStr("no change\r\n");
    return;
  }
  if((mode >= 1) && (mode <= 3))
  {
    ETS_UART_INTR_DISABLE();
    wifi_set_opmode(mode);
    ETS_UART_INTR_ENABLE();
    at_backOk;
//    system_restart();
  }
  else
  {
    at_backError;
  }
}
Exemplo n.º 3
0
size_t uart_resize_rx_buffer(uart_t* uart, size_t new_size)
{
    if(uart == NULL || !uart->rx_enabled) {
        return 0;
    }
    if(uart->rx_buffer->size == new_size) {
        return uart->rx_buffer->size;
    }
    uint8_t * new_buf = (uint8_t*)malloc(new_size);
    if(!new_buf) {
        return uart->rx_buffer->size;
    }
    size_t new_wpos = 0;
    ETS_UART_INTR_DISABLE();
    while(uart_rx_available(uart) && new_wpos < new_size) {
        new_buf[new_wpos++] = uart_read_char(uart);
    }
    uint8_t * old_buf = uart->rx_buffer->buffer;
    uart->rx_buffer->rpos = 0;
    uart->rx_buffer->wpos = new_wpos;
    uart->rx_buffer->size = new_size;
    uart->rx_buffer->buffer = new_buf;
    free(old_buf);
    ETS_UART_INTR_ENABLE();
    return uart->rx_buffer->size;
}
Exemplo n.º 4
0
/**
  * @brief  Uart receive task.
  * @param  events: contain the uart receive data
  * @retval None
  */
static void ICACHE_FLASH_ATTR ///////
at_recvTask(os_event_t *events)
{
  
  uint8_t temp;

  while(READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S))
  {
    
    temp = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;     
      
    if (ser_count>64) ser_count = 0;
    ser[ser_count] = temp;
    ser_count++;
    ser[64] = ser_count;   
    feedwdt();
  }
  
  if(UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST))
  {
    WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR);
  }
  else if(UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_TOUT_INT_ST))
  {
    WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_TOUT_INT_CLR);
  }
  ETS_UART_INTR_ENABLE();
}
//Read from UART0(requires special uart.c!)
static void ICACHE_FLASH_ATTR recvTask(os_event_t *events)
{
	uint8_t c, i;
  char ch[1000];
  c = 0;
  i = 0;
  
  //uart0_tx_buffer("uart",4);
  
	while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S))
	{
		WRITE_PERI_REG(0X60000914, 0x73); //WTD
		c = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF; 
		
		ch[i] = c;
		i++;
  }

	if(UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST))
	{
		WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR);
	}
	else if(UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_TOUT_INT_ST))
	{
		WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_TOUT_INT_CLR);
	}
	ETS_UART_INTR_ENABLE();
	
	// send to Server if available
	if (pconn && i != 0) 
	{
	  espconn_sent(pconn, ch, i);
	}		
}
Exemplo n.º 6
0
/**
  * @brief  Setup commad of join to wifi ap.
  * @param  id: commad id number
  * @param  pPara: AT input param
  * @retval None
  */
static void ICACHE_FLASH_ATTR wifi_connect(char * ssid, char * password, char * bssid)
{
	char temp[64];
	struct station_config stationConf;
	int8_t len;
	connect_attempts++;
	//wifi_station_get_config(&stationConf);
	os_bzero(&stationConf, sizeof(struct station_config));
	os_memcpy(&stationConf.ssid, ssid, os_strlen(ssid));
	//os_memcpy(&stationConf.password, password, os_strlen(password));
	os_memcpy(&stationConf.bssid, bssid, 6);
	stationConf.bssid_set = 1;
    wifi_station_disconnect();
    os_printf("stationConf.ssid: -%s-\r\n", stationConf.ssid);
    os_printf("stationConf.password: -%s-\r\n", stationConf.password);

    ETS_UART_INTR_DISABLE();
    wifi_station_set_config(&stationConf);
    ETS_UART_INTR_ENABLE();
    wifi_station_connect();
    os_timer_disarm(&at_japDelayChack);
    os_timer_setfn(&at_japDelayChack, (os_timer_func_t *)at_japChack, NULL);
    os_timer_arm(&at_japDelayChack, 3000, 0);

}
Exemplo n.º 7
0
/**
 * Setting the ESP8266 station to connect to the AP (which is recorded)
 * automatically or not when powered on. Enable auto-connect by default.
 * @param autoConnect bool
 * @return if saved
 */
bool ESP8266WiFiSTAClass::setAutoConnect(bool autoConnect) {
    bool ret;
    ETS_UART_INTR_DISABLE();
    ret = wifi_station_set_auto_connect(autoConnect);
    ETS_UART_INTR_ENABLE();
    return ret;
}
Exemplo n.º 8
0
static void ICACHE_FLASH_ATTR recvTask(os_event_t *events)
{
	uint8_t i;

	while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S))
	{
		WRITE_PERI_REG(0X60000914, 0x73); //WTD
		uint16 length = 0;
		while ((READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) && (length<MAX_UARTBUFFER))
			uartbuffer[length++] = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
		for (i = 0; i < MAX_CONN; ++i)
			if (connData[i].conn) 
				espbuffsent(&connData[i], uartbuffer, length);		
	}

	if(UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST))
	{
		WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR);
	}
	else if(UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_TOUT_INT_ST))
	{
		WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_TOUT_INT_CLR);
	}
	ETS_UART_INTR_ENABLE();
}
Exemplo n.º 9
0
void user_init(void)
{
		ETS_UART_INTR_DISABLE();
		UART_SetBaudrate(UART0, BIT_RATE_9600);
		UART_ResetFifo(UART0);

		UART_SetBaudrate(UART1, BIT_RATE_115200);
		UART_ResetFifo(UART1);

		flash_param_init();
		flash_param = flash_param_get();

		emsRxBuf = allocateRcvMsgBuff();
		uart_init(BIT_RATE_9600, BIT_RATE_115200);

		rtc_clock_calibration = system_rtc_clock_cali_proc();			// get RTC clock period
		os_printf("rtc_clock_calibration: %0x\n", rtc_clock_calibration >>12 );
		os_printf("system_get_rtc_time:   %d\n", system_get_rtc_time());
		os_printf("system_get_time:       %d\n", system_get_time());

		serverInit(flash_param->port);

		wifi_set_sleep_type(LIGHT_SLEEP_T);
		system_os_task(recvTask, recvTaskPrio, recvTaskQueue, recvTaskQueueLen);

		ETS_UART_INTR_ENABLE();
}
Exemplo n.º 10
0
int ESP8266WiFiClass::disconnect(bool wifioff)
{
    struct station_config conf;
    *conf.ssid = 0;
    *conf.password = 0;
    ETS_UART_INTR_DISABLE();
    if (_persistent)
        wifi_station_set_config(&conf);
    else
        wifi_station_set_config_current(&conf);
    wifi_station_disconnect();
    ETS_UART_INTR_ENABLE();

    if(wifioff) {
        _useClientMode = false;

        if(_useApMode) {
            // turn on AP
            _mode(WIFI_AP);
        } else {
            // turn wifi off
            _mode(WIFI_OFF);
        }
    }

    return 0;
}
Exemplo n.º 11
0
//// modified for LASS , receive data from UART0 (sensor)
static void ICACHE_FLASH_ATTR recvTask(os_event_t *events)
{
	uint8_t i;
	uint16 length = 0;
  //char* p;
  //p=&LASSstring[0];
	while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S))
	{
		WRITE_PERI_REG(0X60000914, 0x73); //WTD
    //length=0;
		while ((READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) && (length<MAX_UARTBUFFER))
			uartbuffer[length++] = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
		//refer to Plantower PMS5003 
			p1_0 = (uint32)uartbuffer[4]*256+(uint32)uartbuffer[5];
			p2_5 = (uint32)uartbuffer[6]*256+(uint32)uartbuffer[7];
			p10_0 = (uint32)uartbuffer[8]*256+(uint32)uartbuffer[9];
	}

	if(UART_RXFIFO_FULL_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_FULL_INT_ST))
	{
		WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_FULL_INT_CLR);
	}
	else if(UART_RXFIFO_TOUT_INT_ST == (READ_PERI_REG(UART_INT_ST(UART0)) & UART_RXFIFO_TOUT_INT_ST))
	{
		WRITE_PERI_REG(UART_INT_CLR(UART0), UART_RXFIFO_TOUT_INT_CLR);
	}
  
  INFO("%s\r\n",LASSstring);
	//uart_rx_intr_enable(UART0);
  ETS_UART_INTR_ENABLE();
  ///// BUG ! TX malfunctioned!
}
Exemplo n.º 12
0
/**
 * set new mode
 * @param m WiFiMode_t
 */
bool ESP8266WiFiGenericClass::mode(WiFiMode_t m) {
    if(_persistent){
        if(wifi_get_opmode() == (uint8) m && wifi_get_opmode_default() == (uint8) m){
            return true;
        }
    } else if(wifi_get_opmode() == (uint8) m){
        return true;
    }

    bool ret = false;

    if (m != WIFI_STA && m != WIFI_AP_STA)
        // calls lwIP's dhcp_stop(),
        // safe to call even if not started
        wifi_station_dhcpc_stop();

    ETS_UART_INTR_DISABLE();
    if(_persistent) {
        ret = wifi_set_opmode(m);
    } else {
        ret = wifi_set_opmode_current(m);
    }
    ETS_UART_INTR_ENABLE();

    return ret;
}
Exemplo n.º 13
0
void ESP8266WiFiClass::mode(WiFiMode m)
{
    if(wifi_get_opmode() == (uint8)m) {
        return;
    }
    ETS_UART_INTR_DISABLE();
    wifi_set_opmode(m);
    ETS_UART_INTR_ENABLE();
}
Exemplo n.º 14
0
void ESP8266WiFiClass::softAP(const char* ssid, const char* passphrase, int channel, int ssid_hidden)
{
    _useApMode = true;
    if(_useClientMode) {
        // turn on AP+STA mode
        _mode(WIFI_AP_STA);
    } else {
        // turn on STA mode
        _mode(WIFI_AP);
    }

    if(!ssid || *ssid == 0 || strlen(ssid) > 31) {
        // fail SSID too long or missing!
        return;
    }

    if(passphrase && strlen(passphrase) > 63) {
        // fail passphrase to long!
        return;
    }

    struct softap_config conf;
    wifi_softap_get_config(&conf);
    strcpy(reinterpret_cast<char*>(conf.ssid), ssid);
    conf.channel = channel;
    conf.ssid_len = strlen(ssid);
    conf.ssid_hidden = ssid_hidden;
    conf.max_connection = 4;
    conf.beacon_interval = 100;

    if (!passphrase || strlen(passphrase) == 0)
    {
        conf.authmode = AUTH_OPEN;
        *conf.password = 0;
    }
    else
    {
        conf.authmode = AUTH_WPA2_PSK;
        strcpy(reinterpret_cast<char*>(conf.password), passphrase);
    }

    struct softap_config conf_current;
    wifi_softap_get_config(&conf_current);
    if (softap_config_equal(conf, conf_current))
    {
        DEBUGV("softap config unchanged");
        return;
    }

    ETS_UART_INTR_DISABLE();
    if (_persistent)
        wifi_softap_set_config(&conf);
    else
        wifi_softap_set_config_current(&conf);
    ETS_UART_INTR_ENABLE();
}
Exemplo n.º 15
0
/**
  * @brief  Setup commad of module as wifi ap.
  * @param  id: commad id number
  * @param  pPara: AT input param
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_setupCmdCwsap(uint8_t id, char *pPara)
{
  char temp[64];
  int8_t len;
  struct softap_config apConfig;

  wifi_softap_get_config(&apConfig);

  if(at_wifiMode == STATION_MODE)
  {
    at_backError;
    return;
  }
  pPara++;
  len = at_dataStrCpy(apConfig.ssid, pPara, 32);
  if(len < 1)
  {
    uart0_sendStr("ssid ERROR\r\n");
    return;
  }
  pPara += (len+3);
  len = at_dataStrCpy(apConfig.password, pPara, 64);
  if(len < 8)
  {
    uart0_sendStr("pwd ERROR\r\n");
    return;
  }
  pPara += (len+3);
  apConfig.channel = atoi(pPara);
  if(apConfig.channel<1 || apConfig.channel>13)
  {
    uart0_sendStr("ch ERROR\r\n");
    return;
  }
  pPara++;
  pPara = strchr(pPara, ',');
  pPara++;
  apConfig.authmode = atoi(pPara);
  if(apConfig.authmode >= 5)
  {
    uart0_sendStr("s ERROR\r\n");
    return;
  }
//  os_sprintf(temp,"%s,%s,%d,%d\r\n",
//             apConfig.ssid,
//             apConfig.password,
//             apConfig.channel,
//             apConfig.authmode);
//  uart0_sendStr(temp);
  ETS_UART_INTR_DISABLE();
  wifi_softap_set_config(&apConfig);
  ETS_UART_INTR_ENABLE();
  at_backOk;
//  system_restart();
}
Exemplo n.º 16
0
int ESP8266WiFiClass::begin()
{
    ETS_UART_INTR_DISABLE();
    wifi_station_connect();
    ETS_UART_INTR_ENABLE();

    if(!_useStaticIp)
        wifi_station_dhcpc_start();
    return status();
}
Exemplo n.º 17
0
void EEPROMClass::commit()
{
    if (!_size || !_dirty)
        return;

    ETS_UART_INTR_DISABLE();
    spi_flash_erase_sector(CONFIG_SECTOR);
    spi_flash_write(CONFIG_ADDR, reinterpret_cast<uint32_t*>(_data), _size);
    ETS_UART_INTR_ENABLE();
    _dirty = false;
}
Exemplo n.º 18
0
int ESP8266WiFiClass::disconnect()
{
    struct station_config conf;
    *conf.ssid = 0;
    *conf.password = 0;
    ETS_UART_INTR_DISABLE();
    wifi_station_set_config(&conf);
    wifi_station_disconnect();
    ETS_UART_INTR_ENABLE();
    return 0;
}
Exemplo n.º 19
0
/******************************************************************************
 * FunctionName : uart_init
 * Description  : user interface for init uart
 * Parameters   : UartBautRate uart0_br - uart0 bautrate
 *                UartBautRate uart1_br - uart1 bautrate
 * Returns      : NONE
 *******************************************************************************/
void ICACHE_FLASH_ATTR uart_init (UartBautRate uart0_br, UartBautRate uart1_br)
{
	// rom use 74880 baut_rate, here reinitialize
	UartDev.baut_rate = uart0_br;
	uart_config (UART0);
	UartDev.baut_rate = uart1_br;
	uart_config (UART1);
	ETS_UART_INTR_ENABLE();

	// install uart1 putc callback
	os_install_putc1 ((void *)uart1_write_char);
}
Exemplo n.º 20
0
/******************************************************************************
 * FunctionName : user_init
 * Description  : entry of user application, init user function here
 * Parameters   : none
 * Returns      : none
*******************************************************************************/
void user_init(void)
{
    bool ret;
    PIN_FUNC_SELECT(LED_GPIO_MUX, LED_GPIO_FUNC);
    xUARTQueue = xQueueCreate(128, sizeof(char));
    uart_init_new();
    UART_intr_handler_register(&uart0_rx_intr_handler, &xUARTQueue);
    ETS_UART_INTR_ENABLE();
    printf("SDK version:%s\n", system_get_sdk_version());
    GPIO_OUTPUT_SET(LED_GPIO, 0);

   
   //Set  station mode
   wifi_set_opmode(STATIONAP_MODE);

   // ESP8266 connect to router.
   // user_set_station_config();

   // Setup TCP server
   


   wifi_station_set_auto_connect(0);
    // wifi_station_set_reconnect_policy(0);

    printf("Wifi Button example program. \r\n");
    if (!read_user_config(&user_config))
    {
        ret = wifi_set_opmode(STATIONAP_MODE);
        DBG("wifi_set_opmode returns %d op_mode now %d\r\n", ret, wifi_get_opmode());
        // user_set_station_config();
        user_tcpserver_init(SERVER_LOCAL_PORT);
        // user_tcpserver_init(SERVER_LOCAL_PORT);
        wifi_station_set_auto_connect(1);
    }
    else
    {
        printf ("No valid config\r\n");
    }

    printf("Hiya");
    // sys_init_timing();
   lwip_init();

   // while(1);

   // xTaskCreate(check_input, "input", 256, &xUARTQueue, 3, NULL);

   // xTaskCreate(helloworld, "hw", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
   // xTaskCreate(blinky, "bl", configMINIMAL_STACK_SIZE, NULL, 2, NULL);
}
Exemplo n.º 21
0
void ICACHE_FLASH_ATTR flash_read() {
    os_printf("flashRead() size-%d\n", sizeof(FlashData));

    flashData->magic =0;
    ETS_UART_INTR_DISABLE();
    spi_flash_read((PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE) * SPI_FLASH_SEC_SIZE,
                (uint32 *)flashData, sizeof(FlashData));
    ETS_UART_INTR_ENABLE();
    if (flashData->magic != MAGIC_NUM)
    {
    	os_printf("ReadFlash ERROR!\n");
    	initFlash();
    }
}
Exemplo n.º 22
0
void ESP8266WiFiClass::_mode(WiFiMode m)
{
    if(wifi_get_opmode() == (uint8)m) {
        return;
    }

    ETS_UART_INTR_DISABLE();
    if (_persistent)
        wifi_set_opmode(m);
    else
        wifi_set_opmode_current(m);
    ETS_UART_INTR_ENABLE();

}
Exemplo n.º 23
0
int ESP8266WiFiClass::begin(const char* ssid, const char *passphrase, int32_t channel, uint8_t bssid[6]){
    _useClientMode = true;

    if(_useApMode) {
        // turn on AP+STA mode
        mode(WIFI_AP_STA);
    } else {
        // turn on STA mode
        mode(WIFI_STA);
    }

    if(!ssid || *ssid == 0x00 || strlen(ssid) > 31) {
        // fail SSID to long or missing!
        return WL_CONNECT_FAILED;
    }

    if(passphrase && strlen(passphrase) > 63) {
        // fail passphrase to long!
        return WL_CONNECT_FAILED;
    }

    struct station_config conf;
    strcpy(reinterpret_cast<char*>(conf.ssid), ssid);

    if (passphrase) {
        strcpy(reinterpret_cast<char*>(conf.password), passphrase);
    } else {
        *conf.password = 0;
    }

    if (bssid) {
        conf.bssid_set = 1;
        memcpy((void *) &conf.bssid[0], (void *) bssid, 6);
    } else {
        conf.bssid_set = 0;
    }

    ETS_UART_INTR_DISABLE();
    wifi_station_set_config(&conf);
    wifi_station_connect();
    ETS_UART_INTR_ENABLE();

    if(channel > 0 && channel <= 13) {
        wifi_set_channel(channel);
    }

    if(!_useStaticIp)
        wifi_station_dhcpc_start();
    return status();
}
Exemplo n.º 24
0
void ICACHE_FLASH_ATTR flash_write() {
    os_printf("flashWrite() size-%d\n", sizeof(FlashData));
    ETS_UART_INTR_DISABLE();

    spi_flash_erase_sector(PRIV_PARAM_START_SEC + PRIV_PARAM_SAVE);
    spi_flash_write(0x3c000, (uint32 *)flashData, sizeof(FlashData));

    ETS_UART_INTR_ENABLE();

  // spi_flash_read(0x3C000, (uint32 *) settings, 1024);
 
  // spi_flash_erase_sector(0x3C);
  // spi_flash_write(0x3C000,(uint32 *)settings,1024);
 
}
Exemplo n.º 25
0
// Turn UART interrupts off and poll for nchars or until timeout hits
uint16_t ICACHE_FLASH_ATTR
uart0_rx_poll(char *buff, uint16_t nchars, uint32_t timeout_us) {
  ETS_UART_INTR_DISABLE();
  uint16_t got = 0;
  uint32_t start = system_get_time(); // time in us
  while (system_get_time()-start < timeout_us) {
    while (READ_PERI_REG(UART_STATUS(UART0)) & (UART_RXFIFO_CNT << UART_RXFIFO_CNT_S)) {
      buff[got++] = READ_PERI_REG(UART_FIFO(UART0)) & 0xFF;
      if (got == nchars) goto done;
    }
  }
done:
  ETS_UART_INTR_ENABLE();
  return got;
}
Exemplo n.º 26
0
/**
 * Use to connect to SDK config.
 * @return wl_status_t
 */
wl_status_t ESP8266WiFiSTAClass::begin() {

    if(!WiFi.enableSTA(true)) {
        // enable STA failed
        return WL_CONNECT_FAILED;
    }

    ETS_UART_INTR_DISABLE();
    wifi_station_connect();
    ETS_UART_INTR_ENABLE();

    if(!_useStaticIp) {
        wifi_station_dhcpc_start();
    }
    return status();
}
Exemplo n.º 27
0
/**
  * @brief  Setup commad of join to wifi ap.
  * @param  id: commad id number
  * @param  pPara: AT input param
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_setupCmdCwjap(uint8_t id, char *pPara)
{
  char temp[64];
  struct station_config stationConf;

  int8_t len;

  if (at_wifiMode == SOFTAP_MODE)
  {
    at_backError;
    return;
  }
  pPara++;
  len = at_dataStrCpy(&stationConf.ssid, pPara, 32);
  if(len != -1)
  {
    pPara += (len+3);
    len = at_dataStrCpy(&stationConf.password, pPara, 64);
  }
  if(len != -1)
  {
    wifi_station_disconnect();
    mdState = m_wdact;
    ETS_UART_INTR_DISABLE();
    wifi_station_set_config(&stationConf);
    ETS_UART_INTR_ENABLE();
    wifi_station_connect();
//    if(1)
//    {
//      mdState = m_wact;
//    }
//    os_sprintf(temp,"%s:%s,%s\r\n",
//               at_fun[id].at_cmdName,
//               stationConf.ssid,
//               stationConf.password);
//    uart0_sendStr(temp);
    os_timer_disarm(&at_japDelayChack);
    os_timer_setfn(&at_japDelayChack, (os_timer_func_t *)at_japChack, NULL);
    os_timer_arm(&at_japDelayChack, 3000, 0);
    specialAtState = FALSE;
  }
  else
  {
    at_backError;
  }
}
Exemplo n.º 28
0
/******************************************************************************
 * FunctionName : uart_init
 * Description  : user interface for init uart
 * Parameters   : UartBautRate uart0_br - uart0 bautrate
 *                UartBautRate uart1_br - uart1 bautrate
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
uart_init(UartBautRate uart0_br, UartBautRate uart1_br)
{
  // rom use 74880 baut_rate, here reinitialize
  UartDev.baut_rate = uart0_br;
  uart_config(UART0);
  UartDev.baut_rate = uart1_br;
  uart_config(UART1);
  for (int i=0; i<4; i++) uart_tx_one_char(UART1, '\n');
  for (int i=0; i<4; i++) uart_tx_one_char(UART0, '\n');
  ETS_UART_INTR_ENABLE();

  // install uart1 putc callback
  os_install_putc1((void *)uart0_write_char);

  uart_recvTaskNum = register_usr_task(uart_recvTask);
}
/**
 * set new mode
 * @param m WiFiMode_t
 */
bool ESP8266WiFiGenericClass::mode(WiFiMode_t m) {
    if(wifi_get_opmode() == (uint8) m) {
        return true;
    }

    bool ret = false;

    ETS_UART_INTR_DISABLE();
    if(_persistent) {
        ret = wifi_set_opmode(m);
    } else {
        ret = wifi_set_opmode_current(m);
    }
    ETS_UART_INTR_ENABLE();

    return ret;
}
Exemplo n.º 30
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;
}