PDP context and the Socket Connection

Hi forum,

Can any one help me:
1. How to activate OR deactivate the PDP context by using an application?
2. How to open a remote connection via socket by using an application?

Thanks in advance.

I try to send a test message to the server but failed, see the code below:


#include <netinet/in.h>
#include <arpa/inet.h>

void upd_client(void)
	int client_sockfd;
	int len;
	struct sockaddr_in remote_addr;	//remote address 
	//int sin_size;
	char buf[BUFSIZ];				//transmit buffer
	memset(&remote_addr,0,sizeof(remote_addr));	//clearing
	remote_addr.sin_family = AF_INET;			// IP
	remote_addr.sin_addr.s_addr = inet_addr("xxx.yyy.net");	// remote address IP
	remote_addr.sin_port = htons(9006);			//remote port

	 /* Create socket: IPv4,UDP */
	strcpy(buf,"This is a test message for 4G");
	//sin_size = sizeof(struct sockaddr_in);
	 /*send message to remote host*/
	if((len=sendto(client_sockfd,buf,strlen(buf),0,(struct sockaddr *)&remote_addr,sizeof(struct sockaddr)))<0)

the output ERROR logs:

Jan 6 00:07:49 | =ERR= | clientExe[2268] | recvfrom: Network is unreachable

Can you help me? Thank you.


I think, there is a bug. I have got the same problem.
I set up GPRS correctly.
I called function le_data_Request() - handler returns “Connected”.
Function le_data_GetTechnology() returns LE_DATA_CELLULAR.
But when I try to open socket, I have got “Network is unreachable”.
If I release handler using le_data_Release (HandleDataRequest), I have got WIFICLIENT DISCONNECT.

System tries to connect to my server via WIFI.
When call le_data_Request() again, system uses GPRS and I can send message to my server.
So basically I have to call le_data_Request() twice

			le_data_RequestObjRef_t HandleDataRequest = le_data_Request();
			le_data_Release (HandleDataRequest);
			HandleDataRequest = le_data_Request(); 

I have tried to change Technology rank ( le_data_SetTechnologyRank ) but no effect.

Which version are you running @TheGod ?

Looks like you’re getting a “Connected” notification while it is still going through available technologies.
One thing you can do to make WiFi not available is uninstall wifiService.

I use version 16.10.3. Yes, I get “Connected”, le_data_GetTechnology() returns LE_DATA_CELLULAR (Not LE_DATA_WIFI) and it is also correct. But “Network is unreachable” when I try to connect to a server. If I call le_data_Release (HandleDataRequest);, I have got message about WiFi. I use mangoH Green and I don’t have WiFi on it, so I cannot be connected to WiFi :slight_smile:. Also I should not get “WIFICLIENT DISCONNECTED” in my opinion.

In other words, system tells me, that everything is ok and I am connected to the network via GPRS, but I cannot send data.

If it goes through available technologies and WiFi is first (le_data_SetTechnologyRank should be respected but it is not). I shoud get message discconnected and le_data_GetTechnology() == LE_DATA_WIFI. I would know, system tried to connected to WiFi and failed. Information from the system right now is misleading.

I could try to uninstall wifiservice, but I am going to use it in the near future as well. I don’t think it is good solution for the issue.

Well that’s a bit of a mess.
Could you try with a more recent version of Legato by any chance, such as 17.09.0?

It is pointless. You have answered my previous thread

When I stopped wifiService, nothing has changed. I still had to call le_data_Request(); twice. I did not have messages about WiFi, it was only difference.

Hi everyone,

I’m trying to send a simple message (using UDP) from the WP7607-1 module to a Python script that’s running on a server.
Now, it seems like some sort of action is denied but I don’t know which action and where to find the culprit that’s causing this error.

The log says the following:

Oct  6 11:37:17 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[826]/supervisor T=main |proc.c proc_Start() 1390 | Starting process 'PyCommunication' with pid 13653
Oct  6 11:37:17 swi-mdm9x28-wp user.info Legato:  INFO | supervisor[13653]/supervisor T=main | proc.c proc_Start() 1355 | Execing 'PyCommunication'
Oct  6 11:37:17 swi-mdm9x28-wp user.info Legato:  INFO | PyCommunication[13653] | Start of the client script. 
Oct  6 11:37:17 swi-mdm9x28-wp user.info Legato:  INFO | PyCommunication[13653] | Hello message sent.
Oct  6 11:37:17 swi-mdm9x28-wp user.info Legato:  INFO | PyCommunication[13653] | Closed the socket.
Oct  6 11:37:17 swi-mdm9x28-wp user.notice kernel: [ 6297.982717] audit: type=1400 audit(1601977037.746:8): lsm=SMACK fn=smack_inode_getattr action=denied subject="app.Py_Communication" object="admin" requested=r pid=13653 comm="PyCommunication" path="pipe:[43168]" dev="pipefs"

This is the C code (running on the WP7607-1):

// Client side implementation of UDP client-server model 
#include "legato.h"
#include "interfaces.h"

#include "stdio.h"
#include "stdlib.h" 
#include "unistd.h" 
#include "string.h" 
#include "sys/types.h" 
#include "sys/socket.h"  
#include "arpa/inet.h"
#include "netinet/in.h" 

#define PORT samePortasPython
#define SERVER_IP "xxx.yyy.zzz" 

void com_main(void);


// Driver code 
void com_main() { 
    struct sockaddr_in     servaddr; 
    int sockfd, slen = sizeof(servaddr); 
    char *message = "Hello from C";     

printf("Start of the client script. \n");
    // Creating socket file descriptor 
    if ( (sockfd = socket(AF_INET, SOCK_DGRAM, 0)) < 0 ) { 
        perror("socket creation failed"); 

    memset(&servaddr, 0, sizeof(servaddr)); 
    // Filling server information 
    servaddr.sin_family = AF_INET; 
    servaddr.sin_port = htons(PORT); 
    if (inet_aton(SERVER_IP , &servaddr.sin_addr) == 0) 
        fprintf(stderr, "inet_aton() failed\n");

    //send the message
    sendto(sockfd, message, strlen(message), 0, (struct sockaddr *) &servaddr, slen);
    printf("Hello message sent.\n"); 

    printf("Closed the socket.\n"); 
    // return 0; 

And this is the Python Script (running on the server) that should receive the message:

import time
import socket

print('Start of the server script.')

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)  # UDP
s.bind(('', same port as C))

while True:
    print('inside while loop')
    data, address = s.recvfrom(1024)
    print(data, address)
    i = 0
for d in data:
    print(f'Data[{i}]: {d},\tin hex: {hex(d)}')
    i += 1
print(f'Length of data: {len(data)}')
print(f'Connection from: {address}.')
print(f'This is the data: {data}.')


All I can see in the console of the server is:

Start of the server script.
inside while loop

is your python script running on same module?
i.e. your UDP socket is sending to IP address

No it’s not running on the same module but it is running on a server.
The Python script is not sending anything. It’s just supposed to receive data.
The C code running on the module is sending data to the server’s IP address which is not

Have you tried nc command to send data to server to make sure data connection is ok?

We have a application note about sending tcp data to server, you can refer to the following:

Problem solved.
The firewall on the server blocked the port.
Thank you though!