In my work, I often run simulation scripts using MATLAB, which can sometimes take several hours or even days. The running time is not exactly predictable and therefore I would like to be informed as soon as the script is ready, especially also if an error occurs. This way I can fix the error directly and run the script again without waiting for the time it would take for the script to run without errors. Additionally, I no longer need to keep an eye on the console output to see if the execution was successful or if an error occurred.
I was looking for a simple solution and found Pushover.
Pushover is a service using a REST API that receive messages and send them to device clients, e.g. the Pushover app for Android.
After a few steps, the script is able to send you messages on your smartphone:
- Register at https://pushover.net/ to get a User Token.
- Create an API Token at https://pushover.net/apps/build.
- Download the Pushover device client for Android or iOS, login with your login data and add your device to your user account.
POST
anHTTPS
request tohttps://api.pushover.net/1/messages.json
by using your User Token and API Token.
That’s it.
In my case the MATLAB function for sending a message to my smartphone is:
function pushover(title, message)
API_TOKEN = 'api_abc123'; % insert your own API Token
USER_TOKEN = 'user_abc123'; % insert your own User Token
if length(message) > 512
disp('Maximum character length for messages is 512.');
end
post_params = {'token', API_TOKEN,... % API token
'user', USER_TOKEN,... % user's ID token
'message', message,... % message to push
'title', title}; % message title in notification bar
try
urlread('https://api.pushover.net/1/messages.json', 'Post', post_params);
catch ME
disp(ME.message);
disp(ME.stack);
end
disp('Send message to Pushover...');
end
Using this feature results in notifications in my Pushover Android client:
The message length is limited to 512 characters and each application (=one API Token) can send 10.000 messages per month 1. Furthermore one has to pay a one-time purchase to receive notifications on e.g. your android client 2.
For me, this simple feature of sending notifications to my smartphone is enough. However, there are many more options. It should be noted that currently no end-to-end encryption is supported 3. It is therefore better not to send private data via the service.