Coder Social home page Coder Social logo

jruipinto / modemjs Goto Github PK

View Code? Open in Web Editor NEW
11.0 1.0 3.0 471 KB

ModemJS is a node.js module that helps you send SMS, via serialport, with a GSM Modem.

Home Page: https://jruipinto.github.io/modemjs/

License: Apache License 2.0

TypeScript 100.00%
modem gsm-modems sms serialport typescript phones android-phones nodejs node-module

modemjs's Introduction

Logo

Modem.js

NPM package to simplify sending and receiving SMS with a GSM Modem on Node.js over serialport.

Check the documentation site to learn more.

(PS: Modem.js and its respective documentation is still under active development until mids of January 2020)

Introduction

Modem.js born from the need of a node.js library that would help me abstract the communication with a GSM Modem to handle the sending and reception of SMS.

Before starting the development of this package I searched NPM (node package manager) and didn't find any package simple enough that would fit my needs so I got to work and Modem.js born.

This package is tested with an android phone as GSM Modem (Samsung GT-S6312 with android version: 4.1.2) but other Modems or android phones may work, very likely.

Later, I may test Modem.js with other phones / gsm modems and make a list of supported / tested equipments (you may contribute too ๐Ÿ˜).

Skills needed

Prerequisites

Mandatory
  • NodeJS v12+ installed (earlier versions may work but weren't tested)
  • GSM Modem connected to serialport (it may be a virtual com port, instead of the old RS232, you know... ๐Ÿ˜)

(PS: You may check supported environments here)

Optional
  • Typescript v3+ (earlier versions may work but weren't tested)
  • VSCode

(Typescript + VSCode will help you understand and implement the Modem.js library more easily)

Quickstart

quickstart docs

Install

npm i modemjs

Usage

Example of minimal code to receive and send SMS with your node app / bot ๐Ÿค–

// this example app is actually tested by me. So it MUST work if 
//  you use a valid phone number as recipient and the same gsm modem as me


// import { Modem } from 'modemjs'; // if you use typescript with nodejs
const Modem = require('modemjs').Modem; // if you prefer to use the standard nodejs' style javascript

const modem = new Modem({
    port: 'COM10', // change this 
    baudRate: 230400, // change this
    initCommands: [
        '\u241bAT', 'AT+CMGF=1', 'AT+CNMI=1,1,0,1,0',
        'AT+CNMI=2', 'AT+CSMP=49,167,0,0', 'AT+CPMS=\"SM\",\"SM\",\"SM\"'
    ],
    msPause: 10000
});
// this config is necessary but will be simplified soon, in the next updates of modem.js
// PS: the msPause of 10000ms is recommended by now to avoid
//  missed delivery reports but are free to try smaller periods

modem.onReceivedSMS().subscribe(sms => console.log('SMS Received:', sms));
// this observable will log every SMS that your modem receives

modem.sendSMS({ phoneNumber: 910000000, text: 'Hi! I\'m a robot!' })
    .subscribe(data => console.log('Message delivered! Here is the report:', data));
// this funtion will send 'Hi! I\'m a robot!' to '910000000' as a text message / SMS and when
//  the message gets delivered to the recipient, the delivery report will be logged

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.