# Charge for Routing

**URL:** <https://discuss.blues.com/t/charge-for-routing/285>\
**Category:** Notehub.io\
**Created:** [June 3, 2021, 3:56pm UTC](https://discuss.blues.com/t/charge-for-routing/285 "2021-06-03T15:56:23Z")\
**Posts on this page:** 4\
**Page:** 2

<div class="post-metadata">

**Author:** ![gwolff](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@gwolff](https://discuss.blues.com/u/gwolff)\
**Post date:** [June 7, 2021, 4:36pm UTC](https://discuss.blues.com/t/charge-for-routing/285/21 "2021-06-07T16:36:16Z")

</div>

Try this example:

```auto

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.

```auto

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)

```

---

<div class="post-metadata">

**Author:** ![vstadmin](https://avatars.discourse-cdn.com/v4/letter/v/439d5e/32.png) [@vstadmin](https://discuss.blues.com/u/vstadmin)\
**Post date:** [June 8, 2021, 12:50pm UTC](https://discuss.blues.com/t/charge-for-routing/285/22 "2021-06-08T12:50:45Z")

</div>

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.

```auto

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

```

---

<div class="post-metadata">

**Author:** ![gwolff](https://avatars.discourse-cdn.com/v4/letter/g/a88e57/32.png) [@gwolff](https://discuss.blues.com/u/gwolff)\
**Post date:** [June 9, 2021, 12:37am UTC](https://discuss.blues.com/t/charge-for-routing/285/23 "2021-06-09T00:37:48Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![ptbkt](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.blues.com/ptbkt/32/181_2.png) [@ptbkt](https://discuss.blues.com/u/ptbkt)\
**Post date:** [June 9, 2021, 6:08pm UTC](https://discuss.blues.com/t/charge-for-routing/285/24 "2021-06-09T18:08:01Z")

</div>

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?!

[Previous page](https://discuss.blues.com/t/charge-for-routing/285.md?page=1)
