Skip to content

Make our own multicast group and join it. #137

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

Merged
merged 1 commit into from
Oct 4, 2017
Merged
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
14 changes: 10 additions & 4 deletions mesh_led_control_example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ static void blink();
static void update_state(uint8_t state);
static void handle_message(char* msg);

// mesh local multicast to all nodes
#define multicast_addr_str "ff02::1"
#define multicast_addr_str "ff15::810a:64d1"
#define TRACE_GROUP "example"
#define UDP_PORT 1234
#define MESSAGE_WAIT_TIMEOUT (30.0)
Expand Down Expand Up @@ -180,7 +179,7 @@ static void receive() {
// there was nothing to read.
something_in_socket=false;
}
}
}
}

static void handle_socket() {
Expand All @@ -192,8 +191,15 @@ static void init_socket()
{
my_socket = new UDPSocket(network_if);
my_socket->set_blocking(false);
my_socket->bind(UDP_PORT);
my_socket->bind(UDP_PORT);
my_socket->setsockopt(SOCKET_IPPROTO_IPV6, SOCKET_IPV6_MULTICAST_HOPS, &multicast_hops, sizeof(multicast_hops));

ns_ipv6_mreq_t mreq;
memcpy(mreq.ipv6mr_multiaddr, multi_cast_addr, 16);
mreq.ipv6mr_interface = 0;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why zero? Can it change?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Zero means "default". Best we can do as we don't have visibility of Nanostack interface IDs.

There is a PR going through to add a generic NSAPI for this - ARMmbed/mbed-os#4820. That is intending to use interface address instead.


my_socket->setsockopt(SOCKET_IPPROTO_IPV6, SOCKET_IPV6_JOIN_GROUP, &mreq, sizeof mreq);

if (MBED_CONF_APP_BUTTON != NC) {
my_button.fall(&my_button_isr);
my_button.mode(PullUp);
Expand Down