sdk-gnss-mqtt-publish.are
HOST = "123.123.123.123"; 
PORT = 1883;
KEEPALIVE = 60;
PROTOCOL = "V31";
USERNAME = "mqtt-username";
PASSWORD = "mqtt-password";
CLIENT_ID = "SDK-GPS";
TOPIC = "your-topic";
QOS = 0;
RETAIN = 0; 
MESSAGE = "";
CLEAN_SESSION = true;
MQTT_HANDLE = 0;
 
/*create new mqtt instance*/
MQTT_HANDLE = nb_mqttlib_new(CLIENT_ID, CLEAN_SESSION);
 
if (nb_mqttlib_set_protocol_version(MQTT_HANDLE, PROTOCOL)  < 0 ) {
  printf("Unable to set Protocol version\n");
    exit(1);
}
 
if (nb_mqttlib_set_user_pw(MQTT_HANDLE, USERNAME, PASSWORD) < 0 ) {
	printf("Unable to set Username and Passsword\n");
 
	exit(1);
}
 
if (nb_mqttlib_connect(MQTT_HANDLE, HOST, PORT, KEEPALIVE) < 0 ) {
	printf("Unable to connect\n");
	exit(1);
}
 
 
while (1) {
	sys_tmp = nb_status("system").TEMPERATURE;
	gps_long = nb_status("gnss").GNSS1_LONGITUDE;
	gps_lat = nb_status("gnss").GNSS1_LATITUDE;
	gps_hdop = nb_status("gnss").GNSS1_HDOP;
	gps_vdop = nb_status("gnss").GNSS1_VDOP;
	gps_pdop = nb_status("gnss").GNSS1_PDOP;
	gps_altitude = nb_status("gnss").GNSS1_ALTITUDE;
	gps_satellites_used = nb_status("gnss").GNSS1_SATELLITES_USED;
	gps_satellites_inview = nb_status("gnss").GNSS1_SATELLITES_INVIEW;
	gps_horizontal_speed = nb_status("gnss").GNSS1_HORIZONTAL_SPEED;
 
	/* create the message */
	MESSAGE=sprintf("%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",sys_tmp, gps_long, gps_lat, gps_hdop, gps_vdop, gps_pdop, gps_altitude, gps_satellites_used, gps_satellites_inview, gps_horizontal_speed);
 
	/*uncomment to view MESSAGE*/
	//printf("%s", MESSAGE);
 
	/* publish the message to mqtt broker */
	ret = nb_mqttlib_publish(MQTT_HANDLE, TOPIC, MESSAGE, QOS, RETAIN);
 
if(ret<0){
			nb_syslog("Failed to publish mqtt message");
	}
 
sleep(30);
}
 
exit(0);