Integration between Arduino MKR GSM 1400 and Hologram Cloud


#1

Hi Hologram community,

I’m want to use my MKR GSM 1400 board and using Hologram Sim to send the data to the hologram cloud. The board is using the same GSM module like Dash. As far as I know there is already a library to send the data to the cloud but i think this library is only compatible for Dash board. Is there any information/library on how could I send the data?

Based on my assumption of the incompability of the library for MKR board, so I tried to understand what the function i.e HologramCloud.sendMessage() actually do.

Link to Hologram.cpp on github

But I’m stucked on modem.command() function inside sendMessage() function as I dont really understand what “+HMRST” really mean for. I thought that it maybe one of the AT command for U201 module. But there is no reference on it as I look at the manual. So I assume it is the command for Hologram server side. Am I right?

Thanks,
ZZ


#2

Update to the integration test between MKR GSM 1400 and Hologram Cloud:

Sending data to the cloud via Socket API is successful.

The message form were created and replicated based on the hologram-SIMCOM library from @benstr github repository as reference.

I’m using GSMWebClient example from MKRGSM library then as example to send the data to the cloud.


#3

Hi, can you post some of your code on how you have got your MKR1400 connected? I’ve been struggling with this for a few weeks now. I would be grateful for any help. Thanks


#5

Re-opened for adding new code.


#6

@millsy I just ran into this post and wanted to share some code that I wrote to get the Arduino GSM MKR to send Cloud Data Messages to the Hologram Dashboard using our Embedded API

/*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[] = " ";
String HOLOGRAM_API_KEY = "YOUR HOLOGRAM API 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 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);
    }
  }

  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_API_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 (;;)
      ;
  }
}

Library Requested to Support the MKR Series
Library Requested to Support the MKR Series
#7

Thanks Maiky

1-sorry for my ignorance, but by activating a sim card and using this code, I could send a message directly out of the box? Or there are additional steps apart from adding the board with “board manager from arduino IDE”?

2-What about data consumption? will it be identical to the Dash?

3-I can not find documentation about consumption in deep sleep, is it similar to the Dash 1.2? Does anyone have this data?


#8

Hey Titus,

No need to apologize, we’re all learning here!

  1. There is some setup required on the Arduino IDE here. I followed the steps on the Arduino page: https://www.arduino.cc/en/Guide/MKRGSM1400#toc2

  2. Data consumption for cloud messages will be close to, but not identical to the Dash. This is because there are differences in firmware.

  3. I am not sure about this, but looking at the Arduino documentation on the page would be my first suggestion.


#9

If you have the board in front of you, could you test it just to save time: 1st 10 bytes message with a fresh connection then a second one a minute later. I think Particle user use about 6kb for the first message. I hope this product is not in this range.


#10

Hey Titus,

I don’t have the board anymore, but as you suggest measuring this on your own should be a breeze if you use the Dashboard’s data inspect feature.


#11

@Titus the cloud protocol will determine data usage and not the board. Hologram’s cloud uses TCP and Particle uses UDP. Going further, behind the scenes MQTT uses TCP and CoAP uses UDP.

When using our SIM and the MKR 1400 you can use any cloud and protocol.

There is a possibility our SIM meets your needs but our cloud does not. In that case, I’d recommend looking to integrate 3rd party cloud services like AWS IoT or Adafruit.io Pro

This is a good comparison: https://www.diffen.com/difference/TCP_vs_UDP

TL;DR: TCP uses more data but is more reliable and ordered. UDP is efficient but does not guarantee message delivery or order.


#12

Cheers for this!! I’ll need to get the board out again and give it a go.


#13

My pleasure millsy!


#14

Just got back from MakerFaire - Bay Area. One of my meetings was with Arduino. There are no details I can publish right now, but I wanted to let you all know good things are in the works!


#15

Malky, thanks for the great sketch on connecting the world of Hologram to the world of MKR1400!

When I run

Serial.println(gsmAccess.begin());

it returns a 3 (usually on cold boot) or 0 (on reset).

I’ve poked around in pretty much every library, and can’t find any references to linking numeric codes to verbose info.

Any ideas / thoughts as to what “3” means?

Thanks!

Michael


#16

Hey @MichaelM,

Thanks! Happy to know others have found it useful!

Have you seen Arduino’s page on this? Haven’t experimented myself or looked at the code to verify, but extrapolating a bit I’d think 0 could be the error code and the 3 is GSM_Ready. Does that seem to fit into what you see happening? Also have you posted something about this in Arduino’s forums? If so can you post the link here? I’d love to follow up and see what the real answer is.

Cheers,
Maiky


#17

Maiky,

I tried your example with my API key and got the following response:

Starting Arduino web client.
Begin MSM Access
GSM Access Success
connecting…
connected
[3,0]
disconnecting.

Shouldn’t I see in the log for this device, “TOPIC” and “Your message here”? So far I don’t see anything.

Thanks,
Alan


#18

Hi, Alano,

I saw literally the exact same thing on my first try.

The “3” is a “invalid credential code.” Likely reason? You may (as I did) have used your general APN key, (the long one), instead of the 8-digit device API. Hologram will generate a unique APN for each SIM. Use that, and you should be good to go! There a “device key” window on the top right of the page for each SIM on you Hologram dashboard. :slight_smile:

NOTE: The “3” code here is NOT the one I’m asking about above (which is related to the modem). Odd conicidence, for sure.

Michael


#19

Michael,

Thanks, that was the issue! Now on to see if I can get the MKR 1400 board into a low-power state periodically. Does this happen to be one of your goals as well?


#20

Glad it worked! Yes, low power mode, together with general robustness for data connections after long periods of no communication (hours / days) is what I’m after. That, and figuring out how the power management operates on this thing…