arduino-libraries / MKRWAN

An Arduino library for sending and receiving data using LoRaWAN protocol and LoRa® radios.
https://www.arduino.cc
GNU Lesser General Public License v3.0
84 stars 60 forks source link

modem.restart() hangs #38

Open sslupsky opened 5 years ago

sslupsky commented 5 years ago

The modem.restart() function does not return. It appears to hang on:

sendAT(GF("+REBOOT"));
facchinm commented 5 years ago

I just tested with a super stupid sketch


void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  while (!Serial);
  // change this to your regional band (eg. US915, AS923, ...)
  if (!modem.begin(EU868)) {
    Serial.println("Failed to start module");
    while (1) {}
  };
  Serial.print("Your module version is: ");
  Serial.println(modem.version());
  Serial.print("Your device EUI is: ");
  Serial.println(modem.deviceEUI());

  modem.restart();

  Serial.print("Your module version is: ");
  Serial.println(modem.version());
  Serial.print("Your device EUI is: ");
  Serial.println(modem.deviceEUI());
}

and the output is correct

Your module version is: ARD-078 1.1.8
Your device EUI is: a8610axxxxxxxxxx
Your module version is: ARD-078 1.1.8
Your device EUI is: a8610axxxxxxxxxx

Can you share the sketch that hangs?

sslupsky commented 5 years ago

Ok. I see the problem now. I called modem.restart() before modem.begin() to force a reset of the radio when the MKRWAN boots. This is in case there is some form of reset other than a POR. That is, if the radio is the problem, then reboot it.

I did not realize modem.begin() needed to be called before this function. I expected that after rebooting the radio, I would have to configure the band again with a call to modem.begin(). Is the band configured properly after modem.restart()? Do you know if modem.begin() needs to be called again after restart()?

So, I think if you modify your example you will experience the hang.

facchinm commented 5 years ago

begin() already resets the module, so restart() is only needed for "runtime restart". The band selection must be reapplied through another begin (or configureBand) though; I can understand the problem, will try to think about a proper API that leaves no space for ordering issues.

sslupsky commented 5 years ago

Just to clarify, I do not recall that begin() resets the module, rather it resets the modem object?

facchinm commented 5 years ago

begin() toggles RESET pin (https://github.com/arduino-libraries/MKRWAN/blob/master/src/MKRWAN.h#L406) , so it reboots the module, in a certain way :slightly_smiling_face:

sslupsky commented 5 years ago

Oh, for some reason I though that was excluded by the #ifdef SerialloRa? The default condition is that SerialloRa is defined? I could not find it defined anywhere and I do not do so in my code.

facchinm commented 5 years ago

It's defined in MKRWAN core, so it can adapt to any other board using the Murata module.

sslupsky commented 5 years ago

Ahh, that sheds a whole new light on my understanding of things. Thank you for that clarification. So, SerialloRa is intended to be defined when you use the SPI interface to communicate the the Murata module? (For some reason I misinterpreted its' intended use for when the UART interface is used).

sslupsky commented 5 years ago

Since begin() does a module reset calling restart() then begin() is redundant.

I suppose one could call restart() then configureBand() to avoid a pin reset of the module. Is there any reason to avoid a pin reset? If not, should restart() should be removed from the API?

You may want to document on the Arduino website that begin() does a pin (hardware) reset of the module.