Skip to content

Commit

Permalink
added 2 new examples and added APN connect to the existing ones
Browse files Browse the repository at this point in the history
  • Loading branch information
developersteve committed Sep 9, 2018
1 parent 5627260 commit 4d472f3
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 1 deletion.
3 changes: 3 additions & 0 deletions examples/Dweet/Dweet.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@ Connection4G conn(false,&shieldif);

const char host[] = "dweet.io";
String deviceName = "";
const char apn[] = "telstra.m2m";

void setup() {
Serial.begin(115200);
Serial.println("Starting....");

delay(500);

conn.activatePDP(apn, "", "");

if(!shield.isShieldReady())
{
Expand Down
35 changes: 35 additions & 0 deletions examples/NetworkConnect/NetworkConnect.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#include <connection4g.h>
#include <telstraiot.h>
#include <iotshield.h>
#include <shieldinterface.h>

ShieldInterface shieldif;
IoTShield shield(&shieldif);
Connection4G conn(false,&shieldif);

const char host[] = "google.com";
const char apn[] = "telstra.m2m";

void setup() {
Serial.begin(115200);
Serial.println("Starting....");

conn.activatePDP(apn, "", "");

delay(500);

if(!shield.isShieldReady())
{
Serial.println("Waiting for network");
shield.waitUntilShieldIsReady();
} else {
Serial.println("Network ready!");
}

conn.openTCP(host,80);
}


void loop() {

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const char tenant[] = "XXXXX";
const char username[] = "";
const char password[] = "";
const char appkey[] = "";
const char apn[] = "telstra.m2m";


TelstraIoT iotPlatform(host, tenant, username, password, appkey, &conn, &shield);

Expand All @@ -30,6 +32,7 @@ void setup() {
shield.waitUntilShieldIsReady();
Serial.println(F("[ ] ******* Shield ready *********"));

conn.activatePDP(apn, "", "");

// Check if shield is connected to 4G network
if(shield.isPDPContextActive()) {
Expand Down
94 changes: 94 additions & 0 deletions examples/RegisterAndSendLight/RegisterAndSendLight.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#include <connection4g.h>
#include <telstraiot.h>
#include <iotshield.h>
#include <shieldinterface.h>

ShieldInterface shieldif;
IoTShield shield(&shieldif);
Connection4G conn(true,&shieldif);

#define DeviceName "device1"

const char host[] = "XXXXX.cumulocity.com";
const char tenant[] = "XXXXX";
const char username[] = "username from cumulocity";
const char password[] = "password from cumulocity";
const char appkey[] = "needs to be empty";
const char apn[] = "telstra.m2m";
char id[9];


TelstraIoT iotPlatform(host, tenant, username, password, appkey, &conn, &shield);

void setup() {
Serial.begin(115200);
delay(5000);

conn.activatePDP(apn, "", "");

Serial.print(F("[START] Starting Registration Script using device name: "));
Serial.println(DeviceName);

while(!Serial); // Wait for serial character before starting

Serial.println(F("[ ] ******* Waiting for shield *********"));
shield.waitUntilShieldIsReady();
Serial.println(F("[ ] ******* Shield ready *********"));


// Check if shield is connected to 4G network
if(shield.isPDPContextActive()) {
Serial.println(F("[ OK ] ******* Connected to network *********"));

// Open secure TCP connection to IoT Platform host
Serial.println("############################ OPENING TCP CONNECTION #########################");
conn.openTCP(host,443);

// Register device on IoT Platform
Serial.println("############################ REGISTERING DEVICE #############################");

const char* supportedMeasurements[1];
supportedMeasurements[0] = "LightMeasurement";

int result = iotPlatform.registerDevice(DeviceName, id, 9, supportedMeasurements, 1);

if(result<0) {
Serial.println(F("[FAIL] Registration error. Please retry."));
while(true);
} else {
Serial.print(F("[ ] Arduino registered with id: "));
Serial.println(id);
}

} else {
Serial.println(F("[FAIL] Shield is not connected to 4G network!"));
while(true);
{
delay(5000);
Serial.println(F("[FAIL] Shield is not connected to 4G network!"));
}
}
}

void loop() {

if(id>0){

char lightString[15];

shield.getLightLevel(lightString);

Serial.print(F("[ ] Light: "));
Serial.println(lightString);

Serial.println("############################ Preparing to send MEASUREMENTS #############################");
iotPlatform.sendMeasurement("LightMeasurement", "LightMeasurement", "Light level (lux)", lightString, "lux");

delay(5000);

} else {
Serial.println("Something went wrong and an id isnt assigned, please check the number and try again");
}

}

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const char tenant[] = "XXXXX";
const char username[] = "";
const char password[] = "";
const char appkey[] = "";
const char apn[] = "telstra.m2m";


TelstraIoT iotPlatform(host, tenant, username, password, appkey, &conn, &shield);
Expand All @@ -30,7 +31,8 @@ void setup() {
Serial.println(F("[ ] ******* Waiting for shield *********"));
shield.waitUntilShieldIsReady();
Serial.println(F("[ ] ******* Shield ready *********"));


conn.activatePDP(apn, "", "");

// Check if shield is connected to 4G network
if(shield.isPDPContextActive()) {
Expand Down
3 changes: 3 additions & 0 deletions examples/SendAccMeasurmentData/SendAccMeasurmentData.ino
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Connection4G conn(true,&shieldif);
TelstraIoT iotPlatform(&conn,&shield);

const char host[] = "XXXXX.iot.telstra.com";
const char apn[] = "telstra.m2m";

char id[9];
char tenant[32];
Expand All @@ -26,6 +27,8 @@ void setup() {
delay(500);

Serial.println(F("[START] Starting Send All Measurments Script"));

conn.activatePDP(apn, "", "");

if(!shield.isShieldReady())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Connection4G conn(true,&shieldif);
TelstraIoT iotPlatform(&conn,&shield);

const char host[] = "XXXXX.iot.telstra.com";
const char apn[] = "telstra.m2m";

char id[9];
char tenant[32];
Expand All @@ -21,6 +22,8 @@ void setup() {
delay(500);

Serial.println(F("[START] Starting Send All Measurments Script"));

conn.activatePDP(apn, "", "");

if(!shield.isShieldReady())
{
Expand Down

0 comments on commit 4d472f3

Please sign in to comment.