mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-07-07 13:29:19 +00:00
Add note about MEMP_NUM_SYS_TIMEOUT in four apps
This commit is contained in:
parent
a329bdd607
commit
4b10b4dab3
|
@ -3,11 +3,13 @@ MQTT client for lwIP
|
||||||
Author: Erik Andersson
|
Author: Erik Andersson
|
||||||
|
|
||||||
Details of the MQTT protocol can be found at:
|
Details of the MQTT protocol can be found at:
|
||||||
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
|
http://docs.oasis-open.org/mqtt/mqtt/v3.1.1/os/mqtt-v3.1.1-os.html
|
||||||
|
|
||||||
-----------------------------------------------------------------
|
-----------------------------------------------------------------
|
||||||
1. Initial steps, reserve memory and make connection to server:
|
1. Initial steps, reserve memory and make connection to server:
|
||||||
|
|
||||||
|
You need to increase MEMP_NUM_SYS_TIMEOUT by one if you use MQTT!
|
||||||
|
|
||||||
1.1: Provide storage
|
1.1: Provide storage
|
||||||
|
|
||||||
Static allocation:
|
Static allocation:
|
||||||
|
@ -19,34 +21,34 @@ Dynamic allocation:
|
||||||
if(client != NULL) {
|
if(client != NULL) {
|
||||||
example_do_connect(&client);
|
example_do_connect(&client);
|
||||||
}
|
}
|
||||||
|
|
||||||
1.2: Establish Connection with server
|
1.2: Establish Connection with server
|
||||||
|
|
||||||
void example_do_connect(mqtt_client_t *client)
|
void example_do_connect(mqtt_client_t *client)
|
||||||
{
|
{
|
||||||
struct mqtt_connect_client_info_t ci;
|
struct mqtt_connect_client_info_t ci;
|
||||||
err_t err;
|
err_t err;
|
||||||
|
|
||||||
/* Setup an empty client info structure */
|
/* Setup an empty client info structure */
|
||||||
memset(&ci, 0, sizeof(ci));
|
memset(&ci, 0, sizeof(ci));
|
||||||
|
|
||||||
/* Minimal amount of information required is client identifier, so set it here */
|
/* Minimal amount of information required is client identifier, so set it here */
|
||||||
ci.client_id = "lwip_test";
|
ci.client_id = "lwip_test";
|
||||||
|
|
||||||
/* Initiate client and connect to server, if this fails immediately an error code is returned
|
/* Initiate client and connect to server, if this fails immediately an error code is returned
|
||||||
otherwise mqtt_connection_cb will be called with connection result after attempting
|
otherwise mqtt_connection_cb will be called with connection result after attempting
|
||||||
to establish a connection with the server.
|
to establish a connection with the server.
|
||||||
For now MQTT version 3.1.1 is always used */
|
For now MQTT version 3.1.1 is always used */
|
||||||
|
|
||||||
err = mqtt_client_connect(client, ip_addr, MQTT_PORT, mqtt_connection_cb, 0, &ci);
|
err = mqtt_client_connect(client, ip_addr, MQTT_PORT, mqtt_connection_cb, 0, &ci);
|
||||||
|
|
||||||
/* For now just print the result code if something goes wrong */
|
/* For now just print the result code if something goes wrong */
|
||||||
if(err != ERR_OK) {
|
if(err != ERR_OK) {
|
||||||
printf("mqtt_connect return %d\n", err);
|
printf("mqtt_connect return %d\n", err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Connection to server can also be probed by calling mqtt_client_is_connected(client)
|
Connection to server can also be probed by calling mqtt_client_is_connected(client)
|
||||||
|
|
||||||
-----------------------------------------------------------------
|
-----------------------------------------------------------------
|
||||||
2. Implementing the connection status callback
|
2. Implementing the connection status callback
|
||||||
|
@ -57,11 +59,11 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection
|
||||||
err_t err;
|
err_t err;
|
||||||
if(status == MQTT_CONNECT_ACCEPTED) {
|
if(status == MQTT_CONNECT_ACCEPTED) {
|
||||||
printf("mqtt_connection_cb: Successfully connected\n");
|
printf("mqtt_connection_cb: Successfully connected\n");
|
||||||
|
|
||||||
/* Setup callback for incoming publish requests */
|
/* Setup callback for incoming publish requests */
|
||||||
mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg);
|
mqtt_set_inpub_callback(client, mqtt_incoming_publish_cb, mqtt_incoming_data_cb, arg);
|
||||||
|
|
||||||
/* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */
|
/* Subscribe to a topic named "subtopic" with QoS level 1, call mqtt_sub_request_cb with result */
|
||||||
err = mqtt_subscribe(client, "subtopic", 1, mqtt_sub_request_cb, arg);
|
err = mqtt_subscribe(client, "subtopic", 1, mqtt_sub_request_cb, arg);
|
||||||
|
|
||||||
if(err != ERR_OK) {
|
if(err != ERR_OK) {
|
||||||
|
@ -69,16 +71,16 @@ static void mqtt_connection_cb(mqtt_client_t *client, void *arg, mqtt_connection
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
printf("mqtt_connection_cb: Disconnected, reason: %d\n", status);
|
printf("mqtt_connection_cb: Disconnected, reason: %d\n", status);
|
||||||
|
|
||||||
/* Its more nice to be connected, so try to reconnect */
|
/* Its more nice to be connected, so try to reconnect */
|
||||||
example_do_connect(client);
|
example_do_connect(client);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mqtt_sub_request_cb(void *arg, err_t result)
|
static void mqtt_sub_request_cb(void *arg, err_t result)
|
||||||
{
|
{
|
||||||
/* Just print the result code here for simplicity,
|
/* Just print the result code here for simplicity,
|
||||||
normal behaviour would be to take some action if subscribe fails like
|
normal behaviour would be to take some action if subscribe fails like
|
||||||
notifying user, retry subscribe or disconnect from server */
|
notifying user, retry subscribe or disconnect from server */
|
||||||
printf("Subscribe result: %d\n", result);
|
printf("Subscribe result: %d\n", result);
|
||||||
}
|
}
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
* RFC 6762 - Multicast DNS\n
|
* RFC 6762 - Multicast DNS\n
|
||||||
* RFC 6763 - DNS-Based Service Discovery\n
|
* RFC 6763 - DNS-Based Service Discovery\n
|
||||||
*
|
*
|
||||||
|
* You need to increase MEMP_NUM_SYS_TIMEOUT by one if you use MDNS!
|
||||||
|
*
|
||||||
* @verbinclude mdns.txt
|
* @verbinclude mdns.txt
|
||||||
*
|
*
|
||||||
* Things left to implement:
|
* Things left to implement:
|
||||||
|
|
|
@ -42,6 +42,8 @@
|
||||||
* This is simple "SNTP" client for the lwIP raw API.
|
* This is simple "SNTP" client for the lwIP raw API.
|
||||||
* It is a minimal implementation of SNTPv4 as specified in RFC 4330.
|
* It is a minimal implementation of SNTPv4 as specified in RFC 4330.
|
||||||
*
|
*
|
||||||
|
* You need to increase MEMP_NUM_SYS_TIMEOUT by one if you use SNTP!
|
||||||
|
*
|
||||||
* For a list of some public NTP servers, see this link:
|
* For a list of some public NTP servers, see this link:
|
||||||
* http://support.ntp.org/bin/view/Servers/NTPPoolServers
|
* http://support.ntp.org/bin/view/Servers/NTPPoolServers
|
||||||
*
|
*
|
||||||
|
|
|
@ -45,6 +45,7 @@
|
||||||
* @ingroup apps
|
* @ingroup apps
|
||||||
*
|
*
|
||||||
* This is simple TFTP client/server for the lwIP raw API.
|
* This is simple TFTP client/server for the lwIP raw API.
|
||||||
|
* You need to increase MEMP_NUM_SYS_TIMEOUT by one if you use TFTP!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "lwip/apps/tftp_client.h"
|
#include "lwip/apps/tftp_client.h"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user