Sms sample digi to digi

From Digi Developer

Jump to: navigation, search

SMS Sample showing Digi Python sending and receiving messages

Using these building blocks you can create simple poll-response systems. One of the nice things about SMS is it allows sleeping systems, where the messaging system buffers messages on your behalf.

Sending Messages

This script sends a block of messages to remote SMS peers, which may be other Digi devices.

import digisms
import time
 
addresses = ["15551234567", "15551234568"]
num_messages = 10
 
for address in addresses:
  for i in xrange(num_messages):
    cur_time = time.strftime("%a, %d %b %Y %H:%M:%S", time.gmtime())
    msg = "%s: Message %s" % (cur_time, i)
    digisms.send(address, msg)
    time.sleep( 1.0)

Receiving Messages

This script sleeps forever, display any SMS messages received. Note that is this script exits, the callback might go out of scope and message receipt stops.

import digisms
import time
 
def ping_callback(a):
  print """\
 
Message from: %s
at: %s
====================
%s
====================
""" % (a.source_addr, a.timestamp, a.message)
 
h = digisms.Callback(ping_callback)
 
while( True):
    print '.'
    time.sleep( 15.0)
Personal tools
Wiki Editing