4 years, 6 months ago.

Does statically assigning the mbed an IP address no longer work?


I've managed to communicate with my mbed using DHCP. However, I need to integrate the mbed with LabView, and need to statically assign the mbed an IP address to be specified in LabView..

Here's my code:

#include "mbed.h"
#include "EthernetInterface.h"
EthernetInterface eth;    //ethernet object
TCPSocketConnection socket;  //socket object
Serial pc(USBTX,USBRX);      //interface with TeraTerm
AnalogIn mux_output(p17);
const char * mbedIp = "";
const char * mbedMask = "";
const char * mbedGateway = "';
// A data structure of the data to send
// In this case it's fairly pointless, you may as well just use a uint16_t[] directly in place of this
// But if you package what you want into a structure then you don't need to change the 
// transmission code if you change what is being sent, you just change the structure definition.
typedef struct packetToSent_s {   
float data[160];   //specify data types within the struct, in this case an 80 element array of 16-bit unsigned int
} packetToSend_t;
packetToSend_t dataOut;  //an instance of the packet to send
int main()
    wait(2);    //allow the mbed time to be dynamically assigned an IP and to connect before printing IP address
    pc.printf("IP address is %s\n\n", eth.getIPAddress()); //function in ethernet library to return string containing IP
    socket.connect("", 1001);  //ip address of PC, and port to be listened to by the HOST     
            //specify data to be sent. Here we would desire the output from the multiplexer.
            for(int i=0;i<160;i++) {
                float a = mux_output.read()-0.11;
                dataOut.data[i]=a;  //populate array with analogue readings from pin 17. Remove offset.
    //send the data packet by passing a pointer to the start of the data, and specifying its size. 

As mentioned, I can connect the mbed to a TCP server using DHCP and send the packet. However, when using Static IP addressing the server will not connect to the client. Assuming this is an issue with the commands to do such operations.

Thanks, Joel

1 Answer

4 years, 6 months ago.

The IP address you are assigning to the mbed is on a different subnet to the device you are trying to connect to. This is possible if happens to be the IP address of the router on your LAN and things are all configured correctly however given the values used that would implies a very very unusual network configuration.

I strongly suspect that you've simply copied the IP address lines from some example rather than entered the correct values for your LAN.

Contact the person who maintains your network and ask them for a static IP address that you can use and the correct subnet mask and default gateway values for your network. Do NOT use the same IP address as you are issued when you used DHCP, that can break the network.