Application doesn't start automatically after reboot

My first application is quite large at 3000 lines and I think I've followed the guidelines OK. It has the required installed() updated() uninstalled() and initialize() methods. Everything seems fine I can install, run, re-run the app from within the UI but after a reboot the app doesn't run. The initialize() method is never called. I even reduced it to a single log statement , it doesn't appear in the log. What could be wrong ?

I have totally uninstalled the app and code and then re-installed it with no change.

def initialize()
{
	log.info "${app.name} alpha3b  Initialized"
}

After a restart it can be run successfully from the UI where it immediately displays it's preferences configuration.

Just as background there's an associated driver with this - that does startup OK after a reboot. It generates a lot of events and could be doing so for handlers in the main app that have not yet been setup. Indeed I can see some log statements (from my main app that never initialized) and so it seems they are processed in the main app ..seems the code is running as such in that respect. The application uses atomicState extensively

I have also tried disabling the device driver so events didn't arrive early but again my main app does not run initialize() after a reboot.

So what am I missing and what could cause this ? I realise you're going to say .. post your code but there's a lot of it ... I can dig out the preferences and definitions sections if they might be contributing to this ? There are no errors logged on a UI start of the application.

K

I've experienced a similar issue with Envisalink Integration. I never figured out why, but it started working properly all by itself, or so it seemed. I'm sorry I don't have more valuable info for you only commiseration.

If you need initialize to run in a driver at system startup one need add initialize as a capability to the driver.

This is in the application .. rather than the driver

If you want an application to start after a reboot, you need to subscribe to the reboot event.

subscribe(location, "systemStart", hubRestartHandler)

And then have your handler start up any processing as needed.

def hubRestartHandler(evt) {
}

1 Like

Well I've totally missed that.. thanks...

It's strange I've looked at other peoples code (that startup OK after a reboot) and not seen this.. but I'll give it a go

That's not true. None of my apps subscribe to that event and they all start up at boot.

@kevin in your initialize function, are you subscribing to your device events using subscribeNow()?

It all depends on what you are doing. If you are using schedule or runevery to run methods they will continue after a reboot. If you use runin to do loops then in a reboot they may be lost.

This is a way of having something execute on a system reboot.

Hmmm , how might I do that if I can't execute any code at restart ?

Yes...but that's not required. Only if your app is running on a schedule. If you are subscribing to events, then you don't have to do that.

Put that in your initialize. Once your app is subscribed to it, it will execute the method on every reboot.

You have to re-subscribe to your events....
subscribeNow() should be in your initialize function if you are subscribing to device events.

It all depends on what you are trying to accomplish with the reboot.

One of my apps sends me a notification every time it reboots... I use this method.

Another one of my apps reconnects to a telnet session after every reboot. I use this method.

If you are just worried about polling or a looping method you don't really need this.

I'm just explaining how to execute something after a reboot.

Yes....but that isn't required to initialize your app after a reboot. You're talking about subscribing to reboot events. The OP is saying his app isn't running after reboot, which I don't understand.

So initialize() is not routinely called on a reboot (but would be if I added Gavins' subscribe) ?

After initialisation my app is purely event driven. So an alternative is to generate a 'reinitialize' event from my device driver ? Which in my case is used to connect to & create subscriptions to the MQTT topics the driver needs.

For drivers, initialize is execute after a reboot if they have the initialize capability.

For apps, you need to subscribe to have a method of your choosing execute after a reboot.

Without knowing exactly what is going on in his code, I'm guessing he wants something to start executing on a reboot. Maybe has a loop running that doesn't continue after. That is why I'm suggesting this.

1 Like

What is your initialize function currently?

NO!!! He's saying the app isn't starting at all after reboot. As in:

That's why all your talk of subscribing to reboot is just confusing the issue. The issue is his initialize function.

I understand what he is saying. Without code it can be interpreted different ways.

I'll let you guys sort it out.

It basically goes out and connects to an MQTT broker and publishes enabled HE devices for MQTT status and control. It also subscribes to MQTT topics that are mapped to HE virtual devices. Lastly it tries to discover any new devices on MQTT that use the HomeAssistant or homie3 discovery protocols. It's quite arduous as it does a lot of work building all these subscriptions