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

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

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

Returns

GPRS 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_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)

No Network/No Sim: LED Off Searching Network: 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

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
enumerator NET_TYPE_GSM
enumerator NET_TYPE_LTE