/* DESC: This script will publish router status informations to * an mqtt broker using nb_mqtt_publish(). Status infos published to one topic * every minute for max messages amount. * For details about status infos check API Documentation about nb_status(); * Copyright (C) 2018 NetModule AG, Switzerland */ HOST = "192.168.240.1"; PORT = 1883; USERNAME = "test"; PASSWORD = "test"; TOPIC = "mycompany/bus1/"; /* QOS Values */ /* 0 = publish at most one (fire & forget) */ /* 1 = publish at least once */ /* 2 = publish exactly once */ QOS = 0; /* Retain values */ /* 0 = the message will not be stored */ /* 1 = the message will be stored and sent to a new subscriber of that topic */ RETAIN = 0; MESSAGE = ""; MAX_MESSAGES = 10 ; // /* max. number messages */ for (cnt = 0; cnt < MAX_MESSAGES;) { /* get different example values via nb_status() */ sys_tmp = nb_status("system").TEMPERATURE; mob1_service = nb_status("wwan").MOBILE1_SERVICE_TYPE; mob1_signal = nb_status("wwan").MOBILE1_SIGNAL_LEVEL; gps_long = nb_status("gnss").GNSS1_LONGITUDE; gps_lat = nb_status("gnss").GNSS1_LATITUDE; /* create the message */ MESSAGE=sprintf("Status info: \n temp: %s \n mobile1 service: %s\n mobile 1 signal: %s\n gps long: %s\n gps lat %s\n",sys_tmp, mob1_service, mob1_signal, gps_long, gps_lat); //printf("%s", MESSAGE); /* publish the message to mqtt broker */ ret = nb_mqtt_publish (HOST, PORT, USERNAME, PASSWORD, TOPIC, QOS, RETAIN, MESSAGE); if(ret<0){ nb_syslog("Failed to publish mqtt message"); } sleep(60); cnt ++; } exit(0);