convert lock state to string
This commit is contained in:
@@ -124,9 +124,7 @@ void Network::onMqttDataReceived(char *&topic, byte *&payload, unsigned int &len
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Network::publishKeyTurnerState(const KeyTurnerState &state)
|
void Network::publishKeyTurnerState(const char* state)
|
||||||
{
|
{
|
||||||
char cstr[10];
|
_mqttClient.publish(mqtt_topc_lockstate, state);
|
||||||
itoa((int)state.lockState, cstr, 10);
|
|
||||||
_mqttClient.publish(mqtt_topc_lockstate, cstr);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ public:
|
|||||||
void initialize();
|
void initialize();
|
||||||
void update();
|
void update();
|
||||||
|
|
||||||
void publishKeyTurnerState(const KeyTurnerState& state);
|
void publishKeyTurnerState(const char* state);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void onMqttDataReceivedCallback(char* topic, byte* payload, unsigned int length);
|
static void onMqttDataReceivedCallback(char* topic, byte* payload, unsigned int length);
|
||||||
|
|||||||
48
Nuki.cpp
48
Nuki.cpp
@@ -25,21 +25,65 @@ void Nuki::update()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
vTaskDelay( 200 / portTICK_PERIOD_MS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vTaskDelay( 100 / portTICK_PERIOD_MS);
|
vTaskDelay( 100 / portTICK_PERIOD_MS);
|
||||||
_nukiBle.requestKeyTurnerState(&_keyTurnerState);
|
_nukiBle.requestKeyTurnerState(&_keyTurnerState);
|
||||||
|
|
||||||
|
char str[20];
|
||||||
|
stateToString(_keyTurnerState.lockState, str);
|
||||||
Serial.print(F("Nuki lock state: "));
|
Serial.print(F("Nuki lock state: "));
|
||||||
Serial.println((int)_keyTurnerState.lockState);
|
Serial.println(str);
|
||||||
|
|
||||||
if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState)
|
if(_keyTurnerState.lockState != _lastKeyTurnerState.lockState)
|
||||||
{
|
{
|
||||||
_network->publishKeyTurnerState(_keyTurnerState);
|
_network->publishKeyTurnerState(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(KeyTurnerState));
|
memcpy(&_lastKeyTurnerState, &_keyTurnerState, sizeof(KeyTurnerState));
|
||||||
|
|
||||||
vTaskDelay( 20000 / portTICK_PERIOD_MS);
|
vTaskDelay( 20000 / portTICK_PERIOD_MS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Nuki::stateToString(LockState state, char* str)
|
||||||
|
{
|
||||||
|
switch(state)
|
||||||
|
{
|
||||||
|
case LockState::uncalibrated:
|
||||||
|
strcpy(str, "uncalibrated");
|
||||||
|
break;
|
||||||
|
case LockState::locked:
|
||||||
|
strcpy(str, "locked");
|
||||||
|
break;
|
||||||
|
case LockState::locking:
|
||||||
|
strcpy(str, "locking");
|
||||||
|
break;
|
||||||
|
case LockState::unlocked:
|
||||||
|
strcpy(str, "unlocked");
|
||||||
|
break;
|
||||||
|
case LockState::unlatched:
|
||||||
|
strcpy(str, "unlatched");
|
||||||
|
break;
|
||||||
|
case LockState::unlockedLnga:
|
||||||
|
strcpy(str, "unlockedLnga");
|
||||||
|
break;
|
||||||
|
case LockState::unlatching:
|
||||||
|
strcpy(str, "unlatching");
|
||||||
|
break;
|
||||||
|
case LockState::calibration:
|
||||||
|
strcpy(str, "calibration");
|
||||||
|
break;
|
||||||
|
case LockState::bootRun:
|
||||||
|
strcpy(str, "bootRun");
|
||||||
|
break;
|
||||||
|
case LockState::motorBlocked:
|
||||||
|
strcpy(str, "motorBlocked");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
strcpy(str, "undefined");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user