esp8266 websocket and socket
ESP8266.h@0:46166e7d81a8, 2015-06-12 (annotated)
- Committer:
- metabi814
- Date:
- Fri Jun 12 10:06:12 2015 +0000
- Revision:
- 0:46166e7d81a8
ESP8266 socket and websocket ; -set ip ; -set mac
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
metabi814 | 0:46166e7d81a8 | 1 | //#ifndef __esp8266_H__ |
metabi814 | 0:46166e7d81a8 | 2 | //#define __esp8266_H__ |
metabi814 | 0:46166e7d81a8 | 3 | |
metabi814 | 0:46166e7d81a8 | 4 | #include "mbed.h" |
metabi814 | 0:46166e7d81a8 | 5 | #include "modem.h" |
metabi814 | 0:46166e7d81a8 | 6 | |
metabi814 | 0:46166e7d81a8 | 7 | #define MAX_SOCK_NUM 4 //(0~4) |
metabi814 | 0:46166e7d81a8 | 8 | class esp8266: public Modem |
metabi814 | 0:46166e7d81a8 | 9 | { |
metabi814 | 0:46166e7d81a8 | 10 | public: |
metabi814 | 0:46166e7d81a8 | 11 | /*Constructor*/ |
metabi814 | 0:46166e7d81a8 | 12 | esp8266(PinName tx,PinName rx,int baudRate,const char *ssid =NULL,const char *password=NULL,const char *host=NULL,const char *port=NULL); |
metabi814 | 0:46166e7d81a8 | 13 | |
metabi814 | 0:46166e7d81a8 | 14 | static esp8266* getInstance() { |
metabi814 | 0:46166e7d81a8 | 15 | return inst; |
metabi814 | 0:46166e7d81a8 | 16 | }; |
metabi814 | 0:46166e7d81a8 | 17 | //-------------------------------wifi socket---------------------------- |
metabi814 | 0:46166e7d81a8 | 18 | bool join(); // connection au access point return true false |
metabi814 | 0:46166e7d81a8 | 19 | |
metabi814 | 0:46166e7d81a8 | 20 | int connect(int socket); // return 0 success -1 error |
metabi814 | 0:46166e7d81a8 | 21 | |
metabi814 | 0:46166e7d81a8 | 22 | int send(int socket,const char * str,int len); |
metabi814 | 0:46166e7d81a8 | 23 | |
metabi814 | 0:46166e7d81a8 | 24 | int recv(char* buf, int len); |
metabi814 | 0:46166e7d81a8 | 25 | |
metabi814 | 0:46166e7d81a8 | 26 | bool disconnect(int socket); |
metabi814 | 0:46166e7d81a8 | 27 | |
metabi814 | 0:46166e7d81a8 | 28 | bool is_connected(); |
metabi814 | 0:46166e7d81a8 | 29 | |
metabi814 | 0:46166e7d81a8 | 30 | void reset(); // reset esp8266 |
metabi814 | 0:46166e7d81a8 | 31 | |
metabi814 | 0:46166e7d81a8 | 32 | void set_sta_ip(char * s_ip); |
metabi814 | 0:46166e7d81a8 | 33 | void list_ap(); |
metabi814 | 0:46166e7d81a8 | 34 | void getip(); |
metabi814 | 0:46166e7d81a8 | 35 | char _ip[100]; |
metabi814 | 0:46166e7d81a8 | 36 | char _lap[2000]; |
metabi814 | 0:46166e7d81a8 | 37 | //-------------------------------wifi websocket---------------------------- |
metabi814 | 0:46166e7d81a8 | 38 | void websocket(char * url); |
metabi814 | 0:46166e7d81a8 | 39 | bool w_connect(int socket); |
metabi814 | 0:46166e7d81a8 | 40 | int w_send(char * str); |
metabi814 | 0:46166e7d81a8 | 41 | bool w_read(char * message); |
metabi814 | 0:46166e7d81a8 | 42 | //bool w_is_connected(); |
metabi814 | 0:46166e7d81a8 | 43 | //bool close(); |
metabi814 | 0:46166e7d81a8 | 44 | char* getPath(); |
metabi814 | 0:46166e7d81a8 | 45 | |
metabi814 | 0:46166e7d81a8 | 46 | //------------------------------------------------------------------------- |
metabi814 | 0:46166e7d81a8 | 47 | |
metabi814 | 0:46166e7d81a8 | 48 | |
metabi814 | 0:46166e7d81a8 | 49 | protected: |
metabi814 | 0:46166e7d81a8 | 50 | |
metabi814 | 0:46166e7d81a8 | 51 | static esp8266* inst; |
metabi814 | 0:46166e7d81a8 | 52 | const char* _ssid; |
metabi814 | 0:46166e7d81a8 | 53 | const char* _password; |
metabi814 | 0:46166e7d81a8 | 54 | const char* _host; |
metabi814 | 0:46166e7d81a8 | 55 | const char* _port; |
metabi814 | 0:46166e7d81a8 | 56 | |
metabi814 | 0:46166e7d81a8 | 57 | private : |
metabi814 | 0:46166e7d81a8 | 58 | |
metabi814 | 0:46166e7d81a8 | 59 | //void fillFields(char * url); |
metabi814 | 0:46166e7d81a8 | 60 | int parseURL(const char* url, char* scheme, size_t maxSchemeLen, char* host, size_t maxHostLen, uint16_t* port, char* path, size_t maxPathLen); //Parse URL |
metabi814 | 0:46166e7d81a8 | 61 | int sendOpcode(uint8_t opcode, char * msg); |
metabi814 | 0:46166e7d81a8 | 62 | int sendLength(uint32_t len, char * msg); |
metabi814 | 0:46166e7d81a8 | 63 | int sendMask(char * msg); |
metabi814 | 0:46166e7d81a8 | 64 | int readChar(char * pC, bool block = true); |
metabi814 | 0:46166e7d81a8 | 65 | |
metabi814 | 0:46166e7d81a8 | 66 | char scheme[8]; |
metabi814 | 0:46166e7d81a8 | 67 | uint16_t port; |
metabi814 | 0:46166e7d81a8 | 68 | char host[32]; |
metabi814 | 0:46166e7d81a8 | 69 | char path[64]; |
metabi814 | 0:46166e7d81a8 | 70 | |
metabi814 | 0:46166e7d81a8 | 71 | int read(char * buf, int len, int min_len = -1); |
metabi814 | 0:46166e7d81a8 | 72 | int write(char * buf, int len); |
metabi814 | 0:46166e7d81a8 | 73 | |
metabi814 | 0:46166e7d81a8 | 74 | |
metabi814 | 0:46166e7d81a8 | 75 | }; |
metabi814 | 0:46166e7d81a8 | 76 | //#endif |