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

    Expose Pygate events with the forwarder payload

    Scheduled Pinned Locked Moved Expansion Board
    pygateevent
    6 Posts 3 Posters 65 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.
    • A Offline
      Alexey Novikov
      last edited by Alexey Novikov

      Hi everyone,

      I'm building a very quick POC that involves Pygate (with WIPY). The goal is to capture the payload (the diagram JSON built by packet forwarder) and provide it to a higher level, so I can access it withing Python environment. This data will be passed over to another hardware component of the POC.

      I can not fully digest the architecture so may miss some essential bits, but here's what's done so far:

      I've added another method to set machine status to include more

      void machine_pygate_set_status_args(machine_pygate_states_t status, void* data) 
      {
          bool trig = false;
          pygate_status = status;
          switch (pygate_status)
          {
          case PYGATE_LORA_PCKT_IN:
              if(machine_obj.trigger & PYGATE_LORA_EVENT)
              {
                  trig = true;
                  machine_obj.events |= PYGATE_LORA_EVENT;
                  machine_obj.handler_arg = data;
              }
              break;
          default:
              break;
          }
          if(trig)
          {
              mp_irq_queue_interrupt(machine_callback_handler, &machine_obj);
          }
      }
      

      and call it once the diagram sent to the server like this:

      machine_pygate_set_status_args(PYGATE_LORA_PCKT_IN, (char *)(buff_up + 12));
      

      I can see the event is triggered if I include it in main.py like this

      elif (evt & machine.PYGATE_LORA_EVT):
              print('LoRa Event\n')
      

      However, I'm not sure how do I access the payload, ie the machine_obj.handler_arg. Might be something trivial, but having very little familiarity with backend architecture doesn't help much.

      Also, is the approach is right or there's a better solution I've overlooked?

      Many thanks in advance!

      P.S. I did omit some details of the firmware code for brevity

      S 1 Reply Last reply Reply Quote 1
      • G Offline
        Gijs
        last edited by

        The Payload is handled and parsed around this line in the sourcecode: https://github.com/pycom/pycom-micropython-sigfox/blob/Dev/esp32/pygate/lora_pkt_fwd/lora_pkt_fwd.c#L1526, which Im not sure how to couple with your function..

        Interesting to see you were able to make the callback work!

        A 1 Reply Last reply Reply Quote 0
        • A Offline
          Alexey Novikov @Gijs
          last edited by

          @Gijs thanks! Do you think I posted in the wrong forum - there are very few views. I'm really after architectural hint as it's not documented anywhere.

          1 Reply Last reply Reply Quote 0
          • G Offline
            Gijs
            last edited by

            The Pygate LoRaWAN stack is very similar to the loranet/packet forwarder repository on github: https://github.com/Lora-net/packet_forwarder/tree/master/lora_pkt_fwd/src. Maybe they can provide you some answers. I sort of have an idea of what you are trying to achieve, but Im not sure how to accomplish it in combination with the micropython layer

            A 1 Reply Last reply Reply Quote 1
            • A Offline
              Alexey Novikov @Gijs
              last edited by

              @Gijs I managed to get the event payload to the higher level, thanks for the hint! I can see the whole diagram sent which is built by the packet forwarder, ie the full PUSH_DATA packet as per Semtech specs.

              Basically, I can do this now:

                  elif (evt & machine.PYGATE_LORA_EVT):
                      print('LoRa Event')
                      print(arg, end='\n')
                      print('\n')
              

              and get normal Python byte string with PUSH_DATA packet in arg

              1 Reply Last reply Reply Quote 2
              • S Offline
                Stefano Floriani @Alexey Novikov
                last edited by Stefano Floriani

                This post is deleted!
                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