Arduino Pro Mini + Lmic+OTAA with Multi Channel Gateway

(Somsak) #1

My gateway seems to work fine with ABP but when I try with OTAA on my gateway console displays

My Sketch serial output :
403: engineUpdate, opmode=0x808
Packet queued
1453: engineUpdate, opmode=0xc
15698: engineUpdate, opmode=0xc
16310: TXMODE, freq=923600000, len=23, SF=12, BW=125, CR=4/5, IH=0
423012: RXMODE_SINGLE, freq=923600000, SF=12, BW=125, CR=4/5, IH=0
483208: RXMODE_SINGLE, freq=923200000, SF=10, BW=125, CR=4/5, IH=0
485698: engineUpdate, opmode=0xc

But nothing shows on Frames up number.
I cannot find the solution or where the problem came from.

(Somsak) #2

After forget to unplug the node for an hour, I found that it start to join and display EV_TXCOMPLETE.

100894170: EV_JOINED
100894236: engineUpdate, opmode=0x808
100895202: TXMODE, freq=923200000, len=26, SF=12, BW=125, CR=4/5, IH=0
101060622: RXMODE_SINGLE, freq=923200000, SF=12, BW=125, CR=4/5, IH=0
101120817: RXMODE_SINGLE, freq=923200000, SF=10, BW=125, CR=4/5, IH=0
101399743: EV_TXCOMPLETE (includes waiting for RX windows)
101399846: engineUpdate, opmode=0x800
105149848: engineUpdate, opmode=0x808
105150812: TXMODE, freq=922200000, len=26, SF=12, BW=125, CR=4/5, IH=0
Packet queued
105317513: RXMODE_SINGLE, freq=922200000, SF=12, BW=125, CR=4/5, IH=0
105377710: RXMODE_SINGLE, freq=923200000, SF=10, BW=125, CR=4/5, IH=0
105643267: EV_TXCOMPLETE (includes waiting for RX windows)
105643368: engineUpdate, opmode=0x800
109393370: engineUpdate, opmode=0x808

Checking the payload data and it is "Hello, world!". So, it is now working ok.


Cool, are you also using an RF95 with the mini?

(Jezd) #4

whats your sketch code look like?

(Arjan) #5

Probably unrelated to the Join problems, but your DevEUI DDDDDDDD... does not seem to be a proper EUI. From the specifications, emphasis mine:

6.2.1 End-device identifier (DevEUI)

The DevEUI is a global end-device ID in IEEE EUI64 address space that uniquely identifies the end-device.

If your device does not provide a proper EUI then better let TTN Console generate one for you.

That said, the screenshot of your gateway shows that TTN sent a Join Accept to the gateway, so somehow either the gateway was not transmitting that, or the node did not receive it. Make sure there are at least a few meters between node and gateway. And for LMiC, search this forum for MAX_CLOCK_ERROR.

(Also, I guess you know you should not send text.)

(Somsak) #6

Yes, I am using RFM95W. Thank for the Kicad files from douglarue.

(Somsak) #7

I used the sketch generator at . Hope he will add more sensors in the future.

Thank for pointing me to look back again about DevEUI. Now, I find the way to let TTN generate it for me. First, I thought there wasn't auto gen. I also found the problem why my script did not join in the first attempt. The gateway freq is AS1 while my node is AS2. My friend modified LMIC and changed name to AS923_Upper that I thought it is AS2. In fact, it is AS1 freq. When I set to the right freq, it can join in a few seconds.

Changing a text message to a Hex string will take me some time because I am not a real programmer. I might ask someone around here to help me.

(Arjan) #8

The examples in the sketch generator already send sensor data in a proper way. Like when selecting "Moisture, Temp and Light" then you'll see:

void build_data() {
  dataTX[0] = (light << 4) | (tempK / 256);
  dataTX[1] = tempK;
  dataTX[2] = moisture / 256;
  dataTX[3] = moisture;

This sends a total of 4 bytes (32 bits) for 3 sensors:

  • 4 bits for light in a scale from 0 to 15 (hexadecimal 0x0 - 0xF)
  • 12 bits for temperature in Kelvin with one decimal, in a scale from 0.0 to 409.5 (0x000 - 0xFFF)
  • 16 bits for moisture in a scale from 0 to 65535 (0x0000 - 0xFFFF)

If you'd send that as human-readable text, you'd need many more bytes (like 14 characters, so 14 bytes, when sending separated with semi-colons as 15;409.5;65535, or 0x31353B3430392E353B3635353335 when displayed as hexadecimal ).

It even explains how to decode:

/* **************************************************************
 * build data to transmit in dataTX
 * Suggested payload function for this data
 *  var light = (bytes[0] & 0xF0) >> 4;
 *  var temp = (((bytes[0] & 0x0F) <<8 | bytes[1]) - 2731) / 10;
 *  var moisture = bytes[2] << 8 | bytes[3];
 *  return { payload: light + ";" + temp + ";" + moisture };
 * *************************************************************/

...which you could use to decode and then return the values any way you want:

function Decoder(bytes, port) {

    // Test with 0A470000 for 0, -10, 0, or FB78FFFF for 15, 20.5, 65535
    var light = (bytes[0] & 0xF0) >> 4;
    var temp = (((bytes[0] & 0x0F) << 8 | bytes[1]) - 2731) / 10;
    var moisture = bytes[2] << 8 | bytes[3];
    return {
        light: light,
        celcius: temp,
        // Unary plus-operator to cast string result of toFixed to a number:
        fahrenheit: +(32 + 1.8 * temp).toFixed(1),
        moisture: moisture

What is the maximum number of characters I can send with LMiC?
(Somsak) #9


Thank. It makes my life a lot easier. First glance on those lines in my sketch, I don't know what they are for.

(Arjan) #10


(Danielpardede) #11

Recently I facing this problem too and realized it’s all AS1 freq, could you tell me more about your modified LMIC for AS2 freq support?

(Somsak) #12

The gateway must listen on the right frequency exact as your node sends. Check on your gateway first, I use Raspberry PI with RAK831. I choose one of global_conf.json from and replace the original file in my RPI .

For my node, I changed freq in this file lorabase.h (LMIC library.)

(Danielpardede) #13

Thanks @Somsak, now GW and nodes completely in synced.:smiley:

but there is a thing still bugging me out, how to deal with 500Khz_UPFBASE/UPFSTEP and DNFBASE/DNFSTEP for AS2 in lorabase.h file?

// Default frequency plan for US 915MHz   
enum { US915_125kHz_UPFBASE = 902300000,
   US915_125kHz_UPFSTEP =    200000,
   US915_500kHz_UPFBASE = 903000000,
   US915_500kHz_UPFSTEP =   1600000,
   US915_500kHz_DNFBASE = 923300000,
   US915_500kHz_DNFSTEP =    600000 };

(Arjan) #14

It’s the other way around.

A gateway will be listening continuously, and on multiple frequencies and spreading factors. A node, however, must listen at the exact same time as the gateway transmits, and using the exact same frequency and spreading factor. (RX1, and RX2 if nothing was received in RX1, both using a specific frequency and spreading factor as defined in the given frequency plan.)

(Somsak) #15

Thank @arjanvanb for making it clear.
@danielpardede In fact, I did not modify lorabase.h by myself.
There is an example on Look at “arduino-lmic-as923
Added AS923 code into LMIC”. It might answer what you try to ask.


(Danielpardede) #16

thanks @arjanvanb @Somsak , it is clear now.

(Rhinoteknl) #17

Hi i am also using Arduino Pro Mini +Lmic(otaa) by node is working and serial monitors show
message queued
and noting else, may there is no Gateway nearby also my console device status is “not seen”
and data uplink bytes.

What is this problem?? please help


like you wrote … ’ maybe there is no Gateway nearby

(Rhinoteknl) #19

so i must have my own gateway???


if you want to be 100% sure to connect to The Things Network… yes.
even if there is a GW nearby (and there is one… see map in your console) it’s not sure that it receives your nodes signal.
and the owner can switch it on/off whenever he wants.

see also