BG96 Module MQTT client example

Dependencies:   MQTT NetworkSocketAPI mbed

Fork of Nucleo_NbIotBG96_A2_cloud_IBM by Avnet Silica

Files at this revision

API Documentation at this revision

Comitter:
WaleedElmughrabi
Date:
Sun Sep 09 23:01:12 2018 +0000
Parent:
2:b72797c38464
Commit message:
Modified for the STM32L496AG

Changed in this revision

X_NUCLEO_IKS01A2.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r b72797c38464 -r e26690c0e2c7 X_NUCLEO_IKS01A2.lib
--- a/X_NUCLEO_IKS01A2.lib	Mon Nov 20 16:23:22 2017 +0100
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://developer.mbed.org/teams/ST/code/X_NUCLEO_IKS01A2/#138a7a28bd21
diff -r b72797c38464 -r e26690c0e2c7 main.cpp
--- a/main.cpp	Mon Nov 20 16:23:22 2017 +0100
+++ b/main.cpp	Sun Sep 09 23:01:12 2018 +0000
@@ -20,9 +20,6 @@
 #include "MQTTClient.h"
 #include "MQTT_GSM.h"
 #include <ctype.h>
-//#include "x_nucleo_iks01a1.h"
-#include "XNucleoIKS01A2.h"
-
 #include "BG96.h"
 
 //------------------------------------
@@ -41,7 +38,9 @@
 //#define SUBSCRIBE              							// uncomment to subscribe to broker msgs (not to be used with IBM broker) 
 
  // Configuration values needed to connect to IBM IoT Cloud
-#define BROKER_URL ".messaging.internetofthings.ibmcloud.com";     
+//#define BROKER_URL "BTL-IOT-Hub.azure-devices.net";     
+#define BROKER_URL ".messaging.internetofthings.ibmcloud.com";  
+
 #ifdef ORG_QUICKSTART
 	#define ORG "quickstart"     								// connect to quickstart.internetofthings.ibmcloud.com/ For a registered connection, replace with your org 
 	#define ID ""
@@ -49,18 +48,18 @@
 	#define DEFAULT_TYPE_NAME "iotsample-mbed-Nucleo"
 	#define TOPIC  "iot-2/evt/status/fmt/json" 
 #else   // not def ORG_QUICKSTART
-	#define ORG "pvko17"             						// connect to play.internetofthings.ibmcloud.com/ For a registered connection, replace with your org
-	#define ID "testtype_112233445566"       		// For a registered connection, replace with your id
-	#define AUTH_TOKEN "testtype_112233445566"	// For a registered connection, replace with your auth-token
-	#define DEFAULT_TYPE_NAME "TestType"
-	#define TOPIC   "iot-2/type/TestType/id/testtype_112233445566/evt/status/fmt/json" 
+	#define ORG "Test-Device-1"             						// connect to play.internetofthings.ibmcloud.com/ For a registered connection, replace with your org
+	#define ID "Test-Device-1"       		// For a registered connection, replace with your id
+	#define AUTH_TOKEN ""	// For a registered connection, replace with your auth-token
+	#define DEFAULT_TYPE_NAME "Test-Device-1"
+	#define TOPIC   "devices/Test-Device-1/messages/events" 
 #endif
 
 // network credential
-#define APN   "web.omnitel.it"  //VODAFONE apn definition's
+#define APN   "m2m.tele2.com"  //VODAFONE apn definition's
 //#define APN			"internet.wind"		//WIND apn definition's
-#define PASSW  ""
-#define USNAME ""
+#define PASSW  "Waleed29"
+#define USNAME "Ianthomson"
 
 #define TYPE DEFAULT_TYPE_NAME       // For a registered connection, replace with your type
 #define MQTT_PORT 1883
@@ -83,28 +82,17 @@
 int retryAttempt = 0;
 char subscription_url[MQTT_MAX_PAYLOAD_SIZE];
 
-#define SENSOR_ENABLED		1
-#define SENSOR_MODEL			2
+
 
 #define FW_REV						"1.0a"
 
-PressureSensor *pressure_sensor;
-HumiditySensor *humidity_sensor;
-TempSensor *temp_sensor1;
+
 
 MQTT::Message message;
 MQTTString TopicName={TOPIC};
 MQTT::MessageData MsgData(TopicName, message);
 
-/* Instantiate the expansion board */
-static XNucleoIKS01A2 *mems_expansion_board = XNucleoIKS01A2::instance(D14, D15, D4, D5);
 
-/* Retrieve the composing elements of the expansion board */
-static LSM303AGRMagSensor *magnetometer = mems_expansion_board->magnetometer;
-static HTS221Sensor *hum_temp = mems_expansion_board->ht_sensor;
-static LPS22HBSensor *press_temp = mems_expansion_board->pt_sensor;
-static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro;
-static LSM303AGRAccSensor *accelerometer = mems_expansion_board->accelerometer;
 
 void subscribe_cb(MQTT::MessageData & msgMQTT) {
     char msg[MQTT_MAX_PAYLOAD_SIZE];
@@ -180,6 +168,7 @@
     return rc;
 }
 
+
 int getConnTimeout(int attemptNumber)
 {  // First 10 attempts try within 3 seconds, next 10 attempts retry after every 1 minute
    // after 20 attempts, retry every 10 minutes
@@ -220,26 +209,14 @@
             
     char buf[MQTT_MAX_PAYLOAD_SIZE];
     float temp, temp1, temp2, press, hum;
-	
-	#if SENSOR_ENABLED
-		pc.printf("A02 reading sensors...");
 
-	    hum_temp->get_temperature(&temp1);
-			hum_temp->get_humidity(&hum);
-   
-			press_temp->get_temperature(&temp2);
-			press_temp->get_pressure(&press);
-			temp = (temp1+temp2)/2;
-		
-	pc.printf(" DONE\r\n");
-	#else
 		temp=25.5;
 		hum_global +=0.1;
 		if (hum_global>99.0)
 			hum_global = 50.0;
 		hum=hum_global;
 		press=999;
-	#endif
+
 		
 	#ifdef ORG_QUICKSTART
     sprintf(buf,
@@ -272,7 +249,7 @@
     const char * apn = APN; // Network must be visible otherwise it can't connect
     const char * username = USNAME;
 		const char * password = PASSW;
-    BG96Interface bg96_if(D8, D2, false);
+    BG96Interface bg96_if(PG_7, PG_8, false);
 		//sprintf(sensor_id,"%s",bg96_if.get_mac_address()); 
 		//Timer tyeld;
 
@@ -291,16 +268,8 @@
     //pc.printf("\r\nwait for APN ready ...\r\n");  
     //wait( 0.1 );     
 	
-	 #if SENSOR_ENABLED
-				/* Enable all sensors */
-				hum_temp->enable();
-				press_temp->enable();
-				//magnetometer->enable();
-				//accelerometer->enable();
-				//acc_gyro->enable_x();
-				//acc_gyro->enable_g();
-	 #endif
 
+	
 
    quickstartMode=false;
    if (strcmp(org, "quickstart") == 0){quickstartMode = true;}
@@ -390,26 +359,4 @@
 }
 
 
-		//for testing sensor board ...
-void test_sens(void)
-{	
-		while(1)
-		{
-			
-			  float value1, value2;
-			  char buffer1[32], buffer2[32];
-			  printf("\r\n");
 
-			  hum_temp->get_temperature(&value1);
-				hum_temp->get_humidity(&value2);
-				printf("HTS221: [temp] %7s C,   [hum] %s%%\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
-    
-				press_temp->get_temperature(&value1);
-				press_temp->get_pressure(&value2);
-				printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
-				
-				wait(2);
-			
-		}
-}
-
diff -r b72797c38464 -r e26690c0e2c7 mbed.bld
--- a/mbed.bld	Mon Nov 20 16:23:22 2017 +0100
+++ b/mbed.bld	Sun Sep 09 23:01:12 2018 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file