Announcement

Collapse
No announcement yet.

rpc ack for large loop

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • rpc ack for large loop

    I have a simple logging function in Portal and another simple eeprom reader in a radio. I want to write the entire eeprom to file. I can do this for one rpc but when looped to read the entire eeprom, the radio times out. I had a conversation with Greg and John about using callback() or a hook. There can be no data loss and this func. need only be called once every so often. Thank you for your time.
    Code:
    def readPage(add):
        i2cWrite("\xA0" + add, 1, False)
        page = i2cRead("\xA1", 64, 1, False)
        pageStr = ""
        dataItr = 0
        while (dataItr < 64):
            pageStr += ord(page[dataItr])<<8 + ord(page[dataItr + 1]) + '\n'
            dataItr += 2
        print page
        rpc("\x00\x00\x01", "logToCSV", 'testLog.txt', pageStr)

  • #2
    Here is some Pseudo Code towards what you are trying to accomplish

    BIG NOTE: There are many ways to accomplish your task; this is simply one approach. It uses the ACK sequence to be more sure that you get each piece of data.

    In Portal:

    Code:
    def startReading():
        <<rpc to remote node => "startRead"
        << Start a timer in case you never hear back
        
    def reportData(pgNum, data):
        # This is called by the remote to report the EEPROM data (one pg at a time)
        << Log the data to a file
        << Reset any timers used to track the need for a retry
        << Ask for the next data  => "readNextPg(pgNum + 1)"
        << Start a timer in case you never hear back
        
        
    def reportLastData(pgNum, data):
        # This is called by the remote to report the last page of EEPROM data
        << Log the data to a file
        << Reset any timers used to track the need for a retry
        << Send ACK to remote telling it that you got the last pg => "finalAck"
        << Close the log file
    On the remote node:

    Code:
    def startRead():
        # Called by Portal to start the process
        << Read the first pg from EEPROM
        << RPC resulting data to the Portal address => "reportData(1, data)"
        << Wait for Portal to request the next pg => "readNextPg"
        << Optional: Start a timer that will resend this data if it does not hear an ACK from Portal
        
        
    def readNextPg(pgNum):
        # Called by Portal to read the next pg of EEPROM data
        << Reset any timers used to track the need for a retry
        if more data left in EEPROM:
            << Read EEPROM Pg = pgNum
            if last page in EEPROM:
                  << RPC to Portal telling it you are done = > "reportLastData"
                  << Optional: Wait for Portal to ACK it received the last pg
            else:
                   << RPC resulting data to the Portal address => "reportData"
                   << Wait for Portal to request the next pg
             << Optional: Start a timer that will resend this data if it does not hear an ACK from Portal
        else: # you have read all there is to read
            << Return an error to whom ever asked
            
        
    Optional:
    def finalAck():
        << Reset any timers used to track the need for a retry
    Last edited by Jheath; 05-16-2013, 06:18 PM.
    sigpic
    Proven Solutions for the Internet of Things
    www.synapse-wireless.com

    Comment


    • #3
      The flow would be...

      1) Portal calls the "startRead" function on the remote
      2) The remote returns the first page to Portal
      3) Portal requests the next pg
      4) The remote returns the next page
      5 ) repeat 3 and 4 until it gets to the final pg
      6) The remote returns the final page
      7) Portal ACKs that it got the final page


      Here the request for the next page of data acts as the "ACK" from Portal to the remote. You can run timers on both the remote and Portal in order to resend any data that is not either sent by the the remote or acknowledged by Portal. (probably only need Portal to be the one to re-request data if it doesn't hear back on it's request).
      sigpic
      Proven Solutions for the Internet of Things
      www.synapse-wireless.com

      Comment

      X