GainSpan Wi-Fi library see: http://mbed.org/users/gsfan/notebook/gainspan_wifi/

Dependents:   GSwifi_httpd GSwifi_websocket GSwifi_tcpclient GSwifi_tcpserver ... more

Fork of GSwifi by gs fan

Embed: (wiki syntax)

« Back to documentation index

GSwifi Class Reference

GSwifi Class Reference

GSwifi class. More...

#include <GSwifi.h>

Public Types

enum  GSSECURITY
 

Wi-Fi security.

More...
enum  GSPROTOCOL
 

TCP/IP protocol.

More...
enum  GSTYPE
 

Client/Server.

More...
typedef void(* onGsReceiveFunc )(int cid, int len)
 data receive callback function

Public Member Functions

 GSwifi (PinName p_tx, PinName p_rx, PinName p_reset, PinName p_alarm=NC, int baud=GS_BAUD)
 default constructor (no fllow controll)
 GSwifi (PinName p_tx, PinName p_rx, PinName p_cts, PinName p_rts, PinName p_reset, PinName p_alarm=NC, int baud=GS_BAUD)
 default constructor (with hardware fllow controll)
void poll ()
 polling
int command (const char *cmd, GSRESPONCE res, int timeout=GS_TIMEOUT)
 send command
void resetResponse (GSRESPONCE res)
 reset recv responce
int waitResponse (int ms)
 wait recv responce
int connect (GSSECURITY sec, const char *ssid, const char *pass, int dhcp=1, int reconnect=GS_RECONNECT, char *name=NULL)
 associate infrastructure
int adhock (GSSECURITY sec, const char *ssid, const char *pass, IpAddr ipaddr, IpAddr netmask)
 adhock
int limitedap (GSSECURITY sec, const char *ssid, const char *pass, IpAddr ipaddr, IpAddr netmask, char *dns=NULL)
 limited AP
int disconnect ()
 unassociate
int reconnect ()
 re-connect
int setBaud (int baud)
 main polling
int setRegion (int reg=GS_WREGDOMAIN)
 change radio region
int setAddress (char *name=NULL)
 use DHCP
int setAddress (IpAddr ipaddr, IpAddr netmask, IpAddr gateway, IpAddr nameserver)
 use static ip address
int getAddress (IpAddr &ipaddr, IpAddr &netmask, IpAddr &gateway, IpAddr &nameserver)
 get ip address
int getMacAddress (char *mac)
 get mac address
int getHostByName (const char *name, IpAddr &addr)
 resolv hostname
int getHostByName (Host &host)
 resolv hostname
bool isConnected ()
 wifi connected
GSSTATUS getStatus ()
 status
int getRssi ()
 RSSI.
int setRFPower (int power)
 RF power.
int powerSave (int active, int save)
 power save mode
int standby (int msec)
 standby mode
int wakeup ()
 restore standby
int deepSleep ()
 deep sleep mode
int ntpdate (Host host, int sec=0)
 set NTP server
int setTime (time_t time)
 set system time
time_t getTime ()
 get RTC time
int gpioOut (int port, int out)
 GPIO output.
int provisioning (char *user, char *pass)
 Web server.
int certAdd (const char *name, const char *cert, int len)
 certificate
int open (Host &host, GSPROTOCOL pro, int port=0)
 tcp/udp client
int listen (int port, GSPROTOCOL pro)
 tcp/udp server
int close (int cid)
 close client/server
int send (int cid, const char *buf, int len)
 send data tcp(s/c), udp(c)
int send (int cid, const char *buf, int len, Host &host)
 send data udp(s)
int recv (int cid, char *buf, int len)
 recv data tcp(s/c), udp(c)
int recv (int cid, char *buf, int len, Host &host)
 recv data udp(s)
bool isConnected (int cid)
 tcp/udp connected
int httpGet (Host &host, const char *uri, const char *user, const char *pwd, int ssl=0, onGsReceiveFunc ponGsReceive=NULL)
 http request (GET method)
int httpPost (Host &host, const char *uri, const char *body, const char *user, const char *pwd, int ssl=0, onGsReceiveFunc ponGsReceive=NULL)
 http request (POST method)
int wsOpen (Host &host, const char *uri, const char *user, const char *pwd, onGsReceiveFunc ponGsReceive=NULL)
 websocket request (Upgrade method)
int wsSend (int cid, const char *buf, int len, const char *mask=NULL)
 send data websocket
int base64encode (char *input, int length, char *output, int len)
 base64 encode
int urlencode (char *str, char *buf, int len)
 url encode
int urldecode (char *str, char *buf, int len)
 url decode
int mail (Host &host, const char *to, const char *from, const char *subject, const char *mesg, const char *user=NULL, const char *pwd=NULL)
 send mail (smtp)
int httpd (int port=80)
 start http server
void send_httpd_error (int cid, int err)
 attach uri to dirctory handler
int attach_httpd (const char *uri, const char *dir)
 attach uri to dirctory handler
int attach_httpd (const char *uri, onHttpdCgiFunc ponHttpCgi)
 attach uri to cgi handler

Detailed Description

GSwifi class.

Definition at line 60 of file GSwifi.h.


Member Typedef Documentation

typedef void(* onGsReceiveFunc)(int cid, int len)

data receive callback function

Definition at line 131 of file GSwifi.h.


Member Enumeration Documentation

enum GSPROTOCOL

TCP/IP protocol.

Definition at line 82 of file GSwifi.h.

enum GSSECURITY

Wi-Fi security.

Definition at line 66 of file GSwifi.h.

enum GSTYPE

Client/Server.

Definition at line 93 of file GSwifi.h.


Constructor & Destructor Documentation

GSwifi ( PinName  p_tx,
PinName  p_rx,
PinName  p_reset,
PinName  p_alarm = NC,
int  baud = GS_BAUD 
)

default constructor (no fllow controll)

Parameters:
p_txmbed TXD pin (GS RXD)
p_rxmbed RXD pin (GS TXD)
p_resetGS RESET pin
p_alarmGS ALARM pin
bauduart baud rate

Definition at line 27 of file GSwifi.cpp.

GSwifi ( PinName  p_tx,
PinName  p_rx,
PinName  p_cts,
PinName  p_rts,
PinName  p_reset,
PinName  p_alarm = NC,
int  baud = GS_BAUD 
)

default constructor (with hardware fllow controll)

Parameters:
p_txmbed TXD pin (GS RXD)
p_rxmbed RXD pin (GS TXD)
p_ctsmbed CTS pin (GS RTS)
p_rtsmbed RTS pin (GS CTS)
p_resetGS RESET pin
p_alarmGS ALARM pin
bauduart baud rate

Definition at line 54 of file GSwifi.cpp.


Member Function Documentation

int adhock ( GSSECURITY  sec,
const char *  ssid,
const char *  pass,
IpAddr  ipaddr,
IpAddr  netmask 
)

adhock

Parameters:
secGSSEC_OPEN or GSSEC_WEP
ssidSSID
pass10 or 26 hexadecimal digits
ipaddrmy ip address
netmasksubnet mask
Return values:
0success
-1failure

Definition at line 842 of file GSwifi.cpp.

int attach_httpd ( const char *  uri,
const char *  dir 
)

attach uri to dirctory handler

Definition at line 395 of file GSwifi_httpd.cpp.

int attach_httpd ( const char *  uri,
onHttpdCgiFunc  ponHttpCgi 
)

attach uri to cgi handler

Definition at line 409 of file GSwifi_httpd.cpp.

int base64encode ( char *  input,
int  length,
char *  output,
int  len 
)

base64 encode

Definition at line 281 of file GSwifi_http.cpp.

int certAdd ( const char *  name,
const char *  cert,
int  len 
)

certificate

Definition at line 1252 of file GSwifi.cpp.

int close ( int  cid )

close client/server

Definition at line 89 of file GSwifi_sock.cpp.

int command ( const char *  cmd,
GSRESPONCE  res,
int  timeout = GS_TIMEOUT 
)

send command

Definition at line 672 of file GSwifi.cpp.

int connect ( GSSECURITY  sec,
const char *  ssid,
const char *  pass,
int  dhcp = 1,
int  reconnect = GS_RECONNECT,
char *  name = NULL 
)

associate infrastructure

Parameters:
secGSSEC_OPEN, GSSEC_WEP, GSSEC_WPA_PSK, GSSEC_WPA2_PSK, GSSEC_WPS_BUTTON
ssidSSID
passpass phrase
dhcp0:static ip, 1:dhcp
reconnectauto re-connect time
namemy host name
Return values:
0success
-1failure

Definition at line 730 of file GSwifi.cpp.

int deepSleep (  )

deep sleep mode

Definition at line 1195 of file GSwifi.cpp.

int disconnect (  )

unassociate

Definition at line 941 of file GSwifi.cpp.

int getAddress ( IpAddr ipaddr,
IpAddr netmask,
IpAddr gateway,
IpAddr nameserver 
)

get ip address

Definition at line 1029 of file GSwifi.cpp.

int getHostByName ( const char *  name,
IpAddr addr 
)

resolv hostname

Parameters:
namehostname
addrresolved ip address

Definition at line 1047 of file GSwifi.cpp.

int getHostByName ( Host host )

resolv hostname

Parameters:
host.namehostname
host.ipaddrresolved ip address

Definition at line 1059 of file GSwifi.cpp.

int getMacAddress ( char *  mac )

get mac address

Definition at line 1037 of file GSwifi.cpp.

int getRssi (  )

RSSI.

Returns:
RSSI (dBm)

Definition at line 1084 of file GSwifi.cpp.

GSwifi::GSSTATUS getStatus (  )

status

Returns:
GSSTATUS

Definition at line 1080 of file GSwifi.cpp.

time_t getTime (  )

get RTC time

Returns:
date time (UTC)

Definition at line 1235 of file GSwifi.cpp.

int gpioOut ( int  port,
int  out 
)

GPIO output.

Parameters:
port10,11,30,31
out0:set(high), 1:reset(low)

Definition at line 1243 of file GSwifi.cpp.

int httpd ( int  port = 80 )

start http server

Parameters:
port

Definition at line 48 of file GSwifi_httpd.cpp.

int httpGet ( Host host,
const char *  uri,
const char *  user,
const char *  pwd,
int  ssl = 0,
onGsReceiveFunc  ponGsReceive = NULL 
)

http request (GET method)

Definition at line 32 of file GSwifi_http.cpp.

int httpPost ( Host host,
const char *  uri,
const char *  body,
const char *  user,
const char *  pwd,
int  ssl = 0,
onGsReceiveFunc  ponGsReceive = NULL 
)

http request (POST method)

Definition at line 78 of file GSwifi_http.cpp.

bool isConnected (  )

wifi connected

Definition at line 1071 of file GSwifi.cpp.

bool isConnected ( int  cid )

tcp/udp connected

Definition at line 224 of file GSwifi_sock.cpp.

int limitedap ( GSSECURITY  sec,
const char *  ssid,
const char *  pass,
IpAddr  ipaddr,
IpAddr  netmask,
char *  dns = NULL 
)

limited AP

Parameters:
secGSSEC_OPEN or GSSEC_WEP
ssidSSID
pass10 or 26 hexadecimal digits
ipaddrmy ip address (dhcp start address)
netmasksubnet mask
dnsmy host name
Return values:
0success
-1failure firmware: s2w-secureweb, s2w-web, s2w-wpsweb

Definition at line 888 of file GSwifi.cpp.

int listen ( int  port,
GSPROTOCOL  pro 
)

tcp/udp server

Returns:
CID, -1:failure

Definition at line 70 of file GSwifi_sock.cpp.

int mail ( Host host,
const char *  to,
const char *  from,
const char *  subject,
const char *  mesg,
const char *  user = NULL,
const char *  pwd = NULL 
)

send mail (smtp)

Parameters:
hostSMTP server
toTo address
fromFrom address
subjectSubject
mesgMessage
userusername (SMTP Auth)
pwdpassword (SMTP Auth)
Return values:
0success
-1failure

Definition at line 30 of file GSwifi_smtp.cpp.

int ntpdate ( Host  host,
int  sec = 0 
)

set NTP server

Parameters:
hostSNTP server
sectime sync interval, 0:one time

Definition at line 1203 of file GSwifi.cpp.

int open ( Host host,
GSPROTOCOL  pro,
int  port = 0 
)

tcp/udp client

Returns:
CID, -1:failure

Definition at line 43 of file GSwifi_sock.cpp.

void poll (  )

polling

Definition at line 643 of file GSwifi.cpp.

int powerSave ( int  active,
int  save 
)

power save mode

Parameters:
activerx radio 0:switched off, 1:always on
savepower save 0:disable, 1:enable

Definition at line 1125 of file GSwifi.cpp.

int provisioning ( char *  user,
char *  pass 
)

Web server.

Definition at line 1270 of file GSwifi.cpp.

int reconnect (  )

re-connect

Definition at line 955 of file GSwifi.cpp.

int recv ( int  cid,
char *  buf,
int  len 
)

recv data tcp(s/c), udp(c)

Returns:
length

Definition at line 187 of file GSwifi_sock.cpp.

int recv ( int  cid,
char *  buf,
int  len,
Host host 
)

recv data udp(s)

Returns:
length

Definition at line 205 of file GSwifi_sock.cpp.

void resetResponse ( GSRESPONCE  res )

reset recv responce

Definition at line 700 of file GSwifi.cpp.

int send ( int  cid,
const char *  buf,
int  len,
Host host 
)

send data udp(s)

Definition at line 145 of file GSwifi_sock.cpp.

int send ( int  cid,
const char *  buf,
int  len 
)

send data tcp(s/c), udp(c)

Definition at line 101 of file GSwifi_sock.cpp.

void send_httpd_error ( int  cid,
int  err 
)

attach uri to dirctory handler

Definition at line 360 of file GSwifi_httpd.cpp.

int setAddress ( char *  name = NULL )

use DHCP

Definition at line 991 of file GSwifi.cpp.

int setAddress ( IpAddr  ipaddr,
IpAddr  netmask,
IpAddr  gateway,
IpAddr  nameserver 
)

use static ip address

Definition at line 1004 of file GSwifi.cpp.

int setBaud ( int  baud )

main polling

Definition at line 1091 of file GSwifi.cpp.

int setRegion ( int  reg = GS_WREGDOMAIN )

change radio region

Definition at line 1106 of file GSwifi.cpp.

int setRFPower ( int  power )

RF power.

Parameters:
power0(high)-7(low)

Definition at line 1116 of file GSwifi.cpp.

int setTime ( time_t  time )

set system time

Parameters:
timedate time (UTC)

Definition at line 1224 of file GSwifi.cpp.

int standby ( int  msec )

standby mode

Parameters:
msecwakeup after wakeup after msec or alarm1/2 core off, save to RTC ram

Definition at line 1136 of file GSwifi.cpp.

int urldecode ( char *  str,
char *  buf,
int  len 
)

url decode

Definition at line 328 of file GSwifi_http.cpp.

int urlencode ( char *  str,
char *  buf,
int  len 
)

url encode

Definition at line 307 of file GSwifi_http.cpp.

int waitResponse ( int  ms )

wait recv responce

Definition at line 707 of file GSwifi.cpp.

int wakeup (  )

restore standby

Definition at line 1159 of file GSwifi.cpp.

int wsOpen ( Host host,
const char *  uri,
const char *  user,
const char *  pwd,
onGsReceiveFunc  ponGsReceive = NULL 
)

websocket request (Upgrade method)

Definition at line 136 of file GSwifi_http.cpp.

int wsSend ( int  cid,
const char *  buf,
int  len,
const char *  mask = NULL 
)

send data websocket

Definition at line 244 of file GSwifi_http.cpp.