Arduino LMIC library updated


#12

I have checked your question/assumption about the counters and OTAA. If I restart the LMIC code (a port to RaspberryPi) while using OTAA, the device gets new keys (as can be seen in the ttnctl devices info DEVEUI output) and the counters are reset to 0.
So no need to store the counters with OTAA.


(Arjan) #13

You mean the counters in the TTN backend? (I knew they are reset in the node; I just didn't check if they are reset in the TTN backend too. But indeed, I agree with matthijs that they should be reset in the backend as well; if not then that would be a bug.)


#14

They are reset correctly in the TTN backend.


#15

@matthijs: I just joined a Ideetron Nexus with OTAA using your library without much trouble (once I figured out which bits go where, reversed or not), so that seems to be working (in case you didn't know yet).

Had to DISABLE_PING and/or DISABLE_BEACONS to fit it in the Nexus.

And getting non-zero FCntUp in ttnctl devices info :grinning:

Edit: downlink works, too!

Edit2: after a while I get EV_LINK_DEAD, followed by EV_REJOIN_FAILED (SF increments each time this happens), but everything keeps working, FCntUp increments, EV_TXCOMPLETEs, and uplink messages keep showing up in mqtt.


(Matthijs Kooijman) #16

@melvin, cool, I hadn't actually tested OTAA so far.

I also have a Nexus lying around here, waiting for a testrun. Could you share the the pin map from your sketch so I can include it as an example for the Nexus?

I suspect that using OTAA pulls in additional code from the LMIC library, pushing the flash size over the limit. If we replace the AES implementation (which is waiting for a license change), then more space should become available (see https://www.thethingsnetwork.org/forum/t/lmic-1-51-fitting-in-arduino-atmega-328/1239/13?u=matthijs)

Not sure what happens there, perhaps ACKs aren't being sent by TTN, which makes LMIC think the link is dead? I can't remember if the staging backend already supports ACKs.


(Hylke Visser) #17

Yes, the backend supports ACKs, but apparently we're sending them on the wrong port, see this issue on github.


#18

Sure.

const lmic_pinmap lmic_pins = {
    .nss = 10,
    .rxtx = LMIC_UNUSED_PIN,
    .rst = LMIC_UNUSED_PIN, // hardwired to AtMega RESET
    .dio = {4, 5, 7},
};

Want to get started with NEXUS, don't know were to begin
#19

Has anyone been able to get this running using https://github.com/sudar/Arduino-Makefile? It works for me in the Arduino IDE, but not as soon as I use the arduino-mk - I added the CFLAGS_STD = -std=c99 setting, but no difference.


#20

@joscha : if I remember correctly, I had to add teensy31.build.flags.c=-std=gnu99 in boards.txt to each type of teensy; because it was empty.
probably that helps


#21

I changed some code to store the counter values in EEPROM memory so it will survive resets. In the Arduino sketch, I added (sorry, I don't know how to format it properly):

// Source: https://arduino.stackexchange.com/questions/9349/possible-to-store-variables-directly-in-eeprom
// MACRO : Combines FROM_BYTES into TO_OBJECT of datatype "DATATYPE"
#define CombineBytes(FROM_BYTES, DATATYPE, TO_OBJECT) \
TO_OBJECT = *((DATATYPE *)FROM_BYTES);

// MACRO : Splits FROM_DATA of DATATYPE into equivalent byte array TO_BYTES
#define GetBytes(FROM_DATA, DATATYPE, TO_BYTES) \
*((DATATYPE *)TO_BYTES) = FROM_DATA;

// Writes Integer's equivalent bytes to Address and Address + 1
void EEPROM_Write_Int(unsigned int Address, int Data)
{
// Get the size of datatype to write number of bytes
const byte SizeOf_DataType = sizeof(int);

// Create tem buffer to get Bytes of Datatype
byte Temp_Buffer[SizeOf_DataType];

// Call macro to store byte array into Temp_Buffer from Data
GetBytes(Data, int, Temp_Buffer);

// Write number of bytes to memory location specified in Address and so on
for(byte Index = 0; Index < SizeOf_DataType; Index++)
{
EEPROM.write(Address + Index, Temp_Buffer[Index]);
}
}

// Reads two bytes from Address and Address + 1 and returns equivalent int
int EEPROM_Read_Int(unsigned int Address)
{
// Get the size of datatype to write number of bytes
const byte SizeOf_DataType = sizeof(int);

// Create tem buffer to get Bytes of Datatype
byte Temp_Buffer[SizeOf_DataType];

int Result;

// Read number of bytes from memory location
for(byte Index = 0; Index < SizeOf_DataType; Index++)
{
Temp_Buffer[Index] = EEPROM.read(Address + Index);
}

// Call macro to combine bytes into equivalent to int
CombineBytes(Temp_Buffer, int, Result);

return Result;
}

int counter = EEPROM_Read_Int(0);

Then in the do_send() function add:
EEPROM_Write_Int(0,++counter);

and in setup() at the end add:
//Set the counter from memory
LMIC.seqnoUp=counter;

Maybe someone could improve on the code, it's my first quick and dirty programming steps for Arduino.


Where in LMiC is the "fCnt" parameter stored?
Big ESP32 + SX127x topic part 2
#22

maybe you can use an EEPROM I2C memory module
- http://www.ebay.com/itm/New-AT24C256-I2C-interface-EEPROM-Memory-Module-for-arduino-/191149165917?hash=item2c8160cd5d:g:H7YAAOSwe7BWw-xK

or a combined I2C RTC/memory module
- http://www.ebay.com/itm/Arduino-Tiny-RTC-I2C-Module-24C32-Memory-DS1307-Clock-/281012402441?hash=item416da4f909:g:My0AAOSwDk5T4d~Y

or even a single chip
- http://www.hobbytronics.co.uk/arduino-external-eeprom


(ANders) #23

I'm running the ttn example from the LMIC library on a arduino UNO. I am using a Semtech SX1276mb1mas board and a level converter between the arudino and the semtech board. But when trying uploading the ttn example to the arduino i get the following in the serial monitor:

Starting
FAILURE C:\Users***\Documents\Arduino\libraries\IBM_LMIC_framework\src\lmic\radio.c:657

I have the right pin mapping, and have set the library to SX1276 in the config.h file. What can be the problem? Thank you in regards!


(Matthijs Kooijman) #24

What does it say on that line with your library version? What version of LMIC are you running?

I suspect the failure happens at this line:

   ASSERT(v == 0x12 );

Where it checks if the transceiver responds with the correct hardware version. This either means that the transceiver is incorrect, or the SPI connection is not working properly. You should probably check your wiring, and perhaps lower the SPI speed (see this pull request: https://github.com/matthijskooijman/arduino-lmic/pull/27).


(ANders) #25

Thanks for the answer, it is very appreciated!
The command is:
u1_t v = readReg(RegVersion);

Im using LMIC 1.5. Where can I find the SPI settings? There is nothing in the config.h file. And also, should i use the ICSP header or pin 11, 12 and 13 on the UNO for SPI?
The chip is a SX1276 in a SX1276MB1MAS shield.


(Matthijs Kooijman) #26

Are you sure? It's a failed assertion, so I would expect the error line to actually contain an ASSERT.

Did you look at the pullrequest I linked?

They're connected to the same pins on the Uno, so it doesn't matter.


(ANders) #27

I looked at the forum but i cant find the function for setting the spi speed. In the forum it ia described as the function should be in config.h


#28

@akoen
It is mentioned in https://github.com/matthijskooijman/arduino-lmic/pull/27 , so for the moment you can change hal/hall.cpp


(Matthijs Kooijman) #29

Right, seems you're not aware of what a pull request is. It's not a forum, it's a proposal to change the LMIC library, along with comments about that change. On the page, there is a link to the "commits", the actual proposed changes. Here's one that should show you where to look for the SPI settings: https://github.com/matthijskooijman/arduino-lmic/pull/27/commits/b413c8ddf8bfb730c74a06abf5a3e71f4c99494a


#30

Just for others encountering same problem. There probably is an SPI connection not correct.

      I'm running the ttn example from the LMIC library on a

arduino UNO. I am using a Semtech SX1276mb1mas board and a level
converter between the arudino and the semtech board. But when trying
uploading the ttn example to the arduino i get the following in the
serial monitor:

Starting
FAILURE C:\Users***\Documents\Arduino\libraries\IBM_LMIC_framework\src\lmic\radio.c:657

I have the right pin mapping, and have set the library to SX1276 in
the config.h file. What can be the problem? Thank you in regards!

I know (from experience :smile: ) that you will get this error for example when NSS on SX1276 (.nss in sketch and pin 10 on Arduino) is not connected right.

Maarten


#31

To follow up on the EV_DEAD event that people get; you get this event on OTAA nodes mostly. This is because a lot of sketches set the linkCheckMode off for LMIC in the setup() function.

When using OTAA you have to set check mode off after receiving the EV_JOINED event in the event handler.


case EV_JOINED:
// Disable link check validation
LMIC_setLinkCheckMode(0);
...
...
break;

@matthijs maybe you can update your example on github.

Maarten