예제 #1
0
from datetime import datetime

modem = pygsm.GsmModem(port="/dev/ttyUSB1", baudrate=115200)

print "loaded modem"

while True:
    # check for new messages
    msg = modem.next_message()
    
    while msg:
        print msg
	i = Incoming()
        i.message = msg.text
        i.date_queued = datetime.now()
        i.date_sent = None
        i.sender = msg.sender
        i.save()
        
	
        #import code; code.interact(local=locals())
        
    # get all the data the incoming messages that haven't been sent to the ec2

    
        
    #url_file = urllib2.urlopen("http://haiti.opensgi.net/mednet/api/0.1/rest/outsms/")
    #json = url_file.read()
    #obj = simplejson.loads(json)
    #print obj
    #if Outgoing.objects.filter(
예제 #2
0
            try:
                pygsm_msg = modem.next_message()
            except serial.serialutil.SerialException, e:
                # Raise these and crash the program. Something external
                # should restart it.
                print str(e)
                raise serial.serialutil.SerialException(e)
    
            if(pygsm_msg == None):
                # No messages are available. break.
                break

            msg = Incoming()
            msg.sender = pygsm_msg.sender    # string, sending phone number
            msg.message = pygsm_msg.text     # string, actual message
            msg.date_sent = pygsm_msg.sent   # datetime object, reported by modem
            msg.date_queued = datetime.now()
            #pygsm_msg.device    # string, device that received the SMS
            msg.save()

        # If there are incoming messages to be pushed (i.e. POST) to the EC2
        # instance, identify those messages from the incoming queue, pickle them
        # urlencode (NOT to json), and POST (with mime-type as JSON).  Yeah, this
        # last part is weird.

        #### POST incoming SMS to EC2 ####
        print "Posting incoming messages to EC2"

        incoming_msgs = Incoming.objects.filter(receipt=None)
        
        print "incoming_msgs = %s" % str(incoming_msgs)