Exemple #1
0
def get_message(config=None,modem=None,log=None): 
    """
    Take messages off of the modem
    """
    try:
        gsmMsg = modem.next_message()   
        if gsmMsg:
            msg = Message(
                uuid=str(uuid.uuid4()),
                sent=False,
                dest=int(config.get("app","number")),
                source="gsm",
                time=datetime.datetime.now(),
                text=gsmMsg.text,
                origin=int(gsmMsg.sender))
            msg.add_state("received-gsm") 
            log.info("Got msg<%s> from modem" % msg.uuid)            
            remote.send_message(config,msg,log)
    except GsmReadError:
        log.error("Error talking to modem skipping and trying again.")
Exemple #2
0
def send_local_messages(config=None,modem=None,log=None): 
    """
    Sends to remote a local cache of messages
    """
    unsentMsgs = Message.selectBy(sent=False,source="gsm") 
    if unsentMsgs.count() > 0: 
        log.info("Unsent messages %s" % unsentMsgs.count())
        for msg in unsentMsgs:
            send_message(
                config=config,
                log=log,
                msg=msg)
Exemple #3
0
def send_local_messages(config=None,modem=None,log=None):
    """
    Query database to find message that need to be sent via
    the modem.
    """
    unsentMsgs = Message.selectBy(sent=False,source="http")
    if unsentMsgs.count() > 0:
        log.info("Unsent messages %s" % unsentMsgs.count())
        for msg in unsentMsgs:
            send_message(
                modem=modem,
                log=log,
                msg=msg)