Program used to setup Ethernet Static IP Port

Dependencies:   EthernetInterface mbed-rtos mbed

/media/uploads/Rbinas/ethenet_setup.jpg Ethernet Cat6 cable rom MCU to PC/media/uploads/Rbinas/ethenet_setup2.jpg /media/uploads/Rbinas/hercules_sotware.jpg

main.cpp

Committer:
Rbinas
Date:
2018-05-05
Revision:
0:31ba7a9a7743

File content as of revision 0:31ba7a9a7743:


//-----------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);
             
        }
             
    }   
}