How can I start session mdc?

I want to start the data connection by my legato app.
On documentation, I found the function: le_mdc_StartSession

#define NB_PROFILE  1
static le_mdc_ProfileRef_t ProfileRef[NB_PROFILE];
COMPONENT_INIT
{
	LE_INFO("begin app");
	le_mdc_StartSession(ProfileRef[0]);

But when I build the app, the following error occurs:

    /home/victor/ftsmartmind/modem-fx30s/conversor-mqtt/vscode/fx30s/components/fx30sSerialMqttComponent/fx30sSerialMqttComponent.c:23:8: error: unknown type name ‘le_mdc_ProfileRef_t’
     static le_mdc_ProfileRef_t ProfileRef[NB_PROFILE];
            ^~~~~~~~~~~~~~~~~~~
    /home/victor/ftsmartmind/modem-fx30s/conversor-mqtt/vscode/fx30s/components/fx30sSerialMqttComponent/fx30sSerialMqttComponent.c: In function ‘_fx30sSerialMqttComponent_COMPONENT_INIT’:
    /home/victor/ftsmartmind/modem-fx30s/conversor-mqtt/vscode/fx30s/components/fx30sSerialMqttComponent/fx30sSerialMqttComponent.c:29:2: error: implicit declaration of function ‘le_mdc_StartSession’; did you mean ‘le_msg_GetSession’? [-Werror=implicit-function-declaration]
      le_mdc_StartSession(ProfileRef[0]);

Is it necessary to include some lib on the project to use this function? I found some examples but nothing works.

I don’t see problem, you can use my application and put your code in demo.c
modemDemo1.rar (2.0 MB)

I compiled in VSCode with swi-fx30-catm_2.0.0 package:

  1. leaf shell
  2. cd apps/Demo/modemDemo1
  3. make

Running your example, I see that the le_mdc_StartSession function is successfully executed

root@fx30s:~# cm data
Index:                         1
APN:                           allcom.swir
PDP Type:                      IPV4V6
Connected:                     yes
Auth type:                     PAP
User name:                     allcom
Password:                      allcom
Interface:                     rmnet_data0
Family[IPv4]:                  inet
IP[IPv4]:                      10.110.47.74
Gateway[IPv4]:                 10.110.47.73
Dns1[IPv4]:                    8.8.8.8
Dns2[IPv4]:                    4.2.2.2

It looks like it starts the network interface but I don’t have internet connectivity

root@fx30s:~# ping google.com
ping: bad address 'google.com'
root@fx30s:~# 

I can only connect to the internet when I execute the command in the terminal:

root@fx30s:~# cm data connect
Checking if device 'rmnet_data0' is up ... ok
Routing inet ... ok
Updating /etc/resolv.conf ... ok
Updating /etc/resolv.conf ... ok

root@fx30s:~# ping google.com
PING google.com (172.217.1.46): 56 data bytes
64 bytes from 172.217.1.46: seq=0 ttl=116 time=1258.533 ms

How do I start an internet connection through my legato application?

Is it ok to ping 8.8.8.8?

Btw, you can call “cm data connect” within unsandboxed legato app with systen() api.

Fyi, it should work fine:

Using le_mdc_StartSession I get the following ping return

root@fx30s:~# ping 8.8.8.8
PING 8.8.8.8 (8.8.8.8): 56 data bytes
ping: sendto: Network is unreachable

I changed one implementation per system (“cm data connect”); disabling the sandbox, but the cm command was not recognized:

Feb 23 08:35:05 fx30s user.err Legato: =ERR= | mqttPublisher[2788] | cm: not found

But it worked out using the full path to the cm.

system("/legato/systems/current/bin/cm data connect");

Thank you for your help!