For test

Dependencies:   mbed

Committer:
shennongmin
Date:
Tue Feb 03 09:10:16 2015 +0000
Revision:
14:40b1decf03f3
Parent:
10:9d4ec0359a5c
Child:
17:c449356787f1
Simple Log Okay

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shennongmin 10:9d4ec0359a5c 1 #ifndef __ESP8266_H__
shennongmin 10:9d4ec0359a5c 2 #define __ESP8266_H__
shennongmin 4:962bf18523f4 3
shennongmin 7:a11e381ce969 4 #include "mbed.h"
shennongmin 14:40b1decf03f3 5 #include "log.h"
shennongmin 10:9d4ec0359a5c 6 #include "time.h"
shennongmin 10:9d4ec0359a5c 7 #include "ArduinoSerial.h"
shennongmin 7:a11e381ce969 8
shennongmin 4:962bf18523f4 9
shennongmin 4:962bf18523f4 10 //The way of encrypstion
shennongmin 7:a11e381ce969 11 #define ESP8266_ECN_OPEN 0
shennongmin 7:a11e381ce969 12 #define ESP8266_ECN_WEP 1
shennongmin 7:a11e381ce969 13 #define ESP8266_ECN_WAP_PSK 2
shennongmin 7:a11e381ce969 14 #define ESP8266_ECN_WAP2_PSK 3
shennongmin 7:a11e381ce969 15 #define ESP8266_ECN_WAP_WAP2_PSK 4
shennongmin 4:962bf18523f4 16
shennongmin 4:962bf18523f4 17 //Communication mode
shennongmin 7:a11e381ce969 18 #define ESP8266_TCP 1
shennongmin 7:a11e381ce969 19 #define ESP8266_UDP 0
shennongmin 4:962bf18523f4 20
shennongmin 9:95a0ce98e12b 21 //The type of initialized ESP8266
shennongmin 7:a11e381ce969 22 #define ESP8266_MODE_STA 1
shennongmin 7:a11e381ce969 23 #define ESP8266_MODE_SAP 2
shennongmin 7:a11e381ce969 24 #define ESP8266_MODE_STA_SAP 3
shennongmin 4:962bf18523f4 25
shennongmin 9:95a0ce98e12b 26 //Default channel
shennongmin 9:95a0ce98e12b 27 #define ESP8266_DEFAULT_CHANNEL (7) /* 1 - 13 */
shennongmin 4:962bf18523f4 28
shennongmin 10:9d4ec0359a5c 29 class ArduinoSerial;
shennongmin 10:9d4ec0359a5c 30
shennongmin 9:95a0ce98e12b 31 class ESP8266
shennongmin 4:962bf18523f4 32 {
shennongmin 4:962bf18523f4 33 public:
shennongmin 10:9d4ec0359a5c 34 ESP8266(PinName tx, PinName rx);
shennongmin 10:9d4ec0359a5c 35
shennongmin 4:962bf18523f4 36 void begin(void);
shennongmin 4:962bf18523f4 37
shennongmin 4:962bf18523f4 38 //Initialize port
shennongmin 10:9d4ec0359a5c 39 bool Initialize(uint8_t mode, String ssid, String pwd, uint8_t chl = ESP8266_DEFAULT_CHANNEL, uint8_t ecn = ESP8266_ECN_WAP_WAP2_PSK);
shennongmin 7:a11e381ce969 40
shennongmin 10:9d4ec0359a5c 41 bool ipConfig(uint8_t type, String addr, int port, uint8_t a = 0, uint8_t id = 0);
shennongmin 4:962bf18523f4 42
shennongmin 7:a11e381ce969 43 //send data in sigle connection mode
shennongmin 7:a11e381ce969 44 bool Send(String str);
shennongmin 7:a11e381ce969 45
shennongmin 7:a11e381ce969 46 //send data int multiple connection mode
shennongmin 10:9d4ec0359a5c 47 bool Send(uint8_t id, String str);
shennongmin 4:962bf18523f4 48
shennongmin 4:962bf18523f4 49 int ReceiveMessage(char *buf);
shennongmin 4:962bf18523f4 50
shennongmin 7:a11e381ce969 51 //reset the module
shennongmin 7:a11e381ce969 52 void Reset(void);
shennongmin 7:a11e381ce969 53
shennongmin 7:a11e381ce969 54 //set the working mode of module
shennongmin 10:9d4ec0359a5c 55 bool confMode(uint8_t a);
shennongmin 7:a11e381ce969 56
shennongmin 7:a11e381ce969 57 //set the name and password of wifi
shennongmin 7:a11e381ce969 58 bool confJAP(String ssid , String pwd);
shennongmin 7:a11e381ce969 59
shennongmin 7:a11e381ce969 60 //set the parametter of SSID, password, channel, encryption in AP mode.
shennongmin 10:9d4ec0359a5c 61 bool confSAP(String ssid , String pwd , uint8_t chl , uint8_t ecn);
shennongmin 4:962bf18523f4 62
shennongmin 7:a11e381ce969 63 //inquire the current mode of wifi module
shennongmin 7:a11e381ce969 64 String showMode(void);
shennongmin 7:a11e381ce969 65
shennongmin 7:a11e381ce969 66 //show the list of wifi hotspot
shennongmin 7:a11e381ce969 67 String showAP(void);
shennongmin 7:a11e381ce969 68
shennongmin 7:a11e381ce969 69 //show the name of current wifi access port
shennongmin 7:a11e381ce969 70 String showJAP(void);
shennongmin 7:a11e381ce969 71
shennongmin 7:a11e381ce969 72 //quit the connection of current wifi
shennongmin 7:a11e381ce969 73 bool quitAP(void);
shennongmin 7:a11e381ce969 74
shennongmin 7:a11e381ce969 75 //show the parameter of ssid, password, channel, encryption in AP mode
shennongmin 7:a11e381ce969 76 String showSAP(void);
shennongmin 4:962bf18523f4 77
shennongmin 7:a11e381ce969 78 //inquire the connection status
shennongmin 7:a11e381ce969 79 String showStatus(void);
shennongmin 7:a11e381ce969 80
shennongmin 7:a11e381ce969 81 //show the current connection mode(sigle or multiple)
shennongmin 7:a11e381ce969 82 String showMux(void);
shennongmin 7:a11e381ce969 83
shennongmin 7:a11e381ce969 84 //set the connection mode(sigle:0 or multiple:1)
shennongmin 8:577f955031ea 85 bool confMux(int a);
shennongmin 7:a11e381ce969 86
shennongmin 7:a11e381ce969 87 //create new tcp or udp connection (sigle connection mode)
shennongmin 10:9d4ec0359a5c 88 bool newMux(uint8_t type, String addr, int port);
shennongmin 4:962bf18523f4 89
shennongmin 7:a11e381ce969 90 //create new tcp or udp connection (multiple connection mode)(id:0-4)
shennongmin 10:9d4ec0359a5c 91 bool newMux(uint8_t id, uint8_t type, String addr, int port);
shennongmin 7:a11e381ce969 92
shennongmin 7:a11e381ce969 93 //close tcp or udp (sigle connection mode)
shennongmin 7:a11e381ce969 94 void closeMux(void);
shennongmin 7:a11e381ce969 95
shennongmin 7:a11e381ce969 96 //close tcp or udp (multiple connection mode)
shennongmin 10:9d4ec0359a5c 97 void closeMux(uint8_t id);
shennongmin 7:a11e381ce969 98
shennongmin 7:a11e381ce969 99 //show the current ip address
shennongmin 7:a11e381ce969 100 String showIP(void);
shennongmin 7:a11e381ce969 101
shennongmin 7:a11e381ce969 102 //set the parameter of server
shennongmin 10:9d4ec0359a5c 103 bool confServer(uint8_t mode, int port);
shennongmin 4:962bf18523f4 104
shennongmin 10:9d4ec0359a5c 105 // get chlID
shennongmin 10:9d4ec0359a5c 106 int get_chlID(void);
shennongmin 10:9d4ec0359a5c 107
shennongmin 10:9d4ec0359a5c 108 private:
shennongmin 10:9d4ec0359a5c 109 ArduinoSerial esp_uart;
shennongmin 10:9d4ec0359a5c 110 int chlID;
shennongmin 4:962bf18523f4 111 };
shennongmin 9:95a0ce98e12b 112
shennongmin 10:9d4ec0359a5c 113 #endif /* #ifndef __ESP8266_H__ */