Giter Club home page Giter Club logo

lua-lluv-gsmmodem's Introduction

lua-lluv-gsmmodem

Licence Build Status Coverage Status

Usage

  • Open and configure

    local device = GsmModem.new('COM3', {
        baud         = '_9600';
        data_bits    = '_8';
        parity       = 'NONE';
        stop_bits    = '_1';
        flow_control = 'OFF';
        rts          = 'ON';
    })
    device:open(function(self, err, info)
      if err then
        print('Fail open port:', err)
        return self:close()
      end
      print('Connected to port:', info)
      -- Now we should configure modem to allow GsmModem class works properly
      -- (e.g. sms pdu mode, notify mode for sms and calls)
      -- Ofcourse you can use it as-is with out configure.
      self:configure(function(self, err, cmd)
        if err then
          print('Configure error:', err, ' Command:', cmd)
          return self:close()
        end
        print('Configure done')
        -------------------------------------------
        -- Here you can start do your work
        -------------------------------------------
      end)
    end)
  • Send SMS

    device:send_sms('+7777777', 'Hello world', function(self, err, ref)
      print('SMS Send result:', err or 'OK', 'Message reference:', ref or '<NONE>')
    end)
  • Send SMS and wait report

    device:send_sms('+7777777', 'Hello world', {waitReport = 'final'}, function(self, err, ref, response)
      if err or not response.success then
        print('SMS Send fail:', err or response.info, 'Message reference:', ref or '<NONE>')
      else
        print('SMS Send pass', 'Message reference:', ref or '<NONE>')
      end
    end)
  • Send USSD

    device:send_ussd('*100#', function(self, err, msg)
      print('USSD Result:', err, msg and msg:status(), msg and msg:text())
    end)
  • Recv SMS

    device:on('sms::recv', function(self, event, sms)
      print("SMS from:", sms:number(), "Text:", sms:text())
    end)
  • Proceed SMS delivery report

    device:on('report::recv', function(self, event, sms)
      local success, status = sms:delivery_status()
      print("SMS reference:", sms:reference(), "Number:", sms:number(), "Success:", success, "Status:", status.info)
    end)
  • Read SMS

    -- read and delete first SMS from SIM card
    device:read_sms(1, {memory = 'SM', delete = true}, function(self, err, sms)
      print("SMS from:", sms:number(), "Text:", sms:text())
    end)
    
    -- read all unreaded sms from phone memory
    device:each_sms(GsmModem.REC_UNREAD, {memory='ME'}, function(self, err, idx, sms)
      if err and not index then
        -- e.g. invalid memory
        return print("List SMS error:", err)
      end
    
      if err then
        -- Some times device can return invalid sms on list (CMGL), but you can
        -- try read sms directly (CMGR) (e.g. device:read_sms(idx ...)
        -- This is works on my WaveCom SIM300
        return print("Read SMS #" .. idx .. " error:", err)
      end
    
      print("#" .. idx, "SMS from:", sms:number(), "Text:", sms:text())
    end)

lua-lluv-gsmmodem's People

Contributors

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