TTN does not receive sent data

Hello,

This is my first attempt to work with LORA in generall so i hope i have not missunderstood to many things.

I am using the LMIC library on an ESP32 to send a two byte message to TTN (and from there to the MQTT service). I managed to get the OTA “registration” to work and I can see many received messages in the TTN Console. The problem is, that so far I was not able to get any of my data decoded.

I have configured a payload formatter with the following code:

function decodeUplink(input) {
      return {
        data: {
          "temp": (((input.bytes[0] << 8) | input.bytes[1])-3000 ) / 100,
          "byte0": input.bytes[0],
          "byte1": input.bytes[1]
        },
        warnings: [],
        errors: []
      };
    }

when I put my two hex bytes into the test input, it decodes it in an expected way.

now the problem is that when i send a message via my ESP32 the payload formatter seems to not recieve any data and just displays the following data:

"decoded_payload": {
              "byte0": null,
              "byte1": null,
              "temp": -30
            }

I will also attach the two JSON data “files” as it may allow someone more experienced to see where the problem originates.

{
    "name": "as.up.data.forward",
    "time": "2022-02-04T17:58:51.825417610Z",
    "identifiers": [
      {
        "device_ids": {
          "device_id": "eui-70b3d57ed004bfcd",
          "application_ids": {
            "application_id": "kili-test1"
          }
        }
      },
      {
        "device_ids": {
          "device_id": "eui-70b3d57ed004bfcd",
          "application_ids": {
            "application_id": "kili-test1"
          },
          "dev_eui": "70B3D57ED004BFCD",
          "join_eui": "0000000000000000",
          "dev_addr": "260B5243"
        }
      }
    ],
    "data": {
      "@type": "type.googleapis.com/ttn.lorawan.v3.ApplicationUp",
      "end_device_ids": {
        "device_id": "eui-70b3d57ed004bfcd",
        "application_ids": {
          "application_id": "kili-test1"
        },
        "dev_eui": "70B3D57ED004BFCD",
        "join_eui": "0000000000000000",
        "dev_addr": "260B5243"
      },
      "correlation_ids": [
        "as:up:01FV2Y73NCD6EREBES99E73311",
        "gs:conn:01FTR3WACTZCK2X3C97T1PM4G2",
        "gs:up:host:01FTR3WADQXW9K254990S440FH",
        "gs:uplink:01FV2Y73ES5J6J42MF93ZRJ6N4",
        "ns:uplink:01FV2Y73EVKWB275MZGMMCB8XC",
        "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FV2Y73EVVWNYFKA8Q07X6RTX",
        "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01FV2Y73NB99H1RGCDYXQS0XTT"
      ],
      "received_at": "2022-02-04T17:58:51.822273242Z",
      "uplink_message": {
        "session_key_id": "AX7F02RR2w16RlU5IQUOqQ==",
        "f_port": 1,
        "f_cnt": 30,
        "decoded_payload": {
          "byte0": null,
          "byte1": null,
          "temp": -30
        },
        "rx_metadata": [
          {
            "gateway_ids": {
              "gateway_id": "cless79gw",
              "eui": "AC1F09FFFE046567"
            },
            "time": "2022-02-04T17:58:51.583Z",
            "timestamp": 565002771,
            "rssi": -115,
            "channel_rssi": -115,
            "snr": -2.5,
            "location": {
              "latitude": 48.3031173,
              "longitude": 16.4123684,
              "altitude": 283,
              "source": "SOURCE_REGISTRY"
            },
            "uplink_token": "ChcKFQoJY2xlc3M3OWd3EgisHwn//gRlZxCThLWNAhoMCNvS9Y8GEKHQv6ICILi0qOa4kVMqDAjb0vWPBhDAv/+VAg==",
            "channel_index": 4
          }
        ],
        "settings": {
          "data_rate": {
            "lora": {
              "bandwidth": 125000,
              "spreading_factor": 7
            }
          },
          "coding_rate": "4/5",
          "frequency": "867300000",
          "timestamp": 565002771,
          "time": "2022-02-04T17:58:51.583Z"
        },
        "received_at": "2022-02-04T17:58:51.611239575Z",
        "consumed_airtime": "0.046336s",
        "network_ids": {
          "net_id": "000013",
          "tenant_id": "ttn",
          "cluster_id": "ttn-eu1"
        }
      }
    },
    "correlation_ids": [
      "as:up:01FV2Y73NCD6EREBES99E73311",
      "gs:conn:01FTR3WACTZCK2X3C97T1PM4G2",
      "gs:up:host:01FTR3WADQXW9K254990S440FH",
      "gs:uplink:01FV2Y73ES5J6J42MF93ZRJ6N4",
      "ns:uplink:01FV2Y73EVKWB275MZGMMCB8XC",
      "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FV2Y73EVVWNYFKA8Q07X6RTX",
      "rpc:/ttn.lorawan.v3.NsAs/HandleUplink:01FV2Y73NB99H1RGCDYXQS0XTT"
    ],
    "origin": "ip-10-100-15-123.eu-west-1.compute.internal",
    "context": {
      "tenant-id": "CgN0dG4="
    },
    "visibility": {
      "rights": [
        "RIGHT_APPLICATION_TRAFFIC_READ",
        "RIGHT_APPLICATION_TRAFFIC_READ"
      ]
    },
    "unique_id": "01FV2Y73NHT6T00H078Q7FXA11"
  }
{
  "name": "ns.up.data.process",
  "time": "2022-02-04T17:58:51.819023715Z",
  "identifiers": [
    {
      "device_ids": {
        "device_id": "eui-70b3d57ed004bfcd",
        "application_ids": {
          "application_id": "kili-test1"
        }
      }
    },
    {
      "device_ids": {
        "device_id": "eui-70b3d57ed004bfcd",
        "application_ids": {
          "application_id": "kili-test1"
        },
        "dev_eui": "70B3D57ED004BFCD",
        "join_eui": "0000000000000000",
        "dev_addr": "260B5243"
      }
    }
  ],
  "data": {
    "@type": "type.googleapis.com/ttn.lorawan.v3.UplinkMessage",
    "raw_payload": "QENSCyaAHgABbWp10w==",
    "payload": {
      "m_hdr": {
        "m_type": "UNCONFIRMED_UP"
      },
      "mic": "bWp10w==",
      "mac_payload": {
        "f_hdr": {
          "dev_addr": "260B5243",
          "f_ctrl": {
            "adr": true
          },
          "f_cnt": 30
        },
        "f_port": 1,
        "full_f_cnt": 30
      }
    },
    "settings": {
      "data_rate": {
        "lora": {
          "bandwidth": 125000,
          "spreading_factor": 7
        }
      },
      "coding_rate": "4/5",
      "frequency": "867300000",
      "timestamp": 565002771,
      "time": "2022-02-04T17:58:51.583Z"
    },
    "rx_metadata": [
      {
        "gateway_ids": {
          "gateway_id": "cless79gw",
          "eui": "AC1F09FFFE046567"
        },
        "time": "2022-02-04T17:58:51.583Z",
        "timestamp": 565002771,
        "rssi": -115,
        "channel_rssi": -115,
        "snr": -2.5,
        "location": {
          "latitude": 48.3031173,
          "longitude": 16.4123684,
          "altitude": 283,
          "source": "SOURCE_REGISTRY"
        },
        "uplink_token": "ChcKFQoJY2xlc3M3OWd3EgisHwn//gRlZxCThLWNAhoMCNvS9Y8GEKHQv6ICILi0qOa4kVMqDAjb0vWPBhDAv/+VAg==",
        "channel_index": 4
      }
    ],
    "received_at": "2022-02-04T17:58:51.611239575Z",
    "correlation_ids": [
      "gs:conn:01FTR3WACTZCK2X3C97T1PM4G2",
      "gs:up:host:01FTR3WADQXW9K254990S440FH",
      "gs:uplink:01FV2Y73ES5J6J42MF93ZRJ6N4",
      "ns:uplink:01FV2Y73EVKWB275MZGMMCB8XC",
      "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FV2Y73EVVWNYFKA8Q07X6RTX"
    ],
    "device_channel_index": 4,
    "consumed_airtime": "0.046336s"
  },
  "correlation_ids": [
    "gs:conn:01FTR3WACTZCK2X3C97T1PM4G2",
    "gs:up:host:01FTR3WADQXW9K254990S440FH",
    "gs:uplink:01FV2Y73ES5J6J42MF93ZRJ6N4",
    "ns:uplink:01FV2Y73EVKWB275MZGMMCB8XC",
    "rpc:/ttn.lorawan.v3.GsNs/HandleUplink:01FV2Y73EVVWNYFKA8Q07X6RTX"
  ],
  "origin": "ip-10-100-7-32.eu-west-1.compute.internal",
  "context": {
    "tenant-id": "CgN0dG4="
  },
  "visibility": {
    "rights": [
      "RIGHT_APPLICATION_TRAFFIC_READ",
      "RIGHT_APPLICATION_TRAFFIC_READ"
    ]
  },
  "unique_id": "01FV2Y73NBX6P9CKZMK64Q2N3C"
}

so my question is, does any data arrive at TTN and, if so, where does it get lost?

thank you very much in advance!

Kilian

Your device isn’t actually sending anything - just an empty uplink. There should be a line like:

"frm_payload":"ZGVzY2FydGVz",

beside the port and count info. See Data Formats | The Things Stack for LoRaWAN for a full package.

Thank you very much for the quick reply.

As TTN is correctly identifying my uplink I would assume it is safe to say that hardware is not an issue?

As for the sketch, I am using a only slightly modified version of the MCCI LMIC Example for OTAA with TTN.

#include <lmic.h>
#include <hal/hal.h>
#include <SPI.h>

#include <OneWire.h> //for DS18B20
#include <DallasTemperature.h> //for DS18B20
#define ONE_WIRE_BUS 13 // Data wire of DS18B20 is plugged into GPIO 13 on the esp



//
// For normal use, we require that you edit the sketch to replace FILLMEIN
// with values assigned by the TTN console. However, for regression tests,
// we want to be able to compile these scripts. The regression tests define
// COMPILE_REGRESSION_TEST, and in that case we define FILLMEIN to a non-
// working but innocuous value.
//
#ifdef COMPILE_REGRESSION_TEST
# define FILLMEIN 0
#else
# warning "You must replace the values marked FILLMEIN with real values from the TTN control panel!"
# define FILLMEIN //(#dont edit this, edit the lines that use FILLMEIN)
#endif

// This EUI must be in little-endian format, so least-significant-byte
// first. When copying an EUI from ttnctl output, this means to reverse
// the bytes. For TTN issued EUIs the last bytes should be 0xD5, 0xB3,
// 0x70.
static const u1_t PROGMEM APPEUI[8]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
void os_getArtEui (u1_t* buf) { memcpy_P(buf, APPEUI, 8);}

// This should also be in little endian format, see above.
static const u1_t PROGMEM DEVEUI[8]={ 0x.., 0x.., 0x.., 0x.., 0x7E, 0x.., 0xB3, 0x70 };
void os_getDevEui (u1_t* buf) { memcpy_P(buf, DEVEUI, 8);}

// This key should be in big endian format (or, since it is not really a
// number but a block of memory, endianness does not really apply). In
// practice, a key taken from ttnctl can be copied as-is.
static const u1_t PROGMEM APPKEY[16] = { 0xE3, 0x0E, 0x3A, 0x77, 0x.., 0x.., 0x.., 0x.., 0x.., 0x.., 0x.., 0x.., 0x.., 0x.., 0x3B, 0x8C };
void os_getDevKey (u1_t* buf) {  memcpy_P(buf, APPKEY, 16);}

static uint8_t mydata[] = {0x12, 0x34};
static osjob_t sendjob;

// Schedule TX every this many seconds (might become longer due to duty
// cycle limitations).
const unsigned TX_INTERVAL = 120;

// Pin mapping
const lmic_pinmap lmic_pins = {
    .nss = 5,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = 17,
    .dio = {16, 2, 4},
};

void printHex2(unsigned v) {
    v &= 0xff;
    if (v < 16)
        Serial.print('0');
    Serial.print(v, HEX);
}

void onEvent (ev_t ev) {
    Serial.print(os_getTime());
    Serial.print(": ");
    switch(ev) {
        case EV_SCAN_TIMEOUT:
            Serial.println(F("EV_SCAN_TIMEOUT"));
            break;
        case EV_BEACON_FOUND:
            Serial.println(F("EV_BEACON_FOUND"));
            break;
        case EV_BEACON_MISSED:
            Serial.println(F("EV_BEACON_MISSED"));
            break;
        case EV_BEACON_TRACKED:
            Serial.println(F("EV_BEACON_TRACKED"));
            break;
        case EV_JOINING:
            Serial.println(F("EV_JOINING"));
            break;
        case EV_JOINED:
            Serial.println(F("EV_JOINED"));
            {
              u4_t netid = 0;
              devaddr_t devaddr = 0;
              u1_t nwkKey[16];
              u1_t artKey[16];
              LMIC_getSessionKeys(&netid, &devaddr, nwkKey, artKey);
              Serial.print("netid: ");
              Serial.println(netid, DEC);
              Serial.print("devaddr: ");
              Serial.println(devaddr, HEX);
              Serial.print("AppSKey: ");
              for (size_t i=0; i<sizeof(artKey); ++i) {
                if (i != 0)
                  Serial.print("-");
                printHex2(artKey[i]);
              }
              Serial.println("");
              Serial.print("NwkSKey: ");
              for (size_t i=0; i<sizeof(nwkKey); ++i) {
                      if (i != 0)
                              Serial.print("-");
                      printHex2(nwkKey[i]);
              }
              Serial.println();
            }
            // Disable link check validation (automatically enabled
            // during join, but because slow data rates change max TX
	    // size, we don't use it in this example.
            LMIC_setLinkCheckMode(0);
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_RFU1:
        ||     Serial.println(F("EV_RFU1"));
        ||     break;
        */
        case EV_JOIN_FAILED:
            Serial.println(F("EV_JOIN_FAILED"));
            break;
        case EV_REJOIN_FAILED:
            Serial.println(F("EV_REJOIN_FAILED"));
            break;
        case EV_TXCOMPLETE:
            Serial.println(F("EV_TXCOMPLETE (includes waiting for RX windows)"));
            if (LMIC.txrxFlags & TXRX_ACK)
              Serial.println(F("Received ack"));
            if (LMIC.dataLen) {
              Serial.print(F("Received "));
              Serial.print(LMIC.dataLen);
              Serial.println(F(" bytes of payload"));
            }
            // Schedule next transmission
            os_setTimedCallback(&sendjob, os_getTime()+sec2osticks(TX_INTERVAL), do_send);
            break;
        case EV_LOST_TSYNC:
            Serial.println(F("EV_LOST_TSYNC"));
            break;
        case EV_RESET:
            Serial.println(F("EV_RESET"));
            break;
        case EV_RXCOMPLETE:
            // data received in ping slot
            Serial.println(F("EV_RXCOMPLETE"));
            break;
        case EV_LINK_DEAD:
            Serial.println(F("EV_LINK_DEAD"));
            break;
        case EV_LINK_ALIVE:
            Serial.println(F("EV_LINK_ALIVE"));
            break;
        /*
        || This event is defined but not used in the code. No
        || point in wasting codespace on it.
        ||
        || case EV_SCAN_FOUND:
        ||    Serial.println(F("EV_SCAN_FOUND"));
        ||    break;
        */
        case EV_TXSTART:
            Serial.println(F("EV_TXSTART"));
            break;
        case EV_TXCANCELED:
            Serial.println(F("EV_TXCANCELED"));
            break;
        case EV_RXSTART:
            /* do not print anything -- it wrecks timing */
            break;
        case EV_JOIN_TXCOMPLETE:
            Serial.println(F("EV_JOIN_TXCOMPLETE: no JoinAccept"));
            break;

        default:
            Serial.print(F("Unknown event: "));
            Serial.println((unsigned) ev);
            break;
    }
}

void do_send(osjob_t* j){
    // Check if there is not a current TX/RX job running
    if (LMIC.opmode & OP_TXRXPEND) {
        Serial.println(F("OP_TXRXPEND, not sending"));
    } else {
        // Prepare upstream data transmission at the next possible time.
        LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);
        Serial.println(F("Packet queued"));
    }
    // Next TX is scheduled after TX_COMPLETE event.
}

void setup() {
    Serial.begin(9600);

    Serial.println(F("Starting"));

    //#############get Temp##############
    OneWire oneWire(ONE_WIRE_BUS); // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)    
    DallasTemperature sensors(&oneWire); // Pass our oneWire reference to Dallas Temperature. 
    sensors.begin(); // start Library for DS18B20
    
    sensors.requestTemperatures(); // Send the command to get temperatures
    float tempC = sensors.getTempCByIndex(0);// We use the function ByIndex, and as an example get the temperature from the first sensor only.
    uint16_t temp100 = ((int) (tempC * 100)) + 3000; //first multiply by 100 to get two decimal places into the int. then add 3000 to offset it by 30 degreeC so that a Value of zero is -30C 

    temp100 = 4242;
    
    mydata[0] = highByte(temp100);
    mydata[1] = lowByte(temp100);

    Serial.println(tempC);
    Serial.println(temp100);
    
    Serial.print(F("kili data: "));
    Serial.print(mydata[0], BIN);
    Serial.println(mydata[1], BIN);

    Serial.print("sizeofdata: ");
    Serial.println(sizeof(mydata));
    //#############get Temp##############
    

    // LMIC init
    os_init();
    // Reset the MAC state. Session and pending data transfers will be discarded.
    LMIC_reset();

    // Start job (sending automatically starts OTAA too)
    do_send(&sendjob);
}

void loop() {
    os_runloop_once();
}

I tried taking the sensor out of the equation and hardcoding a value, but this didn’t change anything.

I can’t seem to find the culprit, even the print output is as expected.

I hope it is not too much to ask if anyone could have a quick look at the code and maybe give me a pointer on what could cause this empty uplink

Thanks

Compare your Serial print of the Sizeof mydata against the very silly example provided that started life out as a string so removing the 0x00 end of string terminator made sense but as no one ever should send text, the whole premise is borked in the do_send:

LMIC_setTxData2(1, mydata, sizeof(mydata)-1, 0);

Effectively it’s sending one byte and I suspect that’s maybe causing the LMIC some issues to boot.

If you can remove the -1 that would be cool.

If that doesn’t work, please revert to the “example” provided as it does work, even if it has issues. Then we can build from there.

But until we get a frm_payload appearing, not worth doing anything else.

Thank you that did the trick!

I was confused by the -1 but thought that there must have been a reason. Now with your explanation it makes perfect sense.

1 Like

There is a plan to update the LMIC repro to solve some of these issues, I just need to find a ‘spare’ weekend to enact it!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.