Please use the Image 4.1.2.1 to have the mqtt function in our SDK.
This script reads some defined values from the router via the nb_status() function. For a demo purpose the routers temperature, the service type and signal level from the modem as well as gps longitude and latitude get queried. Then nb_mqtt_publish() is used to publish the message to a given topic on the specified mqtt broker (see variables at the beginning of the script). Interessting setttings are QOS and RETAIN.
If you are interessted in other status values, please refer to the API manual and read about the nb_status() function. You can use dump() to get all the fields (ex: GNSS1_LATITUDE) of the struct returned by nb_status.
With default settings the script publishes 10 mqtt messages to a given topic and waits 60 secs between every new status query and message publish.
/* 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);