Exemple #1
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();
}
Exemple #2
0
void ICACHE_FLASH_ATTR
at_setupCmdCifsr(uint8_t id, char *pPara)
{
  struct ip_info pTempIp;
  int8_t len;
  char ipTemp[64];
//  char temp[64];

  if(at_wifiMode == STATION_MODE)
  {
    at_backError;
    return;
  }
  pPara = strchr(pPara, '\"');
  len = at_dataStrCpy(ipTemp, pPara, 32);
  if(len == -1)
  {
    uart0_sendStr("IP ERROR\r\n");
    return;
  }

  wifi_get_ip_info(0x01, &pTempIp);
  pTempIp.ip.addr = ipaddr_addr(ipTemp);

  os_printf("%d.%d.%d.%d\r\n",
                 IP2STR(&pTempIp.ip));

  if(!wifi_set_ip_info(0x01, &pTempIp))
  {
    at_backError;
    return;
  }
  at_backOk;
  return;
}
Exemple #3
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;
  }
}
Exemple #4
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)
  {
    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);
    at_backOk;
  }
  else
  {
    at_backError;
  }
}
Exemple #5
0
/**
  * @brief  Setup commad of start client.
  * @param  id: commad id number
  * @param  pPara: AT input param
  * @retval None
  */
void ICACHE_FLASH_ATTR
at_setupCmdCipstart(uint8_t id, char *pPara)
{
  char temp[64];
//  enum espconn_type linkType;
  int8_t len;
  enum espconn_type linkType = ESPCONN_INVALID;
  uint32_t ip = 0;
  char ipTemp[128];
  int32_t port;
  uint8_t linkID;

//  if(mdState != m_unlink)
//  {
//    uart0_sendStr("no ip\r\n");
//    return;
//  }
  if(at_wifiMode == 1)
  {
    if(wifi_station_get_connect_status() != STATION_GOT_IP)
    {
      uart0_sendStr("no ip\r\n");
      return;
    }
  }
  pPara++;
  if(at_ipMux)
  {
    linkID = atoi(pPara);
    pPara++;
    pPara = strchr(pPara, '\"');
  }
  else
  {
    linkID = 0;
  }
  if(linkID >= at_linkMax)
  {
    uart0_sendStr("ID ERROR\r\n");
    return;
  }
  len = at_dataStrCpy(temp, pPara, 6);
  if(len == -1)
  {
    uart0_sendStr("Link typ ERROR\r\n");
    return;
  }
  if(os_strcmp(temp, "TCP") == 0)
  {
    linkType = ESPCONN_TCP;
  }
  else if(os_strcmp(temp, "UDP") == 0)
  {
    linkType = ESPCONN_UDP;
  }
  else
  {
    uart0_sendStr("Link typ ERROR\r\n");
    return;
  }
  pPara += (len+3);
  len = at_dataStrCpy(ipTemp, pPara, 64);
  if(len == -1)
  {
    uart0_sendStr("IP ERROR\r\n");
    return;
  }
  pPara += (len+2);
  if(*pPara != ',')
  {
    uart0_sendStr("ENTRY ERROR\r\n");
    return;
  }
  pPara += (1);
  port = atoi(pPara);

  if(pLink[linkID].linkEn)
  {
    uart0_sendStr("ALREAY CONNECT\r\n");
    return;
  }
  pLink[linkID].pCon = (struct espconn *)os_zalloc(sizeof(struct espconn));
  if (pLink[linkID].pCon == NULL)
  {
    uart0_sendStr("CONNECT FAIL\r\n");
    return;
  }
  pLink[linkID].pCon->type = linkType;
  pLink[linkID].pCon->state = ESPCONN_NONE;
  pLink[linkID].linkId = linkID;
  ip = ipaddr_addr(ipTemp);

  switch(linkType)
  {
  case ESPCONN_TCP:
    pLink[linkID].pCon->proto.tcp = (esp_tcp *)os_zalloc(sizeof(esp_tcp));
    pLink[linkID].pCon->proto.tcp->local_port = espconn_port();
    pLink[linkID].pCon->proto.tcp->remote_port = port;

    os_memcpy(pLink[linkID].pCon->proto.tcp->remote_ip, &ip, 4);

    pLink[linkID].pCon->reverse = &pLink[linkID];

    espconn_regist_connectcb(pLink[linkID].pCon, at_tcpclient_connect_cb);
    espconn_regist_reconcb(pLink[linkID].pCon, at_tcpclient_recon_cb);
    specialAtState = FALSE;
    if((ip == 0xffffffff) && (os_memcmp(ipTemp,"255.255.255.255",16) != 0))
    {
      espconn_gethostbyname(pLink[linkID].pCon, ipTemp, &host_ip, at_dns_found);
    }
    else
    {
      espconn_connect(pLink[linkID].pCon);
      at_linkNum++;
    }
    break;

  case ESPCONN_UDP:
    pLink[linkID].pCon->proto.udp = (esp_udp *)os_zalloc(sizeof(esp_udp));
    pLink[linkID].pCon->proto.udp->local_port = espconn_port();
    pLink[linkID].pCon->proto.udp->remote_port = port;
    os_memcpy(pLink[linkID].pCon->proto.udp->remote_ip, &ip, 4);

    pLink[linkID].pCon->reverse = &pLink[linkID];
//    os_printf("%d\r\n",pLink[linkID].pCon->proto.udp->local_port);///

    pLink[linkID].linkId = linkID;
    pLink[linkID].linkEn = TRUE;
    pLink[linkID].teType = teClient;
    espconn_regist_recvcb(pLink[linkID].pCon, at_tcpclient_recv);
    espconn_regist_sentcb(pLink[linkID].pCon, at_tcpclient_sent_cb);
    if((ip == 0xffffffff) && (os_memcmp(ipTemp,"255.255.255.255",16) != 0))
    {
      specialAtState = FALSE;
      espconn_gethostbyname(pLink[linkID].pCon, ipTemp, &host_ip, at_dns_found);
    }
    else
    {
      espconn_create(pLink[linkID].pCon);
      at_linkNum++;
      at_backOk;
    }
    break;

  default:
    break;
  }
//  os_sprintf(temp, "%d.%d.%d.%d:%d\r\n",/////
//             IP2STR(&ip), port);/////
//  uart0_sendStr(temp);////
//  at_backOk;/////
}
Exemple #6
0
void ICACHE_FLASH_ATTR
at_setupCmdCwlap(uint8_t id, char *pPara)
{
  struct scan_config config;
  int8_t len;
  char ssid[32];
  char bssidT[18];
  char bssid[6];
  uint8_t channel;
  uint8_t i;

  pPara++;
//  os_printf("%x\r\n",*pPara);////
//  os_bzero(ssid, 32);

  len = at_dataStrCpy(ssid, pPara, 32);
//  os_printf("%d\r\n",len);////

  if(len == -1)
  {
    at_backError;
//    uart0_sendStr(at_backTeError"11\r\n");
    return;
  }
  if(len == 0)
  {
    config.ssid = NULL;
  }
  else
  {
    config.ssid = ssid;
  }
  pPara += (len+3);
//  os_printf("%x\r\n",*pPara);/////
  len = at_dataStrCpy(bssidT, pPara, 18);
//  os_printf("%d\r\n",len);////
  if(len == -1)
  {
    at_backError;
  //    uart0_sendStr(at_backTeError"11\r\n");
    return;
  }
  if(len == 0)
  {
    config.bssid = NULL;
  }
  else
  {
    if(os_str2macaddr(bssid, bssidT) == 0)
    {
      at_backError;
      return;
    }
    config.bssid = bssid;
  }
//  if(*pPara == ',')
//  {
//    config.bssid = NULL;
//  }
//  else
//  {
//    os_memcpy(bssidT,pPara,17);
//    bssidT[17] = '\0';
//    os_str2macaddr(bssid, bssidT);
//    config.bssid = bssid;
//  }
  pPara += (len+3);
  config.channel = atoi(pPara);

//  os_printf("%s,%s,%d\r\n",
//            config.ssid,
//            config.bssid,
//            config.channel);
  if(wifi_station_scan(&config, scan_done))
  {
    specialAtState = FALSE;
  }
  else
  {
    at_backError;
  }
}