Skip to content

Library to use A9G (GPS GPRS module) with AT commands in Arduino framework-based systems. Supports JSON as payload in MQTT mode!

License

Notifications You must be signed in to change notification settings

import-tiago/A9G-Arduino-Library

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A9G Arduino Library

Library to use A9G with AT commands in Arduino framework-based systems.

A9G is a quad-band module from Ai-Thinker based on RDA8955 SoC - [GSM/GPRS] [GPS/BDS] (850/900/1800/1900MHz).

Official A9G repository: Ai-Thinker GPRS C SDK.

This library configures the A9G's GPS data output using the NMEA data specification. So to decode this NMEA packet this library incorporated Mikal Hart's amazing TinyGPSPlus library.

Big difference compared to other libraries: this one supports JSON as payload in MQTT mode! 💁

Minimal example code snippet:

#include "A9G.h"

A9G_Controller A9G(A9G_RESET_PIN, A9G_INIT_PIN);
GPS_Controller GPS(Serial1);
GPRS_Controller GPRS(Serial2);

void mqtt_callback(char* topic, char* payload, int length) {
	Serial.printf("\r\nFrom MQTT subscription: topic: %s, payload: %s, length: %d\r\n\r\n", topic, payload, length);
	// GPRS.mqtt_unsubscribe(MQTT_SUB_TOPIC, MQTT_SUB_QOS);
}

void setup() {

	Serial.begin(115200);

	while (!A9G.turn_on(MODEM_INIT_TIMEOUT_SECS)) {
		Serial.println("\r\nA9G init fail. Retrying...\r\n");
		A9G.turn_off();
	}

	A9G.echo(true);

	GPRS.cellular_network_connect(NETWORK_APN);

	GPS.enable(GPS_REFRESH_INTERVAL_SECS);

	GPRS.mqtt_connect_broker(MQTT_BROKER_ADDR,
				 MQTT_BROKER_PORT,
				 MQTT_BROKER_AUTH_USER,
				 MQTT_BROKER_AUTH_PASSWORD,
				 MQTT_CLIENT_ID,
				 MQTT_CLIENT_KEEPALIVE_SECS);

	GPRS.mqtt_subscribe(MQTT_SUB_TOPIC, MQTT_SUB_QOS, mqtt_callback);

	GPRS.mqtt_publish(MQTT_PUB_TOPIC, MQTT_PUB_PAYLOAD, MQTT_PUB_QOS);
}

void loop() {

	A9G.loop();
	GPRS.mqtt_loop();

	static uint32_t t0 = millis();

	if (millis() - t0 > 1000) {
		t0 = millis();

		static char JSON_payload[100];

		sprintf(JSON_payload, "{\"variable\":\"location\",\"value\":\"A9G\",\"location\":{\"lat\":%.8f,\"lng\":%.8f}}", GPS.location(LAT), GPS.location(LNG));

		GPRS.mqtt_publish((char*)"GPS", JSON_payload, MQTT_PUB_QOS);
	}
}

Minimal Hardware

PDF Download

About

Library to use A9G (GPS GPRS module) with AT commands in Arduino framework-based systems. Supports JSON as payload in MQTT mode!

Topics

Resources

License

Stars

Watchers

Forks

Packages