
Test network communications
Dependencies: EthernetInterface mbed-rtos mbed
Diff: main.cpp
- Revision:
- 0:9eba2bd74769
- Child:
- 1:429f7bca62aa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sun May 04 02:09:14 2014 +0000 @@ -0,0 +1,59 @@ +#include "EthernetInterface.h" +#include "Thread.h" +#include "mbed.h" + + + +// Construct the Ethernet interface +EthernetInterface eth; + +// Led thread procedure +void ledThreadProc(const void *) +{ + // Create a digital output pin on LED1 (the Red LED) + DigitalOut led1(LED1); + + // Loop forever + for (;;) + { + // Turn LED off + led1 = 1; + + // Wait for 100ms + Thread::wait(100); + + // Turn LED on + led1 = 0; + + // Wait for 100ms + Thread::wait(100); + } +} + +int main(void) +{ + // Configure the Ethernet interface + eth.init("192.168.5.100", "255.255.255.0", "0.0.0.0"); + + // Start the ethernet interface + eth.connect(); + + // Start a thread for led blink + Thread ledThread(ledThreadProc, 0, osPriorityHigh); + + UDPSocket sock; + sock.init(); + + Endpoint ep; + ep.set_address("192.168.5.1", 1234); + + // Loop forever + for (;;) + { + char msg[] = "Hello World"; + sock.sendTo(ep, msg, sizeof(msg) - 1); + + // Wait 1 second + Thread::wait(1000); + } +} \ No newline at end of file