Easily use any SIMCOM cellular module with Hologram's cloud.
HologramSIMCOM
is a library that makes it easier to interact with Hologram's Cloud using cellular modules from SIMCOM. SIMCOM 2G/3G modules are some of the most popular and affordable GPRS/GSM modules on the market.
NOTE: Hologram offers global 2G coverage, U.S. 2G coverage to mid-2020.
This library is confirmed working with the following modules:
A Hologram account and SIM Card is required to use this library.
Required. This goes before your start function. It instantiates HologramSIMCOM and gives the library the info it needs to connect to the device and Hologram's cloud.
#include <HologramSIMCOM.h>
#define RX_PIN 8
#define TX_PIN 7
#define RESET_PIN 10
#define HOLO_KEY "********"
HologramSIMCOM Hologram(TX_PIN, RX_PIN, RESET_PIN, HOLO_KEY);
Start-up the modem and connect to the cellular network. Typically this would go inside start()
but could also be useful to re-establish connection inside the loop()
.
19200
is typical for SIMCOM modules.Returns a boolean depending if it successfully connected or not.
void setup() {
// connect to the network and start listening for incoming data
Hologram.begin(19200, 8888);
}
Send data to the Hologram cloud where you can manipulate and route it to multiple cloud providers.
Returns a boolean whether send was successful or not.
void loop() {
// Send a char array to the cloud
Hologram.send("Hello World");
// Send a String to the cloud
Hologram.send(String("Hello World"));
// Send a JSON string that can be parsed by the Hologram Router
Hologram.send("{\"desc\":\"sensor-1\",\"temp\":78,\"hum\":20}");
// Publish to one topic
Hologram.send("Hello World", "cool-topic");
// Publish to multiple topics
Hologram.send("Hello World", "cool-topic,cooler-topic");
}
Send an outgoing SMS. This is a soft-SMS, which means it send a data string to the Hologram cloud then Hologram sends the SMS to it's destination. Optionally you can purchase a phone number for your SIM. If you do then the receiver will get the SMS from that number. Otherwise one of Hologram's generic system numbers will be the sender.
We choose to implement a soft-SMS over standard SMS because of price, performance, and reliability.
Returns a boolean whether send was successful or not.
void loop() {
Hologram.sendSMS("+13125554444", "Hello World");
}
Check if there's an unread inbound message. In the background, this triggers a read of the modem's buffer. This is used for both incoming TCP data and incoming SMS messages.
Returns the string length of the unread message. If 0 then there's nothing to read, sorry.
void loop() {
if(Hologram.availableMessage() > 0) {
// do something
}
}
Get a stored inbound data or inbound SMS string. This returns the stored String then purges it from memory after reading. That means and subsequent calls will return nothing until a new message is received by the modem.
Returns the message as a String.
void loop() {
String inbound;
if(Hologram.availableMessage() > 0) {
inbound = Hologram.readMessage();
}
}
Checks to see if you're connected or not.
Returns true if connected, false if disconnected.
void loop() {
if(Hologram.cellService()) {
// do something
}
}
Lets you know how good your connection is.
Returns an integer as follows:
void loop() {
switch(Hologram.cellStrength()) {
case 0:
// do something
case 3:
// do something else
}
}
When debug is active anything written to the Serial
is passed to the modem and anything read from the modem will be displayed in the Serial monitor.
void setup() {
Serial.begin(19200);
while(!Serial);
Hologram.debug(); // put debug before begin() to monitor connection initialization
Hologram.begin(19200, 8888);
}
void loop() {
Hologram.debug();
}
String
.