Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RN2903 and Arduino Uno not Working with Library #248

Closed
ElectronicallyE opened this issue Dec 28, 2018 · 27 comments
Closed

RN2903 and Arduino Uno not Working with Library #248

ElectronicallyE opened this issue Dec 28, 2018 · 27 comments

Comments

@ElectronicallyE
Copy link

ElectronicallyE commented Dec 28, 2018

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
@johanstokking
Copy link
Member

Thanks for the extensive writeup.

Can you confirm that a serial passthrough works, i.e. executing commands on the RN module manually?

@jpmeijers any idea?

@ElectronicallyE
Copy link
Author

Hi @johanstokking,

Using @jpmeijers library I am able to execute commands on the RN2903.

In addition, I have used the following code without either @jpmeijers or the TTN library and it succeeded in send a message to the RN2903 and sending one back. On my board a LED is connect to GPIO10, so for testing I flicked it on and off.

Below is my code. It's not pretty, but it shows that it works with my current setup:

#include <AltSoftSerial.h>

AltSoftSerial loraSerial;

void setup()
{
  Serial.begin(57600); //serial port to computer
  loraSerial.begin(9600); //serial port to radio
  Serial.println("Startup");
  initialize_radio();
  delay(2000);
  Serial.println("RN2xx3 firmware version:");
  Serial.println(sysver());
}

void loop()
{
  sendRawCommand(F("sys set pindig GPIO10 1"));
  delay(1000);
  sendRawCommand(F("sys set pindig GPIO10 0"));
  delay(1000);
}

void initialize_radio()
{
  //reset rn2483
  pinMode(12, OUTPUT);
  digitalWrite(12, LOW);
  delay(500);
  digitalWrite(12, HIGH);

  delay(100); //Wait for the RN2xx3's startup message
  loraSerial.flush();
  
  autobaud(); //Autobaud the rn2483 module to 9600. The default would otherwise be 57600.
}

String sendRawCommand(String c)
{
  while(loraSerial.available())
  {
    loraSerial.read();
  }
  loraSerial.println(c);
  String ret = loraSerial.readStringUntil('\n');
  ret.trim();
  return ret;
}

String sysver()
{
  String ver = sendRawCommand(F("sys get ver"));
  ver.trim();
  return ver;
}

void autobaud()
{
  String response = "";
  while (response=="")
  {
    delay(1000);
    loraSerial.write((byte)0x00);
    loraSerial.write(0x55);
    loraSerial.println();
    loraSerial.println("sys get ver");
    response = loraSerial.readStringUntil('\n');
  }
}

@johanstokking
Copy link
Member

So the issue is that this bare code is faster than when you use the library?

That's pretty weird...

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jan 1, 2019

I'd say so, but the bigger issue is that the board simply does not play nice with the official TTN library.

@johanstokking
Copy link
Member

Which library does not play nice with the TTN library?

The only obvious thing I see in your code is that you swapped the baud rates for debug and the radio; if you use 9600 for the RN module instead of 57600 then everything is clearly slower.

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jan 2, 2019

Sorry, I meant to say board. ;) The baud rate I normally use is 9600, I'll try changing that and report back.

@johanstokking
Copy link
Member

Any news @ElectronicallyE ?

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jan 21, 2019

Hey @johanstokking,

Changed the baud rate 9600 and there is no difference. The code I used was:

#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(9600);

  // 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 the serial printing of what is happening in the newly updated library using the following code:

size_t TheThingsNetwork::readLine(char *buffer, size_t size, uint8_t attempts)
{
  size_t read = 0;
  while (!read && attempts--)
  {
    read = modemStream->readBytesUntil('\n', buffer, size);
    debugPrint("read value: ");
    debugPrintLn(read);
    debugPrint("buffer value: ");
    debugPrintLn(buffer);
    debugPrint("size value: ");
    debugPrintLn(size);
  }
  if (attempts<=0)
  { // If attempts is activated return 0 and set RN state marker
    this->needsHardReset = true; // Inform the application about the radio module is not responsive.
    debugPrintLn("No response from RN module.");
    return 0;
  }
  debugPrintLn(read);
  debugPrintLn("After1");
  buffer[read - 1] = '\0'; // set \r to \0
  debugPrintLn("After2");
  buffer[read - 1] = '\0'; // set \r to \0
  return read;
}

And got this output:

-- PERSONALIZE
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
0
After1
After2
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
0
After1
After2
Model: Version: read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
0
After1
After2
Sending: mac set deveui 
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
0
After1
After2
Sending: mac set adr off
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
0
After1
After2
Sending: mac set devaddr 2600169B
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
0
After1
After2
Sending: mac set nwkskey 973BF07958259FD82714A2A8AC2389C2
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
read value: 0
buffer value: 
size value: 512
0
After1
After2
Sending: mac set appskey BA2CD38A6B7229B5AC74E3524E15F571
read value: 0
buffer value: 
size value: 512

It keeps going on, so I'm assuming it'll do what was happening before when I had previously change the files.

@johanstokking
Copy link
Member

Which change did you actually apply? Because I still see baud rate 9600 for the LoRa serial, while that should be 57600.

@ElectronicallyE
Copy link
Author

I changed both to 9600. I’ve updated it in my post, because that’s what I actually did.

@johanstokking
Copy link
Member

OK. It is normal that you experience slower communication on a lower baud rate. You can and should use 57600 for the RN module.

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jan 23, 2019

I believe the problem is still present. It seems to me that the print out takes a lot longer than necessary at about 40 minutes, and yet, I still do not see a transmission on the TTN Console.

I have used other code with the jpmeijers RN2483-Arduino-Library where I communicate at 57600, so I don't think that is the problem.

@johanstokking
Copy link
Member

@jpmeijers any idea?

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jan 25, 2019

I have tested a TTN Uno using my adjusted code.

The code I have adjusted is in TheThingsNetwork.cpp is the readLine function, where I have some values printed:

size_t TheThingsNetwork::readLine(char *buffer, size_t size, uint8_t attempts)
{
  Serial.println("BEFORE");
  size_t read = 0;
  while (!read && attempts--)
  {
    read = modemStream->readBytesUntil('\n', buffer, size);
    debugPrint("read value: ");
    debugPrintLn(read);
    debugPrint("buffer value: ");
    debugPrintLn(buffer);
    debugPrint("size value: ");
    debugPrintLn(size);
  }
  if (attempts<=0)
  { // If attempts is activated return 0 and set RN state marker
    this->needsHardReset = true; // Inform the application about the radio module is not responsive.
    debugPrintLn("No response from RN module.");
    return 0;
  }
  debugPrintLn(read);
  debugPrintLn("After1");
  buffer[read - 1] = '\0'; // set \r to \0
  debugPrintLn("After2");
  buffer[read - 1] = '\0'; // set \r to \0
  return read;
}

The output from a TTN Uno is:

-- PERSONALIZE
BEFORE
read value: 36
buffer value: RN2903 SA1.0.3 Jan 23 2018 14:34:40

size value: 512
36
After1
After2
BEFORE
read value: 36
buffer value: RN2903 SA1.0.3 Jan 23 2018 14:34:40

size value: 512
36
After1
After2
Model: RN2903
Version: SA1.0.3
BEFORE
read value: 17
buffer value: 0004A30B001C07D5
n 23 2018 14:34:40
size value: 512
17
After1
After2
Sending: mac set deveui 0004A30B001C07D5
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set adr off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set devaddr 26002A9D
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set nwkskey 4992D120AC1812678ECA5317841D8E68
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set appskey 4109C30CCEDF0335DDB00E1E0D1C7684
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 0 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 1 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 2 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 3 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 4 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 5 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 6 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 7 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 8 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 8 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 9 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 9 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 10 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 10 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 11 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 11 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 12 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 12 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 13 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 13 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 14 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 14 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 15 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch drrange 15 0 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 16 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 17 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 18 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 19 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 20 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 21 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 22 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 23 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 24 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 25 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 26 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 27 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 28 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 29 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 30 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 31 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 32 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 33 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 34 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 35 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 36 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 37 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 38 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 39 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 40 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 41 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 42 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 43 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 44 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 45 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 46 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 47 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 48 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 49 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 50 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 51 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 52 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 53 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 54 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 55 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 56 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 57 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 58 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 59 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 60 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 61 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 62 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 63 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 64 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 65 on
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 66 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 67 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 68 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 69 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 70 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set ch status 71 off
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set pwridx 5
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set retx 7
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac set dr 3
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
Sending: mac join abp 
BEFORE
read value: 3
buffer value: ok
4A30B001C07D5
size value: 512
3
After1
After2
BEFORE
read value: 9
buffer value: accepted
01C07D5
size value: 512
9
After1
After2
BEFORE
read value: 9
buffer value: 00000001
01C07D5
size value: 512
9
After1
After2
Personalize accepted. Status: 00000001
-- STATUS
BEFORE
read value: 17
buffer value: 0004A30B001C07D5
n 23 2018 14:34:40
size value: 512
17
After1
After2
EUI: 0004A30B001C07D5
BEFORE
read value: 5
buffer value: 3294
30B001C07D5
size value: 512
5
After1
After2
Battery: 3294
BEFORE
read value: 17
buffer value: 70B3D57ED0016BA2
n 23 2018 14:34:40
size value: 512
17
After1
After2
AppEUI: 70B3D57ED0016BA2
BEFORE
read value: 17
buffer value: 0004A30B001C07D5
n 23 2018 14:34:40
size value: 512
17
After1
After2
DevEUI: 0004A30B001C07D5
BEFORE
read value: 2
buffer value: 3
04A30B001C07D5
size value: 512
2
After1
After2
Data Rate: 3
BEFORE
read value: 5
buffer value: 1000
30B001C07D5
size value: 512
5
After1
After2
RX Delay 1: 1000
BEFORE
read value: 5
buffer value: 2000
30B001C07D5
size value: 512
5
After1
After2
RX Delay 2: 2000
-- LOOP
Sending: mac tx uncnf 1 00
BEFORE
read value: 3
buffer value: ok
0
size value: 512
3
After1
After2
BEFORE
read value: 10
buffer value: mac_tx_ok
1C07D5
size value: 512
10
After1
After2
Successful transmission

And the output from my board is:

09:46:13.979 -> ⸮d⸮B⸮W⸮⸮2w⸮t�⸮⸮0w⸮t�⸮⸮⸮⸮-- PERSONALIZE
09:46:36.622 -> BEFORE
09:46:46.602 -> read value: 0
09:46:46.602 -> buffer value: 
09:46:46.602 -> size value: 512
09:46:56.613 -> read value: 0
09:46:56.613 -> buffer value: 
09:46:56.613 -> size value: 512
09:47:06.618 -> read value: 0
09:47:06.618 -> buffer value: 
09:47:06.618 -> size value: 512
09:47:06.618 -> 0
09:47:06.618 -> After1
09:47:06.618 -> After2
09:47:27.710 -> BEFORE
09:47:37.697 -> read value: 0
09:47:37.697 -> buffer value: 
09:47:37.697 -> size value: 512
09:47:47.707 -> read value: 0
09:47:47.707 -> buffer value: 
09:47:47.707 -> size value: 512
09:47:57.716 -> read value: 0
09:47:57.716 -> buffer value: 
09:47:57.716 -> size value: 512
09:47:57.716 -> 0
09:47:57.716 -> After1
09:47:57.716 -> After2
09:47:57.750 -> Model: Version: BEFORE
09:48:07.712 -> read value: 0
09:48:07.712 -> buffer value: 
09:48:07.712 -> size value: 512
09:48:17.716 -> read value: 0
09:48:17.716 -> buffer value: 
09:48:17.716 -> size value: 512
09:48:27.709 -> read value: 0
09:48:27.709 -> buffer value: 
09:48:27.709 -> size value: 512
09:48:27.709 -> 0
09:48:27.709 -> After1
09:48:27.709 -> After2
09:48:27.709 -> Sending: mac set deveui 
09:48:27.709 -> BEFORE
09:48:37.707 -> read value: 0
09:48:37.707 -> buffer value: 
09:48:37.707 -> size value: 512
09:48:47.725 -> read value: 0
09:48:47.725 -> buffer value: 
09:48:47.725 -> size value: 512
09:48:57.728 -> read value: 0
09:48:57.728 -> buffer value: 
09:48:57.728 -> size value: 512
09:48:57.728 -> 0
09:48:57.728 -> After1
09:48:57.728 -> After2
09:48:57.728 -> Sending: mac set adr off
09:48:57.728 -> BEFORE
09:49:07.717 -> read value: 0
09:49:07.717 -> buffer value: 
09:49:07.717 -> size value: 512
09:49:17.721 -> read value: 0
09:49:17.721 -> buffer value: 
09:49:17.721 -> size value: 512
09:49:27.726 -> read value: 0
09:49:27.726 -> buffer value: 
09:49:27.726 -> size value: 512
09:49:27.726 -> 0
09:49:27.726 -> After1
09:49:27.726 -> After2
09:49:27.726 -> Sending: mac set devaddr 2600169B
09:49:27.762 -> BEFORE
09:49:37.705 -> read value: 0
09:49:37.705 -> buffer value: 
09:49:37.705 -> size value: 512
09:49:47.735 -> read value: 0
09:49:47.735 -> buffer value: 
09:49:47.735 -> size value: 512
09:49:57.713 -> read value: 0
09:49:57.713 -> buffer value: 
09:49:57.713 -> size value: 512
09:49:57.713 -> 0
09:49:57.713 -> After1
09:49:57.713 -> After2
09:49:57.713 -> Sending: mac set nwkskey 973BF07958259FD82714A2A8AC2389C2
09:49:57.746 -> BEFORE
09:50:07.731 -> read value: 0
09:50:07.731 -> buffer value: 
09:50:07.731 -> size value: 512
09:50:17.724 -> read value: 0
09:50:17.724 -> buffer value: 
09:50:17.724 -> size value: 512
09:50:27.712 -> read value: 0
09:50:27.712 -> buffer value: 
09:50:27.712 -> size value: 512
09:50:27.749 -> 0
09:50:27.749 -> After1
09:50:27.749 -> After2
09:50:27.749 -> Sending: mac set appskey BA2CD38A6B7229B5AC74E3524E15F571
09:50:27.749 -> BEFORE
09:50:37.754 -> read value: 0
09:50:37.754 -> buffer value: 
09:50:37.754 -> size value: 512
09:50:47.732 -> read value: 0
09:50:47.732 -> buffer value: 
09:50:47.732 -> size value: 512
09:50:57.731 -> read value: 0
09:50:57.731 -> buffer value: 
09:50:57.731 -> size value: 512
09:50:57.731 -> 0
09:50:57.731 -> After1
09:50:57.731 -> After2
09:50:57.731 -> Sending: mac set ch status 0 off
09:50:57.766 -> BEFORE
09:51:07.734 -> read value: 0
09:51:07.734 -> buffer value: 
09:51:07.734 -> size value: 512
09:51:17.738 -> read value: 0
09:51:17.738 -> buffer value: 
09:51:17.738 -> size value: 512
09:51:27.753 -> read value: 0
09:51:27.753 -> buffer value: 
09:51:27.753 -> size value: 512
09:51:27.753 -> 0
09:51:27.753 -> After1
09:51:27.753 -> After2
09:51:27.753 -> Sending: mac set ch status 1 off
09:51:27.786 -> BEFORE
09:51:37.766 -> read value: 0
09:51:37.766 -> buffer value: 
09:51:37.766 -> size value: 512
09:51:47.737 -> read value: 0
09:51:47.737 -> buffer value: 
09:51:47.737 -> size value: 512
09:51:57.736 -> read value: 0
09:51:57.736 -> buffer value: 
09:51:57.736 -> size value: 512
09:51:57.736 -> 0
09:51:57.736 -> After1
09:51:57.736 -> After2
09:51:57.772 -> Sending: mac set ch status 2 off
09:51:57.772 -> BEFORE
09:52:07.762 -> read value: 0
09:52:07.762 -> buffer value: 
09:52:07.762 -> size value: 512
09:52:17.745 -> read value: 0
09:52:17.745 -> buffer value: 
09:52:17.745 -> size value: 512
09:52:27.747 -> read value: 0
09:52:27.747 -> buffer value: 
09:52:27.747 -> size value: 512
09:52:27.747 -> 0
09:52:27.747 -> After1
09:52:27.747 -> After2
09:52:27.747 -> Sending: mac set ch status 3 off
09:52:27.784 -> BEFORE
09:52:37.755 -> read value: 0
09:52:37.755 -> buffer value: 
09:52:37.755 -> size value: 512
09:52:47.744 -> read value: 0
09:52:47.744 -> buffer value: 
09:52:47.744 -> size value: 512
09:52:57.768 -> read value: 0
09:52:57.768 -> buffer value: 
09:52:57.768 -> size value: 512
09:52:57.768 -> 0
09:52:57.768 -> After1
09:52:57.768 -> After2
09:52:57.768 -> Sending: mac set ch status 4 off
09:52:57.801 -> BEFORE
09:53:07.753 -> read value: 0
09:53:07.753 -> buffer value: 
09:53:07.753 -> size value: 512

I do not have my full output, because this will go on for a while, as shown by the time to the left.

Hopefully this makes some sense to you. It's a bit messy, but shows that the code is struggling to read my board. I'll look into this some more.

@ElectronicallyE
Copy link
Author

ElectronicallyE commented Jan 25, 2019

I can get the @jpmeijers library to work without issue on both OTAA and ABP.

Just to reiterate, the current code I am using in Jp's library is:

#include <rn2xx3.h>
#include <AltSoftSerial.h>

AltSoftSerial mySerial;

// create an instance of the rn2xx3 library,
// giving the software serial as port to use
rn2xx3 myLora(mySerial);

// the setup routine runs once when you press reset:
void setup()
{

  // open serial communications and wait for port to open:
  Serial.begin(57600); //serial port to computer
  mySerial.begin(9600); //serial port to radio
  
  Serial.println("It's start'n up mate!");

  initialize_radio();

  myLora.sendRawCommand(F("sys set pindig GPIO0 1"));
  led_on();

  // transmit a startup message
  //myLora.tx("Hello!");

  // setting the frequency plan to AU915
  myLora.setFrequencyPlan(TTN_AU);

  led_off();
  delay(2000);
}

void initialize_radio()
{
  //reset rn2483
  pinMode(12, OUTPUT);
  digitalWrite(12, LOW);
  delay(500);
  digitalWrite(12, HIGH);

  delay(100); //wait for the RN2xx3's startup message
  mySerial.flush();

  // autobaud the rn2483 module to 9600. The default would otherwise be 57600.
  myLora.autobaud();

  // check communication with radio
  String hweui = myLora.hweui();
  while(hweui.length() != 16)
  {
    Serial.println("Communication with RN2xx3 unsuccessful. Start that baby right up again.");
    Serial.println(hweui);
    delay(10000);
    hweui = myLora.hweui();
  }

  // Setting the frequency plan to AU915
  myLora.setFrequencyPlan(TTN_US);

  // print out the HWEUI so that we can register it via ttnctl
  Serial.println("When using OTAA, register this DevEUI: ");
  Serial.println(myLora.hweui());
  Serial.println("RN2xx3 firmware version:");
  Serial.println(myLora.sysver());

  // configure your keys and join the network
  Serial.println("Trying to join TTN");
  bool join_result = false;

  /*
   * ABP: initABP(String addr, String AppSKey, String NwkSKey);
   * Paste the example code from the TTN console here:
   */
//  const char *devAddr = "";
//  const char *nwkSKey = "";
//  const char *appSKey = "";
//
//  join_result = myLora.initABP(devAddr, appSKey, nwkSKey);

  /*
   * OTAA: initOTAA(String AppEUI, String AppKey);
   * If you are using OTAA, paste the example code from the TTN console here:
   */
  const char *appEui = "";
  const char *appKey = "";

  join_result = myLora.initOTAA(appEui, appKey);

  while(!join_result)
  {
    Serial.println("Unable to join. Are your keys correct and are you in the middle of the outback?");
    delay(5000); //delay a minute before retry
    join_result = myLora.init();
  }
  Serial.println("Successfully joined TTN. You beauty!");

  // Setting the frequency plan to TTN_AU. Not needed for OTAA.
  myLora.setFrequencyPlan(TTN_US);
}

// the loop routine runs over and over again forever:
void loop()
{
    led_on();
    Serial.println("TXing");
    myLora.tx("01234567890"); // three bytes, blocking function
    led_off();
    delay(2000);
}

void led_on()
{
  myLora.sendRawCommand(F("sys set pindig GPIO10 1"));
}

void led_off()
{
  myLora.sendRawCommand(F("sys set pindig GPIO10 0"));
}

@johanstokking
Copy link
Member

@ElectronicallyE did you figure out in the meantime why the TTN library doesn't work?

@ElectronicallyE
Copy link
Author

@johanstokking, unfortunately I haven't. Completely slipped out of my mind. I won't be able to get back into it till the end of the year, but when I make progress, I'll be sure to get back in touch.

@johanstokking
Copy link
Member

OK please reopen when the issue is still there.

@brolly759
Copy link

Was this ever fixed? I tried the RN2903 module and still cant get this to work.

@ElectronicallyE
Copy link
Author

Hey @brolly759 I didn’t end up resolving this issue as I no longer had the need to develop a board I was designing which used the RN2903. Have a look at this library, which I believe I got working, but was stuck on SF12 packet size limits: https://github.com/jpmeijers/RN2483-Arduino-Library

@brolly759
Copy link

I tested that library out as well. I couldn't do more than 11 byte payloads. Also running into issues trying to get network status on there. In their code they have a switch statement for the RN2903, I guess I could compare the TTN library verse theirs to see the differences. Maybe I will just go with a different UART Lora module. ;)

@ElectronicallyE
Copy link
Author

Yep, that’s about where I stopped. Was just putting a heap of time into it with very little progress and by the end it was more effective to just go with a MKR WAN 1310.

Oddly enough, the TTN Uno as far as I know didn’t have these problems, which makes me suspect it was something about the Uno and the RN2903.

@brolly759
Copy link

MKR WAN 1310. That uses a Murata module and looks like SPI to control it over an SAMD21 processor. Not as easy as UART.

@brolly759
Copy link

Nevermind, looking at the source code it looks like UART. Still a bit overkill if I wanted to use an ATMEGA328P.

@brolly759
Copy link

brolly759 commented Sep 6, 2020

haha, I got it to work! That was easier than I thought. Make sure the baudrate for both serial ports is set to 9600. 57600 is too fast and data can get corrupted with the softwareserial library. Then all you had to do was call ttn.reset(); after loraSerial.begin(9600); debugSerial.begin(9600);

My theory is this, the autobaud() function isnt called after the serial ports are initialized and we have a baudrate mismatch.
The OTAA example works fine.

@jpmeijers
Copy link
Collaborator

@brolly759 your solution, how much does it differ from that is documented at https://www.thethingsnetwork.org/docs/devices/arduino/usage.html#serial-ports?

If the documentation is wrong or incomplete, please let us know, or file a pull request to fix it.

@brolly759
Copy link

@jpmeijers First off, great work!
The documentation isn't wrong at all.
The only thing you need to add, at least for the "Arduino Uno, Arduino Nano or other devices using SoftwareSerial" section is ttn.reset(); in the setup() function after the serial.begin statements.

Reasoning: because we are changing the baudrate from 57600 to 9600 we need to run the autobaud function after the serial ports are initialized. The autobaud() function is private in the library and the only time its called is in ttn.reset(); Its also good habit to reset the Microchip module on startup anyways.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants