Charge for Routing

Try this example:


import notecard
import serial
port = serial.Serial("COM4", 9600)

card = notecard.OpenSerial(port)

numRecords = 4
dataTemplate =  modem_template = {"seq":11, "pressure":12.1, "runcycles":12, "faults":12, "mode": 11, "temp": 12.1 }
arrayTemplate = [dataTemplate] *numRecords




req = {"req": "note.template","file":"mydata.qo","body":{"data":arrayTemplate}}
rsp = card.Transaction(req)


modem = []
for i in range(0, numRecords):
    cont = {'seq':i, 'pressure':0+i,"pressure":27.3+i, "runcycles":13+i,"faults":19+i,"mode":2+i,"temp":31.2+i}
    data_to_store = {key:cont[key] for key in ['seq','pressure','runcycles','faults','mode','temp']}
    modem.append(data_to_store)



req = {"req": "note.add","file":"mydata.qo","body":{"data":modem}}
rsp = card.Transaction(req)
print(rsp)

You only need to do the note.template request when you set the template the first time, or change the template size.

Templates do require knowing the size before adding the Note to the Notefile.

You could rearrange to do the following, though there is a little overhead in storing the template description, so you may only want to do that when absolutely necessary.


import notecard
import serial
port = serial.Serial("COM4", 9600)

card = notecard.OpenSerial(port)

numRecords = 4 #could be some other integer, but not super large
dataTemplate =  modem_template = {"seq":11, "pressure":12.1, "runcycles":12, "faults":12, "mode": 11, "temp": 12.1 }



modem = []
for i in range(0, numRecords):
    cont = {'seq':i, 'pressure':0+i,"pressure":27.3+i, "runcycles":13+i,"faults":19+i,"mode":2+i,"temp":31.2+i}
    data_to_store = {key:cont[key] for key in ['seq','pressure','runcycles','faults','mode','temp']}
    modem.append(data_to_store)


#reset template size if size is different from last time.
if(numRecords != numRecordsLastTime):
    arrayTemplate = [dataTemplate] *numRecords
    req = {"req": "note.template","file":"mydata.qo","body":{"data":arrayTemplate}}
    rsp = card.Transaction(req)

#add Note body to templated file
req = {"req": "note.add","file":"mydata.qo","body":{"data":modem}}
rsp = card.Transaction(req)
print(rsp)

1 Like

approximately how much data do you save by using the template versus not?

I was able to make my efforts work this morning without a template.

I am saving 40 records inside a single event. I just truncated the fieldnames down to a single character. I will still pursue the template if you think it will save a significant amount of data?

I am having trouble understanding this line.


cont = {'seq':i, 'pressure':0+i,"pressure":27.3+i, "runcycles":13+i,"faults":19+i,"mode":2+i,"temp":31.2+i}

That line is just for simulation of data generation. That way each element had a different values.

Sorry! Should have put a comment in there for you. :slight_smile:

I’m surprised to see this as well. That’s at least 2 order of magnitudes more expensive than before unless I’m missing something?!