For test

Dependencies:   mbed

ESP8266.h

Committer:
shennongmin
Date:
2015-02-04
Revision:
18:37254b357abd
Parent:
17:c449356787f1
Child:
21:af9656e070d3

File content as of revision 18:37254b357abd:

#ifndef __ESP8266_H__
#define __ESP8266_H__

#include "mbed.h"
#include "time.h"
#include "ArduinoSerial.h"


//The way of encrypstion
#define    ESP8266_ECN_OPEN          0
#define    ESP8266_ECN_WEP           1
#define    ESP8266_ECN_WAP_PSK       2
#define    ESP8266_ECN_WAP2_PSK      3
#define    ESP8266_ECN_WAP_WAP2_PSK  4

//Communication mode 
#define    ESP8266_TCP              1
#define    ESP8266_UDP              0

//The type of initialized ESP8266
#define    ESP8266_MODE_STA         1
#define    ESP8266_MODE_SAP         2
#define    ESP8266_MODE_STA_SAP     3

//Default channel 
#define ESP8266_DEFAULT_CHANNEL     (7) /* 1 - 13 */

class ArduinoSerial;

class ESP8266
{
  public:
    ESP8266(PinName tx, PinName rx);
    
    bool begin(void);
    
    //Initialize port
    bool Initialize(uint8_t mode, String ssid, String pwd, uint8_t chl = ESP8266_DEFAULT_CHANNEL, uint8_t ecn = ESP8266_ECN_WAP_WAP2_PSK);
    
    bool ipConfig(uint8_t type, String addr, int port, uint8_t mux = 0, uint8_t id = 0);
    
    //send data in sigle connection mode
    bool Send(String str);  
    
    //send data int multiple connection mode
    bool Send(uint8_t id, String str);  
        
    int ReceiveMessage(char *buf);
    
    //reset the module
    void Reset(void);    
    
    //set the working mode of module
    bool confMode(uint8_t mode);   
    
    //set the name and password of wifi 
    bool confJAP(String ssid , String pwd);    
    
    //set the parametter of SSID, password, channel, encryption in AP mode.
    bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn);       
    
    //inquire the current mode of wifi module
    String showMode(void);   
    
    //show the list of wifi hotspot
    String showAP(void);   
    
    //show the name of current wifi access port
    String showJAP(void);  
    
    //quit the connection of current wifi
    bool quitAP(void);    
    
    //show the parameter of ssid, password, channel, encryption in AP mode
    String showSAP(void);     

    //inquire the connection status
    String showStatus(void);  
    
    //show the current connection mode(sigle or multiple)
    String showMux(void);  
    
    //set the connection mode(sigle:0 or multiple:1)     
    bool confMux(int mux);    
    
    //create new tcp or udp connection (sigle connection mode)
    bool newMux(uint8_t type, String addr, int port);   
    
    //create new tcp or udp connection (multiple connection mode)(id:0-4) 
    bool newMux(uint8_t id, uint8_t type, String addr, int port);   
    
    //close tcp or udp (sigle connection mode)
    void closeMux(void);   
    
    //close tcp or udp (multiple connection mode)
    void closeMux(uint8_t id); 
    
    //show the current ip address
    String showIP(void);    
    
    //set the parameter of server
    bool confServer(uint8_t mode, int port);  

    // get chlID
    int get_chlID(void);
    
private:
    ArduinoSerial esp_uart;
    int chlID;
};

#endif /* #ifndef __ESP8266_H__ */