-
Notifications
You must be signed in to change notification settings - Fork 96
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
Adding attempts to readLine and state marker if radio module is unres… #244
Adding attempts to readLine and state marker if radio module is unres… #244
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
src/TheThingsNetwork.cpp
Outdated
this->radioModuleInvalidState = true; // Inform the application about the radio module is not responsive. | ||
return 0; | ||
} | ||
else{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make spacing consistent around braces and brackets. Also no need for else
after a return
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
src/TheThingsNetwork.cpp
Outdated
@@ -357,15 +357,21 @@ void TheThingsNetwork::clearReadBuffer() | |||
} | |||
} | |||
|
|||
size_t TheThingsNetwork::readLine(char *buffer, size_t size) | |||
size_t TheThingsNetwork::readLine(char *buffer, size_t size, uint8_t attempts = 3) // Default timeout value 10s and is set in class initiator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is it set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
timeout is set in:
arduino-device-lib/src/TheThingsNetwork.cpp
Line 294 in 4629038
this->modemStream->setTimeout(10000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set defaults in the header file
@johanstokking did you have time to review the changes? |
src/TheThingsNetwork.cpp
Outdated
@@ -357,15 +357,21 @@ void TheThingsNetwork::clearReadBuffer() | |||
} | |||
} | |||
|
|||
size_t TheThingsNetwork::readLine(char *buffer, size_t size) | |||
size_t TheThingsNetwork::readLine(char *buffer, size_t size, uint8_t attempts = 3) // Default timeout value 10s and is set in class initiator |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Set defaults in the header file
src/TheThingsNetwork.cpp
Outdated
{ | ||
size_t read = 0; | ||
while (read == 0) | ||
while (read == 0 && attempts>0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Spacing; attempts > 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't you be decrementing attempts
somewhere? Like while (!read && attempts--)
?
src/TheThingsNetwork.cpp
Outdated
{ | ||
read = modemStream->readBytesUntil('\n', buffer, size); | ||
} | ||
if(attempts<=0) | ||
{ // If attempts is activated return 0 and set RN state marker | ||
this->radioModuleInvalidState = true; // Inform the application about the radio module is not responsive. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although this is a way to signal, still it requires action from the application. I don't really know if application developers know how to resolve this.
The best way to resolve this is to reset the RN module through the reset pin. Would it be a good idea to configure (optionally) the reset pin, and engage a soft reset in the library at this point?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your valid point. Now a good question is should we let the library handle the reset or give the decision to the application. If the library is resetting the RN module we will need to let the application know so the application can handle this, eg. by re-joining the network.
But in either way we must raise a flag to the application and abort the current task.
If we reset the RN module in the library we can do a soft-reset by sending a sys_reset cmd or a hard-reset using the reset pin. In either way the library needs to rejoin the network and then re-execute the function. Should the module then retry for infinity or a limited tries?
One option could be to soft/hard reset the module every time this error occur, print a debug message with details and raise the flag. In this way we have raised awareness of a problem and tried to resolve it while giving power over the exception handling to the application.
readLine is used in:
- readResponse
- personalize
- join
- sendBytes
- waitForOk
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However maybe the simple solution is the best. On error exit with debug message and error flag. Then update documentation and make a good example on how to handle the error on application level.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My wording was wrong; I meant hard reset, by using the reset pin. Sending the soft reset command is not going to work as the serial is broken already.
And you're right, doing a hard reset in the midst of a join or TX operation, and restoring the state (i.e. joining again) is not going to work either.
So I'm good with the signaling to the application. Please rename to needsHardReset
, introduce a resetHard()
that takes a pin number as parameter, and reset the needsHardReset
after hard resetting. Also documentation would be helpful. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay. I will work on this and come back soon.
src/TheThingsNetwork.h
Outdated
void (*messageCallback)(const uint8_t *payload, size_t size, port_t port); | ||
|
||
void clearReadBuffer(); | ||
size_t readLine(char *buffer, size_t size); | ||
size_t readLine(char *buffer, size_t size, uint8_t attempts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So add the default always in the header file
… a public variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good. Almost there
src/TheThingsNetwork.cpp
Outdated
unsigned long time_now = milis(); | ||
int period = 1000; | ||
while(millis() < time_now + period){ | ||
// wait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not use delay()
, and do we need a whole second?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was just to make it non-blocking in case the application is using interrupt. The reset function is not time critical.
I have looked in the datasheet and there is no advice on minimum time for the signal for a reset to be triggered. I know that 1s works by test, but I have not tested <1s.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually delay() is the better one to use. On some platforms where it is necessary delay() will call yield(), while a while loop will not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you implement this @savnik ?
…nstant too long for its type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest is good.
I would like to see consistent spacing, i.e. before and after (...)
and around operators, though.
src/TheThingsNetwork.cpp
Outdated
unsigned long time_now = milis(); | ||
int period = 1000; | ||
while(millis() < time_now + period){ | ||
// wait |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you implement this @savnik ?
So the wait function is implemented. I have tried to make it more clear now. |
Only saw the review request now. I'll try and give this PR a proper look and review during the coming week. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only two small changes please. For the rest I am happy with this PR.
Thanks guys on making progress on this. I was about to write up an issue about this, but seems like you've got a handle on it already. Would be glad to start using TTN as soon as this is resolved as I have be unable to because of this hanging problem. |
…8266 background operations will work
@jpmeijers good to go now? |
@jpmeijers have you had time to take a look at the two changes you sugested? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Proposal to fix issue #242