
Test network communications
Dependencies: EthernetInterface mbed-rtos mbed
main.cpp
- Committer:
- MalcolmNixon
- Date:
- 2014-05-04
- Revision:
- 0:9eba2bd74769
- Child:
- 1:429f7bca62aa
File content as of revision 0:9eba2bd74769:
#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); } }