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

    Strategy for LoRaWAN with deepsleep 2

    Scheduled Pinned Locked Moved LoPy
    deepsleepjoinwake up
    34 Posts 9 Posters 12.5k Views 12 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.
    • _ Offline
      _peter @Camot
      last edited by

      @Camot That's exactly what I meant. Normally who uses the lopy in lorawan should use these escamotage? I do not think it's possible to use it in the right way. Or miss me something?

      T 1 Reply Last reply Reply Quote 0
      • T Offline
        Thosch42 @_peter
        last edited by

        @_peter While I was planning a board with the OEM LoPy, I run into the same problem. Currently I think about a small I2C NVRAM to save DevAddr and keys. I think there's no other way. Possibly something similar could be implemented in a future release of the Expansionboard.

        Cheers,
        Thomas

        _ 1 Reply Last reply Reply Quote 0
        • _ Offline
          _peter @Thosch42
          last edited by

          @Thosch42 What you think seems to me very clever. This means, however, that it is not possible to have full functionality with the supplied hardware now. In your opinion, what can be the best compromise at this time?

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

            @_peter said in Strategy for LoRaWAN with deepsleep 2:

            I do not have an sd card in my project

            but you have internal flash where you can write files same as into SD card.

            think about people first, then computers

            T 1 Reply Last reply Reply Quote 0
            • T Offline
              Thosch42 @livius
              last edited by

              @livius Yes, that's right. But it depends a little bit on how often the keys change. I need to reed the datasheets and specs. It would be not very clever to stress the internal flash and kill the module slowly.

              Cheers,
              Thomas

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

                @Thosch42 said in Strategy for LoRaWAN with deepsleep 2:

                It would be not very clever to stress the internal flash and kill the module slowly.

                Yes, as i say before it is not recommended way - but you must test how offten you need to write.
                But why not SD card? It is really cheap and small :)

                think about people first, then computers

                J 1 Reply Last reply Reply Quote 0
                • J Offline
                  jmarcelino @livius
                  last edited by

                  SD cards tend to consume a godawful amount of power so they're not a good pairing for generally very power efficient LoRa stuff :-)

                  I wouldn't worry too much about flash wear, by the time you've killed the flash by writing sequence numbers a new Py with proper deepsleep (and more importantly RTC NVRAM preservation) will be out :)

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

                    @jmarcelino
                    one fet for control power of SD card start it read value and deinit and "close fet" :) same for write :)
                    I think the same as you here:

                    I wouldn't worry too much about flash wear

                    think about people first, then computers

                    1 Reply Last reply Reply Quote 0
                    • papasmurphP Offline
                      papasmurph @_peter
                      last edited by papasmurph

                      @_peter My experience: I tried testing for whether it had already joined, but that flag doesn't seem to be set until you attempt and succeed to join, indicating it's always "unjoined" (?) after a deep sleep, so it wouldn't have helped to save state. The service I connect to doesn't mind though.

                      E 1 Reply Last reply Reply Quote 0
                      • E Offline
                        Eric24 @papasmurph
                        last edited by

                        @papasmurph It seems that the issue is not so much about whether it's possible to re-join, but the additional "on time" and radio power budget required to do so. Ideally, a LoRaWAN device should join very infrequently, sleep most of the time, and minimize its "on time" and radio usage (i.e. no re-joining) as much as possible. And that's not only a battery-life issue, but can also become a duty-cycle or simply system capacity issue at scale.

                        Ultimately, I think storing the information needed to wake-up and transmit without re-joining is a necessity (especially for battery-powered devices). How that information is stored is another matter (the RTC NVRAM would be ideal, as soon as it's supported). But the question your comment brings up is what to do about the "joined" flag? If it's always necessary to re-join after deep sleep, that would be a significant issue. Has anyone else been able to "force" a joined state after deep sleep?

                        J 1 Reply Last reply Reply Quote 0
                        • J Offline
                          jmarcelino @Eric24
                          last edited by jmarcelino

                          @Eric24
                          That's not possible yet because you have to tell the LoRa stack: "here reuse these keys I stored somewhere to connect" and that's not possible yet. Of course all the source code is out there so if anyone wants to have a go don't let me stop you. That's a functionality me and I'm sure many others will need for larger deployments so, even if Pycom doesn't get around to doing it, it'll come at some point.

                          The other problem - but that's more an issue with LoRa and similar protocols - is it's not possible to know if the keys generated for an OTAA session are still valid without actually getting a response from the network, something you get for "free" with a fresh join. So always doing a join is safer. It's a balancing act.

                          E 2 Replies Last reply Reply Quote 0
                          • E Offline
                            Eric24 @jmarcelino
                            last edited by

                            @jmarcelino Right--ability to set keys will be needed. Regarding not knowing if they keys are valid, just thinking out loud...if you have some knowledge (or control) of the server behavior, you could know how long until the keys expire; let's say they last for 24 hours; given that, maybe the device (using the RTC) transmits without re-join for up to 23 hours (or so) and then re-joins on the next interval. Any flaw in that logic? Of course my objective here is to maximize battery life, and for a device that reports every 5 minutes, all that re-joining will add up.

                            J 1 Reply Last reply Reply Quote 0
                            • J Offline
                              jmarcelino @Eric24
                              last edited by

                              @Eric24 ]
                              If you have some control of the network some good advice I've heard - but not implemented personally yet - is to forget OTAA, run ADP with frame counters relaxed and implement your own authentication system using for example a crypto chip like the ATECC508A

                              E 2 Replies Last reply Reply Quote 0
                              • E Offline
                                Eric24 @jmarcelino
                                last edited by

                                @jmarcelino Hmmm. I suppose so, if you have control of the network (although some would argue that this would be less secure). But I was also thinking about public networks where you don't have control, but could have specific knowledge of key lifetimes. Of course there's no technical problem with re-joining on every transmission, but it's definitely not optimal. It makes me wonder if a lot of LoRaWAN implementations are actually doing just that, because it's easier to implement?

                                papasmurphP 1 Reply Last reply Reply Quote 0
                                • papasmurphP Offline
                                  papasmurph @Eric24
                                  last edited by papasmurph

                                  Anyone knows what approach thingamagogs like this use? I guess ABP and pre-generated random keys, but I didn't find any details: http://ecubelabs.com/integrated-waste-management/ultrasonic-fill-level-sensor/

                                  1 Reply Last reply Reply Quote 0
                                  • E Offline
                                    Eric24 @jmarcelino
                                    last edited by

                                    @jmarcelino Question about the ATECC508A that you mentioned (as it relates to LoRaWAN, not "my own" authentication system): Does it support AES-128? I can't find any mention of anything other than AES-256, which makes it useless for working with LoRaWAN keys, etc. I was looking at the ATAES132A for this purpose. Any experience or thoughts on this?

                                    1 Reply Last reply Reply Quote 0
                                    • E Offline
                                      Eric24 @jmarcelino
                                      last edited by

                                      @jmarcelino I did some additional research on the topic of expiring keys, and based on this post at TTN (https://www.thethingsnetwork.org/forum/t/otaa-node-sleep-mode/5188/7) and a review of the LoRaWAN specs, it appears that the server will never expire the keys after a join (the node can re-join if it wants new keys or if the message counter rolls over or is about to roll over). Although I have found mentions of session key expiration, so at least that concept is "out there". Do you have specific experience with networks/servers that expire the OTAA session keys?

                                      Bottom line, if the keys aren't expired by the server, then the idea of reusing the keys without re-joining is pretty straightforward (pending the ability to "set" the keys from some non-volatile memory).

                                      J 1 Reply Last reply Reply Quote 0
                                      • J Offline
                                        jmarcelino @Eric24
                                        last edited by jmarcelino

                                        @Eric24
                                        Well TTN not long ago 'expired' all OTAA keys when they moved servers to production, the expectation was that OTAA nodes would pick up the new keys automatically. From what I understand this expectation is still in place at TTN and other networks.

                                        Also keep in mind there is a valid window for LoRaWAN frame counters - maxFCntGap = 16384 in the TTN source - for example if a node sends 16384 packets that for some reason (out of range, gateway down..) don't get picked up by TTN there will be a mismatch and TTN won't accept further data from the node - so you may want to reset those counters occasionally via rejoin.

                                        E 1 Reply Last reply Reply Quote 0
                                        • E Offline
                                          Eric24 @jmarcelino
                                          last edited by

                                          @jmarcelino OK, that's reasonable. I see that as an exception case rather than normal operation. Also, the basic idea is to increase battery life and minimize airtime usage, so even if I rejoined every 10 message intervals, that's still a 10X reduction of "join overhead". The "right" interval of re-joins will be up to the application, of course, but it's hopefully somewhat less frequently than "every time" and much more than "once". I wonder if TTN (and other networks) generally provide a way for the application to know that a message was received from a known device with invalid keys?

                                          1 Reply Last reply Reply Quote 1
                                          • _ Offline
                                            _peter @Camot
                                            last edited by jmarcelino

                                            @Camot
                                            I tried with relaxed frame counter in ABP mode but it does not work. Send the data once and then nothing.
                                            Below the code on lopy:

                                            from network import LoRa
                                            import socket
                                            import binascii
                                            import struct
                                            
                                            # Initialize LoRa in LORAWAN mode.
                                            lora = LoRa(mode=LoRa.LORAWAN)
                                            
                                            # create an ABP authentication params
                                            dev_addr = struct.unpack(">l", binascii.unhexlify('07 11 7d e5'.replace(' ','')))[0]
                                            nwk_swkey = binascii.unhexlify('1b a9 32 60 6e e0 9d 0d 41 6a 51 af 98 6e ec 5b'.replace(' ',''))
                                            app_swkey = binascii.unhexlify('9a 28 99 2c 03 79 78 2a 3d 93 f5 c6 df b4 af e4'.replace(' ',''))
                                            
                                            # join a network using ABP (Activation By Personalization)
                                            lora.join(activation=LoRa.ABP, auth=(dev_addr, nwk_swkey, app_swkey))
                                            
                                            # create a LoRa socket
                                            s = socket.socket(socket.AF_LORA, socket.SOCK_RAW)
                                            
                                            # set the LoRaWAN data rate
                                            s.setsockopt(socket.SOL_LORA, socket.SO_DR, 5)
                                            
                                            # make the socket blocking
                                            # (waits for the data to be sent and for the 2 receive windows to expire)
                                            s.setblocking(True)
                                            print('send')
                                            # send some data
                                            s.send(bytes([0x01, 0x02, 0x03]))
                                            
                                            # make the socket non-blocking
                                            # (because if there's no data received it will block forever...)
                                            s.setblocking(False)
                                            
                                            # get any data received (if any...)
                                            data = s.recv(64)
                                            print(data)
                                            machine.deepsleep(60000)
                                            
                                            J 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
                                            • 2
                                            • 2 / 2
                                            • First post
                                              Last post

                                            Pycom on Twitter

                                            Pycom