Skip to content

Improvements to Paho MQTT (GIT8266O-492) #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions components/mqtt/paho/MQTTClient-C/src/FreeRTOS/MQTTFreeRTOS.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ int ThreadStart(Thread* thread, void (*fn)(void*), void* arg)
return rc;
}

void ThreadStop(Thread* thread)
{
vTaskDelete(thread->task);
}

void MutexInit(Mutex* mutex)
{
Expand Down Expand Up @@ -209,6 +213,34 @@ int NetworkConnect(Network* n, char* addr, int port)
return retVal;
}

int NetworkConnectIP(Network* n, char* addr, int port)
{
struct sockaddr_in sAddr;
int retVal = -1;

sAddr.sin_family = AF_INET;
sAddr.sin_addr.s_addr = inet_addr(addr);
sAddr.sin_port = htons(port);

if ((n->my_socket = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
goto exit;
}

if ((retVal = connect(n->my_socket, (struct sockaddr*)&sAddr, sizeof(sAddr))) < 0) {
close(n->my_socket);
goto exit;
}

exit:
return retVal;
}

void NetworkDisconnect(Network* n)
{
close(n->my_socket);
}


#ifdef CONFIG_SSL_USING_MBEDTLS
static int esp_ssl_read(Network* n, unsigned char* buffer, unsigned int len, unsigned int timeout_ms)
{
Expand Down
22 changes: 22 additions & 0 deletions components/mqtt/paho/MQTTClient-C/src/FreeRTOS/MQTTFreeRTOS.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef struct Thread
} Thread;

int ThreadStart(Thread*, void (*fn)(void*), void* arg);
void ThreadStop(Thread* thread);

/**
* @brief Initialize the network structure
Expand All @@ -89,6 +90,27 @@ void NetworkInit(Network*);
*/
int NetworkConnect(Network* n, char* addr, int port);

/**
* @brief connect with mqtt broker using ip address
*
* @param n - mqtt network struct
* @param addr - mqtt broker address
* @param port - mqtt broker port
*
* @return connect status
*/
int NetworkConnectIP(Network* n, char* addr, int port);

/**
* @brief Disconnect from mqtt broker
*
* @param n - mqtt network struct
*
* @return void
*/

void NetworkDisconnect(Network* n);

#ifdef CONFIG_SSL_USING_MBEDTLS
typedef struct ssl_ca_crt_key {
unsigned char* cacrt;
Expand Down
7 changes: 7 additions & 0 deletions components/mqtt/paho/MQTTClient-C/src/MQTTClient.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,13 @@ int MQTTStartTask(MQTTClient* client)
{
return ThreadStart(&client->thread, &MQTTRun, client);
}

void MQTTStopTask(MQTTClient* client)
{
ThreadStop(&client->thread);

return;
}
#endif


Expand Down
7 changes: 7 additions & 0 deletions components/mqtt/paho/MQTTClient-C/src/MQTTClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,13 @@ static inline DLLExport int MQTTIsConnected(MQTTClient* client)
* @return success code
*/
DLLExport int MQTTStartTask(MQTTClient* client);

/** MQTT stop background thread for a client.
* @param client - the client object to use
* @return void
*/
DLLExport void MQTTStopTask(MQTTClient* client);

#endif

#if defined(__cplusplus)
Expand Down