Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    Lopy & Pytrack sending data by Lora KPN network

    Scheduled Pinned Locked Moved LoPy
    loralopy
    9 Posts 3 Posters 1.6k Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      han
      last edited by

      Hello everybody,

      I am using a Lopy in combination with a Pytrack.
      I want to send the data from the accelerometer by the KPN to mij cloud.

      But that do not work!

      First if I start up the module and upload the code there pops up a error message.
      It looks like this:
      File "main.py", line 66, in <module>
      FIle "/flash/lib/L76GNSS.py", line 56, in coordinates
      MemoryError: memory allocation failed, allocating 4009 bytes

      After a few times startup the module it will sometimes go to work, mostly not.
      But if it works then it sens one package with data over the KPN network.
      If I write a code with static data like "A1, B2, C3" there is no problem but when I want to send data from the accelerometer id doesn`t work.

      Does somebody know how I can solve both problems?

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @han
        last edited by livius

        @han
        are you sure that you have most recent version of files?
        https://github.com/pycom/pycom-libraries/blob/master/pytrack/lib/L76GNSS.py
        Especially with this commit for L76GNSS.py
        https://github.com/pycom/pycom-libraries/pull/43/files

        think about people first, then computers

        H 1 Reply Last reply Reply Quote 0
        • H Offline
          han @livius
          last edited by

          @livius It looks like I have the newest version of the L76GNSS library

          1 Reply Last reply Reply Quote 0
          • H Offline
            han
            last edited by

            Is it possible that my message is to big?

            Now i am using this part
            for i in range (200):
            mqData = {}
            mqData["data"] = {}
            mqData["data"]["mov"] = {}
            mqData["data"]["mov"]["acc"] = {}
            accTuple = li.acceleration()
            mqData["data"]["mov"]["acc"]["x"] = accTuple[0]
            mqData["data"]["mov"]["acc"]["y"] = accTuple[1]
            mqData["data"]["mov"]["acc"]["z"] = accTuple[2]
            mqData["data"]["mov"]["rol"] = li.roll()
            mqData["data"]["mov"]["pit"] = li.pitch()
            mqData["data"]["loc"] = {}
            locTuple = l76.coordinates()
            time.sleep(0.5)
            mqData["data"]["loc"]["lat"] = locTuple[0]
            mqData["data"]["loc"]["lon"] = locTuple[1]
            enc = ujson.dumps(mqData)

            L C 2 Replies Last reply Reply Quote 0
            • L Offline
              livius @han
              last edited by livius

              @han
              200 * something maybe it is too big...

              but above error message point to line 56 which is brake line.
              Go to device by ftp and look like file looks like - maybe it is not synchronized properly..

              think about people first, then computers

              1 Reply Last reply Reply Quote 0
              • C Offline
                crumble @han
                last edited by crumble

                @han said in Lopy & Pytrack sending data by Lora KPN network:

                your LoPy has around 30KByte of free RAM *). Your loop creates a lot of objects, so the 30KB are filled and fragmented very fast. Call gc.collect() at the start of the loop and before enc. this may help.

                There will be two other solutions.

                1. Building the json string manualy will use less memory/fragmentation
                2. Buying a LoPy 4 with plenty of RAM

                *) Sometimes the LoPy has up to 60KB free. But if you calculate with this number, your program will crash when the LoPy has only 30KB free RAM after reboot.

                H 1 Reply Last reply Reply Quote 0
                • H Offline
                  han @crumble
                  last edited by

                  @crumble thanks for tip help.
                  I am pretty new with Micropython. Where is de exactly place where I should place the gc.collect()?

                  gc.collect()
                  for i in range (200):
                  mqData = {}

                  mqData["data"]["loc"]["lat"] = locTuple[0]
                  mqData["data"]["loc"]["lon"] = locTuple[1]
                  enc = ujson.dumps(mqData)

                  s.send(enc)
                  gc.collect()?

                  C 1 Reply Last reply Reply Quote 0
                  • C Offline
                    crumble @han
                    last edited by

                    @han said in Lopy & Pytrack sending data by Lora KPN network:

                    Where you set the empty list, you free a lot of memory. place the collect() after this statement:

                    for i in range (200):
                        mqData = {}
                        gc.collect()
                        #don't know if you have to wait for the gc at this point
                        mqData["data"]["loc"]["lat"] = locTuple[0]
                        mqData["data"]["loc"]["lon"] = locTuple[1]
                        enc = ujson.dumps(mqData)
                        gc.collect()
                        s.send(enc)
                    #end of loop
                    

                    a second good place may be between the json encoding and the send, so you clean up the json part which may have created a lot of temporary objects.

                    If this will not help, build the json string by your own. This may not be as convenient as the dump of the data structure, but it will have a much less memory footprint. If this is still too much, you have to preallocate a buffer as early as possible and override only the variable part in it. This will be really unconvenient but it will do the trick. If you do not need json on the receiving machine, you can send the data in a binary format.

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      han
                      last edited by

                      Hello everybody,
                      I have tested the Lopy with the gc.collect function. It isn`t giving a error message anymore!
                      Thanks for the help.

                      1 Reply Last reply Reply Quote 0

                      Hello! It looks like you're interested in this conversation, but you don't have an account yet.

                      Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

                      With your input, this post could be even better 💗

                      Register Login
                      • 1 / 1
                      • First post
                        Last post

                      Pycom on Twitter

                      Pycom