uint8_t* EspDrv::getMacAddress() { LOGDEBUG(F("> getMacAddress")); memset(_mac, 0, WL_MAC_ADDR_LENGTH); char buf[20]; if (sendCmdGet(F("AT+CIFSR"), F(":STAMAC,\""), F("\""), buf, sizeof(buf))) { char* token; token = strtok(buf, ":"); _mac[5] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _mac[4] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _mac[3] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _mac[2] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _mac[1] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _mac[0] = (byte)strtol(token, NULL, 16); } return _mac; }
uint8_t* EspDrv::getCurrentBSSID() { LOGDEBUG(F("> getCurrentBSSID")); memset(_bssid, 0, WL_MAC_ADDR_LENGTH); char buf[20]; if (sendCmdGet(F("AT+CWJAP?"), F(",\""), F("\","), buf, sizeof(buf))) { char* token; token = strtok(buf, ":"); _bssid[5] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _bssid[4] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _bssid[3] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _bssid[2] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _bssid[1] = (byte)strtol(token, NULL, 16); token = strtok(NULL, ":"); _bssid[0] = (byte)strtol(token, NULL, 16); } return _bssid; }
char* EspDrv::getCurrentSSID() { LOGDEBUG(F("> getCurrentSSID")); _ssid[0] = 0; sendCmdGet(F("AT+CWJAP?"), F("+CWJAP:\""), F("\""), _ssid, sizeof(_ssid)); return _ssid; }
bool EspDrv::sendCmdGet(const __FlashStringHelper* cmd, const __FlashStringHelper* startTag, const __FlashStringHelper* endTag, char* outStr, int outStrLen) { char _startTag[strlen_P((char*)startTag)+1]; strcpy_P(_startTag, (char*)startTag); char _endTag[strlen_P((char*)endTag)+1]; strcpy_P(_endTag, (char*)endTag); return sendCmdGet(cmd, _startTag, _endTag, outStr, outStrLen); }
char* EspDrv::getFwVersion() { LOGDEBUG(F("> getFwVersion")); fwVersion[0] = 0; sendCmdGet(F("AT+GMR"), F("SDK version:"), F("\r\n"), fwVersion, sizeof(fwVersion)); return fwVersion; }
bool EspDrv::getNetmask(IPAddress& mask) { LOGDEBUG(F("> getNetmask")); char buf[20]; if (sendCmdGet(F("AT+CIPSTA?"), F("+CIPSTA:netmask:\""), F("\""), buf, sizeof(buf))) { mask.fromString (buf); return true; } return false; }
bool EspDrv::getGateway(IPAddress& gw) { LOGDEBUG(F("> getGateway")); char buf[20]; if (sendCmdGet(F("AT+CIPSTA?"), F("+CIPSTA:gateway:\""), F("\""), buf, sizeof(buf))) { gw.fromString (buf); return true; } return false; }
int32_t EspDrv::getCurrentRSSI() { LOGDEBUG(F("> getCurrentRSSI")); int ret=0; char buf[10]; sendCmdGet(F("AT+CWJAP?"), F(",-"), F("\r\n"), buf, sizeof(buf)); if (isDigit(buf[0])) { ret = -atoi(buf); } return ret; }
uint8_t EspDrv::getClientState(uint8_t sock) { LOGDEBUG1(F("> getClientState"), sock); char findBuf[20]; sprintf_P(findBuf, PSTR("+CIPSTATUS:%d,"), sock); char buf[10]; if (sendCmdGet(F("AT+CIPSTATUS"), findBuf, ",", buf, sizeof(buf))) { LOGDEBUG(F("Connected")); return true; } LOGDEBUG(F("Not connected")); return false; }
uint8_t EspDrv::getConnectionStatus() { LOGDEBUG(F("> getConnectionStatus")); /* AT+CIPSTATUS Response STATUS:<stat> +CIPSTATUS:<link ID>,<type>,<remote_IP>,<remote_port>,<local_port>,<tetype> Parameters <stat> 2: Got IP 3: Connected 4: Disconnected <link ID> ID of the connection (0~4), for multi-connect <type> string, "TCP" or "UDP" <remote_IP> string, remote IP address. <remote_port> remote port number <local_port> ESP8266 local port number <tetype> 0: ESP8266 runs as client 1: ESP8266 runs as server */ char buf[10]; if(!sendCmdGet(F("AT+CIPSTATUS"), F("STATUS:"), F("\r\n"), buf, sizeof(buf))) return WL_NO_SHIELD; // 4: client disconnected // 5: wifi disconnected int s = atoi(buf); if(s==2 or s==3 or s==4) return WL_CONNECTED; else if(s==5) return WL_DISCONNECTED; return WL_IDLE_STATUS; }
void EspDrv::getIpAddressAP(IPAddress& ip) { LOGDEBUG(F("> getIpAddressAP")); char buf[20]; if (sendCmdGet(F("AT+CIPAP?"), F("+CIPAP:ip:\""), F("\""), buf, sizeof(buf))) { char* token; token = strtok(buf, "."); _localIp[0] = atoi(token); token = strtok(NULL, "."); _localIp[1] = atoi(token); token = strtok(NULL, "."); _localIp[2] = atoi(token); token = strtok(NULL, "."); _localIp[3] = atoi(token); ip = _localIp; } }
void EspDrv::getIpAddress(IPAddress& ip) { LOGDEBUG(F("> getIpAddress")); // AT+CIFSR or AT+CIPSTA? char buf[20]; if (sendCmdGet(F("AT+CIFSR"), F(":STAIP,\""), F("\""), buf, sizeof(buf))) { char* token; token = strtok(buf, "."); _localIp[0] = atoi(token); token = strtok(NULL, "."); _localIp[1] = atoi(token); token = strtok(NULL, "."); _localIp[2] = atoi(token); token = strtok(NULL, "."); _localIp[3] = atoi(token); ip = _localIp; } }