Skip to content

RN2903 and Arduino Uno not Working with Library #248

Closed
@ElectronicallyE

Description

@ElectronicallyE

I have been trying to use the official TTN Library with my Arduino Uno wired to my Microchip RN2903 with the SA1.0.3 firmware. I am using this board for the RN2903 and have wired it to my Arduino with using a logic level converter for the RN2903 TX -> Uno RX line and two voltage dividers for the RESET line and the Uno RX -> RN2903 TX line.

I had been using the jpmeijers with success and since been testing this library with the exact same pinouts, wiring setup and AltSoftSerial. My first issue I faced was the code repeating in the while section of the readLine function which from my understanding is in the process of being resolved as documented firstly here and secondly here.

My pinouts are:

  • RN2xx3 -- Arduino
  • Uart TX -- 8
  • Uart RX -- 9
  • Reset -- 12
  • Vcc -- 3.3V
  • Gnd -- Gnd

My Arduino code for all testing was based on the SendABP example, however was adjusted to support the Arduino Uno as shown below. Do note that I am using the AU915 frequency plan:

#include <TheThingsNetwork.h>
#include <AltSoftSerial.h>

AltSoftSerial loraSerial;

// Set your DevAddr, NwkSKey, AppSKey and the frequency plan
const char *devAddr = "ADDR GOES HERE";
const char *nwkSKey = "NWKSKEY GOES HERE";
const char *appSKey = "APPSKEY GOES HERE";

#define debugSerial Serial

// Replace REPLACE_ME with TTN_FP_EU868 or TTN_FP_US915
#define freqPlan TTN_FP_AU915

TheThingsNetwork ttn(loraSerial, debugSerial, freqPlan);

void setup()
{
  loraSerial.begin(9600);
  debugSerial.begin(57600);

  // Wait a maximum of 10s for Serial Monitor
  while (!debugSerial && millis() < 10000)
    ;

  debugSerial.println("-- PERSONALIZE");
  ttn.personalize(devAddr, nwkSKey, appSKey);
  debugSerial.println("-- STATUS");
  ttn.showStatus();
}

void loop()
{
  debugSerial.println("-- LOOP");

  // Prepare payload of 1 byte to indicate LED status
  byte payload[1];
  payload[0] = (digitalRead(LED_BUILTIN) == HIGH) ? 1 : 0;

  // Send it off
  ttn.sendBytes(payload, sizeof(payload));

  delay(10000);
}

I did some testing printing the read, buffer and size values by adjusting the TheThinksNetwork.cpp as follows starting on line 360:

size_t TheThingsNetwork::readLine(char *buffer, size_t size)
{
  debugPrintLn("Before1");
  size_t read = 0;
  debugPrintLn("Before2");
  while (read == 0)
  {
    read = modemStream->readBytesUntil('\n', buffer, size);
    debugPrint("read value: ");
    debugPrintLn(read);
    debugPrint("buffer value: ");
    debugPrintLn(buffer);
    debugPrint("size value: ");
    debugPrintLn(size);
  }
  debugPrintLn(read);
  debugPrintLn("After1");
  buffer[read - 1] = '\0'; // set \r to \0
  debugPrintLn("After2");
  return read;
}

My output from this is as follows:

-- PERSONALIZE
Before1
Before2
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
...

As I didn't know where to go from here, I resorted to copying the content of the three files changed in the pull request by savnik.

These three adjusted files are:
TheThingsNetwork.md
TheThingsNetwork.cpp
TheThingsNetwork.h


The output from these changes are below. This output took about 40 minutes, with each `mac set ch status` taking about 30 seconds each to appear.

-- PERSONALIZE
Model: Version: Sending: mac set deveui 
Sending: mac set adr off
Sending: mac set devaddr DEVADDR IS HERE!
Sending: mac set nwkskey NWKSKEY IS HERE!
Sending: mac set appskey APPSKEY IS HERE!
Sending: mac set ch status 0 off
Sending: mac set ch status 1 off
Sending: mac set ch status 2 off
Sending: mac set ch status 3 off
Sending: mac set ch status 4 off
Sending: mac set ch status 5 off
Sending: mac set ch status 6 off
Sending: mac set ch status 7 off
Sending: mac set ch status 8 on
Sending: mac set ch drrange 8 0 3
Sending: mac set ch status 9 on
Sending: mac set ch drrange 9 0 3
Sending: mac set ch status 10 on
Sending: mac set ch drrange 10 0 3
Sending: mac set ch status 11 on
Sending: mac set ch drrange 11 0 3
Sending: mac set ch status 12 on
Sending: mac set ch drrange 12 0 3
Sending: mac set ch status 13 on
Sending: mac set ch drrange 13 0 3
Sending: mac set ch status 14 on
Sending: mac set ch drrange 14 0 3
Sending: mac set ch status 15 on
Sending: mac set ch drrange 15 0 3
Sending: mac set ch status 16 off
Sending: mac set ch status 17 off
Sending: mac set ch status 18 off
Sending: mac set ch status 19 off
Sending: mac set ch status 20 off
Sending: mac set ch status 21 off
Sending: mac set ch status 22 off
Sending: mac set ch status 23 off
Sending: mac set ch status 24 off
Sending: mac set ch status 25 off
Sending: mac set ch status 26 off
Sending: mac set ch status 27 off
Sending: mac set ch status 28 off
Sending: mac set ch status 29 off
Sending: mac set ch status 30 off
Sending: mac set ch status 31 off
Sending: mac set ch status 32 off
Sending: mac set ch status 33 off
Sending: mac set ch status 34 off
Sending: mac set ch status 35 off
Sending: mac set ch status 36 off
Sending: mac set ch status 37 off
Sending: mac set ch status 38 off
Sending: mac set ch status 39 off
Sending: mac set ch status 40 off
Sending: mac set ch status 41 off
Sending: mac set ch status 42 off
Sending: mac set ch status 43 off
Sending: mac set ch status 44 off
Sending: mac set ch status 45 off
Sending: mac set ch status 46 off
Sending: mac set ch status 47 off
Sending: mac set ch status 48 off
Sending: mac set ch status 49 off
Sending: mac set ch status 50 off
Sending: mac set ch status 51 off
Sending: mac set ch status 52 off
Sending: mac set ch status 53 off
Sending: mac set ch status 54 off
Sending: mac set ch status 55 off
Sending: mac set ch status 56 off
Sending: mac set ch status 57 off
Sending: mac set ch status 58 off
Sending: mac set ch status 59 off
Sending: mac set ch status 60 off
Sending: mac set ch status 61 off
Sending: mac set ch status 62 off
Sending: mac set ch status 63 off
Sending: mac set ch status 64 off
Sending: mac set ch status 65 on
Sending: mac set ch status 66 off
Sending: mac set ch status 67 off
Sending: mac set ch status 68 off
Sending: mac set ch status 69 off
Sending: mac set ch status 70 off
Sending: mac set ch status 71 off
Sending: mac set pwridx 5
Sending: mac set retx 7
Sending: mac set dr 3
Sending: mac join abp 
Personalize accepted. Status: 
-- STATUS
EUI: 
Battery: 
AppEUI: 
DevEUI: 
Data Rate: 
RX Delay 1: 
RX Delay 2: 
-- LOOP
Sending: mac tx uncnf 1 01
Successful transmission
-- LOOP
Sending: mac tx uncnf 1 01
Successful transmission
-- LOOP
Sending: mac tx uncnf 1 01
Successful transmission
-- LOOP
Sending: mac tx uncnf 1 01
Successful transmission
-- LOOP
Sending: mac tx uncnf 1 01
Successful transmission

The node began transmitting and did it rather consistently, which appeared in the gateway console, however nothing appeared within the node console. I checked to make sure that my credentials were correct and they were, so on the TTN side everything should have worked.

Also note the blank value under STATUS which I can only assume should contain information.

The above channels also look correct being from channels 8-15 and then 65, so there is nothing wrong with the frequency plan either.

So the current problems are as follows:

  1. Looping in the readLine function
  2. Long initialisation setup time for adjusted library
  3. Missing values under STATUS

From my perspective part of the problem is the same as that which is present with the readLine function, but I think there may be something else which is causing a problem. From my testing of this library over the last 6 months using both an Arduino Uno or an Arduino Nano, never have I successfully used it, unlike some people I know who have been able to with The Things Uno.

What I do know are correct:

  • Wiring
  • AltSoftSerial
  • Hardware
  • Frequency plan
  • Credentials
  • Antenna
  • RN2903 firmware

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions