6 years, 8 months ago.  This question has been closed. Reason: Duplicate question

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

Hello,

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 = "192.168.0.83";
const char * mbedMask = "255.255.255.0";
const char * mbedGateway = "192.168.0.1';

// 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()
{    
    eth.init(mbedIp,mbedMask,mbedGateway);
    wait(2);
    eth.connect();
    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("10.58.74.19", 1001);  //ip address of PC, and port to be listened to by the HOST     
    wait(2);
    
            //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.
                wait(0.1);
                }
    
    //send the data packet by passing a pointer to the start of the data, and specifying its size. 
    
    socket.send_all((char*)&dataOut,sizeof(packetToSend_t));



}

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