For test

Dependencies:   mbed

ESP8266.h

Committer:
shennongmin
Date:
2015-02-04
Revision:
23:4cec7b9e3715
Parent:
22:f5d148878815
Child:
28:c25aff31dcc5

File content as of revision 23:4cec7b9e3715:

#ifndef __ESP8266_H__
#define __ESP8266_H__

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


typedef enum {
    ESP8266_ECN_OPEN          = 0,
    ESP8266_ECN_WEP           = 1,
    ESP8266_ECN_WAP_PSK       = 2,
    ESP8266_ECN_WAP2_PSK      = 3,
    ESP8266_ECN_WAP_WAP2_PSK  = 4,
} ESP8266Encrypstion;

typedef enum {
    ESP8266_COMM_UDP              = 0,
    ESP8266_COMM_TCP              = 1,
} ESP8266CommMode; 

typedef enum {
    ESP8266_MODE_STA         = 1,
    ESP8266_MODE_SAP         = 2,
    ESP8266_MODE_STA_SAP     = 3,
} ESP8266WorkMode;


class ESP8266
{
  public:
    ESP8266(PinName tx, PinName rx);
    
    bool begin(void);
    
    //init port
    bool init(uint8_t mode, String ssid, String pwd, uint8_t chl = 7, 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 recvData(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 m_chl_id
    int getChannelID(void);
    
private:
    ArduinoSerial m_esp_uart;
    int m_chl_id;
};

#endif /* #ifndef __ESP8266_H__ */