Delta / NNN50_WIFI_API

Dependents:   NNN50_CE_Test_UDP NNN50_linux_firmware NNN50_SoftAP_HelloWorld NNN50_BLEWIFISensor ... more

Embed: (wiki syntax)

« Back to documentation index

socketInit

socketInit
[Function]

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

  • A check made by the global variable gbSocketInit, ensuring that initialization for sockets is performed only once, in-order to prevent reseting the socket instances already created in the global socket array (gastrSockets).
More...

Functions

NMI_API void socketInit (void)
NMI_API void socketDeinit (void)
 Socket Layer De-initialization.

Detailed Description

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

  • A check made by the global variable gbSocketInit, ensuring that initialization for sockets is performed only once, in-order to prevent reseting the socket instances already created in the global socket array (gastrSockets).
  • Zero initializations to the global socket array (gastrSockets), which holds the list of TCP sockets.
  • Registers the socket (Host Interface)hif callback function through the call to the hif_register_cb function. This facilitates handling all of the socket related functions received through interrupts from the firmware.

Function Documentation

NMI_API void socketDeinit ( void   )

Socket Layer De-initialization.

The function performs the necessary cleanup for the socket library static data It must be invoked as the last any socket operation is performed on any active sockets.

NMI_API void socketInit ( void   )
Parameters:
[in]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.

    tstrWifiInitParam param;
    int8_t ret;
    char topic[strlen(MAIN_CHAT_TOPIC) + MAIN_CHAT_USER_NAME_SIZE + 1];

    //Initialize the board.
    system_init();

    //Initialize the UART console. 
    configure_console();

    // Initialize the BSP.
    nm_bsp_init();
    
     ----------
     
    // Initialize socket interface.
    socketInit ();
    registerSocketCallback (socket_event_handler, socket_resolve_handler);

    // Connect to router. 
    m2m_wifi_connect((char *)MAIN_WLAN_SSID, sizeof(MAIN_WLAN_SSID),
            MAIN_WLAN_AUTH, (char *)MAIN_WLAN_PSK, M2M_WIFI_CH_ALL);