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

Adding attempts to readLine and state marker if radio module is unres… #244

Merged
merged 24 commits into from
Jan 14, 2019
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
4629038
Adding attempts to readLine and state marker if radio module is unres…
savnik Aug 17, 2018
0653d8d
Fix spacing around brackets
savnik Aug 24, 2018
012e651
Adding attempts to TheTHingsNetwork.h
savnik Aug 24, 2018
9693732
No need for else when if has return
savnik Aug 24, 2018
77403c6
Set default in header file
savnik Oct 3, 2018
2a1968e
decrement attempts
savnik Oct 3, 2018
91d5b8b
Proposal to handle exception when RN module does not respond
savnik Oct 3, 2018
2df5307
Changed variable name from radioModuleInvalidState to needsHardReset
savnik Oct 26, 2018
d4a6ce5
Added hardReset function with non-blocking delay. made needsHardReset…
savnik Oct 26, 2018
72fc4f2
Updating documentation for hardreset
savnik Oct 26, 2018
71e3d0a
Changed wording of unresponsive rn module in readline function
savnik Dec 1, 2018
833ec1e
Spacing in if statement in readline function
savnik Dec 1, 2018
0fc3bc2
Removing comment at readline function
savnik Dec 1, 2018
d74d17d
Fixed spelling mistake of millis in resetHard
savnik Dec 1, 2018
fe0c8ab
Replacing single qoute with double qoute to fix warning: character co…
savnik Dec 1, 2018
a0afabf
remove empty line
savnik Dec 1, 2018
69ef443
Fixed missing (
savnik Dec 5, 2018
896a8aa
moved adr parameter to reset and added parameter description for hard…
savnik Dec 5, 2018
88c81a0
Spelling mistake
savnik Dec 5, 2018
13b554f
Reformulated the non i/o blocking wait function to make it more under…
savnik Dec 5, 2018
8c8cb8c
Updated the way while brackets are placed in resetHard
savnik Dec 5, 2018
8ec0a25
Updated hardreset documentation to include initial pinmode setup
savnik Dec 22, 2018
a17f5e4
rewording of hardreset output pin config
savnik Dec 22, 2018
87dacf4
Using delay(1000) instead of custom delay function to ensure that ESP…
savnik Dec 28, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/TheThingsNetwork.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,16 @@ void reset(bool adr);

- `bool adr`: Enable/disable Adaptive Data Rate.

## Method: `hardReset`

Performs a hardware reset of the RN module. Input parameter is the pin which the reset pin from the module is connected to. This does clear saved state, e.g. provisioned keys.

```c
void hardReset(uint8_t resetPin);
```

- `uint8_t resetPin`: The output pin that is connected to the module's reset pin.

savnik marked this conversation as resolved.
Show resolved Hide resolved
## Method: `getHardwareEui`

Gets the unique hardware EUI, often used as the DevEUI.
Expand Down
32 changes: 25 additions & 7 deletions src/TheThingsNetwork.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,19 @@ void TheThingsNetwork::clearReadBuffer()
}
}

size_t TheThingsNetwork::readLine(char *buffer, size_t size)
size_t TheThingsNetwork::readLine(char *buffer, size_t size, uint8_t attempts)
{
size_t read = 0;
while (read == 0)
while (!read && attempts--)
{
read = modemStream->readBytesUntil('\n', buffer, 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;
}
buffer[read - 1] = '\0'; // set \r to \0
return read;
}
Expand Down Expand Up @@ -417,7 +423,7 @@ void TheThingsNetwork::reset(bool adr)
size_t length = readResponse(SYS_TABLE, SYS_RESET, buffer, sizeof(buffer));

autoBaud();
length = readResponse(SYS_TABLE, SYS_TABLE, SYS_GET_VER, buffer, sizeof(buffer));
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, " ");
Expand All @@ -436,6 +442,18 @@ void TheThingsNetwork::reset(bool adr)
sendMacSet(MAC_ADR, "off");
}
this->adr = adr;
this->needsHardReset = false;
}

void TheThingsNetwork::resetHard(uint8_t resetPin){
digitalWrite(resetPin, LOW);
unsigned long time_now = millis();
int period = 1000;
// Non I/O blocking wait function
while(millis() < time_now + period)
{
}
digitalWrite(resetPin, HIGH);
savnik marked this conversation as resolved.
Show resolved Hide resolved
}

void TheThingsNetwork::saveState()
Expand Down Expand Up @@ -776,8 +794,8 @@ void TheThingsNetwork::configureKR920_923()
void TheThingsNetwork::configureIN865_867()
{
sendMacSet(MAC_ADR, "off"); // TODO: remove when ADR is implemented for this plan
sendMacSet(MAC_RX2, "2 866550000"); // SF10
sendMacSet(MAC_RX2, "2 866550000"); // SF10

// Disable the three default LoRaWAN channels
sendChSet(MAC_CHANNEL_STATUS, 0, "off");
sendChSet(MAC_CHANNEL_STATUS, 1, "off");
Expand Down Expand Up @@ -1035,7 +1053,7 @@ void TheThingsNetwork::sleep(uint32_t mseconds)
}

void TheThingsNetwork::wake()
{
{
autoBaud();
}

Expand All @@ -1051,7 +1069,7 @@ void TheThingsNetwork::linkCheck(uint16_t seconds)
modemStream->write(buffer);
modemStream->write(SEND_MSG);
debugPrintLn(buffer);
waitForOk();
waitForOk();
}

uint8_t TheThingsNetwork::getLinkCheckGateways()
Expand Down
7 changes: 5 additions & 2 deletions src/TheThingsNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class TheThingsNetwork
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 = 3);
size_t readResponse(uint8_t prefixTable, uint8_t indexTable, uint8_t index, char *buffer, size_t size);
size_t readResponse(uint8_t table, uint8_t index, char *buffer, size_t size);

Expand All @@ -84,8 +84,11 @@ class TheThingsNetwork
void sendGetValue(uint8_t table, uint8_t prefix, uint8_t index);

public:
bool needsHardReset = false;

TheThingsNetwork(Stream &modemStream, Stream &debugStream, ttn_fp_t fp, uint8_t sf = TTN_DEFAULT_SF, uint8_t fsb = TTN_DEFAULT_FSB);
void reset(bool adr = true);
void resetHard(uint8_t resetPin);
void showStatus();
size_t getHardwareEui(char *buffer, size_t size);
size_t getAppEui(char *buffer, size_t size);
Expand All @@ -102,7 +105,7 @@ class TheThingsNetwork
void wake();
void saveState();
void linkCheck(uint16_t seconds);
uint8_t getLinkCheckGateways();
uint8_t getLinkCheckGateways();
uint8_t getLinkCheckMargin();
};

Expand Down