mirror of
https://github.com/letscontrolit/ESPEasy.git
synced 2026-09-11 17:14:27 +00:00
[TTNv3] Add selector for TTN stack version
TTN stack version selector does change the RX1 delay so ESPEasy can be used as TTNv3 node.
This commit is contained in:
@@ -237,6 +237,11 @@ bool rn2xx3::setFrequencyPlan(RN2xx3_datatypes::Freq_plan fp)
|
||||
return _rn2xx3_handler.setFrequencyPlan(fp);
|
||||
}
|
||||
|
||||
bool rn2xx3::setTTNstack(RN2xx3_datatypes::TTN_stack_version version)
|
||||
{
|
||||
return _rn2xx3_handler.setTTNstack(version);
|
||||
}
|
||||
|
||||
String rn2xx3::peekLastError() const
|
||||
{
|
||||
return _rn2xx3_handler.peekLastError();
|
||||
|
||||
@@ -285,6 +285,11 @@ public:
|
||||
*/
|
||||
bool setFrequencyPlan(RN2xx3_datatypes::Freq_plan);
|
||||
|
||||
/*
|
||||
* Set version of TTN stack to use.
|
||||
*/
|
||||
bool setTTNstack(RN2xx3_datatypes::TTN_stack_version version);
|
||||
|
||||
/*
|
||||
* Returns the last downlink message HEX string.
|
||||
*/
|
||||
|
||||
@@ -29,6 +29,13 @@ public:
|
||||
DEFAULT_EU
|
||||
};
|
||||
|
||||
enum TTN_stack_version {
|
||||
TTN_v2 = 0,
|
||||
TTN_v3 = 1,
|
||||
|
||||
TTN_NOT_SET
|
||||
};
|
||||
|
||||
enum TX_return_type {
|
||||
TX_FAIL = 0, // The transmission failed.
|
||||
// If you sent a confirmed message and it is not acked,
|
||||
|
||||
@@ -599,6 +599,24 @@ bool rn2xx3_handler::setFrequencyPlan(RN2xx3_datatypes::Freq_plan fp)
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
bool rn2xx3_handler::setTTNstack(RN2xx3_datatypes::TTN_stack_version version)
|
||||
{
|
||||
switch(version) {
|
||||
case RN2xx3_datatypes::TTN_stack_version::TTN_v2:
|
||||
_rxdelay1 = 1000;
|
||||
_rxdelay2 = 2000;
|
||||
break;
|
||||
case RN2xx3_datatypes::TTN_stack_version::TTN_v3:
|
||||
_rxdelay1 = 5000;
|
||||
_rxdelay2 = 6000;
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
sendMacSet(F("rxdelay1"), String(_rxdelay1));
|
||||
return true;
|
||||
}
|
||||
|
||||
RN2xx3_datatypes::Model rn2xx3_handler::configureModuleType()
|
||||
{
|
||||
RN2xx3_datatypes::Firmware firmware;
|
||||
|
||||
@@ -155,6 +155,8 @@ public:
|
||||
|
||||
bool setFrequencyPlan(RN2xx3_datatypes::Freq_plan fp);
|
||||
|
||||
bool setTTNstack(RN2xx3_datatypes::TTN_stack_version version);
|
||||
|
||||
private:
|
||||
|
||||
// Return the data to send
|
||||
@@ -251,8 +253,8 @@ private:
|
||||
unsigned long _start_prep = 0; // timestamp of preparing command
|
||||
unsigned long _start = 0; // timestamp of last set timeout
|
||||
unsigned long _timeout = 100; // timeout duration
|
||||
uint32_t _rxdelay1 = 1000; // delay from last moment of sending to receive RX1 window
|
||||
uint32_t _rxdelay2 = 2000; // delay from last moment of sending to receive RX2 window
|
||||
uint32_t _rxdelay1 = 5000; // delay from last moment of sending to receive RX1 window
|
||||
uint32_t _rxdelay2 = 6000; // delay from last moment of sending to receive RX2 window
|
||||
uint8_t _busy_count = 0; // Number of times the module replied with "busy"
|
||||
uint8_t _retry_count = 0; // Number of retries of current TX command
|
||||
RN_state _state = RN_state::idle;
|
||||
|
||||
@@ -135,6 +135,14 @@ struct C018_data_struct {
|
||||
return res;
|
||||
}
|
||||
|
||||
bool setTTNstack(RN2xx3_datatypes::TTN_stack_version version) {
|
||||
if (!isInitialized()) { return false; }
|
||||
bool res = myLora->setTTNstack(version);
|
||||
|
||||
C018_logError(F("setTTNstack"));
|
||||
return res;
|
||||
}
|
||||
|
||||
bool setFrequencyPlan(RN2xx3_datatypes::Freq_plan plan) {
|
||||
if (!isInitialized()) { return false; }
|
||||
bool res = myLora->setFrequencyPlan(plan);
|
||||
@@ -419,6 +427,9 @@ struct C018_ConfigStruct
|
||||
if ((baudrate < 2400) || (baudrate > 115200)) {
|
||||
reset();
|
||||
}
|
||||
if (stackVersion >= RN2xx3_datatypes::TTN_stack_version::TTN_NOT_SET) {
|
||||
stackVersion = RN2xx3_datatypes::TTN_stack_version::TTN_v2;
|
||||
}
|
||||
}
|
||||
|
||||
void reset() {
|
||||
@@ -432,6 +443,7 @@ struct C018_ConfigStruct
|
||||
resetpin = -1;
|
||||
sf = 7;
|
||||
frequencyplan = RN2xx3_datatypes::Freq_plan::TTN_EU;
|
||||
stackVersion = RN2xx3_datatypes::TTN_stack_version::TTN_v2;
|
||||
joinmethod = C018_USE_OTAA;
|
||||
}
|
||||
|
||||
@@ -447,6 +459,7 @@ struct C018_ConfigStruct
|
||||
uint8_t frequencyplan = RN2xx3_datatypes::Freq_plan::TTN_EU;
|
||||
uint8_t joinmethod = C018_USE_OTAA;
|
||||
uint8_t serialPort = 0;
|
||||
uint8_t stackVersion = RN2xx3_datatypes::TTN_stack_version::TTN_v2;
|
||||
};
|
||||
|
||||
|
||||
@@ -537,6 +550,7 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
|
||||
uint8_t sf;
|
||||
uint8_t frequencyplan;
|
||||
uint8_t joinmethod;
|
||||
uint8_t stackVersion;
|
||||
|
||||
{
|
||||
// Keep this object in a small scope so we can destruct it as soon as possible again.
|
||||
@@ -554,6 +568,7 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
|
||||
sf = customConfig->sf;
|
||||
frequencyplan = customConfig->frequencyplan;
|
||||
joinmethod = customConfig->joinmethod;
|
||||
stackVersion = customConfig->stackVersion;
|
||||
|
||||
{
|
||||
addFormTextBox(F("Device EUI"), F("deveui"), customConfig->DeviceEUI, C018_DEVICE_EUI_LEN - 1);
|
||||
@@ -592,6 +607,16 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
|
||||
|
||||
addFormSelector(F("Frequency Plan"), F("frequencyplan"), 4, options, values, NULL, frequencyplan, false);
|
||||
}
|
||||
{
|
||||
String options[2] = { F("TTN v2"), F("TTN v3") };
|
||||
int values[2] = {
|
||||
RN2xx3_datatypes::TTN_stack_version::TTN_v2,
|
||||
RN2xx3_datatypes::TTN_stack_version::TTN_v3
|
||||
};
|
||||
|
||||
addFormSelector(F("TTN Stack"), F("ttnstack"), 2, options, values, NULL, stackVersion, false);
|
||||
}
|
||||
|
||||
addFormNumericBox(F("Spread Factor"), F("sf"), sf, 7, 12);
|
||||
|
||||
|
||||
@@ -681,6 +706,7 @@ bool CPlugin_018(CPlugin::Function function, struct EventStruct *event, String&
|
||||
customConfig->sf = getFormItemInt(F("sf"), customConfig->sf);
|
||||
customConfig->frequencyplan = getFormItemInt(F("frequencyplan"), customConfig->frequencyplan);
|
||||
customConfig->joinmethod = getFormItemInt(F("joinmethod"), customConfig->joinmethod);
|
||||
customConfig->stackVersion = getFormItemInt(F("ttnstack"), customConfig->stackVersion);
|
||||
serialHelper_webformSave(customConfig->serialPort, customConfig->rxpin, customConfig->txpin);
|
||||
SaveCustomControllerSettings(event->ControllerIndex, (byte *)customConfig.get(), sizeof(C018_ConfigStruct));
|
||||
}
|
||||
@@ -834,6 +860,10 @@ bool C018_init(struct EventStruct *event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!C018_data->setTTNstack(static_cast<RN2xx3_datatypes::TTN_stack_version>(customConfig->stackVersion))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!C018_data->txUncnf("ESPeasy (TTN)", Port)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user