VLAN with mbed

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

VLAN with mbed

1,990 Views
nada1985
Contributor I

Hello every one

I'm new to NXP community and I'm happy to join.

I have mbed controller to send GPs data to araio system which is accepting the GPS data from an external TCP/IP server.

 

The radio is connected via a VLAN with specific number which is 10.

I've already enabled the VLAN on my mbed and upload the TCP  server program. Everything went well when I run the TCP client on my laptop but when I tried to connect to my radio, the server won't accept the connection.

I'm struggling for few weeks trying to establish the communication but yet didn't reach my goal.

Any help on this would be aprrecieted.

 

Regards

Nada

 

0 Kudos
Reply
5 Replies

1,976 Views
nada1985
Contributor I

Hi Xiangjun

Thank you for your reply.

I'm using Ublox-C027 which is using the LPC1768. The mbed is my server and I'm using the opt.h from  LWIP ethernet stack to enable the VLAN support.

I'm using also OS 5.15

Regards

Nada

0 Kudos
Reply

1,980 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Nada,

Can you tell us the part number you are using? do you use LWIP ethernet stack and  use the MCU as a server?

Regard

Xiangjun Rong

0 Kudos
Reply

1,969 Views
nada1985
Contributor I

Dear all,

Any help regarding my question?

 

Thank you in advance.

 

Nada

0 Kudos
Reply

1,945 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Nada,

can you provide the source code so that we can have a review? can you print the log of the error?

BR

Xiangjun Rong

0 Kudos
Reply

1,941 Views
nada1985
Contributor I

Thank you xiangjun for your reply

Here is my code:

 

 

#include "mbed.h"
#include "gnss.h"
#include<string>
#include "EthernetInterface.h"
#include "rtos.h"
#include "TCPServer.h"
#include "TCPSocket.h"


// LEDs
DigitalOut led_1(P2_4);
DigitalOut led_2(P2_3);
DigitalOut led_3(P1_21);
DigitalOut led_4(P1_24);



// Static IP network variables
static const char*          mbedIP       = "10.5.248.45";  //IP 
static const char*          mbedMask     = "255.255.248.0";  // Mask
static const char*          mbedGateway  = "10.5.248.1";    //Gateway

static const char* recvIP = "10.5.248.121";
 
Serial pc(USBTX, USBRX);

EthernetInterface eth;

int main()
{
    pc.baud(115200);
    pc.printf("TCP server example\r\n");
    
    EthernetInterface eth;
    eth.set_network(mbedIP , mbedMask, mbedGateway );// my device address
    //eth.connect();
    
    if (0 != eth.connect())
        {
            
            pc.printf("Ethernet not connected\n\r");
            led_1=!led_1;
            return -1;
        }
    else
        {
            pc.printf("Connected Ethernet \n\r");
            led_2=!led_2; 
            
        }
            
    
    //pc.printf("The Server IP address is '%s'\r\n", eth.get_ip_address());
        
    TCPServer srv;
    TCPSocket client_sock[MAXCLIENTS];
    SocketAddress client_addr[MAXCLIENTS];
    
    int connectionStatus[MAXCLIENTS];
    
    char *buffer = new char[256];
    
    // Open the server on ethernet stack 
    srv.open(&eth);
    
    // Bind the HTTP port (TCP 80) to the server 
    srv.bind(10110);
    
    // Can handle x simultaneous connections 
    srv.listen(3);
   // srv.set_blocking(false);
    //client_sock[0].set_blocking(false); 
 
    int numClient = 0;
    int rcount = 0;
    int scount = 0;
    
    // initialize connection Status for client
    /*for(int i=0;i<MAXCLIENTS;i++)
        connectionStatus[i] = 0;*/
    
    while(1)
    {
        for(int i=0;i < MAXCLIENTS;i++)
        {
            //pc.printf("coonection : %i/n/r",connectionStatus[i]);
            // if not connected accept connection
            if (connectionStatus[i] == 0)
            {
                pc.printf("accept : %i\n\r",srv.accept(&client_sock[i], &client_addr[i]));
                if(srv.accept(&client_sock[i], &client_addr[i]) == 0)
                {  
                    connectionStatus[i] = 1;
                    //client_sock[i].set_blocking(false); 
                    //srv.set_blocking(false);         
                    numClient++;                    
                    pc.printf("Client Accepted %s:%d,%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port(),numClient);
                    led_3=!led_3; 
                }
            }
            
            // if connected        
            if (connectionStatus[i] == 1)
            {                                             
                rcount = client_sock[i].recv(buffer, sizeof(buffer));
                if(rcount > 0)
                {
                    sprintf(buffer, "Hello Client %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    scount = client_sock[i].send(buffer, strlen(buffer));
                    led_4=!led_4;
                }
                if(rcount == 0) // client disconnected
                {
                    connectionStatus[i] = 0;
                    pc.printf("Client Disconnected %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    client_sock[i].close();
                    numClient--;                
                }                                                        
                if(scount < 0) // unable to send data
                {
                    connectionStatus[i] = 0;
                    pc.printf("Connection lost %s:%d\r\n", client_addr[i].get_ip_address(),client_addr[i].get_port());
                    client_sock[i].close();
                    numClient--;                
                }                                                        
            }
        }
 
        wait(0.5f);
    }
 
}

 

I don't have any errors and the program compiles well but my issue is when I reached the stage when the server accept the client , there will be no acceptance and the program won't show me the IP address of the TCP client.

 

Looking forward to hearing from you.

 

Thank you in advance

 

Nada

 

 

0 Kudos
Reply