This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/TM4C123GH6PM: based on external analog input trigger email using tm4c123gxl launchpad

Part Number: TM4C123GH6PM
Other Parts Discussed in Thread: CC3100

Tool/software: Code Composer Studio

for the below code i have to

1.find  Identify the code that helps in establishing connection over SMTP.

2.Modify the code to trigger E-mail application based upon external analog input. 

so please help me to find out this two question's answer.

/*
* main.c - sample application to send email
*

*
*/

/*
* Application Name - Email
* Application Overview - This sample application demonstrates how CC3100
* can be used to send an email over SMTP. The application
* configures CC3100 to connect w/ an SMTP server and sends
* email to it. SMTP server forwards it to the recipient's
* email-server and the recipient receives the email from
* his email-server using IMAP/POP3 and/or other proprietary
* protocol.
* Application Details - processors.wiki.ti.com/.../CC31xx_Email_Demo_Application
* doc\examples\email.pdf
*/

#include "email.h"
#include "config.h"
#include "sl_common.h"

#define APPLICATION_VERSION "1.2.0"

#define SL_STOP_TIMEOUT 0xFF

/*
* GLOBAL VARIABLES -- Start
*/
_u32 g_Status = 0;
/*
* GLOBAL VARIABLES -- End
*/


/*
* STATIC FUNCTION DEFINITIONS -- Start
*/
static _i32 establishConnectionWithAP();
static _i32 disconnectFromAP();
static _i32 configureSimpleLinkToDefaultState();

static _i32 initializeAppVariables();
static void displayBanner();

static _i32 setEmail();
static _i32 sendEmail();
/*
* STATIC FUNCTION DEFINITIONS -- End
*/


/*
* ASYNCHRONOUS EVENT HANDLERS -- Start
*/

/*!
\brief This function handles WLAN events

\param[in] pWlanEvent is the event passed to the handler

\return None

\note

\warning
*/
void SimpleLinkWlanEventHandler(SlWlanEvent_t *pWlanEvent)
{
if(pWlanEvent == NULL)
{
CLI_Write(" [WLAN EVENT] NULL Pointer Error \n\r");
return;
}

switch(pWlanEvent->Event)
{
case SL_WLAN_CONNECT_EVENT:
{
SET_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);

/*
* Information about the connected AP (like name, MAC etc.) will be
* available in 'slWlanConnectAsyncResponse_t' - Applications
* can use it if required
*
* slWlanConnectAsyncResponse_t *pEventData = NULL;
* pEventData = &pWlanEvent->EventData.STAandP2PModeWlanConnected;
*
*/
}
break;

case SL_WLAN_DISCONNECT_EVENT:
{
slWlanConnectAsyncResponse_t* pEventData = NULL;

CLR_STATUS_BIT(g_Status, STATUS_BIT_CONNECTION);
CLR_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);

pEventData = &pWlanEvent->EventData.STAandP2PModeDisconnected;

/* If the user has initiated 'Disconnect' request, 'reason_code' is SL_USER_INITIATED_DISCONNECTION */
if(SL_WLAN_DISCONNECT_USER_INITIATED_DISCONNECTION == pEventData->reason_code)
{
CLI_Write(" Device disconnected from the AP on application's request \n\r");
}
else
{
CLI_Write(" Device disconnected from the AP on an ERROR..!! \n\r");
}
}
break;

default:
{
CLI_Write(" [WLAN EVENT] Unexpected event \n\r");
}
break;
}
}

/*!
\brief This function handles events for IP address acquisition via DHCP
indication

\param[in] pNetAppEvent is the event passed to the handler

\return None

\note

\warning
*/
void SimpleLinkNetAppEventHandler(SlNetAppEvent_t *pNetAppEvent)
{
if(pNetAppEvent == NULL)
{
CLI_Write(" [NETAPP EVENT] NULL Pointer Error \n\r");
return;
}

switch(pNetAppEvent->Event)
{
case SL_NETAPP_IPV4_IPACQUIRED_EVENT:
{
SET_STATUS_BIT(g_Status, STATUS_BIT_IP_ACQUIRED);

/*
* Information about the connected AP's IP, gateway, DNS etc.
* will be available in 'SlIpV4AcquiredAsync_t' - Applications
* can use it if required
*
* SlIpV4AcquiredAsync_t *pEventData = NULL;
* pEventData = &pNetAppEvent->EventData.ipAcquiredV4;
* <gateway_ip> = pEventData->gateway;
*
*/
}
break;

default:
{
CLI_Write(" [NETAPP EVENT] Unexpected event \n\r");
}
break;
}
}

/*!
\brief This function handles callback for the HTTP server events

\param[in] pHttpEvent - Contains the relevant event information
\param[in] pHttpResponse - Should be filled by the user with the
relevant response information

\return None

\note

\warning
*/
void SimpleLinkHttpServerCallback(SlHttpServerEvent_t *pHttpEvent,
SlHttpServerResponse_t *pHttpResponse)
{
/*
* This application doesn't work with HTTP server - Hence these
* events are not handled/expected here
*/
CLI_Write(" [HTTP EVENT] Unexpected event \n\r");
}

/*!
\brief This function handles general error events indication

\param[in] pDevEvent is the event passed to the handler

\return None
*/
void SimpleLinkGeneralEventHandler(SlDeviceEvent_t *pDevEvent)
{
/*
* Most of the general errors are not FATAL are are to be handled
* appropriately by the application
*/
CLI_Write(" [GENERAL EVENT] \n\r");
}

/*!
\brief This function handles socket events indication

\param[in] pSock is the event passed to the handler

\return None
*/
void SimpleLinkSockEventHandler(SlSockEvent_t *pSock)
{
if(pSock == NULL)
{
CLI_Write(" [SOCK EVENT] NULL Pointer Error \n\r");
return;
}

switch( pSock->Event )
{
case SL_SOCKET_TX_FAILED_EVENT:
{
/*
* TX Failed
*
* Information about the socket descriptor and status will be
* available in 'SlSockEventData_t' - Applications can use it if
* required
*
* SlSockEventData_u *pEventData = NULL;
* pEventData = & pSock->socketAsyncEvent;
*/
switch( pSock->socketAsyncEvent.SockTxFailData.status )
{
case SL_ECLOSE:
CLI_Write(" [SOCK EVENT] Close socket operation failed to transmit all queued packets\n\r");
break;


default:
CLI_Write(" [SOCK EVENT] Unexpected event \n\r");
break;
}
}
break;

default:
CLI_Write(" [SOCK EVENT] Unexpected event \n\r");
break;
}
}
/*
* ASYNCHRONOUS EVENT HANDLERS -- End
*/


/*
* Application's entry point
*/
int main(int argc, char** argv)
{
_i32 retVal = -1;

retVal = initializeAppVariables();
ASSERT_ON_ERROR(retVal);

/* Stop WDT and initialize the system-clock of the MCU */
stopWDT();
initClk();

/* Configure command line interface */
CLI_Configure();

displayBanner();

/*
* Following function configures the device to default state by cleaning
* the persistent settings stored in NVMEM (viz. connection profiles &
* policies, power policy etc)
*
* Applications may choose to skip this step if the developer is sure
* that the device is in its default state at start of application
*
* Note that all profiles and persistent settings that were done on the
* device will be lost
*/
retVal = configureSimpleLinkToDefaultState();
if(retVal < 0)
{
if (DEVICE_NOT_IN_STATION_MODE == retVal)
CLI_Write(" Failed to configure the device in its default state \n\r");

LOOP_FOREVER();
}

CLI_Write(" Device is configured in default state \n\r");

/*
* Initializing the CC3100 device
* Assumption is that the device is configured in station mode already
* and it is in its default state
*/
retVal = sl_Start(0, 0, 0);
if ((retVal < 0) ||
(ROLE_STA != retVal) )
{
CLI_Write(" Failed to start the device \n\r");
LOOP_FOREVER();
}

CLI_Write(" Device started as STATION \n\r");

/* Configure the source email */
retVal = setEmail();
if(retVal < 0)
LOOP_FOREVER();

/* Connecting to WLAN AP */
retVal = establishConnectionWithAP();
if(retVal < 0)
{
CLI_Write(" Failed to establish connection w/ an AP \n\r");
LOOP_FOREVER();
}

CLI_Write(" Connection established w/ AP and IP is acquired \n\r");

/* Configure and send the email */
CLI_Write(" Sending email... \n\r");
retVal = sendEmail();
if (retVal < 0)
{
CLI_Write(" Device couldn't send the email \n\r");
LOOP_FOREVER();
}
else
{
CLI_Write(" Email Sent successfully \n\r");
}

/* Disconnect from AP */
retVal = disconnectFromAP();
if(retVal < 0)
{
CLI_Write(" Failed to disconnect from the AP \n\r");
LOOP_FOREVER();
}

retVal = sl_Stop(SL_STOP_TIMEOUT);
if(retVal < 0)
LOOP_FOREVER();

return 0;
}

/*!
\brief This function configures the source email using parameters defined
in "config.h" file

\param[in] none

\return none

\note

\warning
*/
static _i32 setEmail()
{
_i32 retVal = -1;
SlNetAppSourceEmail_t sourceEmailId = {0};
SlNetAppSourcePassword_t sourceEmailPwd = {0};
SlNetAppEmailOpt_t eMailServerSetting = {0};

pal_Memcpy(sourceEmailId.Username,USER,pal_Strlen(USER)+1);
retVal = sl_NetAppEmailSet(NETAPP_SOURCE_EMAIL,pal_Strlen(USER)+1,
(_u8*)&sourceEmailId);
ASSERT_ON_ERROR(retVal);

pal_Memcpy(sourceEmailPwd.Password,PASS,pal_Strlen(PASS)+1);
retVal = sl_NetAppEmailSet(NETAPP_PASSWORD,pal_Strlen(PASS)+1,
(_u8*)&sourceEmailPwd);
ASSERT_ON_ERROR(retVal);

eMailServerSetting.Family = AF_INET;
eMailServerSetting.Port = GMAIL_HOST_PORT;
eMailServerSetting.Ip = SL_IPV4_VAL(74,125,129,108);
eMailServerSetting.SecurityMethod = SL_SO_SEC_METHOD_SSLv3_TLSV1_2;
//we changed SL_SO_SEC_METHOD_ SSLV3 with SL_SO_SEC_METHOD_SSLv3_TLSV1_2
eMailServerSetting.SecurityCypher = SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256;
//we changed SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5 with SL_SEC_MASK_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256
// eMailServerSetting.SecurityMethod = SL_SO_SEC_METHOD_SSLV3;
// eMailServerSetting.SecurityCypher = SL_SEC_MASK_SSL_RSA_WITH_RC4_128_MD5;

retVal = sl_NetAppEmailSet(NETAPP_ADVANCED_OPT,sizeof(SlNetAppEmailOpt_t),
(_u8*)&eMailServerSetting);
ASSERT_ON_ERROR(retVal);

return SUCCESS;
}

/*!
\brief Send the email to the preconfigured email ID

\param[in] none

\return 0 for success , -1 otherwise

\note

\warning
*/
static _i32 sendEmail()
{
_i32 Status = -1;

Status = sl_NetAppEmailSet(NETAPP_DEST_EMAIL,
pal_Strlen(DESTINATION_EMAIL),
(_u8 *)DESTINATION_EMAIL);
ASSERT_ON_ERROR(Status);

Status = sl_NetAppEmailSet(NETAPP_SUBJECT,
pal_Strlen(EMAIL_SUBJECT),
(_u8 *)EMAIL_SUBJECT);
ASSERT_ON_ERROR(Status);

Status = sl_NetAppEmailSet(NETAPP_MESSAGE,
pal_Strlen(EMAIL_MESSAGE),
(_u8 *)EMAIL_MESSAGE);
ASSERT_ON_ERROR(Status);

Status = sl_NetAppEmailConnect();
ASSERT_ON_ERROR(Status);

Status = sl_NetAppEmailSend();
ASSERT_ON_ERROR(Status);

return SUCCESS;
}

/*!
\brief This function configure the SimpleLink device in its default state. It:
- Sets the mode to STATION
- Configures connection policy to Auto and AutoSmartConfig
- Deletes all the stored profiles
- Enables DHCP
- Disables Scan policy
- Sets Tx power to maximum
- Sets power policy to normal
- Unregisters mDNS services
- Remove all filters

\param[in] none

\return On success, zero is returned. On error, negative is returned
*/
static _i32 configureSimpleLinkToDefaultState()
{
SlVersionFull ver = {0};
_WlanRxFilterOperationCommandBuff_t RxFilterIdMask = {0};

_u8 val = 1;
_u8 configOpt = 0;
_u8 configLen = 0;
_u8 power = 0;

_i32 retVal = -1;
_i32 mode = -1;

mode = sl_Start(0, 0, 0);
ASSERT_ON_ERROR(mode);

/* If the device is not in station-mode, try configuring it in station-mode */
if (ROLE_STA != mode)
{
if (ROLE_AP == mode)
{
/* If the device is in AP mode, we need to wait for this event before doing anything */
while(!IS_IP_ACQUIRED(g_Status)) { _SlNonOsMainLoopTask(); }
}

/* Switch to STA role and restart */
retVal = sl_WlanSetMode(ROLE_STA);
ASSERT_ON_ERROR(retVal);

retVal = sl_Stop(SL_STOP_TIMEOUT);
ASSERT_ON_ERROR(retVal);

retVal = sl_Start(0, 0, 0);
ASSERT_ON_ERROR(retVal);

/* Check if the device is in station again */
if (ROLE_STA != retVal)
{
/* We don't want to proceed if the device is not coming up in station-mode */
ASSERT_ON_ERROR(DEVICE_NOT_IN_STATION_MODE);
}
}

/* Get the device's version-information */
configOpt = SL_DEVICE_GENERAL_VERSION;
configLen = sizeof(ver);
retVal = sl_DevGet(SL_DEVICE_GENERAL_CONFIGURATION, &configOpt, &configLen, (_u8 *)(&ver));
ASSERT_ON_ERROR(retVal);

/* Set connection policy to Auto + SmartConfig (Device's default connection policy) */
retVal = sl_WlanPolicySet(SL_POLICY_CONNECTION, SL_CONNECTION_POLICY(1, 0, 0, 0, 1), NULL, 0);
ASSERT_ON_ERROR(retVal);

/* Remove all profiles */
retVal = sl_WlanProfileDel(0xFF);
ASSERT_ON_ERROR(retVal);

/*
* Device in station-mode. Disconnect previous connection if any
* The function returns 0 if 'Disconnected done', negative number if already disconnected
* Wait for 'disconnection' event if 0 is returned, Ignore other return-codes
*/
retVal = sl_WlanDisconnect();
if(0 == retVal)
{
/* Wait */
while(IS_CONNECTED(g_Status)) { _SlNonOsMainLoopTask(); }
}

/* Enable DHCP client*/
retVal = sl_NetCfgSet(SL_IPV4_STA_P2P_CL_DHCP_ENABLE,1,1,&val);
ASSERT_ON_ERROR(retVal);

/* Disable scan */
configOpt = SL_SCAN_POLICY(0);
retVal = sl_WlanPolicySet(SL_POLICY_SCAN , configOpt, NULL, 0);
ASSERT_ON_ERROR(retVal);

/* Set Tx power level for station mode
Number between 0-15, as dB offset from max power - 0 will set maximum power */
power = 0;
retVal = sl_WlanSet(SL_WLAN_CFG_GENERAL_PARAM_ID, WLAN_GENERAL_PARAM_OPT_STA_TX_POWER, 1, (_u8 *)&power);
ASSERT_ON_ERROR(retVal);

/* Set PM policy to normal */
retVal = sl_WlanPolicySet(SL_POLICY_PM , SL_NORMAL_POLICY, NULL, 0);
ASSERT_ON_ERROR(retVal);

/* Unregister mDNS services */
retVal = sl_NetAppMDNSUnRegisterService(0, 0);
ASSERT_ON_ERROR(retVal);

/* Remove all 64 filters (8*8) */
pal_Memset(RxFilterIdMask.FilterIdMask, 0xFF, 8);
retVal = sl_WlanRxFilterSet(SL_REMOVE_RX_FILTER, (_u8 *)&RxFilterIdMask,
sizeof(_WlanRxFilterOperationCommandBuff_t));
ASSERT_ON_ERROR(retVal);

retVal = sl_Stop(SL_STOP_TIMEOUT);
ASSERT_ON_ERROR(retVal);

retVal = initializeAppVariables();
ASSERT_ON_ERROR(retVal);

return retVal; /* Success */
}

/*!
\brief Connecting to a WLAN Access point

This function connects to the required AP (SSID_NAME).
The function will return once we are connected and have acquired IP address

\param[in] None

\return 0 on success, negative error-code on error

\note

\warning If the WLAN connection fails or we don't acquire an IP address,
We will be stuck in this function forever.
*/
static _i32 establishConnectionWithAP()
{
SlSecParams_t secParams = {0};
_i32 retVal = 0;

secParams.Key = PASSKEY;
secParams.KeyLen = PASSKEY_LEN;
secParams.Type = SEC_TYPE;

retVal = sl_WlanConnect(SSID_NAME, pal_Strlen(SSID_NAME), 0, &secParams, 0);
ASSERT_ON_ERROR(retVal);

/* Wait */
while((!IS_CONNECTED(g_Status)) || (!IS_IP_ACQUIRED(g_Status))) { _SlNonOsMainLoopTask(); }

return SUCCESS;
}

/*!
\brief Disconnecting from a WLAN Access point

This function disconnects from the connected AP

\param[in] None

\return none

\note

\warning If the WLAN disconnection fails, we will be stuck in this function forever.
*/
static _i32 disconnectFromAP()
{
_i32 retVal = -1;

/*
* The function returns 0 if 'Disconnected done', negative number if already disconnected
* Wait for 'disconnection' event if 0 is returned, Ignore other return-codes
*/
retVal = sl_WlanDisconnect();
if(0 == retVal)
{
/* Wait */
while(IS_CONNECTED(g_Status)) { _SlNonOsMainLoopTask(); }
}

return SUCCESS;
}

/*!
\brief This function initializes the application variables

\param[in] None

\return 0 on success, negative error-code on error
*/
static _i32 initializeAppVariables()
{
g_Status = 0;

return SUCCESS;
}

/*!
\brief This function displays the application's banner

\param None

\return None
*/
static void displayBanner()
{
CLI_Write("\n\r\n\r");
CLI_Write(" Email application - Version ");
CLI_Write(APPLICATION_VERSION);
CLI_Write("\n\r*******************************************************************************\n\r");
}