Time parameter at lora-gateway-bridge metadata


#1

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!


#2

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

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


#3

LoRa packet forwarder source code of my physical gateway?

Or you mean the source code of lora gateway bridge?


#4

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


#5

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!


#6

Which gateway are you using?

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


#7

Lorank8v1 from Ideetron


#8

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:


#10
 /* 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


#11

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


#12

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


#13

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


#14

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


#15

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


#16

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


#17

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.


#18

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:


#19

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==”}


#20

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?


#21

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