Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
10 years, 5 months ago.
Problem with UDPSocket and ticker.attach
Hi, i've a problem with UDPSocket class when I try to send a message inside a ticker.attach. In fact the board enters a sort of loop and does nothing; and so not send the message. Has someone a solution to this problem?
This is the code:
#include "mbed.h"
#include <stdio.h>
#include <string>
#include "EthernetInterface.h"
EthernetInterface eth;
UDPSocket sock;
Endpoint echo_server_pc;
void UdpSend(){
//Read EthDevice
char out_buffer[] = "Hello";
sock.sendTo(echo_server_pc, out_buffer, sizeof(out_buffer));
};
int main (void)
{
eth.init("192.168.1.101","255.255.255.0","192.168.1.1"); //Not Use DHCP
eth.connect();
sock.init();
sock.set_blocking(false);
echo_server_pc.set_address("192.168.1.10", 8080);
//Start the ticker
tick.attach_us(&UdpSend, 100*1000);//100ms
while(1){
....
}
...
}
I've a K64F board. Thanks