Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MQTT NetworkSocketAPI X_NUCLEO_IKS01A2 mbed
Fork of Nucleo_NbIotBG96_A2_cloud_IBM by
Diff: main.cpp
- Revision:
- 3:04dbacb98e86
- Parent:
- 2:b72797c38464
--- a/main.cpp Mon Nov 20 16:23:22 2017 +0100
+++ b/main.cpp Tue Mar 20 15:00:12 2018 +0000
@@ -25,10 +25,9 @@
#include "BG96.h"
-//------------------------------------
-// Hyperterminal default configuration
-// 9600 bauds, 8-bit data, no parity
-//------------------------------------
+//--------------------------------------
+// Tera Term configuration: 115200,8N1N
+//--------------------------------------
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
bool quickstartMode = true;
@@ -36,29 +35,34 @@
#define MQTT_MAX_PACKET_SIZE 300
#define MQTT_MAX_PAYLOAD_SIZE 500
-
#define ORG_QUICKSTART // comment to connect to play.internetofthings.ibmcloud.com
-//#define SUBSCRIBE // uncomment to subscribe to broker msgs (not to be used with IBM broker)
+//#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";
#ifdef ORG_QUICKSTART
- #define ORG "quickstart" // connect to quickstart.internetofthings.ibmcloud.com/ For a registered connection, replace with your org
+ #define ORG "quickstart" // connect to quickstart.internetofthings.ibmcloud.com/ For a registered connection, replace with your org
#define ID ""
#define AUTH_TOKEN ""
#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 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 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"
#endif
-// network credential
-#define APN "web.omnitel.it" //VODAFONE apn definition's
-//#define APN "internet.wind" //WIND apn definition's
+// network credentials
+//#define APN "m2m-east.telus.iot" // TELUS APN #1
+//#define APN "m2m-west.telus.iot" // TELUS APN #2
+//#define APN "sp.telus.com" // TELUS APN #3
+//#define APN "pp.telus.com" // TELUS APN #4
+//#define APN "internet-west.prodtest.iot" // TELUS APN #5
+//#define APN "type1-stwi.iot" // TELUS APN #6
+#define APN "m2m.com.attz" // AT&T APN for IoT devices
+
#define PASSW ""
#define USNAME ""
@@ -84,9 +88,9 @@
char subscription_url[MQTT_MAX_PAYLOAD_SIZE];
#define SENSOR_ENABLED 1
-#define SENSOR_MODEL 2
+#define SENSOR_MODEL 2
-#define FW_REV "1.0a"
+#define FW_REV "1.0a"
PressureSensor *pressure_sensor;
HumiditySensor *humidity_sensor;
@@ -251,7 +255,7 @@
sensor_id, temp, hum, press);
#endif
- message.qos = MQTT::QOS0;
+ message.qos = MQTT::QOS0;
message.retained = false;
message.dup = false;
message.payload = (void*)buf;
@@ -269,9 +273,12 @@
int main()
{
+ const char * line_divider = "*******************************************************";
const char * apn = APN; // Network must be visible otherwise it can't connect
const char * username = USNAME;
- const char * password = PASSW;
+ const char * password = PASSW;
+ const char * IMSI_number = "302220XXXXXX"; // IMSI placeholder
+
BG96Interface bg96_if(D8, D2, false);
//sprintf(sensor_id,"%s",bg96_if.get_mac_address());
//Timer tyeld;
@@ -282,29 +289,40 @@
myled=1;
//wait(0.5);
- pc.printf("\r\n*************************************************");
- wait( 0.1 );
- pc.printf("\r\nAvnet Silica NbIotBG96 A02 mbed-os application\r\n");
+// pc.printf("*******************************************************");
+ pc.printf("\r\n%s\r\n", line_divider);
+ wait( 0.1 );
+// pc.printf("\r\nAvnet Silica NbIotBG96 A02 mbed-os application\r\n");
+ pc.printf("TELUS LTE-M IoT Starter Kit: IBM QuickStart application");
wait( 0.1 );
+ pc.printf("\r\n%s\r\n", line_divider);
+ wait( 0.1 );
pc.printf("MBED online version %s\r\n", FW_REV);
wait( 0.1 );
- //pc.printf("\r\nwait for APN ready ...\r\n");
- //wait( 0.1 );
+ pc.printf("APN = %s\r\n", APN);
- #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
-
+ #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;}
MQTT_GSM ipstack(bg96_if, apn, username, password);
+
+ // Get the IMSI number from BG96
+ pc.printf("***********************\r\n");
+ wait( 0.1 );
+ pc.printf("IMSI = %s\r\n", bg96_if.get_IMSI_number()); // IMSI placeholder
+ wait( 0.1 );
+ pc.printf("***********************\r\n");
+ wait( 0.1 );
+
MQTT::Client<MQTT_GSM, Countdown, MQTT_MAX_PACKET_SIZE> client(ipstack);
if (quickstartMode){
char mac[50]; // remove all : from mac
@@ -329,7 +347,7 @@
while (true)
{
- if (++loop_count == 60)
+ if (++loop_count == 10) //pf this was 60
{
// Publish a message every 30 second
pc.printf("\n");
@@ -345,14 +363,9 @@
// int start = tyeld.read_ms();
client.yield(500); // allow the MQTT client to receive messages
pc.printf ("loop %d\r", (loop_count+1)); //: %d\n\r",tyeld.read_ms()-start);
-
}
-
}
-
-
-
/* Helper function for printing floats & doubles */
static char *print_double(char* str, double v, int decimalDigits=2)
{
@@ -395,7 +408,7 @@
{
while(1)
{
-
+
float value1, value2;
char buffer1[32], buffer2[32];
printf("\r\n");
@@ -409,7 +422,5 @@
printf("LPS22HB: [temp] %7s C, [press] %s mbar\r\n", print_double(buffer1, value1), print_double(buffer2, value2));
wait(2);
-
}
}
-
