A library to control esp-8266 from Arduino by AT commands easier.
Arduino Uno | ESPr |
---|---|
5V | Vin |
GND | GND |
D2 | TX |
D3 | RX |
You need SSID and password for your Access Point.
ESPAT espat(<ssid>, <password>);
Caution!!: You should call this method before other methods on this library.
ESPAT espat(<ssid>, <password>);
void setup(){
espat.begin();
}
This method tell you AT command is Available or Not.
espat.checkAT();
This method send AT command(AT+CWMODE).
Arguments:
- mode => Wifi mode. (0: station, 1: softAP, 2: station + softAP)
espat.changeMode(1); // Wifi is station mode.
This method connect with AP.
Caution!!: You should set correct ssid and passwd at Definition.
espat.changeMode(1) // set station mode
espat.tryConnectAP();
This method tell you client IP address.
Returns:
- "192.168.xx.xx" => Correct IP address.
- "" => If failed to get IP address, you get empty.
You can check IP address by:
if(espat.clientIP() != ""){
// do something
}else{
// do something for error
}
This method send GET request and return Body of Response by String.
Caution!!: You should call tryConnectAP before this method.
Caution!!: You also hove to check client IP address is valid by call clientIP().
Caution!!: Limit of return(String) is 1024 chars in default.
Caution!!: Return is NOT include header of response.
Arguments
- optional int port: Default is 80.
Serial.println(espat.get("www.google.co.jp", "/", 80)); // You can display response to serial monitor.(by 1024 chars);
This method send GET request and you can get response by char in callback.
Caution!!: You should call tryConnectAP before this method.
Caution!!: You also hove to check client IP address is valid by call clientIP().
Arguments
- optional int port: Default is 80.
- optional void (*callback)(char): Argument of callback is response by character.
espat.advGet("www.google.co.jp", "/", 80); // response is displayed by serial monitor.
void callback(char c){
Serial.print(c);
}
espat.get("www.google.co.jp", "/", 80, callback) // same with previous call.