Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
socketInit

The function performs the necessary initializations for the socket library through the following steps:

Functions

NMI_API void socketInit (void)
 

NMI_API void socketInit ( void  )
Returns
void
Remarks
This initialization function must be invoked before any socket operation is performed. No error codes from this initialization function since the socket array is statically allocated based in the maximum number of sockets MAX_SOCKET based on the systems capability.

Example

This example demonstrates the use of the socketinit for socket initialization for an mqtt chat application.

tstrNetworkId strNetworkId;
tstrAuthPsk strAuthPsk;
int8_t ret;
char topic[strlen(MAIN_CHAT_TOPIC) + MAIN_CHAT_USER_NAME_SIZE + 1];
//Initialize the board.
//Initialize the UART console.
// Initialize the BSP.
----------
// Initialize socket interface.
// Connect to router.
strNetworkId.pu8Bssid = NULL;
strNetworkId.pu8Ssid = MAIN_WLAN_SSID;
strNetworkId.u8SsidLen = sizeof(MAIN_WLAN_SSID);
strNetworkId.u8Channel = M2M_WIFI_CH_ALL;
strAuthPsk.pu8Psk = NULL;
strAuthPsk.u8PassphraseLen = (uint8)strlen((char*)MAIN_WLAN_PSK);
m2m_wifi_connect_psk(WIFI_CRED_SAVE_ENCRYPTED, &strNetworkId, &strAuthPsk);

References gbSocketInit, gu16SessionID, hif_register_cb(), m2m_ip_cb(), m2m_memset(), M2M_REQ_GROUP_IP, and MAX_SOCKET.

Referenced by main(), NMI_GrowlInit(), and wifi_ap_provision().