Time parameter at lora-gateway-bridge metadata

Hello to all!

Although my physical gateway device has the real date and time , at the /rx topic in the mqtt broker i get packets like this {“rxInfo”:{“mac”:“1dee18c14948a955”,“time”:“0001-01-01T00:00:00Z”,“timestamp”:47425548,“frequency”:868300000,“channel”:1,“rfChain”:1,“crcStatus”:1,“codeRate”:“4/5”,“rssi”:-43,“loRaSNR”:11.2,“size”:20,“dataRate”:{“modulation”:“LORA”,“spreadFactor”:9,“bandwidth”:125}},“phyPayload”:“gFY0EjoABAABNbRksF/2R8KBIOE=”}.

How can i configure the time to have the real value?
The lora-gateway-bridge config file hasn’t any parameter for the time.

Any ideas?
Essentially i would like to know the actual time a packet is published in my mqtt broker.

Greetings!

“New” versions of LoRa Packet forwarder don’t set the time unless there is a well configured GPS.

https://forum.loraserver.io/t/http-integration-post-json-data-has-no-time-property/438/8?u=fma

If you want the parameter to be set by the time gateway gets the package you will have to edit LoRaPacket forwarder source code

LoRa packet forwarder source code of my physical gateway?

Or you mean the source code of lora gateway bridge?

Source code of LoRaPacket forwarder

I have an edited packet_forwarder if you need it I can pass it to you and you can compile it and test if it is what you need

I am using my gateway’s packet forwarder and i bind the lora gateways bridge endpoint inside the gateway…should i use this one?
I wilm search for mine and if i cant configure it i will send you pm!

Which gateway are you using?

Normally all gateways use the same lora_packet_forwarder, sometimes is not even modified by the company.

Lorank8v1 from Ideetron

If you want to modify source code just add this line

else {
                // Add system time if we dont have a GPS
                time_t t_local = time(NULL);
                x = gmtime(&t_local);
                buff_index += snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index, ",\"time\":\"%04i-%02i-%02iT%02i:%02i:%02i.0Z\"", (x->tm_year)+1900, (x->tm_mon)+1, x->tm_mday, x->tm_hour, x->tm_min, x->tm_sec); /* ISO 8601 format */
            }

Here:

 /* Packet RX time (GPS based), 37 useful chars */
        if (ref_ok == true) {
            /* convert packet timestamp to UTC absolute time */
            j = lgw_cnt2utc(local_ref, p->count_us, &pkt_utc_time);
            if (j == LGW_GPS_SUCCESS) {
                /* split the UNIX timestamp to its calendar components */
                x = gmtime(&(pkt_utc_time.tv_sec));
                j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buf$
                if (j > 0) {
                    buff_index += j;
                } else {
                    MSG("ERROR: [up] snprintf failed line %u\n", (__LINE__ - $
                    exit(EXIT_FAILURE);
                }
            }
        }

        /* Packet concentrator channel, RF chain & RX frequency, 34-36 useful$
        j = snprintf((char *)(buff_up + buff_index), TX_BUFF_SIZE-buff_index,$
        if (j > 0) {
            buff_index += j;
        } else {
            MSG("ERROR: [up] snprintf failed line %u\n", (__LINE__ - 4));
            exit(EXIT_FAILURE);
        }

My code there is like this

That’s right seems to be the default pkt_fwd, you have to add the else after the “if (ref_ok == true) {}” block

I added the lines of code and i restart the lorank.service but nothing changes.
You can see that despite the fact that the stats topic has the real date and time , my rx topic hasn’t it.
I don’t know what happens! :confused:screen

Check what happens in the bridge MQTT.
I can attach the changes I made here, but you will have to recompile it. Mine is compiled for Multitech Conduit

So you mean that it is a lora gateway bridge cobfiguratiion; should i change its source code?

No.
I changed the packet_forwarder. Did not touch any of the loraserver source code

I didn’t understand your comment about mqtt bridge…you mean the mqtt broker configuration?

The bridge publish everything pkt_fwd sends.

If you don’t see the field “time” there loraserver won’t publish it and you will have to make the changes in the lora_pkt_fwd.

As you can see on the attatched image on a previous comment ,i can see the time field which the bridge publishes on the mqtt broker,the problem is that it is always with a wrong value of the default 0001-01-01T00:00:00Z :frowning:

The problem seems to be the packet forwarder on your gateway.

If you have edited and recompiled the part I told you, you should have it working. Like this:

{“rxInfo”:{“mac”:“00800000a0001c6c”,“time”:“2018-05-14T13:45:08Z”,“timestamp”:3090613196,“frequency”:867900000,“channel”:7,“rfChain”:0,“crcStatus”:1,“codeRate”:“4/5”,“rssi”:-100,“loRaSNR”:9.8,“size”:19,“dataRate”:{“modulation”:“LORA”,“spreadFactor”:7,“bandwidth”:125},“board”:0,“antenna”:0},“phyPayload”:“QALmHwaAWSoBFZ8xhdXrjrDh2g==”}

When i change the script adding your code…i only have to execute a make command in order to be compiled all .C files, Correct?
Or i missunderstand something about the compilation?

You’ll have to run a make and find the new binary. Check if the make show any kind of error