Command line connection works, but le_data does not in application

I’m using an external sim card with which I have use the command line cm data connect and use netcat to reach my server correctly,
however when I try to create an app that uses le_data API it indicates the connection is stablished but cant reach my server.

I have tried these things:
1.- Remove le_data API from my application. Start the connection with command line cm data connect, then start my app just to verify that application can reach my server which is done correctly.
2.- Remove the code that connects with my server and just use le_data API. Use cm data to verify the state of the connection which it says is connected, but it behaves as if it were not. Any attempt to reach my server or any other results in an error, either with the application code (commented) or with ping in the command line interface.

root@swi-mdm9x28-wp:~# cm data
Index: 1
APN: internet.itelcel.com
PDP Type: IPV4V6
Connected: yes
Auth type: PAP
User name: webgpr
Password: webgprs2002
Interface: rmnet_data0
Family[IPv4]: inet
IP[IPv4]: 10.82.150.48
Gateway[IPv4]: 10.82.150.49
Dns1[IPv4]: 10.182.35.36
Dns2[IPv4]: 10.233.16.4
root@swi-mdm9x28-wp:~# ping google.com
ping: bad address ‘google.com
root@swi-mdm9x28-wp:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
ping: sendto: Network is unreachable
root@swi-mdm9x28-wp:~#

(1) happens with this code:

COMPONENT_INIT
{    
    int status;
    LE_INFO("test init");

    socketFd = socket(AF_INET,SOCK_STREAM,0);

    if (socketFd == -1) 
    { 
        LE_INFO("socket creation failed...\n"); 
        return; 
    } 
    else
    {
        LE_INFO("Socket successfully created..\n"); 
    }

    memset(&servaddr,0, sizeof(servaddr)); 
    // assign IP, PORT 
    servaddr.sin_family = AF_INET; 
    servaddr.sin_addr.s_addr = inet_addr(SERVER_ADDR); 
    servaddr.sin_port = htons(MYPORT); 


    // connect the client socket to server socket 
    status = connect(socketFd, (SA*)&servaddr, sizeof(servaddr));
    if (status != 0) 
    { 
        LE_INFO("connection with the server failed... %d \n",status); 
        return;
    } 
    else
    {
        LE_INFO("connected to the server..\n"); 
    }

    memset(dataRx,0,100);
    read(socketFd, dataRx, 100);
    LE_INFO("Received data: %s", dataRx);
}

(2) happens with this code:

static bool WaitingForConnection;
static le_data_RequestObjRef_t ConnectionRef;


static void TimeoutHandler(le_timer_Ref_t timerRef)
{
    if (WaitingForConnection)
    {
        LE_ERROR("Couldn't establish connection after " STRINGIZE(TIMEOUT_SECS) " seconds");
        exit(EXIT_FAILURE);
    }
}

static void ConnectionStateHandler(const char *intfName,bool isConnected,void *contextPtr)
{
    if (isConnected)
    {
        LE_INFO("Connected!\n");
    /*
        int status;
        WaitingForConnection = false;

        socketFd = socket(AF_INET,SOCK_STREAM,0);

        if (socketFd == -1) 
        { 
            LE_INFO("socket creation failed...\n"); 
            return; 
        } 
        else
        {
            LE_INFO("Socket successfully created..\n"); 
        }

        memset(&servaddr,0, sizeof(servaddr)); 
        // assign IP, PORT 
        servaddr.sin_family = AF_INET; 
        servaddr.sin_addr.s_addr = inet_addr(SERVER_ADDR); 
        servaddr.sin_port = htons(MYPORT); 


        // connect the client socket to server socket 
        status = connect(socketFd, (SA*)&servaddr, sizeof(servaddr));
        if (status != 0) 
        { 
            LE_INFO("connection with the server failed... %d \n",status); 
            return;
        } 
        else
        {
            LE_INFO("connected to the server..\n"); 
        }

        memset(dataRx,0,100);
        read(socketFd, dataRx, 100);
        LE_INFO("Received data: %s", dataRx);
    */
    }   
}



COMPONENT_INIT
{    
    le_timer_Ref_t timerPtr = le_timer_Create("Connection timeout timer");
    le_clk_Time_t interval = {TIMEOUT_SECS, 0};
    le_timer_SetInterval(timerPtr, interval);
    le_timer_SetHandler(timerPtr, &TimeoutHandler);
    WaitingForConnection = true;
    le_timer_Start(timerPtr);

    LE_INFO("test init");
    le_data_AddConnectionStateHandler(&ConnectionStateHandler, NULL);
    LE_INFO("Requesting connection...");
    ConnectionRef = le_data_Request();

}

does any one knows what the problem can be?, any help is really appreciated.

Seems to be same issue

Hi jyijyi,

It is the same issue, however as to me seems like it is related to the framework, I decided to move the request here, is that ok?
Once we get it solved, I will update that post as well.

i mean you can try the modemdemo application.

I did try the demo before, and it did not work for me before.
When I tested it before I receive the msg that the modemDemo is running, but does not matter what I send back it does not answer any sms or does anything in the log.

I decided to give it a couple tries again and notice that the messages I send are somehow getting blocked or something, but after a couple app stop/app start and legato restart I did got some messages into the modemDemo at once.

Jun 18 09:44:32 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[5485]/supervisor T=main | proc.c proc_Start() 1403 | Starting process 'modemDemo' with pid 5696
Jun 18 09:44:32 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[5696]/supervisor T=main | proc.c proc_Start() 1363 | Execing 'modemDemo'
Jun 18 16:44:34 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[5696]/demoComponent T=main | demo.c _demoComponent_COMPONENT_INIT() 1061 | Running modemDemo
Jun 18 16:44:44 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[5696]/demoComponent T=main | demo.c SmsReceivedHandler() 927 | Message content: "Status"
Jun 18 16:44:44 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[5696]/demoComponent T=main | demo.c SmsReceivedHandler() 941 | Message: 6461917200: Status
Jun 18 16:44:44 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[5696]/demoComponent T=main | demo.c SmsReceivedHandler() 927 | Message content: "Status"
Jun 18 16:44:44 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[5696]/demoComponent T=main | demo.c SmsReceivedHandler() 941 | Message: 6461917200: Status
Jun 18 16:44:45 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[5696]/demoComponent T=main | demo.c SmsReceivedHandler() 927 | Message content: "Que paso mango"
Jun 18 16:44:45 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[5696]/demoComponent T=main | demo.c SmsReceivedHandler() 941 | Message: 6461917200: Que paso mango

However, when I try to test the data connection using Online sms command, I cannot make it to receive it again (I did try app stop/start and legato restart).
Something interesting is that no matter how many times I try, the device never fails to send the message to my phone, but I only have made it receive messages once and at this point I cant tell how to replicate that…
Is this SMS process related to data connection?
At this moment I am bypassing the code to try data connection without the need to use SMS as that is unreliable for me and the use case I have at hands at the moment does not depends on SMS.

Any advice is very appreciated, thanks!

Just bypassed the SMS and called GoOnline(); after le_data_AddConnectionStateHandler.

In the handler I added TestDataConnectionV4(buffer); which result in:

Jun 18 13:54:24 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[6376]/supervisor T=main | proc.c proc_Start() 1403 | Starting process 'modemDemo' with pid 6575
Jun 18 13:54:24 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[6575]/supervisor T=main | proc.c proc_Start() 1363 | Execing 'modemDemo'
Jun 18 20:54:26 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[6575]/demoComponent T=main | demo.c _demoComponent_COMPONENT_INIT() 1069 | Running modemDemo
Jun 18 20:54:26 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[6575]/demoComponent T=main | demo.c GoOnline() 327 | Requesting the default data connection: 0x189.
Jun 18 20:54:28 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[6575]/demoComponent T=main | demo.c ConnectionStateHandler() 1009 | Connection State Event: 'rmnet_data0' connected
Jun 18 20:54:28 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[6575]/demoComponent T=main | demo.c TestDataConnectionV4() 380 | Connecting to 69.10.131.102 (www.sierrawireless.com)
Jun 18 20:54:28 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[6575]/demoComponent T=main | demo.c ConnectionStateHandler() 1029 | Result from testConnectionV4: Failed to connect to www.sierrawireless.com.

using TestDataConnectionV6(buffer) I get:
Jun 18 14:25:45 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[10409]/supervisor T=main | proc.c proc_Start() 1403 | Starting process 'modemDemo' with pid 10607
Jun 18 14:25:45 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[10607]/supervisor T=main | proc.c proc_Start() 1363 | Execing 'modemDemo'
Jun 18 21:25:47 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[10607]/demoComponent T=main | demo.c _demoComponent_COMPONENT_INIT() 1069 | Running modemDemo
Jun 18 21:25:47 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[10607]/demoComponent T=main | demo.c GoOnline() 327 | Requesting the default data connection: 0x123.
Jun 18 21:25:49 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[10607]/demoComponent T=main | demo.c ConnectionStateHandler() 1009 | Connection State Event: 'rmnet_data0' connected
Jun 18 21:25:49 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[10607]/demoComponent T=main | demo.c TestDataConnectionV6() 421 | Connecting to 2a01:cd00:ff:ffff::450a:8366 (www.sierrawireless.com)
Jun 18 21:25:49 swi-mdm9x28-wp user.info Legato:  INFO | modemDemo[10607]/demoComponent T=main | demo.c ConnectionStateHandler() 1029 | Result from testConnectionV6: Failed to connect to www.sierrawireless.com.

After looking at what the modemDemo code does regarding the connection… I do not see any difference between it and what I am doing.

I do not know if this is relevant or not… but I did remove any other application in the mangOH yellow system file definition, so it looks like this. I build it with ‘OCTAVE=0 make yellow’ command it is the newest mangoh yellow package… so… what else might be relevant to address this problem?

//--------------------------------------------------------------------------------------------------
// mangOH system definition for the mangOH Yellow board.
//
// Copyright (C) Sierra Wireless Inc.
//--------------------------------------------------------------------------------------------------

#include "shared.sdef"


buildVars:
{
    MANGOH_BOARD = yellow

    LEGATO_WIFI_PA = ${CURDIR}/linux_kernel_modules/cypwifi/scripts/pa_wifi.sh

#if ${MANGOH_WP_CHIPSET_9X07} = 1
    MANGOH_BME680_I2C_BUS = 6
#elif ${MANGOH_WP_CHIPSET_9X15} = 1
    MANGOH_BME680_I2C_BUS = 2
#endif

    // Exclude a few big libraries from the Legato apps to save space in the legato.cwe.
    // These libraries are available in the root file system, but by default they also
    // get added to some apps to prevent potential version mismatches when running on older
    // root file systems.
    USE_ROOTFS_CURL = 1
    USE_ROOTFS_OPENSSL = 1
    USE_ROOTFS_ZLIB = 1
}

#if ${OCTAVE} = 1
#include "sinc/octave_full.sinc"
#endif

apps:
{
    $CURDIR/apps/modemDemo/modemDemo
}



interfaceSearch:
{
    $CURDIR/apps/modemDemo/
}



kernelModules:
{
    $CURDIR/linux_kernel_modules/mangoh/mangoh_yellow_dev
    $CURDIR/linux_kernel_modules/bmi160/bmi160-i2c
    $CURDIR/linux_kernel_modules/bmi160/bmi160
    $CURDIR/linux_kernel_modules/rtc-pcf85063/rtc-pcf85063
    $CURDIR/linux_kernel_modules/rtc_sync/rtc_sync
    $CURDIR/linux_kernel_modules/bq25601/bq25601
    $CURDIR/linux_kernel_modules/bq27xxx/bq27xxx_battery
    $CURDIR/linux_kernel_modules/opt300x/opt300x
    $CURDIR/linux_kernel_modules/expander/expander
    $CURDIR/linux_kernel_modules/cp2130/cp2130
}

sorry, a bit confused, what is the actual problem you have?
data connection or SMS?
Your original question talks about data connection, and now move to SMS…

Hi jyijyi,

The problem is the data connection, I’m bringing the issues with SMS because you suggested to test the modemDemo which requires the usage of SMS to work, so I just reported what is happening with my device when I use it. I tried to bypass the SMS and hardcoding the modemDemo to start a connection using either IPv4 or IPv6 to see if that worked, but I get the same result as in my project, which is that I cannot use data connection from the application framework.
I do not care of the SMS for this project, but I was wondering if that is related or not…

Thanks!

If you just want to go data connection, there is no need to care about SMS.

just need to type:
app runProc modemDemo send --exe=send – 1234567 “Online”

And the result is printed in
cat /legato/systems/current/appsWriteable/modemDemo/smsChat.txt

Ok, so I did revert all changes I made, compile and update the package.
In the command line, after the ssh connection, I tried the command you mention

root@swi-mdm9x28-wp:~# app runProc modemDemo send --exe=send  1234567 "Online"
Invalid arguments.  Try --help.

So I try help:

root@swi-mdm9x28-wp:~# app runProc -- help
Invalid application name.
root@swi-mdm9x28-wp:~# app runProc modemDemo --help
Invalid arguments.  Try --help.

So… what am I missing?
As I am running this from the mangOH yellow 0.6.0 workspace… does this matter for this project? do I have to setup legato af and compile it from there in order to make this work?

Thanks!

You missed the – sign.

app runProc modemDemo send --exe=send --1234567 “Online”

Weird… the copy from here to windows command line does not work for some characters…

I did try:
root@swi-mdm9x28-wp:~# app runProc modemDemo send --exe=send – 1234567 “Online”
Invalid arguments. Try --help.

Which did work to send that SMS, so I tried with TestDataConnectionV4 and then V6, which both failed, these are the results:

root@swi-mdm9x28-wp:~# app runProc modemDemo send --exe=send -- 1234567 "Online"
root@swi-mdm9x28-wp:~# cm data
Index:                         1
APN:                           internet.itelcel.com
PDP Type:                      IPV4V6
Connected:                     yes
Auth type:                     PAP
User name:                     webgpr
Password:                      webgprs2002
Interface:                     rmnet_data0
Family[IPv4]:                  inet
IP[IPv4]:                      10.100.184.10
Gateway[IPv4]:                 10.100.184.9
Dns1[IPv4]:                    10.182.35.36
Dns2[IPv4]:                    10.233.16.4
root@swi-mdm9x28-wp:~# ping google.com
PING google.com (172.217.5.206): 56 data bytes
ping: sendto: Network is unreachable
root@swi-mdm9x28-wp:~# app runProc modemDemo send --exe=send -- 1234567 "TestDataConnectionV4"
root@swi-mdm9x28-wp:~# cat /legato/systems/current/appsWriteable/modemDemo/smsChat.txt
send (+526461917200): Welcome to modemDemo app
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
## Requesting data connection. ##
send (+526461917200): Welcome to modemDemo app
## Requesting data connection. ##
## Failed to connect to www.sierrawireless.com. ##
root@swi-mdm9x28-wp:~# app runProc modemDemo send --exe=send -- 1234567 "TestDataConnectionV6"
root@swi-mdm9x28-wp:~# cat /legato/systems/current/appsWriteable/modemDemo/smsChat.txt
send (+526461917200): Welcome to modemDemo app
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
## Requesting data connection. ##
send (+526461917200): Welcome to modemDemo app
## Requesting data connection. ##
## Failed to connect to www.sierrawireless.com. ##
## Failed to connect to www.sierrawireless.com. ##
root@swi-mdm9x28-wp:~#

I did test disconnecting cm data disconnect, then using command line cm data connect, as before, I could ping google.com and then I tried SMS TestDataConnectionV6 and V4. V4 was successful as the log say (it was the 4th in the list of attempts)

root@swi-mdm9x28-wp:~# cm data disconnect
Disconnecting ... ok
root@swi-mdm9x28-wp:~# cm data connect
Checking if device 'rmnet_data0' is up ... ok
Routing inet ... ok
Updating /etc/resolv.conf ... ok
Updating /etc/resolv.conf ... ok
Testing connection ...



^C
root@swi-mdm9x28-wp:~#
root@swi-mdm9x28-wp:~# cm data
Index:                         1
APN:                           internet.itelcel.com
PDP Type:                      IPV4V6
Connected:                     yes
Auth type:                     PAP
User name:                     webgpr
Password:                      webgprs2002
Interface:                     rmnet_data0
Family[IPv4]:                  inet
IP[IPv4]:                      10.100.184.10
Gateway[IPv4]:                 10.100.184.9
Dns1[IPv4]:                    10.182.35.36
Dns2[IPv4]:                    10.233.16.4
root@swi-mdm9x28-wp:~# ping google.com
PING google.com (172.217.4.174): 56 data bytes
64 bytes from 172.217.4.174: seq=0 ttl=117 time=155.221 ms
64 bytes from 172.217.4.174: seq=1 ttl=117 time=115.510 ms
^C
--- google.com ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 115.510/135.365/155.221 ms
root@swi-mdm9x28-wp:~# app runProc modemDemo send --exe=send -- 1234567 "TestDataConnectionV6"
root@swi-mdm9x28-wp:~# cat /legato/systems/current/appsWriteable/modemDemo/smsChat.txt
send (+526461917200): Welcome to modemDemo app
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
## Requesting data connection. ##
send (+526461917200): Welcome to modemDemo app
## Requesting data connection. ##
## Failed to connect to www.sierrawireless.com. ##
## Failed to connect to www.sierrawireless.com. ##
## Failed to connect to www.sierrawireless.com. ##
root@swi-mdm9x28-wp:~# app runProc modemDemo send --exe=send -- 1234567 "TestDataConnectionV4"
root@swi-mdm9x28-wp:~# cat /legato/systems/current/appsWriteable/modemDemo/smsChat.txt
send (+526461917200): Welcome to modemDemo app
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
send (+526461917200): Welcome to modemDemo app
## registered on its home network ##
## Requesting data connection. ##
send (+526461917200): Welcome to modemDemo app
## Requesting data connection. ##
## Failed to connect to www.sierrawireless.com. ##
## Failed to connect to www.sierrawireless.com. ##
## Failed to connect to www.sierrawireless.com. ##
## Connection to www.sierrawireless.com was successful. ##
root@swi-mdm9x28-wp:~#

I don’t see problem with my module here:

root@swi-mdm9x28-wp:~# app runProc modemDemo1 send --exe=send – 1234567 “Sim”
root@swi-mdm9x28-wp:~#
root@swi-mdm9x28-wp:~# cat /legato/systems/current/appsWriteable/modemDemo1/smsC
hat.txt

SIM 1 is inserted and unlocked. ICCID=8985200012741552068 IMSI=454003074155206

root@swi-mdm9x28-wp:~#
root@swi-mdm9x28-wp:~# app runProc modemDemo1 send --exe=send – 1234567 "Online
"
root@swi-mdm9x28-wp:~#
root@swi-mdm9x28-wp:~# cat /legato/systems/current/appsWriteable/modemDemo1/smsC
hat.txt

SIM 1 is inserted and unlocked. ICCID=8985200012741552068 IMSI=454003074155206

Requesting data connection.

root@swi-mdm9x28-wp:~#
root@swi-mdm9x28-wp:~# cm data
Index: 1
APN: hkcsl
PDP Type: IPV4V6
Connected: yes
Interface: rmnet_data0
Family[IPv4]: inet
IP[IPv4]: 10.179.184.52
Gateway[IPv4]: 10.179.184.53
Dns1[IPv4]: 10.144.148.1
Dns2[IPv4]: 10.145.148.5
root@swi-mdm9x28-wp:~#
root@swi-mdm9x28-wp:~# ping www.google.com
PING www.google.com (216.58.199.4): 56 data bytes
64 bytes from 216.58.199.4: seq=0 ttl=58 time=27.470 ms
64 bytes from 216.58.199.4: seq=1 ttl=58 time=51.416 ms
^C
www.google.com ping statistics —
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 27.470/39.443/51.416 ms
root@swi-mdm9x28-wp:~# cm info
Device: WP7607
IMEI: 359779081234565
IMEISV: 6
FSN: [ 580.328907] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:1 cur:0 tx) bc(rx:0 tx:2) mode:FIFO slv_addr:0x3a MSTR_STS:0x0c1300c8 OPER:0x00000090
VN730485080103
Firmware Version: SWI9X07Y_02.28[ 580.348571] i2c-msm-v2 78b8000.i2c: NACK: slave not responding, ensure its powered: msgs(n:1 cur:0 tx) bc(rx:0 tx:2) mode:FIFO slv_addr:0x3a MSTR_STS:0x0c1300c8 OPER:0x00000090
.03.03 000000 jenkins 2019/05/21 03:33:04
Bootloader Version: SWI9X07Y_02.28.03.03 000000 jenkins 2019/05/21 03:33:04
MCU Version: 002.011
PRI Part Number (PN): 9908958
PRI Revision: 001.000
Carrier PRI Name: GENERIC
Carrier PRI Revision: 002.068_000
SKU: 1104301
Last Reset Cause: Power Down
Resets Count: Expected: 192 Unexpected: 15
root@swi-mdm9x28-wp:~# ip r
default via 10.179.184.53 dev rmnet_data0
10.179.184.48/29 dev rmnet_data0 proto kernel scope link src 10.179.184.52
192.168.2.0/24 dev ecm0 proto kernel scope link src 192.168.2.2
192.168.225.0/24 dev bridge0 proto kernel scope link src 192.168.225.1