Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added 2 new examples and added APN connect to the existing ones #1

Merged
merged 1 commit into from Sep 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/Dweet/Dweet.ino
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
@@ -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() {

}
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
@@ -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");
}

}

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
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
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