GPRS, TCP and MQTT functions implementation.
More...
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include "sim808.h"
#include "network_functions.h"
|
uint8_t | sim_insert_PIN (char *pin) |
|
uint8_t | enable_gprs () |
| gprs_enable() enables 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 | open_tcp_connection (char *server_address, char *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 | close_tcp_connection () |
| closes an open TCP connection. More...
|
|
uint8_t | send_tcp_data (uint8_t *data, uint8_t data_length) |
| sends data over 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...
|
|
GPRS, TCP and MQTT functions implementation.
- Author
- Mohamed Boubaker
- Bug:
- issue #9
uint8_t close_tcp_connection |
( |
| ) |
|
closes an open TCP connection.
- Returns
- SUCCESS if the connection was successfully closed, FAIL otherwise.
gprs_enable() enables 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
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
- Checks if the SIM card is detected
- Checks if the SIM card requires PIN code
- Checks the signal stregth. If it is very low, it returns an error value.
- Checks if the Mobile Equipement (ME) is registered to the Network. If not, it tries to register.
- Checks if ME is attached to GPRS service. if not it tries to attach.
- 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
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_address | is the IP address of the server. it can be an IP adress or DNS hostname. |
tcp_port | is the remote TCP port. |
- Returns
- SUCCESS if the connection was successfully opened, FAIL otherwise
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_address | is the MQTT server IP address or DNS hostname. |
tcp_port | is the MQTT server port |
client_id | is the MQTT client ID. |
topic | is the MQTT topic name. |
message | is the message to be sent. |
- Returns
- SUCCESS if the message is successfully delivered, 0 otherwise.
uint8_t send_tcp_data |
( |
uint8_t * |
data, |
|
|
uint8_t |
data_length |
|
) |
| |
sends data over an open TCP connection.
- Parameters
-
data | is the byte array to be sent |
data_length | is the length of the byte array to be sent. |
- Returns
- SUCCESS if the data was successfully sent, FAIL otherwise.
uint8_t sim_insert_PIN |
( |
char * |
pin | ) |
|