Arduino MKR GSM 1400

Arduino's MKR GSM 1400 is a fantastic cellular enabled micro-controller that is extremely flexible and perfect for embedded, low power solutions. Additionally, as part of Arduino's ecosystem the MKR GSM 1400 has tons of great documentation and a vibrant community.

 In this guide we go over the setup required to get it working on the Hologram network using our global IoT SIM.

Before we begin, please make sure that you have a Hologram account.

Setup

1) First we need to make sure to activate our Hologram SIM on the Dashboard. Here is a guide that walks you through that process. 

mceclip0.png

 

Once your SIM shows a green dot that indicates that its in LIVE status on the Dashboard we are ready to move on to the device.

2) Next to setup the MKR GSM 1400 we need to make sure our Arduino IDE is configured correctly. This page goes over that.


Once you have the SAMD core installed and the MKR GSM 1400 selected as your board we can move on.

3) To connect to the Hologram network we will be using Arduino's MKRGSM library which can be obtained by going to Sketch Include Library Manage Libraries... and searching for it, by name, in the search bar.

4) Now let's get the hardware ready. To do this we need to insert the SIM (use the micro size which is the middle notched size) , attach the antenna, connect the battery, and plug the Arduino into your computer. 

 

5) Next we need to set up the MKR GSM 1400 to use the correct APN information. For this we will use the MKRGSM library's GSM and GPRS classes. This can be done with the following code:

Full copy-pastable code snippets can be found at the bottom of this guide

Congratulations! At this point you should be connected to the network. 

 

Now we will go over using the Hologram messaging protocol to send messages to the Dashboard using the Hologram Embedded API. This is an optional step for users who plan on using this feature.

6) To send messages to the Hologram dashboard we need to establish a TCP connection to a specific host and port and send an API message. This can be achieved with the GSMClient class of Arduino's MKRGSM library. The code for that is as follows:

Full copy-pastable code snippets can be found at the bottom of this guide 

 

That's it! Now you can modify HOLOGRAM_MESSAGE and HOLOGRAM_TOPIC to relay your information to the cloud!

 

CODE SNIPPETS:

Connecting to Hologram's network 

/*Hologram Adaptation of Arduino's GSM Web Client Example Sketch used to send messages to Hologram's Cloud


Arduino information:

  Web client

 Circuit:
 * MKR GSM 1400 board
 * Antenna
 * SIM card with a data plan

 created 8 Mar 2012
 by Tom Igoe

modified 15 May 2017
by Maiky Iberkleid
*/

// libraries
#include <MKRGSM.h>

//We replaced "arduino_secrets.h" as all the information for that is publicly available from https://hologram.io/docs/guide/connect/connect-device/#apn-settings

const char PINNUMBER[] = " ";
// APN data
const char GPRS_APN[] = "hologram";
const char GPRS_LOGIN[] = " ";
const char GPRS_PASSWORD[] = " ";


// initialize the library instance
GPRS gprs;
GSM gsmAccess;

// Hologram's Embedded API (https://hologram.io/docs/reference/cloud/embedded/) URL and port
char server[] = "cloudsocket.hologram.io";
int port = 9999;

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Starting Arduino web client.");
  // connection state
  boolean connected = false;

  // After starting the modem with GSM.begin()
  // attach to the GPRS network with the APN, login and password
  while (!connected) {
     Serial.println("Begin MSM Access");
    //Serial.println(gsmAccess.begin()); //Uncomment for testing
   
    if ((gsmAccess.begin() == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
      Serial.println("GSM Access Success");
    }
    else {
      Serial.println("Not connected");
      delay(1000);
    }
  }
}

void loop() {
}

 

Connecting to Hologram's network and sending messages to the Hologram Dashboard

/*
Holgoram Adaptation of Arduino's GSM Web Client Example Sketch used to send messages to Hologram's Cloud


Arduino information:

  Web client

 Circuit:
 * MKR GSM 1400 board
 * Antenna
 * SIM card with a data plan

 created 8 Mar 2012
 by Tom Igoe

modified 15 May 2017
by Maiky Iberkleid
*/

// libraries
#include <MKRGSM.h>

//We replaced "arduino_secrets.h" as all the information for that is publicly available from https://hologram.io/docs/guide/connect/connect-device/#apn-settings

const char PINNUMBER[] = " ";
// APN data
const char GPRS_APN[] = "hologram";
const char GPRS_LOGIN[] = " ";
const char GPRS_PASSWORD[] = " ";
String HOLOGRAM_DEVICE_KEY = "YOUR HOLOGRAM_DEVICE_KEY";
String HOLOGRAM_MESSAGE = "Your Message here";
String HOLOGRAM_TOPIC = "TOPIC";

// initialize the library instance
GSMClient client;
GPRS gprs;
GSM gsmAccess;

// Hologram's Embedded API (https://hologram.io/docs/reference/cloud/embedded/) URL and port
char server[] = "cloudsocket.hologram.io";
int port = 9999;

void setup() {
  // initialize serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Starting Arduino web client.");
  // connection state
  boolean connected = false;

  // After starting the modem with GSM.begin()
  // attach to the GPRS network with the APN, login and password
  while (!connected) {
     Serial.println("Begin gsm Access");
    //Serial.println(gsmAccess.begin()); //Uncomment for testing
   
    if ((gsmAccess.begin() == GSM_READY) &&
        (gprs.attachGPRS(GPRS_APN, GPRS_LOGIN, GPRS_PASSWORD) == GPRS_READY)) {
      connected = true;
      Serial.println("GSM Access Success");
    }
    else {
      Serial.println("Not connected");
      delay(1000);
    }
  }

  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, port)) {
    Serial.println("connected");
    // Send a Message request:
    client.println("{\"k\":\"" + HOLOGRAM_DEVICE_KEY +"\",\"d\":\""+ HOLOGRAM_MESSAGE+ "\",\"t\":\""+HOLOGRAM_TOPIC+"\"}");
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // if the server's disconnected, stop the client:
  if (!client.available() && !client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();

    // do nothing forevermore:
    for (;;)
      ;
  }
}

 

 

 

Was this article helpful?
0 out of 0 found this helpful