Skip to content

Commit

Permalink
Fix multicast configuration in embedded examples
Browse files Browse the repository at this point in the history
  • Loading branch information
TimofeiBushnev committed Jan 8, 2025
1 parent 2514041 commit 5a75872
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 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/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_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
13 changes: 8 additions & 5 deletions examples/mbed/z_get.cpp
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 @@ -61,10 +61,13 @@ int main(int argc, char **argv) {
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
printf("Opening Zenoh Session...");
z_owned_session_t s;
Expand Down
13 changes: 9 additions & 4 deletions examples/zephyr/z_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,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,13 @@ int main(int argc, char **argv) {
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_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

0 comments on commit 5a75872

Please sign in to comment.