I am using the new Network Stack with Mbed OS 5.1. I have changed the target.json file and the STF7 Hal file for the f767zi to allow ipv4.
It looks like broadcast is not yet supported because when I change the socket options I get a NSAPI_ERROR_UNSUPPORTED error.
So I tried to set up a p2p communication, I can send a string to a python program. When I try to send it back to the f767zi, it just block indefinitely. I have wiresharked the communication and I can see the data come into the PC and go back out so I am unsure what is going wrong.
I will test with TCP just to see if the behavior is the same.
Regards, Seth
PS when will broadcast be available? 5.2 is there a roadmap for future features?
TCP send and receive both work.
Here is the code that I got it work:
#include "mbed.h"
#include "lwip-interface/EthernetInterface.h"
#include <string>
DigitalOut led1(LED1);
using std::string;
const int BROADCAST_PORT_T = 58080;
const int BROADCAST_PORT_R = 58081;
EthernetInterface eth;
void transmit()
{
UDPSocket socket(ð);
string out_buffer = "very important data";
SocketAddress transmit("192.168.1.159", BROADCAST_PORT_T);
while (true)
{
int ret = socket.sendto(transmit, out_buffer.c_str(), out_buffer.size());
printf("sendto return: %d\n", ret);
Thread::wait(5000);
}
}
void receive()
{
SocketAddress receive;
UDPSocket socket(ð);
int bind = socket.bind(BROADCAST_PORT_R);
printf("bind return: %d\n", bind);
char buffer[256];
while (true)
{
printf("\nWait for packet...\n");
int n = socket.recvfrom(&receive, buffer, sizeof(buffer));
buffer[n] = '\0';
printf("Packet from \"%s\": %s\n", receive.get_ip_address(), buffer);
Thread::wait(500);
}
}
int main()
{
Thread transmitter;
Thread receiver;
eth.connect();
printf("Controller IP Address is %s\r\n", eth.get_ip_address());
Thread::wait(5000);
transmitter.start(transmit);
receiver.start(receive);
while (true)
{
led1 = !led1;
Thread::wait(500);
}
}