Join request to TTN with atmega and sx1276

Dear Users,
I’m trying to build node using atmega328 (16mhz) and SX1276 with my own c code. Based on sx1276 config for lorawan and lorawan 1.0.3 datasheet, I created simple join request function.

(sx1276 frequency is 868,1 MHz, SF9, BW125)

As far as I understand, to send join request I have to send 23 bytes:
MHDR (which is 0 in case of join request),
8 bytes of AppEUI (8 times 0x00),
DevEUI (lsb, 8 bytes, ending with 0xD5, 0xB3, 0x70),
two bytes of random number,
and finally 4 bytes of MIC (MIC[3…0] = aes128_cmac(AppKey, MHDR | AppEUI | DevEUI | DevNonce).

The questions are:

  1. Should I see something in end device live data console?
  2. Is my join request procedure corrent?
  3. Are there any other settings that I should set for sx1276 that are not mentioned in semtech document?
  4. To calculate MHDR | AppEUI | DevEUI | DevNonce can I just
    result[0] = MHDR | AppEUI[0] | DevEUI[0] | (DevNonce & 0xFF)
    result[1] = AppEUI[1] | DevEUI[1] | ((DevNonce>>8) & 0xFF)
    result[n] = AppEUI[n] | DevEUI[n] for n from 2 to 8?

Thanks for any help. I really appreciate it. Have a great day.

What sketch are you using?

LMIC-node is the most simplest and best off the shelf one to use - maybe look at that to get some better idea.

Hi!
I’m not using any sketch or arduino, just plain C code. I know that there is LMIC library, but I want get deeper understanding in LoRa and LoRaWAN by writing my own library.

That’s very commendable and there may be some people on here who can answer the very detailed questions you have but they will be few & far between. It’s not that many of us aren’t aware of the use of AES, the MIC etc, but how it’s all pieced together isn’t required to use it.

There’s no harm in referring to known good implementation like LMIC or the reference one like LoRaMAC-node.

However we would ask that you setup your own TTS OS instance as the community is not keen on having what is effectively a production server for many different community applications used as a test bed. You will then benefit from the local logging as well so you can see what happened at the other end.

I borrowed other SX1276 and Raspberry from school for weekend, so I could do some receiving.

Question 4:
No, this is wrong. Apparently in LoRaWAN datasheet, symbol ‘|’ mean concatenate, not ‘or’ operation.
Do simply:
result[] = {mhdr (0x00), 0x00, ... , 0x00, 0xXX, 0xXX, ... , 0xD5, 0xB3, 0x70, nonce (2 bytes)};

Question 3:
No.

Question 2:
Well yes, but…

Question 1:
While it worked for this hacky single channel gateway, it doesn’t show anything when trying to connect to outside gateway. I tested before if connection is possible to nearest gateway and it worked (using LMIC-arduino library). So still I don’t know.

Apart from Single Channel Packet Forwarders not being supported on TTN as they represent a denial of service to other users and, ironically, the owner, but it will be almost impossible to write your own MAC if you can only communicate over one channel. See Single Channel Packet Forwarders (SCPF) are obsolete and not supported

Which school are you studying at?

I know, but gateway module is way far far out of my budget. I don’t get it, why are they so expensive. Maybe I will try again in the future. Thanks for help.

Same reason every other complicated thing costs money - time, materials, RnD, shipping, retailer margin, shipping etc etc. Bet you buy beer thou!

I have one more small question.

To calculate maximum single rx timeout, I’m using formula in 113 page in datasheet where Timeout = RegSymbTimeout * Ts, where Ts is Ts = 1 / Rs and Rs is Rs = BW / 2^SF

So my Rs for 125kHz and SF7 is 976,5625Hz, Ts is 0.001024sec, max value for RegSymbTimeout is 1024, so my maximum timeout is 1024 * 0,001024sec which is 1.048576 sec. Is that correct?

Thanks :slight_smile: