GSM & GPRS API

API Reference

Header File

Source: include/network.h

#include <network.h>

Functions

int network_getparam(struct netparam_t *param)

Get Network parameters

Parameters:

param – [out] Pointer to parameter structure filled on return see netparam_t

Returns:

always return 0

int network_getapn(char *apn, char *user, char *pwd)

Get APN configuration stored in memory

Parameters:
  • apn – [out] Access point name (APN)

  • user – [out] APN user (optional, can be null)

  • pwd – [out] APN Password (optional, can be null)

Returns:

0 on success, negative value on error

int network_setapn(const char *apn, const char *user, const char *pwd)

Configure APN and store in memory. New setting will be applied only after reboot

Parameters:
  • apn – [in] Access point name (APN)

  • user – [in] APN user (optional, can be null)

  • pwd – [in] APN password (optional, can be null)

Returns:

0 on success, negative value on error

int network_getdns(char *pri, char *sec)

Get DNS servers

Parameters:
  • pri – [out] Primary DNS server

  • sec – [out] Secondary DNS server

Returns:

0 on success, negative value on error

int network_setdns(const char *pri, const char *sec)

Set DNS servers

Parameters:
  • pri – [in] Primary DNS server to set

  • sec – [in] Secondary DNS server to set

Returns:

0 on success, negative value on error

int network_resetdns(void)

Reset DNS servers to network default

Returns:

0 on success, negative value on error

int network_getstatus(int sockfd)

Get network status. If socket descriptor is provided, extended network status will be provided with socket status

Parameters:

sockfd – [in] Socket descriptor (optional, 0 if not used)

Returns:

network status see _net_state

int network_isready(void)

Get status of network, if its ready or not for IP data transmission

Deprecated:

since v1.0.0

Returns:

returns 1 if network ready, 0 otherwise

int network_isdataready(void)

Get status of network, if its ready or not for IP data transmission

Returns:

returns 1 if network ready, 0 otherwise

void network_reset(void)

Reset and restart network

int network_gprsenable(int enable)

Enable/Disable GPRS. GPRS is enabled by default

Deprecated:

since v1.0.0

Parameters:

enable – [in] 1 to enable, 0 to disable

Returns:

0 on success, negative value on error

int network_dataenable(int enable)

Enable/Disable data services. Data service is enabled by default

Parameters:

enable – [in] 1 to enable, 0 to disable

Returns:

0 on success, negative value on error

int network_isgprsenable(void)

Get GPRS enable/disable status

Deprecated:

since v1.0.0

Returns:

GPRS status

int network_isdataenable(void)

Get Data service enable/disable status

Returns:

service status

unsigned char *network_getlocalip(void)

Get IP address assigned to module

Returns:

IP Address octets

const char *network_getcurrapn(void)

Get currently used APN

Returns:

currently used APN

uint8_t network_gettype(void)

Get current network type GSM/LTE

Returns:

network type value nettype_e

int network_settype(int type)

Set current network type.

Parameters:

type – Network type nettype_e

Returns:

0 on success, negative on failure

int network_setup_statusled(int gpionum)

Setup Network status LED. Attach GPIO line managed by network thread for status LED.

IO Drive Logic: Positive (1 - High, 0 - Low)

LED Timings in milliseconds (On Time/Off Time):

No Sim: 250/3000 No Network/Searching: 50/500 GSM/GPRS Registered: 50/1000 Socket Connecting: 500/500 Network Idle: 50/2000 Data Sending: 100/100 Unknow error: 50/50

Parameters:

gpionum – [in] GPIO Number to use

Returns:

0 on success, negative value on error

Structures

struct netparam_t

Network parameter structure

Public Members

uint8_t simstate

SIM CPIN status simstate_e

uint8_t creg

GSM status networkstate_e

uint8_t cgreg

EPS Network (4G/NB-Iot)/GPRS status networkstate_e

uint8_t state

Internal state (for debugging)

uint8_t signal

Signal level

For GSM; RSSI Value - 0:-113dBm or less to 31:-55dBm or more,

For 4G/NB-IoT; RSRP Value - 0:-140dBm or less to 97:-44dBm or more,

99: Not detectable

uint8_t mode

Network mode nettype_e

const char *apn

Currently used APN as null terminted string

Enumerations

enum _net_state

Network state

Values:

enumerator NET_STATE_INVALID

Network status unknown/invalid

enumerator NET_STATE_NO_NETWORK

Network status no signal

enumerator NET_STATE_GSM

Network status GSM registered

enumerator NET_STATE_GPRS

Network status GPRS registered

enumerator NET_STATE_SOC_CONNECTING

Network status socket connection in progress

enumerator NET_STATE_SOC_CONNECTED

Network status socket connected

enumerator NET_STATE_SOC_SENDING

Network status sending data over socket

enum nettype_e

Network type.

Values:

enumerator NET_TYPE_UNKNOWN

Unknown network type, applicable to net_gettype()

enumerator NET_TYPE_AUTO

Autoselect network type, applicable to net_settype()

enumerator NET_TYPE_GSM

Network type 2G/GSM

enumerator NET_TYPE_LTE

Network type 4G LTE