# Updating a python File on a raspberry pi via notecard

**URL:** <https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199>\
**Category:** Notecard API\
**Created:** [April 7, 2021, 1:39am UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199 "2021-04-07T01:39:22Z")\
**Posts on this page:** 17\
**Page:** 3

<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 14, 2021, 3:21pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/42 "2021-06-14T15:21:00Z")

</div>

I should point out that I am printing just about every response from the device now for diagnostics. so the responses might look different than you expect.

---

<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 14, 2021, 3:44pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/43 "2021-06-14T15:44:23Z")

</div>

Looking into it this morning.

---

<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 14, 2021, 5:03pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/44 "2021-06-14T17:03:31Z")

</div>

If the http address of the route proxy configured in Notehub is not returning JSON, then you will see this error message.

That is, if you set the address to “[google.com](http://google.com)” or something similar. Please confirm the route in the Notehub project is pointing to an web address that will return JSON.

---

<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 14, 2021, 5:16pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/45 "2021-06-14T17:16:43Z")

</div>

The program on the other endpoint of that IP address is the fileServerApp.py program from last week. I configured it the best I could, but im sure I did something wrong.

---

<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 14, 2021, 5:18pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/46 "2021-06-14T17:18:06Z")

</div>

I just updated the route definition in your Notehub project to be appended with “/download”

which was the configuration for the example web server I sent you.

Testing now

---

<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 14, 2021, 6:23pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/47 "2021-06-14T18:23:17Z")

</div>

So Close.

I was running on a copy of our actual file and got this after a while.

```auto
'total_chunks': 246}, 'result': 200}

Requesting chunk 186 of 246

Step 2: {'body': {'chunk_num': 186, 'crc32': 2752505538, 'payload': 'b250PSgnSGVsdmV0aWNhIDI0Jyksa2V5PSdTdWJtaXQnKSwgc2cuQnV0dG9uKCcwJyxzaXplPSg0LDApLGZvbnQ9KCdIZWx2ZXRpY2EgMjQnKSksIHNnLkJ1dHRvbignQ2xyJyxzaXplPSg0LDApLGZvbnQ9KCdIZWx2ZXRpY2EgMjQnKSxrZXk9J0NsZWFyJyldLAogICAgICAgICAgICAgIFtzZy5UZXh0KHNpemU9KDE1LCAxKSwgZm9udD0oJ0hlbHZldGljYScsIDE4KSwgdGV4dF9jb2xvcj0ncmVkJywga2V5PSdvdXQnKV1dCgogICAgd2luZA==', 'total_chunks': 246}, 'result': 200}

Requesting chunk 187 of 246

Step 2: {'err': 'cannot allocate 2668 bytes {memory}'}
Step 2: {'err': 'cannot allocate 2668 bytes {memory}'}
Step 2: {'err': 'cannot allocate 2668 bytes {memory}'}
Step 2: {'err': 'cannot allocate 2668 bytes {memory}'}
Step 2: {'err': 'cannot allocate 2668 bytes {memory}'}
Step 2: {'err': 'cannot allocate 2668 by

```

Up until then, it was working great! The file in question is 61,407 bytes

---

<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 14, 2021, 6:26pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/48 "2021-06-14T18:26:22Z")

</div>

Checking on this now

---

<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 14, 2021, 6:50pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/49 "2021-06-14T18:50:01Z")

</div>

I’m able to reproduce. Let me see what we can do

---

<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 14, 2021, 6:52pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/50 "2021-06-14T18:52:45Z")

</div>

ok.

from what I saw on the server:

```auto
35.172.219.169 - - [14/Jun/2021 18:49:10] "GET /download?file=test.py&chunk=157 HTTP/1.1" 200 -./../assets/test.py
35.172.219.169 - - [14/Jun/2021 18:49:10] "GET /download?file=test.py&chunk=158 HTTP/1.1" 200 -./../assets/test.py
35.172.219.169 - - [14/Jun/2021 18:49:13] "GET /download?file=test.py&chunk=159 HTTP/1.1" 200 -./../assets/test.py
35.172.219.169 - - [14/Jun/2021 18:49:13] "GET /download?file=test.py&chunk=160 HTTP/1.1" 200 -./../assets/test.py
35.172.219.169 - - [14/Jun/2021 18:49:14] "GET /download?file=test.py&chunk=161 HTTP/1.1" 200 -/../assets/test.py
35.172.219.169 - - [14/Jun/2021 18:49:15] "GET /download?file=test.py&chunk=1 HTTP/1.1" 200 -./../assets/test.py
35.172.219.169 - - [14/Jun/2021 18:49:15] "GET /download?file=test.py&chunk=163 HTTP/1.1" 200 -./../assets/test.py
35.172.219.169 - - [14/Jun/2021 18:49:16] "GET /download?file=test.py&chunk=164 HTTP/1.1" 200

```

After Chunk 161, it momentarily went back to 1 and then back to 163.

---

<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 14, 2021, 9:33pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/51 "2021-06-14T21:33:54Z")

</div>

There does appear to be a memory leak in the `web.get` request.  
Our development team is trying to fix it now, but I’m not sure we’ll be able to get you an update before tomorrow morning.

I would say for now, a Notecard restart after a web request (or several web requests) should clear it out. Not ideal, but will get you moving forward.

```json
{"req":"card.restart"}

```

Once the Notecard comes back up, you can continue to issue requests. In general, this isn’t going to lose data. Though it will result in a new connection to the cell network.

I realize this isn’t a fantastic workaround. Given the time constraints, I don’t think we can get you a firmware update in time.

---

<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 21, 2021, 1:52pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/52 "2021-06-21T13:52:17Z")

</div>

@gwolff Thanks for all your help last week. I have moved forward and when I designate a file, it sends, receives, and translates correctly. I even added a progress bar to the code.

Now, I’m having trouble with the notifying.

How can I send you a zipped file\_notifier.py and get\_update.py? I would drop them in here but they have valid productIDs and sessionIDs and I wanted to leave them in to illustrate that that part is working properly.

It seems to arm the ATTN pin and recognizes that ATTN was fired, but I get the following from printing the req and rsp from that transaction:

```auto
Connecting to Notecard...
Configuring Product: com.xxxxxxx.yyyyyy:zzzzzzz..
Configuring ATTN...
ATTN Fired, checking inbound message...
{'req': 'note.get', 'file': 'file-update.qi', 'delete': True}
{'err': 'no notes available in queue {note-noexist}'}
Rearming ATTN...

```

The dashboard shows:

`file-update.qi	{"name":"test3.py","size":61407}`

So I know the note is there and it gets triggered, but somehow its not seeing something correctly.

Thanks

---

<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 21, 2021, 2:29pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/53 "2021-06-21T14:29:01Z")

</div>

I can take a look at this, but I may not get to it before tomorrow.

It’s possible the ATTN pin is firing for a reason other than the “file-update.qi” having a new Note added from the cloud.

The error message you are seeing is expected if no new Notes are available in the Notefile.

If I remember correctly, the ATTN pin in the example application may also be triggered on a timeout (though I would need to double check on that)

After the ATTN pin is triggered, I recommend issuing a

{“req”:“card.attn”}

request. The response will contain information about why the ATTN was triggered. If it was because of a new Note in “file-update.qi”, then that will be listed in the response to the “card.attn” request above.

---

<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 21, 2021, 2:42pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/54 "2021-06-21T14:42:36Z")

</div>

How do I send you a zip of my current files?

---

<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 21, 2021, 4:07pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/55 "2021-06-21T16:07:22Z")

</div>

Hi Todd,

You can send me a private message on the forum and attach a ZIP. Or you can email it to [support@blues.com](mailto:support@blues.com).

Let me know if you have any issues.

Cheers!

---

<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 21, 2021, 7:00pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/56 "2021-06-21T19:00:41Z")

</div>

Greg,

I switched out

from gpiozero import InputDevice

for

import RPi.GPIO as GPIO

and I am getting more expected results now. I think the gpiozero code might not have been picking the pin up properly.

one thing I am noticing though, the routine is not clearing out old notes from the queue like I would expect.

The following code makes me think it is supposed to be deleting the notification after it reads it:

```auto
def get_updated_file_info(card=nc):
  req = {"req": "note.get"}
  req["file"] = notification_file
  req["delete"] = True

  print(req)
  rsp = card.Transaction(req)

  print(rsp)

  if "err" in rsp:
    return None
  else:
    return rsp["body"]

```

But often if I go into assets and change the name of the file and run the file\_notify.py, it will add a new note with the new filename, but I will notice the old one is still out there and when I run the get\_update.py, it will often (not always) reload the old file.

---

<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 21, 2021, 7:41pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/57 "2021-06-21T19:41:32Z")

</div>

Which file it selects Might have have something to do with timing. I was interrupted and came back after 30 minutes and subsequent tests started downloading the newest file

---

<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 22, 2021, 12:19pm UTC](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199/58 "2021-06-22T12:19:05Z")

</div>

@gwolff Still having problems with the ATTN pin firing. Seems to be firing continually the way I have it written.

I switched from gpiozero to RPi.GPIO:

```auto
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
attn_pin = 6
GPIO.setup(attn_pin, GPIO.IN)

defaultProductUID = 'com.xxxxx.ayyyy:zzzzzz'

port = I2C("/dev/i2c-1")

nc = notecard.OpenI2C(port, 0, 0, debug=False)
notification_file = "file-update.qi"

```

But it seems that when I query the pin, later in the main loop, it’s always high, even when nothing should have triggered it.

`if (GPIO.input(attn_pin) == 1) and (timer() - ten_second_timer > 10):`

[Previous page](https://discuss.blues.com/t/updating-a-python-file-on-a-raspberry-pi-via-notecard/199.md?page=2)
