TheThingsNetwork / arduino-device-lib

Arduino Library for TTN Devices
MIT License
207 stars 96 forks source link

calling join() restore the module to default baud rate... #219

Closed alexbn71 closed 6 years ago

alexbn71 commented 7 years ago

Hello,

I issue an "autobaud" to comunicate with RN2483 (at 9600) but when I call the join() function it calls at the beginning the reset() function that restore RN2483 to default baud rate, thus canceling the effect of my autobaud.

If I comment the code inside reset() that issue the reboot, all works fine.

My proposal is to leave the reset() function PUBLIC and leave the programmer the ability to force a reboot. While in the join() function leave only the setting of devEui.

Regards Alessandro

alexbn71 commented 7 years ago

I'm sorry I was working on an old version of the library but the new one has a similar problem...

alexbn71 commented 7 years ago

this it works:

void TheThingsNetwork::reset(bool adr)
{
  // It's pretty useless this test, the baud rate could be performed every time.    
  //if (!baudDetermined)
  //{
    autoBaud();
  //}

  // Issue a REBOOT using the right baud rate. The response will be garbage if the
  // communication is not done at default baud rate and should be discarded
  size_t length = readResponse(SYS_TABLE, SYS_RESET, buffer, sizeof(buffer));
  // After REBOOT set again the module to the right baud rate.
  autoBaud();
  // And now get all infos about the module 
  length = readResponse(SYS_TABLE, SYS_TABLE, SYS_GET_VER, buffer, sizeof(buffer));

  // buffer contains "RN2xx3[xx] x.x.x ...", splitting model from version
  char *model = strtok(buffer, " ");
  debugPrintIndex(SHOW_MODEL, model);
  char *version = strtok(NULL, " ");
  debugPrintIndex(SHOW_VERSION, version);
johanstokking commented 6 years ago

@alexbn71 thanks for reporting. Can you file a PR?

alexbn71 commented 6 years ago

TheThingsNetwork_Blason.zip

The fix is inside TheThingsNetwork::reset no other changes are necessary to get it working.

PS Ignore the two minor improvments that you could find in the code outside "TheThingsNetwork::reset" function, that are not related to this topic.

Alex

johanstokking commented 6 years ago

Thanks. Can you file a pull request here on GitHub? Otherwise I'll do it, let me know

alexbn71 commented 6 years ago

Sure, sorry...

alexbn71 commented 6 years ago

I hope I did it right, it's my first time

Alex

johanstokking commented 6 years ago

Closed by #223

johanstokking commented 6 years ago

Released in https://github.com/TheThingsNetwork/arduino-device-lib/releases/tag/v2.5.4