This section contains APIs for establishing the device as Web socket client. 

rsi_web_socket_create

Prototype int32_t rsi_web_socket_create(int8_t flags,uint8_t *server_ip_addr,uint16_t server_port,uint16_t device_port,uint8_t *webs_resource_name, uint8_t *webs_host_name, int32_t *socket_id,

void (*web_socket_data_receive_notify_callback) (uint32_t sock_no,uint8_t *buffer,uint32_t length));

Input Arguments int8_t flags : To select IP version and security

BIT(0) – RSI_IPV6

Set this bit to enable IPv6 , by default it is configured to IPv4

BIT(1) – RSI_SSL_ENABLE

Set this bit to enable SSL feature

uint8_t *server_ip_addr: Web server ip address

uint16_t server_port: Web server socket port.

uint16_t device_port: Local port

uint8_t *webs_resource_name: web resource name

Note:string of 50 characters maximum

uint8_t *webs_host_name: web host name

Note:string of 50 characters maximum

void (*web_socket_data_receive_notify_callback): callback when data packet is received on the created socket.

parameters: sock_no , buffer, length, more_data

sock_no:Application socket ID

buffer: buffer pointer

length: length of data

Return Value
  • On Success:  0
  • On Failure:
  • -2 : Invalid parameter
  • -4 : Buffer not available to serve the command
  • if return value is greater than 0
  • 0x0021, 0x0015, 0x0074
  • Please refer Error Codes for description of above error codes.
Description This API is used to create a web socket client.
Example Usage rsi_web_socket_create(flags,(uint8_t*)&server_ip_addr,(uint16_t)SERVER_PORT, (uint16_t)DEVICE_PORT, WEB_SOCKET_RESOURCE_NAME, WEB_SOCKET_HOST_NAME, &sockID, rsi_websocket_data_receive_handler );

rsi_web_socket_send_async

Prototype int32_t rsi_web_socket_send_async(uint32_t sockID,uint8_t opcode, int8_t *msg, int32_t msg_length);

 

Input Arguments uint32_t sockID: Application socket ID

uint8_t opcode: opcode (type of the packet to be included in web socket header). OPCODE should be as follows(Refer RFC 6455):

0 – Continuation frame

1 – Text frame

2 – Binary frame

[3-7] – Reserved for further non-control frames

8 – Connection close frame

9 – Ping frame

10 – Pong frame

[B-F] – Reserved for further control frames

FIN Bit should be as follows:

0: More web socket frames to be followed.

1: Final frame web socket message.

int8_t *msg:data

int32_t msg_length:data length

Return Value
  • On Success:  0
  • On Failure: -1
Description This API  is used to send data from the web socket client .
Example Usage rsi_web_socket_send_async(sockID, opcode, MESSAGE, strlen(MESSAGE));

rsi_web_socket_close

Prototype int32_t rsi_web_socket_close(int32_t sockID);

 

Input Arguments uint32_t sockID: Application socket ID
Return Value
  • On Success:  0
  • On Failure: -1
Description This API  is used to close the web socket client .
Example Usage rsi_web_socket_close(sockID);