Expose Pygate events with the forwarder payload



  • 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



  • This post is deleted!


  • @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



  • 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



  • @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.



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


Log in to reply
 

Pycom on Twitter