Skip to content

How to send push notifications from 3rd party plugins?

Gaston Dombiak edited this page Jul 29, 2021 · 4 revisions

Introduction

OctoPod plugin for OctoPrint allows 3rd party plugins to send arbitrary notifications to OctoPod app on iPhone, iPad and Apple Watch. It is very simple to use since OctoPrint did most of the leg work via Helpers.

How can I use this functionality from my plugin?

Your first step is to use OctoPrint's helper to locate the function exposed by OctoPod. You might want to keep this function as a variable for future usage.

helpers = self._plugin_manager.get_helpers("octopod", "apns_notification")
if helpers and "apns_notification" in helpers:
    self.push_notification = helpers["apns_notification"]

You can send notifications with just text or text and an image. The example below shows how you can use the exposed function to send just text.

try: self.push_notification("My message goes here") except AttributeError: pass

The example below shows how you would use the exposed function when you need to include an image besides text.

from PIL import Image

image = self.image("http://octopi.local/webcam/?action=snapshot")
try: self.push_notification("My message goes here", image) except AttributeError: pass

Reminder

OctoPod is an open source and free project. There is a cost for hosting OctoPod APNS services that is paid with the help of OctoPod sponsors. To keep costs low, we use the cheapest service that has important network, CPU and memory limitations. Be mindful when using this functionality to not exceed limits of the service. Of course, you are welcome to become a sponsor of the project which will help go to a higher tier of the service with smaller limitations. :)