boolean NanoESP::configWifiAP( String ssid, String password) { boolean success = true; this->setTimeout(20000); if (password == "") success &= (sendCom("AT+CWSAP=\"" + String(ssid) + "\",\"\",5,0", "OK")); else success &= (sendCom("AT+CWSAP=\"" + String(ssid) + "\",\"" + String(password) + "\",5,4", "OK")); this->setTimeout(1000); return success; }
boolean NanoESP::sendData(int id, String msg) { boolean success = true; success &= sendCom("AT+CIPSEND=" + String(id) + "," + String(msg.length() + 2), ">"); if (success) { success &= sendCom(msg, "OK"); } return success; }
boolean NanoESP::sendDataClose(int id, String msg) { boolean success = true; success &= sendCom(at+cip+"SEND=" + String(id) + "," + String(msg.length() + 2), ">"); if (success) { success &= sendCom(msg, ok); success &= closeConnection(id); } return success; }
boolean NanoESP::newConnection(int id, String type, String ip ,unsigned int port) { //single direction boolean success = true; this->setTimeout(10000); success &= sendCom(at+cip+"START=" + String(id) + ",\"" + String(type) + "\",\"" + String(ip) + "\"," + String(port), ok); this->setTimeout(1000); return success; }
boolean NanoESP::reset() { boolean success = true; this->setTimeout(5000); success &= sendCom("AT+RST", "ready"); this->setTimeout(1000); return success; }
boolean NanoESP::configWifiStation(String ssid, String password) { boolean success = true; this->setTimeout(20000); success &= (sendCom("AT+CWJAP=\"" + String(ssid) + "\",\"" + String(password) + "\"", "OK")); this->setTimeout(1000); return success; }
boolean NanoESP::configWifiAP( String ssid, String password, int channel, int crypt) { boolean success = true; this->setTimeout(20000); success &= (sendCom("AT+CWSAP=\"" + String(ssid) + "\",\"" + String(password) + "\"," + String(channel) + "," + String(crypt), "OK")); this->setTimeout(1000); return success; }
String ESP8266::listAccessPoints() { //Send AT command to list access points sendCom(LIST_AP); //Get list of access points as a string //Return string }
void ESP8266::setMode(int mode) { //Send AT command to set the mode //of the ESP8266 cmd = MODE; cmd += "="; cmd += String(mode); sendCom(cmd); }
void ESP8266::setConnectionMode(int mode) { //Send the AT command to set the connection mode cmd = MODE; cmd += "="; if(mode == SINGLE) cmd += String(SINGLE); else if(mode == MULTIPLE) cmd += String(MULTIPLE); sendCom(cmd); }
int ESP8266::moduleTest() { //Send the test signal sendCom(TST); //Receive the reply from the module //If the reply is "OK" return 1 //If there is an error return 0 if(esplink.find("OK")) return 1; else return 0; }
void ESP8266::createAccessPoint(String SSID, String password) { //Set the parameters of the ESP8266 //in access point mode cmd = SET_AP_PARAMS; cmd += "=\""; cmd += SSID; cmd += "\",\""; //cmd += ",\""; cmd += password; cmd += "\""; cmd += String(2); cmd += String(1); sendCom(cmd); }
boolean NanoESP::newConnection(int id, String type, String ip , int port) { //single direction boolean success = true; success &= sendCom("AT+CIPSTART=" + String(id) + ",\"" + String(type) + "\",\"" + String(ip) + "\"," + String(port), "OK"); return success; }
boolean NanoESP::startUdpServer(int id, String ip ,unsigned int port,unsigned int recvport, int mode) { //dual direction boolean success = true; success &= sendCom(at+cip+"START=" + String(id) + ",\"UDP\",\"" + String(ip) + "\"," + String(port) + "," + String(recvport) + "," + String(mode), ok); return success; }
boolean NanoESP::closeConnection(int id) { boolean success = true; success &= sendCom(at+cip+"CLOSE=" + String(id), ok); return success; }
boolean NanoESP::startTcpServer(unsigned int port) { boolean success = true; success &= sendCom(at+cip+"SERVER=1," + String(port), ok); return success; }
boolean NanoESP::configWifiMode(int modus) { return (sendCom("AT+CWMODE=" + String(modus), "OK")); }
boolean NanoESP::setMultipleConnections() { boolean success = true; success &= sendCom("AT+CIPMUX=1", "OK"); //Allways multiple connections return success; }
boolean NanoESP::setTransferMode() { boolean success = true; success &= sendCom("AT+CIPMODE=0", "OK"); //Normal trasfer mode return success; }
boolean NanoESP::endTcpServer() { boolean success = true; success &= sendCom(at+cip+"SERVER=0", ok); success &= init(); //Restart?!? return success; }
boolean NanoESP::ping(String address) { boolean success = true; success &= sendCom("AT+PING=" + String(address), "OK"); return success; }
boolean NanoESP::startTcpServer(int port) { boolean success = true; success &= sendCom("AT+CIPSERVER=1," + String(port), "OK"); return success; }
boolean NanoESP::endTcpServer() { boolean success = true; success &= sendCom("AT+CIPSERVER=0", "OK"); success &= init(); //Restart?!? return success; }
boolean NanoESP::startUdpServer(int id, String ip , int port, int recvport, int mode) { //dual direction boolean success = true; success &= sendCom("AT+CIPSTART=" + String(id) + ",\"UDP\",\"" + String(ip) + "\"," + String(port) + "," + String(recvport) + "," + String(mode), "OK"); return success; }
boolean NanoESP::setMultipleConnections() { boolean success = true; success &= sendCom(at+cip+"MUX=1", ok); //Allways multiple connections return success; }
boolean NanoESP::setTransferMode() { boolean success = true; success &= sendCom(at+cip+"MODE=0", ok); //Normal trasfer mode return success; }
String NanoESP::getIp() { return sendCom("AT+CIFSR"); }
boolean NanoESP::disconnectWifi() { boolean success = true; success &= (sendCom("AT+CWWAP", "OK")); return success; }
boolean NanoESP::closeConnection(int id) { boolean success = true; success &= sendCom("AT+CIPCLOSE=" + String(id), "OK"); return success; }
String NanoESP::getIp() { return sendCom(at+"CIFSR"); }