4 years ago.
mbed on ethernet and static ip
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!
4 years ago.
Setting up mbed with a static IP is no problem:
static const char* mbedIp = "192.168.1.102"; //IP static const char* mbedMask = "255.255.255.0"; // Mask static const char* mbedGateway = "192.168.1.1"; //Gateway EthernetInterface eth; eth.init(mbedIp,mbedMask,mbedGateway); //Use these parameters for static IP eth.connect(); 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.
To post an answer, please login