mirror of
https://github.com/espressif/esp-modbus.git
synced 2025-09-25 14:10:56 +02:00
Merge branch 'bugfix/fix_minor_host_name_issues' into 'main'
master minor fixes examples and documentation v2 See merge request idf/esp-modbus!131
This commit is contained in:
@@ -80,11 +80,12 @@ There are three ways to configure how the master example will obtain slave IP ad
|
|||||||
* Configure slave addresses manually as below:
|
* Configure slave addresses manually as below:
|
||||||
```
|
```
|
||||||
char* slave_ip_address_table[MB_DEVICE_COUNT] = {
|
char* slave_ip_address_table[MB_DEVICE_COUNT] = {
|
||||||
"192.168.1.21", // Address corresponds to MB_DEVICE_ADDR1 and set to predefined value by user
|
"01;192.168.1.21", // Address corresponds to UID (slave address) = MB_DEVICE_ADDR1 and set to predefined value by user
|
||||||
"192.168.1.22", // Address corresponds to MB_DEVICE_ADDR2 of slave device in the Modbus data dictionary
|
"02;192.168.1.22", // Address corresponds to MB_DEVICE_ADDR2 of slave device in the Modbus data dictionary
|
||||||
NULL // Marker of end of list
|
NULL // End of list marker (Must be provided!)
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
In the above notation the port option will be treated by default = `CONFIG_FMB_TCP_PORT_DEFAULT` kconfig value. The port can be specified explicitly for each slave as "01;192.168.1.21;1502".
|
||||||
|
|
||||||
### Setup external Modbus slave devices or emulator
|
### Setup external Modbus slave devices or emulator
|
||||||
Option 1:
|
Option 1:
|
||||||
|
@@ -482,8 +482,8 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
|||||||
|
|
||||||
#if CONFIG_LWIP_IPV6
|
#if CONFIG_LWIP_IPV6
|
||||||
// Configuration format:
|
// Configuration format:
|
||||||
// "12:2001:0db8:85a3:0000:0000:8a2e:0370:7334:502"
|
// "12;2001:0db8:85a3:0000:0000:8a2e:0370:7334;502"
|
||||||
// "12:2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
// "12;2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
||||||
ret = sscanf(buffer, "%" PRIu16 ";" IPV6STR ";%" PRIu16, &index, &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &port);
|
ret = sscanf(buffer, "%" PRIu16 ";" IPV6STR ";%" PRIu16, &index, &a[0], &a[1], &a[2], &a[3], &a[4], &a[5], &a[6], &a[7], &port);
|
||||||
if ((ret == MB_STR_LEN_IDX_IP6) || (ret == MB_STR_LEN_IDX_IP6_PORT)) {
|
if ((ret == MB_STR_LEN_IDX_IP6) || (ret == MB_STR_LEN_IDX_IP6_PORT)) {
|
||||||
if (-1 == asprintf(&host_str, IPV6STR, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7])) {
|
if (-1 == asprintf(&host_str, IPV6STR, a[0], a[1], a[2], a[3], a[4], a[5], a[6], a[7])) {
|
||||||
@@ -508,7 +508,7 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
|||||||
}
|
}
|
||||||
info_ptr->node_name_str = host_str;
|
info_ptr->node_name_str = host_str;
|
||||||
info_ptr->ip_addr_str = host_str;
|
info_ptr->ip_addr_str = host_str;
|
||||||
info_ptr->uid = 0;
|
info_ptr->uid = 1;
|
||||||
info_ptr->fd = UNDEF_FD;
|
info_ptr->fd = UNDEF_FD;
|
||||||
info_ptr->port = CONFIG_FMB_TCP_PORT_DEFAULT;
|
info_ptr->port = CONFIG_FMB_TCP_PORT_DEFAULT;
|
||||||
info_ptr->addr_type = MB_IPV6;
|
info_ptr->addr_type = MB_IPV6;
|
||||||
@@ -525,7 +525,7 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
|||||||
}
|
}
|
||||||
info_ptr->node_name_str = host_str;
|
info_ptr->node_name_str = host_str;
|
||||||
info_ptr->ip_addr_str = host_str;
|
info_ptr->ip_addr_str = host_str;
|
||||||
info_ptr->uid = 0;
|
info_ptr->uid = 1;
|
||||||
info_ptr->fd = UNDEF_FD;
|
info_ptr->fd = UNDEF_FD;
|
||||||
info_ptr->port = CONFIG_FMB_TCP_PORT_DEFAULT;
|
info_ptr->port = CONFIG_FMB_TCP_PORT_DEFAULT;
|
||||||
info_ptr->addr_type = MB_IPV4;
|
info_ptr->addr_type = MB_IPV4;
|
||||||
@@ -534,7 +534,7 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configuration format:
|
// Configuration format:
|
||||||
// "1:192.168.1.1:502"
|
// "1;192.168.1.1;502"
|
||||||
ret = sscanf(buffer, "%" PRIu16 ";"IPSTR";%" PRIu16, &index, &a[0], &a[1], &a[2], &a[3], &port);
|
ret = sscanf(buffer, "%" PRIu16 ";"IPSTR";%" PRIu16, &index, &a[0], &a[1], &a[2], &a[3], &port);
|
||||||
if ((ret == MB_STR_LEN_IDX_IP4_PORT) || (ret == MB_STR_LEN_IDX_IP4)) {
|
if ((ret == MB_STR_LEN_IDX_IP4_PORT) || (ret == MB_STR_LEN_IDX_IP4)) {
|
||||||
if (-1 == asprintf(&host_str, IPSTR, a[0], a[1], a[2], a[3])) {
|
if (-1 == asprintf(&host_str, IPSTR, a[0], a[1], a[2], a[3])) {
|
||||||
@@ -551,7 +551,7 @@ int port_scan_addr_string(char *buffer, mb_uid_info_t *info_ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Configuration format:
|
// Configuration format:
|
||||||
// "01:mb_node_tcp_01:502"
|
// "01;mb_node_tcp_01;502"
|
||||||
ret = sscanf(buffer, "%" PRIu16 ";%m[a-z0-9_];%" PRIu16, &index, &host_str, &port);
|
ret = sscanf(buffer, "%" PRIu16 ";%m[a-z0-9_];%" PRIu16, &index, &host_str, &port);
|
||||||
if ((ret == MB_STR_LEN_HOST) || (ret == MB_STR_LEN_IDX_HOST_PORT)) {
|
if ((ret == MB_STR_LEN_HOST) || (ret == MB_STR_LEN_IDX_HOST_PORT)) {
|
||||||
info_ptr->node_name_str = (host_str && strlen(host_str)) ? host_str : info_ptr->node_name_str;
|
info_ptr->node_name_str = (host_str && strlen(host_str)) ? host_str : info_ptr->node_name_str;
|
||||||
|
@@ -62,14 +62,14 @@ extern "C" {
|
|||||||
#define MB_MDNS_QUERY_TIME_MS (2000)
|
#define MB_MDNS_QUERY_TIME_MS (2000)
|
||||||
|
|
||||||
#define MB_STR_LEN_HOST 1 // "mb_node_tcp_01"
|
#define MB_STR_LEN_HOST 1 // "mb_node_tcp_01"
|
||||||
#define MB_STR_LEN_IDX_HOST 2 // "12:mb_node_tcp_01"
|
#define MB_STR_LEN_IDX_HOST 2 // "12;mb_node_tcp_01"
|
||||||
#define MB_STR_LEN_IDX_HOST_PORT 3 // "01:mb_node_tcp_01:1502"
|
#define MB_STR_LEN_IDX_HOST_PORT 3 // "01;mb_node_tcp_01;1502"
|
||||||
#define MB_STR_LEN_IP4_ONLY 4 // "192.168.1.1"
|
#define MB_STR_LEN_IP4_ONLY 4 // "192.168.1.1"
|
||||||
#define MB_STR_LEN_IDX_IP4 5 // "1:192.168.1.1"
|
#define MB_STR_LEN_IDX_IP4 5 // "1;192.168.1.1"
|
||||||
#define MB_STR_LEN_IDX_IP4_PORT 6 // "1:192.168.1.1:502"
|
#define MB_STR_LEN_IDX_IP4_PORT 6 // "1;192.168.1.1;502"
|
||||||
#define MB_STR_LEN_IP6_ONLY 8 // "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
#define MB_STR_LEN_IP6_ONLY 8 // "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
||||||
#define MB_STR_LEN_IDX_IP6 9 // "12:2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
#define MB_STR_LEN_IDX_IP6 9 // "12;2001:0db8:85a3:0000:0000:8a2e:0370:7334"
|
||||||
#define MB_STR_LEN_IDX_IP6_PORT 10 // "12:2001:0db8:85a3:0000:0000:8a2e:0370:7334:502"
|
#define MB_STR_LEN_IDX_IP6_PORT 10 // "12;2001:0db8:85a3:0000:0000:8a2e:0370:7334;502"
|
||||||
|
|
||||||
#define MB_MDNS_STR_MIN_LENGTH 10 // "mb_node_01"
|
#define MB_MDNS_STR_MIN_LENGTH 10 // "mb_node_01"
|
||||||
#define MB_MDNS_SEGMENT_NAME "mb_tcp_segment" // "mb_node_01"
|
#define MB_MDNS_SEGMENT_NAME "mb_tcp_segment" // "mb_node_01"
|
||||||
|
Reference in New Issue
Block a user