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

Proposal: $implementation/reboot #693

Open
maruel opened this issue Nov 8, 2020 · 0 comments
Open

Proposal: $implementation/reboot #693

maruel opened this issue Nov 8, 2020 · 0 comments

Comments

@maruel
Copy link
Contributor

maruel commented Nov 8, 2020

There's already $implementation/reset (which doesn't seem to work on 3.0.1) but none to reboot. It'd be useful to do a end-to-end test after flashing over serial to prepare for OTA update later.

I think the implementation would be relatively simple but I want to double check with owners if they would want such patch.

I think it would boil down to the following:

https://github.com/homieiot/homie-esp8266/blob/develop/src/Homie/Boot/BootNormal.hpp

A new enum SUB_IMPLEMENTATION_REBOOT

https://github.com/homieiot/homie-esp8266/blob/develop/src/Homie/Boot/BootNormal.cpp

In BootNormal::_advertise():

    case AdvertisementProgress::GlobalStep::SUB_IMPLEMENTATION_REBOOT:
      packetId = Interface::get().getMqttClient().subscribe(_prefixMqttTopic(PSTR("/$implementation/reboot")), 1);
      if (packetId != 0) _advertisementProgress.globalStep = AdvertisementProgress::GlobalStep::SUB_IMPLEMENTATION_RESET;
      break;

Then a new function that would be called in BootNormal::_onMqttMessage():

bool HomieInternals::BootNormal::__handleReboot(char * topic, char * payload, const AsyncMqttClientMessageProperties& properties, size_t len, size_t index, size_t total) {
  if (
    _mqttTopicLevelsCount == 3
    && strcmp_P(_mqttTopicLevels.get()[1], PSTR("$implementation")) == 0
    && strcmp_P(_mqttTopicLevels.get()[2], PSTR("reboot")) == 0
    && strcmp_P(_mqttPayloadBuffer.get(), PSTR("true")) == 0
    ) {
    Interface::get().getMqttClient().publish(_prefixMqttTopic(PSTR("/$implementation/reboot")), 1, true, "");
    Interface::get().getLogger() << F("Flagged for reboot by network") << endl;
   _flaggedForReboot = true;
    return true;
  }
  return false;
}

https://github.com/homieiot/homie-esp8266/blob/develop/docs/others/homie-implementation-specifics.md
Update to add the new topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants