Program used to setup Ethernet Static IP Port
Dependencies: EthernetInterface mbed-rtos mbed
Ethernet Cat6 cable rom MCU to PC
Revision 0:31ba7a9a7743, committed 2018-05-05
- Comitter:
- Rbinas
- Date:
- Sat May 05 21:03:36 2018 +0000
- Commit message:
- Set-Up Ethernet port
Changed in this revision
diff -r 000000000000 -r 31ba7a9a7743 EthernetInterface.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Sat May 05 21:03:36 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#183490eb1b4a
diff -r 000000000000 -r 31ba7a9a7743 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 05 21:03:36 2018 +0000 @@ -0,0 +1,59 @@ + +//-----------Program used to Set-up Ethernet Static IPconfig-------------- +//----------Use HW Group Utility to monitor actvity----------------------- +#include "mbed.h" +#include "EthernetInterface.h" +DigitalOut myled(LED1); +DigitalOut myled2(LED2); +Serial pc(USBTX, USBRX); +//-------------Set Ethernet---------------------------- +static const char* mbedIp = "192.168.168.105"; //IP +static const char* mbedMask = "255.255.255.0"; // Mask +static const char* mbedGateway = "192.168.1.1"; //Gateway +const int ECHO_SERVER_PORT = 5000; +char buffer[256]; +EthernetInterface eth; +TCPSocketServer server; +TCPSocketConnection client; +//--------------------------------------------------------------------- +int main() +{ + + +eth.init(mbedIp,mbedMask,mbedGateway); //Use these parameters for static IP +eth.connect(); +server.bind(ECHO_SERVER_PORT); +server.listen(); + + while (true) + { + + server.accept(client); + //-------------Test sending from MCU to PC-------------------------- + client.send("Hello",5); + client.send("\n",1); + client.send("World",5); + client.send("\n",1); + + while (true) + { + + char n = client.receive(buffer, sizeof(buffer)); + //-------------Test sending from PC to MCU------------------- + buffer[n] = '\0'; + if (buffer[0] =='A') //send char A to turn on Led 1 + {myled = 1;} + if (buffer[0] =='B') //send char B to turnoff on Led 1 + {myled = 0;} + + if (buffer[0] =='C')//send char C to turn on Led 2 + {myled2 = 1;} + if (buffer[0] =='D')//send char D to turn off Led 2 + {myled2 = 0;} + + client.send("Test \n",4); + + } + + } +}
diff -r 000000000000 -r 31ba7a9a7743 mbed-rtos.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Sat May 05 21:03:36 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 000000000000 -r 31ba7a9a7743 mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat May 05 21:03:36 2018 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/ef9c61f8c49f \ No newline at end of file