Arduino LMIC library updated


#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


(Matthijs Kooijman) #32

I was planning to do so already, just haven't found the time so far. I originally made the same mistake, and only later discovered that link checking is re-enabled during the join.


#33

@matthijs hi.. i am try to used inair4 which runnning 433Mhz. I cant find this freq supported in the library. Pls enlighten me if it is possible. Thank you


(Matthijs Kooijman) #34

I think this is not supported by the library as it is now, unfortunately.


(Matthijs Kooijman) #35

I just pushed a big update to the lmic library.
* All changes that used to live in the experimental "mjs" branch are now cleaned up and merged into master. This adds an OTAA example, replaces the default AES implementation by something that's smaller and adds compensation for clock drift (manually configured using LMIC_setClockError() from the sketch).
* I've merged most of the pullrequests that were submitted, except for two that need some more thought and/or testing. This improves 915Mhz, adds proper parsing of the RX2 datarate from the join accept (no further need to set LMIC.dn2Dr when using OTAA), fixes the DevStatusAns MAC response and improves compatibility with the ESP platform.
* I added some more bugfixes to the OTAA code that could cause OTAA, or the first packet after a join, to take a lot longer than it should. I also added some debug output to the library (enabled by LMIC_DEBUG_LEVEL in config.h, don't forget to also set LMIC_PRINTF_TO.

Thanks to all the people that contributed patches or suggestions. My apologies for not merging things sooner, but it's great to see so much great quality contributions here!

In other news, @Thomas and myself have been in contact with Marcus Oestreicher, one of the developers of LMIC at IBM. IBM is no longer working on the LMIC code, so the plan is to move the "upstream" LMIC development (as opposed to my arduino-specific port of it) to github as well, maintained by (initially) Marcus, Thomas and myself. All non-Arduino-specific changes in my repository should be merged back to that repository. This should allow other (non-Arduino) users of the library to profit from our work, and vice versa.

On my request, IBM has also agreed to change the license on their code to the three-clause BSD license instead of the Eclipse Public License that was used before. This should make it possible to combine the LMIC library with GPL code or other licenses (including propietary code). I hope this will make LMIC a viable option for more people and projects. A direct gain of this is that the AES libraries that I considered to integrate are now no longer blocked by the license, so we'll likely integrate AVR-AES as well. The license change has been approved internally, and as soon as I've reviewed the proposed changes, a new tarball will be published on their site.

Thanks to Marcus for taking care of this internally at IBM!


Over-the-air-activation OTAA with LMIC
#36

Wow, lot of good news here !!! Thank you for all those new comits, and your work with IBM :smile:
The debug is also a nice improvement !

I will update my PR on MAC parsing in payload to current master after my holydays.


#38

@matthijs,
I'm also working to a new PR so the code be able to compile and run on Raspberry PI for LoRasPi and RPI Lora GW boards.

May be a good approach would be (as RadioHead lib is doing) determining the platform used (RPI, ESP8266, SAMD, 328, ..) in a include file (limc.h or platform.h or other) so we can conditional compile in code later. I can start on this if you agree ?

Tell me if you think it's not the best solution or just if you have another one.


(Matthijs Kooijman) #39

Well, the intention of my repo is to run on Arduino, and hal.cpp uses mostly platform-independent Arduino functions (so effectively, Arduino is the real HAL). So In that usecase, there would not be much conditional code needed at all.


#40

@matthijs
Thanks for your answer, in fact that is exactly what I already done, conditional compile and there are not "too much", what I've done is creating a raspi.cpp and raspi.h exposing Raspberry PI low level such as digitalWrite, millis(), micros(), Serial, .... using bcm2835_lib and of course I added samples, one is using Network MAC address to generate dynamic devEUI on otaa sample code :wink:

The only file I changed (but I added some) is hal.c because managing I/O is quite different on Raspi with bcm2835 and also SPI setup need clock divider and not speed.

But I think I'll move to WiringPi to be able to have a kind of 'attachInterrupts()' to we can really be waked on interrupt and not checking DIO line or RFM95 register in loop (We already had a talk about this one) because we're on a multi-tasking system and we're proud enought not taking all CPU waiting for an level change on a line :wink:

Anyway, I've pushed a specific branch called rpi I still need to solve some problem but you can take a look of what is currently under development (I also updated the readme for Raspberry PI installation)

Any suggestion are welcomed of course


#41

I have the latest update running on a Teensy LC with an RFM. Thank you very much @matthijs.
The sketch runs on a node that I use as a battery-powered pinger on TTN mapper and I do not plan to run it continuously and break the fup. I've tried to find in the code where I can make it transmit more often than the current once per two minutes by changing these lines in the send-v1 example:
// Schedule a timed job to run at the given timestamp (absolute system time)
os_setTimedCallback(j, os_getTime()+sec2osticks(120), do_send);
into
os_setTimedCallback(j, os_getTime()+sec2osticks(10), do_send);
But that does not give me 10 seconds transmissions, in fact it seems to hang when I do that.

Any suggestions?