Ublox C027 -UDP and TCP

Hello Everyone,

Yesterday I was trying the TCP and UDP connection with my UBlox C027. I set a fixed IP address for my mbed and tried the UDP connection, everything went well. Suddenly, I was not able to connect any more or even ping my mbed. The same program is on another UBlox and it’s working fine.

Please find below the part of setting the IP address and my UDP client:

int main()
{
    //printf("hello main\n\r");

    static const char* PB_IP_1;
    static const char* PB_IP_2;
       
    GnssSerial gnss;
    int gnssReturnCode;
    int length;
    char buffer[256];
    
    //printf("Ethernet socket example\n\r");
    /*sprintf(mbedIP,"192.168.220.45");  
    sprintf(mbedMASK,"255.255.252.0");  
    sprintf(mbedGATEWAY,"192.168.220.1");  */  
    
    sprintf(mbedIP,"192.168.1.101");  
    sprintf(mbedMASK,"255.255.252.0");  
    sprintf(mbedGATEWAY,"192.168.1.1"); 
     
    nsapi_error_t set_network=eth.set_network(mbedIP,mbedMASK,mbedGATEWAY);
 
    
    //printf ("Starting up...\n");
    if (gnss.init()) 
    {
            // Bring up the ethernet interface
        
        if (0 != eth.connect())
        {
        
            return -1;
            //led_2= !led_2;
        }
        else
        {
            led_1= !led_1; //  Ethernet connected.
        }
}

UDP Client

void FMS_UDP_Thread()
{
    Double Lat_Local_FMS;
    Double Long_Local_FMS;
    uint8_t local_Safety_Status_FMS[1];
    Float local_Tempreture_FMS;
     uint8_t local_Index_FMS[3] = {0x01,0x00,0x00};
    
   // char *sbuffer_FMS = new char[256];
    const char sbuffer_FMS [] = " Station_001";
    
    for(int i=0;i<256;i++)
    {
        sbuffer_FMS[i]=NULL;
    }
    
    
    while(true)
    {
        Network_Mutex.lock();
        UDPSocket td_sock_FMS(&eth);
        Network_Mutex.unlock();
        
        SocketAddress td_addr_FMS("192.168.1.90", 4466);
        
       
        int ret_04 = td_sock_FMS.sendto(td_addr_FMS, sbuffer_FMS,sizeof(sbuffer_FMS));
        
        td_sock_FMS.close();
    
        Thread::wait(1000);
    }
    
}

Please, your advice.

Regards
Nada

Hello,

If something stop working then just go back to basic and try to Mbed TCP example instead your one, if it works or not.
If you really not changed anything and same program works with one board and not with second one, then it seems like the board is broken.

BR, Jan

Thank you so much Jan for your reply.

That’s wht I was afraid off actually. I tried the basic program which is blinking LED and it worked fine but the UDP is not working.

I will check the basic TCP and I will keep you updated.

Regards
Nada

Hello Jan,

I hope you are doing well.

I want to ask about changing the MAC address for Ublox C027. I tried the following function

#ifdef PRODUCTION_RELEASE
extern “C” void mbed_mac_address(char *s) {
//uint8_t mbed_otp_mac_address(char *s)
{
char mac[6];
memcpy(s, mac, 6);
//return 0;
}
#endif
char mac = {0x00, 0x02, 0xf7, 0xf0, 0x04, 0xA8};
mbed_mac_address(mac);

and also I defined my own MAC address iside the function but both of them didn’t work.

I want to change the MAC address because I have two ublox C027 and both of them have the same MAC.
00 02 f7 f0 00 00
Please your advise

Regards
Nada

Hello,

I do not have personal experiences with this.
But how you can see here, there is a week function what can be overridden. That function also contains the Mac address what you wrote. So you can try to change the Mac address in this file (if you work offline) or try to place the whole function with new Mac address in the main.

You need to change it inside the function not pass it as parameter. Also you not need to call this function, it will be called somewhere in the driver probably.

#incluide "mbed.h"
// rest of includes
extern "C" void mbed_mac_address(char *mac){
    mac[0] = 0x00;
    mac[1] = 0x02;
    mac[2] = 0xf7;
    mac[3] = 0xf0;
    mac[4] = 0x04;
    mac[5] = 0xA8;
}
// rest of main.cpp file

BR, Jan

Thank you Jan for contiuas spport.

Actually I tried that but it didn’t work. I think the device is not semihost.

I will check more about it.

Regards
Nada

From my understanding, when a device is the semihost then that function will try to read the Mac address from that device. If not, the array is used (from above).

BR, Jan

Is there anyway to make the device semihost?

probably add content below to the mbed_app.json

{
    "target_overrides": {
        "*": {
            "target.device_has_add": ["SEMIHOST"]
        }
   }
}

BR, Jan

Thank you Jan so much,

I will try it and let you know

Regards
Nada