1 year, 5 months ago.

mbed on ethernet and static ip

Hey guys,

I have this problem at hand and haven't been able to figure out how to work it out. The problem is as follows:

My mBed is connected toa temperature sensor. It is also connected to an ethernet port in my university and my university gives me a static IP (the DNS, the gateway and the network mask are unknown at this point in time) What I want to do is I want to connect to the mBed from another computer in a different university and fetch the data of the temperature sensor. The computer in the other university will send a request (such as "abc"). Only when this msg is validated should the mbed respond with the data.

What is the best way of doing this? If someone can help me with a code then it would be great. I am pretty naive at this side of computer science!

I cant help you with the mbed side of the ethernet, but is that IP an external or internal IP? If it is an internal IP you need to find out how to forward a port to your mbeds IP. Or you can use a 3G connection and ignore the universities network.

posted by Erik Olieman 20 Nov 2012
Comment on this question

1 Answer

1 year, 5 months ago.

Setting up mbed with a static IP is no problem:

static const char*          mbedIp       = "";  //IP
static const char*          mbedMask     = "";  // Mask
static const char*          mbedGateway  = "";    //Gateway

EthernetInterface eth;
eth.init(mbedIp,mbedMask,mbedGateway); //Use  these parameters for static IP
pc.printf("Connected! IP Address is %s\n", eth.getIPAddress());

Then, you just have to set up the TCP socket, like the example in the official libraries.

Set it up to RECEIVE data before sending, and it will wait for the request from the remote computer.

Then, you can use the C function strcmp() to compare the received data with your valid command, and if true, send back the data. The example code shows how to send a buffer.

Thanks Rod! I appreciate your help!!

posted by Neel Shah 23 Nov 2012

To post an answer, please login