WiFiSSLClient Class
WiFiSSLClient Class
Description
A class for WiFi Secure Socket Layer Client implementation for Ameba.
Syntax
class WiFiSSLClient
Members
| Public Constructors | |
| WiFiSSLClient::WiFiSSLClient | Constructs a WiFiSSLClient instance that always connects in SSL to the specified IP address and port. |
| Public Methods | |
| WiFiSSLClient::connect | Connect to the IP address and port. |
| WiFiSSLClient::write | Write data (single byte) to the server. |
| WiFiSSLClient::available | Get the number of bytes available for reading. |
| WiFiSSLClient::read | Read the incoming byte from the server. |
| WiFiSSLClient::peek | Get the next byte from the current packet without moving on to the next byte. |
| WiFiSSLClient::flush | Clear all the bytes that have been written to the client but not yet read. |
| WiFiSSLClient::stop | Disconnect from the server. |
| WiFiSSLClient::connected | Check if SSL client is connected. |
| WiFiSSLClient::setRootCA | Set Root CA for authentication. |
| WiFiSSLClient::setClientCertificate | Set certificate of the client. |
| WiFiSSLClient::setRecvTimeout | Set receiving timeout. |
| WiFiSSLClient::setPreSharedKey | Set the pre shared key (PSK) to use for authentication. |
Description
Constructs a WiFiSSLClient instance that always connects in SSL to the specified IP address and port.
Syntax
WiFiSSLClient(void);
WiFiSSLClient(uint8_t sock);
Parameters
sock: socket state, default -1.
Returns
NA
Example Code
Example: WiFiSSLClient
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/WiFiSSLClient/WiFiSSLClient.ino)
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Connect to the IP address and port.
Syntax
virtual int connect(IPAddress ip, uint16_t port);
virtual int connect(const char *host, uint16_t port);
virtual uint8_t connected(void);
int connect(const char *host, uint16_t port, unsigned char* rootCABuff, unsigned char* cli_cert, unsigned char* cli_key);
int connect(IPAddress ip, uint16_t port, unsigned char* rootCABuff, unsigned char* cli_cert, unsigned char* cli_key);
int connect(const char *host, uint16_t port, unsigned char* pskIdent, unsigned char* psKey);
int connect(IPAddress ip, uint16_t port, unsigned char* pskIdent, unsigned char* psKey);
Parameters
ip: IP address
host: Host name
port: the port to listen to
rootCABuff: buffer that store root CA
cli_cert: buffer that store client certificate
cli_key: buffer that store client key pair
pskIdent: identity for PSK
psKey: Pre shared key
Returns
This function returns “1” if successful, else returns “0”.
Example Code
Example: WiFiSSLClient
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/WiFiSSLClient/WiFiSSLClient.ino)
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Write data (single byte) to the server the SSL client is connected to.
Syntax
virtual size_t write(uint8_t b);
virtual size_t write(const uint8_t *buf, size_t size);
Parameters
b: the byte or char to write
buf: the outgoing message
buf: a pointer to an array containing the outgoing message
size: the size of the buffer
Returns
This function returns the byte/ character that will be written to the server or the size of the buffer.
Example Code
NA
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Get the number of bytes available for reading.
Syntax
virtual int available(void);
Parameters
NA
Returns
This function returns 1 and number of bytes available for reading if there are available data, else returns 0.
Example Code
Example: WiFiSSLClient
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/WiFiSSLClient/WiFiSSLClient.ino)
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Read the incoming byte from the server that the SSL client is connected to.
Syntax
virtual int read(void);
virtual int read(uint8_t *buf, size_t size);
Parameters
buf: buffer to hold incoming byte
size: maximum size of the buffer
Returns
This function returns the size of the buffer or returns -1 if no buffer is available.
Example Code
Example: WiFiSSLClient
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/WiFiSSLClient/WiFiSSLClient.ino)
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Get the next byte from the current packet without moving on to the next byte.
Syntax
int peek(void);
Parameters
NA
Returns
This function returns the next byte or character, else returns -1 if none is available.
Example Code
NA
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Clear all the bytes that have been written to the client but not yet read.
Syntax
virtual void flush(void);
Parameters
NA
Returns
NA
Example Code
NA
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Disconnect from the server.
Syntax
virtual void stop (void);
Parameters
NA
Returns
NA
Example Code
Example: WiFiSSLClient
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/WiFiSSLClient/WiFiSSLClient.ino)
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Check if SSL client is connected.
Syntax
virtual uint8_t connected(void);
Parameters
NA
Returns
The function returns “1” if connected, returns “0” if not connected.
Example Code
Example: WiFiSSLClient
(https://github.com/ambiot/amb1_arduino/blob/dev/Arduino_package/hardware/libraries/WiFi/examples/WiFiSSLClient/WiFiSSLClient.ino)
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Set Root CA for authentication.
Syntax
void setRootCA(unsigned char *rootCA);
Parameters
rootCA: a string of rootCA
Returns
NA
Example Code
NA
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Set certificate of the client.
Syntax
void setClientCertificate(unsigned char *client_ca, unsigned char *private_key);
Parameters
client_ca: Client certificate
private_key: client’s private key pair
Returns
NA
Example Code
NA
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Set receiving timeout.
Syntax
int setRecvTimeout(int timeout);
Parameters
timeout: timeout in seconds.
Returns
The function returns “0”.
Example Code
NA
Notes and Warnings
“WiFiSSLClient.h” must be included to use the class function.
Description
Set the pre shared key (PSK) to use for authentication.
Syntax
void setPreSharedKey(unsigned char *pskIdent, unsigned char *psKey);
Parameters
pskIdent: identity for PSK
psKey: Pre shared key
Returns
NA
Example Code
NA
Notes and Warnings
Do not set a root CA and client certificate if PSK should be used for authentication. If root CA, client certificate and PSK are all set, certificate-based authentication will be used. “WiFiSSLClient.h” must be included to use the class function.