Skip to content

Commit

Permalink
Fix multicast configuration in embedded examples (#851)
Browse files Browse the repository at this point in the history
  • Loading branch information
TimofeiBushnev authored Jan 9, 2025
1 parent 2514041 commit 8662b28
Show file tree
Hide file tree
Showing 28 changed files with 225 additions and 113 deletions.
12 changes: 8 additions & 4 deletions examples/arduino/z_get.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

// Client mode values (comment/uncomment as needed)
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
// Peer mode values (comment/uncomment as needed)
// #define MODE "peer"
// #define CONNECT "udp/224.0.0.225:7447#iface=en0"
// #define LOCATOR "udp/224.0.0.225:7447#iface=en0"

#define KEYEXPR "demo/example/**"
#define VALUE ""
Expand Down Expand Up @@ -79,8 +79,12 @@ void setup() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/arduino/z_pub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

// Client mode values (comment/uncomment as needed)
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
// Peer mode values (comment/uncomment as needed)
// #define MODE "peer"
// #define CONNECT "udp/224.0.0.225:7447#iface=en0"
// #define LOCATOR "udp/224.0.0.225:7447#iface=en0"

#define KEYEXPR "demo/example/zenoh-pico-pub"
#define VALUE "[ARDUINO]{ESP32} Publication from Zenoh-Pico!"
Expand Down Expand Up @@ -55,8 +55,12 @@ void setup() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/arduino/z_pull.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

// Client mode values (comment/uncomment as needed)
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
// Peer mode values (comment/uncomment as needed)
// #define MODE "peer"
// #define CONNECT "udp/224.0.0.225:7447#iface=en0"
// #define LOCATOR "udp/224.0.0.225:7447#iface=en0"

#define KEYEXPR "demo/example/**"

Expand Down Expand Up @@ -56,8 +56,12 @@ void setup() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/arduino/z_queryable.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

// Client mode values (comment/uncomment as needed)
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
// Peer mode values (comment/uncomment as needed)
// #define MODE "peer"
// #define CONNECT "udp/224.0.0.225:7447#iface=en0"
// #define LOCATOR "udp/224.0.0.225:7447#iface=en0"

#define KEYEXPR "demo/example/zenoh-pico-queryable"
#define VALUE "[ARDUINO]{ESP32} Queryable from Zenoh-Pico!"
Expand Down Expand Up @@ -81,8 +81,12 @@ void setup() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/arduino/z_sub.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@

// Client mode values (comment/uncomment as needed)
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
// Peer mode values (comment/uncomment as needed)
// #define MODE "peer"
// #define CONNECT "udp/224.0.0.225:7447#iface=en0"
// #define LOCATOR "udp/224.0.0.225:7447#iface=en0"

#define KEYEXPR "demo/example/**"

Expand Down Expand Up @@ -68,8 +68,12 @@ void setup() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_config_loan_mut(&config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/espidf/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ static int s_retry_count = 0;
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#define LOCATOR "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand Down Expand Up @@ -140,8 +140,12 @@ void app_main() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/espidf/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ static int s_retry_count = 0;
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#define LOCATOR "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand Down Expand Up @@ -122,8 +122,12 @@ void app_main() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/espidf/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ static int s_retry_count = 0;
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#define LOCATOR "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand Down Expand Up @@ -124,8 +124,12 @@ void app_main() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/espidf/z_queryable.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ static int s_retry_count = 0;
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#define LOCATOR "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand Down Expand Up @@ -149,8 +149,12 @@ void app_main() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/espidf/z_sub.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ static int s_retry_count = 0;
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#define LOCATOR "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand Down Expand Up @@ -132,8 +132,12 @@ void app_main() {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

// Open Zenoh session
Expand Down
12 changes: 8 additions & 4 deletions examples/freertos_plus_tcp/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#define LOCATOR "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand Down Expand Up @@ -57,8 +57,12 @@ void app_main(void) {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

printf("Opening session...\n");
Expand Down
12 changes: 8 additions & 4 deletions examples/freertos_plus_tcp/z_pub.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447"
#define LOCATOR "udp/224.0.0.225:7447"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand All @@ -35,8 +35,12 @@ void app_main(void) {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

printf("Opening session...\n");
Expand Down
12 changes: 8 additions & 4 deletions examples/freertos_plus_tcp/z_pub_st.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447"
#define LOCATOR "udp/224.0.0.225:7447"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand All @@ -36,8 +36,12 @@ void app_main(void) {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

printf("Opening session...\n");
Expand Down
12 changes: 8 additions & 4 deletions examples/freertos_plus_tcp/z_pull.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#define CLIENT_OR_PEER 0 // 0: Client mode; 1: Peer mode
#if CLIENT_OR_PEER == 0
#define MODE "client"
#define CONNECT "" // If empty, it will scout
#define LOCATOR "" // If empty, it will scout
#elif CLIENT_OR_PEER == 1
#define MODE "peer"
#define CONNECT "udp/224.0.0.225:7447#iface=en0"
#define LOCATOR "udp/224.0.0.225:7447#iface=en0"
#else
#error "Unknown Zenoh operation mode. Check CLIENT_OR_PEER value."
#endif
Expand All @@ -35,8 +35,12 @@ void app_main(void) {
z_owned_config_t config;
z_config_default(&config);
zp_config_insert(z_loan_mut(config), Z_CONFIG_MODE_KEY, MODE);
if (strcmp(CONNECT, "") != 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, CONNECT);
if (strcmp(LOCATOR, "") != 0) {
if (strcmp(MODE, "client") == 0) {
zp_config_insert(z_loan_mut(config), Z_CONFIG_CONNECT_KEY, LOCATOR);
} else {
zp_config_insert(z_loan_mut(config), Z_CONFIG_LISTEN_KEY, LOCATOR);
}
}

printf("Opening session...\n");
Expand Down
Loading

0 comments on commit 8662b28

Please sign in to comment.