GSwifiInterface library (interface for GainSpan Wi-Fi GS1011 modules) Please see https://mbed.org/users/gsfan/notebook/GSwifiInterface/
Dependents: GSwifiInterface_HelloWorld GSwifiInterface_HelloServo GSwifiInterface_UDPEchoServer GSwifiInterface_UDPEchoClient ... more
Fork of WiflyInterface by
GainSpan Wi-Fi library
The GS1011/GS2100 is an ultra low power 802.11b wireless module from GainSpan.
mbed RTOS supported.
- about this library: http://mbed.org/users/gsfan/notebook/GSwifiInterface/
- about Wi-Fi module: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
ゲインスパン Wi-Fi モジュール ライブラリ
ゲインスパン社の低電力 Wi-Fiモジュール(無線LAN) GS1011/GS2100 シリーズ用のライブラリです。
mbed RTOS に対応しています。(mbed2.0)
- このライブラリについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- Wi-FIモジュールについて: http://mbed.org/users/gsfan/notebook/gainspan_wifi/
- UARTコマンド、SPIデータインターフェースに対応しました。(2019/09)
Diff: GSwifi/GSwifi.h
- Revision:
- 12:057089026a20
- Parent:
- 11:71d67fea5ace
- Child:
- 13:189e04ac70bd
diff -r 71d67fea5ace -r 057089026a20 GSwifi/GSwifi.h --- a/GSwifi/GSwifi.h Fri Nov 15 04:20:14 2013 +0000 +++ b/GSwifi/GSwifi.h Fri Nov 22 14:03:07 2013 +0000 @@ -42,9 +42,6 @@ #include "rtos.h" #endif -#define MSG_TABLE_NUM 15 -#define RES_TABLE_NUM 10 - //Debug is disabled by default #if defined(DEBUG) and (!defined(TARGET_LPC11U24)) #define DBG(x, ...) std::printf("[DBG]" x "\r\n", ##__VA_ARGS__); @@ -146,10 +143,10 @@ * \param cts mbed pin to use for cts line of Serial interface * \param rts mbed pin to use for rts line of Serial interface * \param reset reset pin of the wifi module - * \param alarm alarm pin of the wifi module - * \param baud baud rate of Serial interface + * \param alarm alarm pin of the wifi module (default NULL) + * \param baud baud rate of Serial interface (default 9600) */ - GSwifi (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm, int baud); + GSwifi (PinName tx, PinName rx, PinName cts, PinName rts, PinName reset, PinName alarm = NC, int baud = 9600); /** Connect the wifi module to the ssid contained in the constructor. * @param sec Security type (NONE, WEP_128 or WPA) @@ -178,18 +175,51 @@ /** Disconnect the wifi module from the access point * @returns 0 if successful */ - int disconnect (); + int dissociate (); + int disconnect () { + return dissociate(); + } - /** Check if a tcp link is active + /** Check if a Wi-Fi link is active * @returns true if successful */ - bool isConnected(); + bool isAssociated(); + /** polling if not use rtos + */ void poll (); + /** get Wi-Fi modue status + * @return Status + */ + Status getStatus (); + + /** set MAC address + */ + int setMacAddress (const char *mac); + /** get MAC address + */ + int getMacAddress (char *mac); + + /** use DHCP + */ int setAddress (const char *name = NULL); + /** use static IP address + * @param ip my ip address (dhcp start address) + * @param netmask subnet mask + * @param gateway default gateway + * @param dns my host name (default NULL) + */ int setAddress (const char *ip, const char *netmask, const char *gateway, const char *name = NULL); + /** get IP address + */ int getAddress (char *ip, char *netmask, char *gateway); + + /** set Wi-Fi security parameter + * @param sec Security + * @param ssid SSID + * @param pass pass phrase + */ int setSsid (Security sec, const char *ssid, const char *phrase); static GSwifi * getInstance() { @@ -199,7 +229,7 @@ // ----- GSwifi_util.cpp ----- int setRegion (int reg); - /** RSSI + /** get RSSI * @return RSSI (dBm) */ int getRssi (); @@ -266,12 +296,12 @@ /** TCP/UDP client * @return CID, -1:failure */ - int open (Protocol proto, const char *ip, int port, int src = 0); + int open (Protocol proto, const char *ip, int port, int src = 0, void(*func)(int) = NULL); /** TCP/UDP server * @return CID, -1:failure */ - int listen (Protocol proto, int port); + int listen (Protocol proto, int port, void(*func)(int) = NULL); /** close client/server */ @@ -281,8 +311,7 @@ */ int send (int cid, const char *buf, int len); - /* - * send data udp(s) + /** send data udp(s) */ int sendto (int cid, const char *buf, int len, const char *ip, int port); @@ -308,12 +337,70 @@ int getRemote(int cid, char **ip, int *port); // ----- GSwifi_http.cpp ----- - int httpGet (const char *host, int port, const char *uri, bool ssl = false, const char *user = NULL, const char *pwd = NULL); - int httpPost (const char *host, int port, const char *uri, const char *body, bool ssl = false, const char *user = NULL, const char *pwd = NULL); + /** http request (GET method) + */ + int httpGet (const char *host, int port, const char *uri, bool ssl = false, const char *user = NULL, const char *pwd = NULL, void(*func)(int) = NULL); + int httpGet (const char *host, int port, const char *uri, void(*func)(int) = NULL) { + return httpGet(host, port, uri, false, NULL, NULL, func); + } + /** http request (POST method) + */ + int httpPost (const char *host, int port, const char *uri, const char *body, bool ssl = false, const char *user = NULL, const char *pwd = NULL, void(*func)(int) = NULL); + int httpPost (const char *host, int port, const char *uri, const char *body, void(*func)(int) = NULL) { + return httpPost(host, port, uri, body, false, NULL, NULL, func); + } + int base64encode (const char *input, int length, char *output, int len); int urlencode (const char *str, char *buf, int len); int urldecode (const char *str, char *buf, int len); +#ifdef CFG_ENABLE_HTTPD + // ----- GSwifi_httpd.cpp ----- + /** start http server + * @param port + */ + int httpd (int port = 80); + + // ----- GSwifi_httpd_util.cpp ----- + /** attach uri to dirctory handler + */ + void httpdError (int cid, int err); + /** attach uri to dirctory handler + */ + int httpdAttach (const char *uri, const char *dir); + /** attach uri to cgi handler + */ + int httpdAttach (const char *uri, void (*funcCgi)(int)); +#endif + +#ifdef CFG_ENABLE_WEBSOCKET + // ----- GSwifi_httpd_ws.cpp ----- + /** websocket request (Upgrade method) + * @return CID, -1:failure + */ + int wsOpen (const char *host, int port, const char *uri, const char *user = NULL, const char *pwd = NULL); + /** send websocket data + */ + int wsSend (int cid, const char *buf, int len, const char *mask = NULL); +#endif + +#ifdef CFG_ENABLE_SMTP + // ----- GSwifi_smtp.cpp ----- + /** send mail (smtp) + * @param host SMTP server + * @param port SMTP port (25 or 587 or etc.) + * @param to To address + * @param from From address + * @param subject Subject + * @param mesg Message + * @param user username (SMTP Auth) + * @param pwd password (SMTP Auth) + * @retval 0 success + * @retval -1 failure + */ + int mail (const char *host, int port, const char *to, const char *from, const char *subject, const char *mesg, const char *user = NULL, const char *pwd = NULL); +#endif + // ----- GSwifi_msg.cpp ----- // ----- GSwifi_at.cpp ----- @@ -353,6 +440,8 @@ LPC_UART1_TypeDef *_uart; #elif defined(TARGET_LPC11U24) LPC_USART_Type *_uart; +#elif defined(TARGET_LPC11XX) + LPC_UART_TypeDef *_uart; #endif DigitalInOut _reset; DigitalInOut *_alarm; @@ -395,20 +484,110 @@ volatile bool received; volatile int parent; volatile bool accept; + void(*func)(int); } _con[16]; +#ifdef CFG_ENABLE_HTTPD + enum HttpdMode { + HTTPDMODE_REQUEST, + HTTPDMODE_REQUEST_STR, + HTTPDMODE_HEADER, + HTTPDMODE_BODY, + HTTPDMODE_ENTER, + HTTPDMODE_ERROR, + HTTPDMODE_WEBSOCKET, + HTTPDMODE_WEBSOCKET_MASK, + HTTPDMODE_WEBSOCKET_BODY, + HTTPDMODE_WEBSOCKET_ENTER, + }; + + enum HttpdReq { + REQ_HTTPGET, + REQ_HTTPPOST, + }; + + struct HTTPD { + HttpdMode mode; + HttpdReq req; + CircBuffer <char>*buf; + char *uri; + char *filename; + char *querystring; + int enter; + int length; + int n; + int keepalive; +#ifdef CFG_ENABLE_WEBSOCKET + int websocket; + char *websocket_key; + int websocket_opcode; + int websocket_flg; + char websocket_mask[4]; + int websocket_payload; +#endif + } _httpd[16]; + + struct HTTPD_HANDLER { + char *uri; + char *dir; + void (*func)(int); + } _httpd_handler[CFG_HTTPD_HANDLER_NUM]; + + int _httpd_cid; + int _handler_count; +#endif // CFG_ENABLE_HTTPD + // ----- GSwifi.cpp ----- #ifdef CFG_ENABLE_RTOS static void threadPoll (void const *args); #endif + // ----- GSwifi_sock.cpp ----- + void initCon (int cid, bool connected); + // ----- GSwifi_util.cpp ----- int x2i (char c); char i2x (int i); int from_hex (int ch); int to_hex (int code); + // ----- GSwifi_http.cpp ----- + +#ifdef CFG_ENABLE_HTTPD + // ----- GSwifi_httpd.cpp ----- + void httpdRecvData (int cid, char c); + int httpdParseRequest (int cid); + void httpdPoll (); + int httpdParseHeader (int cid); + void reqContentLength (int cid, const char *buf); + void reqConnection (int cid, const char *buf); + void reqUpgrade (int cid, const char *buf); + void reqWebSocketVersion (int cid, const char *buf); + void reqWebSocketKey (int cid, const char *buf); + + // ----- GSwifi_httpd_util.cpp ----- + int httpdFile (int cid, char *dir); + int httpdGetHandler (const char *uri); + char *mimetype (char *file); + int strnicmp (const char *p1, const char *p2, int n); +#endif + +#ifdef CFG_ENABLE_WEBSOCKET + // ----- GSwifi_httpd_ws.cpp ----- + int wsWait (int cid, int code); +#ifdef CFG_ENABLE_HTTPD + void wsRecvData (int cid, char c); + int wsParseRequest (int cid); + int wsAccept (int cid); +#endif +#endif + +#ifdef CFG_ENABLE_SMTP + // ----- GSwifi_smtp.cpp ----- + int smtpWait (int cid, int code); +#endif + // ----- GSwifi_msg.cpp ----- void recvData (char c); int parseMessage (); @@ -430,6 +609,7 @@ void resTime (const char*); void resChannel (const char*); void resStatus (const char*); + void resHttp (const char *buf); // ----- GSwifi_at.cpp ----- void clearFlags ();