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:
- All modules from SIM800 family
- All modules from SIM900 family
- Seeed Studio GPRS Shield
A Hologram account and SIM Card is required to use this library.
- None
- Download the latest version of the library from https://github.com/hologram-io/Hologram-SIMCOM/releases and save the file somewhere
- In the Arduino IDE, go to the Sketch -> Import Library -> Add Library... menu option
- Find and select the zip file you saved in the first step.
- If successfully added you should now see Hologram SIMCOM listed among available libraries under Sketch -> Import.
- Activate a SIM card through Hologram's new device form.
- Under that device's details, go to Configuration tab and generate Router Credentials, copy the Device Key.
- (I will soon provide an example sketch adapted to Hardware Serial)
- In your sketch define the Device Key we got from the Router Credentials modal.
- Connect the TX, RX, & Reset pins.
- Upload sketch to your Arduino, open the Serial Monitor and watch the magic happen.
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. You must pass a reference to the hardware serial port you will to use.
#include <HologramSIMCOM.h>
#define RESET_PIN 10
#define HOLO_KEY "********"
HologramSIMCOM Hologram(&Serial, 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()
.
- baud - int : What baud do you want your module to run at?
19200
is typical for SIMCOM modules. - port - int : Optionally, If you want to receive inbound messages you'll need to specify a server port.
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.
- data - char*/String : String or char* to be sent to the cloud
- topic - char*/String : Optionally, Hologram allows you to publish data to a topic(s).
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.
- phoneNumber - char*/String : Destination phone number. Must be in international format (ex. U.S.: +1, France: +33, etc)
- message - char*/String : Text message to be sent.
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:
- 0 No signal
- 1 Very poor signal strength
- 2 Poor signal strength
- 3 Good signal strength
- 4 Very good signal strength
- 5 Excellent signal strength
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();
}
- Problem with reading SMS messages, probably an overflow caused by using strings
- Eliminate usage of Strings & this should optimize memory usage, want it to fit into an Attiny device.