GPS tracker code documentation
 All Classes Files Functions Variables Macros Pages
Macros | Functions
network_functions.h File Reference

GPRS, TCP and MQTT functions' prototypes and definition of related parameters. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DEBUG_MODE   1
 
#define ERR_PHONE_FUNCTION   48
 
#define ERR_SIM_PRESENCE   49
 
#define ERR_PIN_WRONG   50
 
#define ERR_WEAK_SIGNAL   51
 
#define ERR_REGISTRATION   52
 
#define ERR_GPRS_ATTACH   52
 
#define ERR_PDP_DEACTIVATED   53
 
#define ERR_PDP_DEFINE   54
 
#define ERR_PDP_ACTIVATE   55
 
#define ERR_GET_IP   56
 
#define ERR_MQTT_EMPTY_PARAM   100
 
#define APN   "TM"
 
#define APN_LENGTH   2 /* Length of the APN string */
 
#define SIM_PIN   ""
 
#define MAX_LENGTH_MQTT_PACKET   128
 
#define MQTT_KEEP_ALIVE   15
 

Functions

uint8_t enable_gprs ()
 enables the GPRS connection. GPRS must be enabled before trying to establish TCP connection. This function goes through a series of the tests below. action is taken depending on the test result More...
 
uint8_t disable_gprs ()
 disables the GPRS functionality and the whole radio module. More...
 
uint8_t open_tcp_connection (char *ip_address, char *tcp_port)
 opens a new TCP connection. if the function is called when there is already an open TCP connection then it closes it and opens a new connection. More...
 
uint8_t send_tcp_data (uint8_t *data, uint8_t data_length)
 sends data over an open TCP connection. More...
 
uint8_t close_tcp_connection ()
 closes an open TCP connection. More...
 
uint8_t publish_mqtt_msg (char *ip_address, char *tcp_port, char *topic, char *client_id, char *message)
 publishes a message to an MQTT topic with QoS 1 by default. More...
 

Detailed Description

GPRS, TCP and MQTT functions' prototypes and definition of related parameters.

Author
Mohamed Boubaker
Bug:
issue #9

Macro Definition Documentation

#define APN   "TM"
#define APN_LENGTH   2 /* Length of the APN string */
#define DEBUG_MODE   1
#define ERR_GET_IP   56
#define ERR_GPRS_ATTACH   52
#define ERR_MQTT_EMPTY_PARAM   100
#define ERR_PDP_ACTIVATE   55
#define ERR_PDP_DEACTIVATED   53
#define ERR_PDP_DEFINE   54
#define ERR_PHONE_FUNCTION   48
#define ERR_PIN_WRONG   50
#define ERR_REGISTRATION   52
#define ERR_SIM_PRESENCE   49
#define ERR_WEAK_SIGNAL   51
#define MAX_LENGTH_MQTT_PACKET   128
#define MQTT_KEEP_ALIVE   15
#define SIM_PIN   ""

Function Documentation

uint8_t close_tcp_connection ( )

closes an open TCP connection.

Returns
SUCCESS if the connection was successfully closed, FAIL otherwise.

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t disable_gprs ( )

disables the GPRS functionality and the whole radio module.

Returns
1 if the GPRS is successfully disabled, 0 otherwise.
uint8_t enable_gprs ( )

enables the GPRS connection. GPRS must be enabled before trying to establish TCP connection. This function goes through a series of the tests below. action is taken depending on the test result

  1. Checks if the SIM card is detected
  2. Checks if the SIM card requires PIN code
  3. Checks the signal stregth. If it is very low, it returns an error value.
  4. Checks if the Mobile Equipement (ME) is registered to the Network. If not, it tries to register.
  5. Checks if ME is attached to GPRS service. if not it tries to attach.
  6. Checks if GPRS PDP context is defined, if not it tries to define it, enable it, and get IP address.
Returns
1 if gprs is active, 2 if SIM card is not detected, 3 if SIM PIN is incorrect, 4 if the signal is weak, 0 otherwise

enables the GPRS connection. GPRS must be enabled before trying to establish TCP connection. This function goes through a series of the tests below. action is taken depending on the test result

  1. Checks if the SIM card is detected
  2. Checks if the SIM card requires PIN code
  3. Checks the signal stregth. If it is very low, it returns an error value.
  4. Checks if the Mobile Equipement (ME) is registered to the Network. If not, it tries to register.
  5. Checks if ME is attached to GPRS service. if not it tries to attach.
  6. Checks if GPRS PDP context is defined, if not it tries to define it, enable it, and get IP address.
Returns
1 if gprs is active, 2 if SIM card is not detected, 3 if SIM PIN is incorrect, 4 if the signal is weak, 0 otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t open_tcp_connection ( char *  ip_address,
char *  tcp_port 
)

opens a new TCP connection. if the function is called when there is already an open TCP connection then it closes it and opens a new connection.

Parameters
ip_addressis the IP address of the server. it can be an IP adress or DNS hostname.
tcp_portis the remote TCP port.
Returns
SUCCESS if the connection was successfully opened, FAIL otherwise

Here is the call graph for this function:

Here is the caller graph for this function:

uint8_t publish_mqtt_msg ( char *  ip_address,
char *  tcp_port,
char *  topic,
char *  client_id,
char *  message 
)

publishes a message to an MQTT topic with QoS 1 by default.

Parameters
ip_addressis the MQTT server IP address or DNS hostname.
tcp_portis the MQTT server port
client_idis the MQTT client ID.
topicis the MQTT topic name.
messageis the message to be sent.
Returns
SUCCESS if the message is successfully delivered, 0 otherwise.

Here is the call graph for this function:

uint8_t send_tcp_data ( uint8_t *  data,
uint8_t  data_length 
)

sends data over an open TCP connection.

Parameters
datais the byte array to be sent
data_lengthis the length of the byte array to be sent.
Returns
SUCCESS if the data was successfully sent, FAIL otherwise.

Here is the call graph for this function:

Here is the caller graph for this function: