Skip to content

Commit

Permalink
Add update timezone command support
Browse files Browse the repository at this point in the history
  • Loading branch information
robgee86 authored and pennam committed May 17, 2024
1 parent 0f84486 commit 92826b6
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
7 changes: 7 additions & 0 deletions src/ArduinoIoTCloudTCP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,13 @@ void ArduinoIoTCloudTCP::handleMessage(int length)
}
break;

case CommandId::TimezoneCommandDownId:
{
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] timezone update received", __FUNCTION__, millis());
_thing.handleMessage((Message*)&command);
}
break;

case CommandId::LastValuesUpdateCmdId:
{
DEBUG_VERBOSE("ArduinoIoTCloudTCP::%s [%d] last values received", __FUNCTION__, millis());
Expand Down
14 changes: 10 additions & 4 deletions src/ArduinoIoTCloudThing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,20 @@ void ArduinoCloudThing::update() {
}

/* Handle external events */
switch (_command) {
switch (_command.c.id) {
case LastValuesUpdateCmdId:
if (_state == State::RequestLastValues) {
DEBUG_VERBOSE("CloudThing::%s Thing is synced", __FUNCTION__);
nextState = State::Connected;
}
break;

/* We have received a timezone update */
case TimezoneCommandDownId:
TimeService.setTimeZoneData(_command.timezoneCommandDown.params.offset,
_command.timezoneCommandDown.params.until);
break;

/* We have received a reset command */
case ResetCmdId:
nextState = State::Init;
Expand All @@ -86,7 +92,7 @@ void ArduinoCloudThing::update() {
break;
}

_command = UnknownCmdId;
_command.c.id = UnknownCmdId;
_state = nextState;
}

Expand All @@ -95,9 +101,9 @@ int ArduinoCloudThing::connected() {
}

void ArduinoCloudThing::handleMessage(Message* m) {
_command = UnknownCmdId;
_command.c.id = UnknownCmdId;
if (m != nullptr) {
_command = m->id;
memcpy(&_command, m, sizeof(CommandDown));
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/ArduinoIoTCloudThing.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class ArduinoCloudThing : public CloudProcess {
};

State _state;
CommandId _command;
CommandDown _command;
TimedAttempt _syncAttempt;
PropertyContainer _propertyContainer;
unsigned int _propertyContainerIndex;
Expand Down

0 comments on commit 92826b6

Please sign in to comment.