Self._plugin_manager.send_plugin_message does not trigger onDataUpdaterPluginMessage

Hi,

I'm working on a plugin, but can't get the initial data to pass from server to js viewmodel after the server starts.

# server
class HelloworldPlugin(octoprint.plugin.StartupPlugin,
                       octoprint.plugin.TemplatePlugin,
                       octoprint.plugin.SettingsPlugin,
                       octoprint.plugin.AssetPlugin,
                       octoprint.plugin.EventHandlerPlugin,
                       octoprint.plugin.ProgressPlugin):

    def __init__(self):
        self._filaments = None

    def on_after_startup(self):
        self._plugin_manager.send_plugin_message(self._identifier, dict(filaments=self._filaments))

// client
    self.onBeforeBinding = function() {
        console.log("HI before binding"); // <- this is printed in console
    }

    self.onStartupComplete = function() {
        console.log("HI after startup");  // <- this is printed in console
    }

    self.onDataUpdaterPluginMessage = function(plugin, data) {
        console.log("HELLO plugin: " + plugin);  // <- this is NOT printed in the console. Why??
        if (plugin != "helloworld" || !data) {
            return;
        }
    }

onDataUpdaterPluginMessage is not called. Why?

Btw, plugin is registered and server starts without errors.

Basically you haven't sent any data to the client, so there are no messages would be my guess.

Your call to 'on_after_startup' in the server side is executed once only on server startup. Your OctoPrint UI is not going to be connected to receive this message at that time, so it goes nowhere.

If you want to pass initial data to the frontend, you must do this every time the UI loads. You might be able to react to an event, but there is not one I can see that guarantees your plugin will be ready to receive the data in the frontend. Often people will make an API call from the UI for initial load data, but this can be annoying as it increases the UI load time for all the HTTP communication.

1 Like

You might consider returning the initial data set in on_settings_load of your python file as an alternative to sending plugin message, but that would really depend on your use case and when the data is fetched and from where, etc.

Thank you for your help. I have used octoprint.plugin.SimpleApiPlugin mixin.

The problem was port 443 was not enabled by default, therefore I got Https connection errors.
I'm using VS code.