Giter Site home page Giter Site logo

c-9u11 / hologram-simcom Goto Github PK

View Code? Open in Web Editor NEW

This project forked from hologrameducation/hologram-simcom

0.0 0.0 0.0 49 KB

Easily use any SIMCOM cellular module with Hologram's cloud.

Home Page: https://hologram.io

License: MIT License

C++ 100.00%

hologram-simcom's Introduction

Hologram SIMCOM Arduino Helper Library

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.

Dependencies

  • None

Installation

  1. Download the latest version of the library from https://github.com/hologram-io/Hologram-SIMCOM/releases and save the file somewhere
  2. In the Arduino IDE, go to the Sketch -> Import Library -> Add Library... menu option
  3. Find and select the zip file you saved in the first step.
  4. If successfully added you should now see Hologram SIMCOM listed among available libraries under Sketch -> Import.

Getting Started

  1. Activate a SIM card through Hologram's new device form.
  2. Under that device's details, go to Configuration tab and generate Router Credentials, copy the Device Key.
  3. (I will soon provide an example sketch adapted to Hardware Serial)
  4. In your sketch define the Device Key we got from the Router Credentials modal.
  5. Connect the TX, RX, & Reset pins.
  6. Upload sketch to your Arduino, open the Serial Monitor and watch the magic happen.

Reference

HologramSIMCOM Hologram(&Serial,reset,key)

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

.begin(baud, port)

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().

Parameters

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

Return

Returns a boolean depending if it successfully connected or not.

Example

void setup() {
    // connect to the network and start listening for incoming data
    Hologram.begin(19200, 8888);
}

.send(data, topic)

Send data to the Hologram cloud where you can manipulate and route it to multiple cloud providers.

Parameters

  • 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).

Return

Returns a boolean whether send was successful or not.

Example

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

.sendSMS(phoneNumber, message)

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.

Parameters

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

Return

Returns a boolean whether send was successful or not.

Example

void loop() {
    Hologram.sendSMS("+13125554444", "Hello World");
}

.availableMessage()

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.

Return

Returns the string length of the unread message. If 0 then there's nothing to read, sorry.

Example

void loop() {
    if(Hologram.availableMessage() > 0) {
        // do something
    }
}

.readMessage()

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.

Return

Returns the message as a String.

Example

void loop() {
    String inbound;
    
    if(Hologram.availableMessage() > 0) {
        inbound = Hologram.readMessage();
    }
}

.cellService()

Checks to see if you're connected or not.

Return

Returns true if connected, false if disconnected.

Example

void loop() {
    if(Hologram.cellService()) {
        // do something
    }
}

.cellStrength()

Lets you know how good your connection is.

Return

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

Example

void loop() {
    switch(Hologram.cellStrength()) {
        case 0:
            // do something
        case 3:
            // do something else
    }
}

.debug()

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.

Example

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

Issues

  • Problem with reading SMS messages, probably an overflow caused by using strings

Future Goals

  • Eliminate usage of Strings & this should optimize memory usage, want it to fit into an Attiny device.

hologram-simcom's People

Contributors

benstr avatar coollick avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.