Send instant messages to iOS and Android devices with LM
Example: Send instant messages to iOS and Android devices with Logic Machine
Task
How to send instant messages, like alerts to the users phone or tablet? There are ready apps for iOS and Android devices to handle this task.
For example, there is an app called Pushover, available for iOS, Android and desktop clients.
Before using the example below, please register on the Pushover website to get user ID and Application API Token and insert them into even-based script instead of userkey.
Add the following program in User Libraries
- require 'ssl.https'
-
- local pushover_url = 'https://api.pushover.net/1/messages.json'
- local token = 'PUT YOUR APPLICATION TOKEN HERE' -- Your application token, at least 1 app must be created at pushover.net to get the application token
- local user = 'PUT YOUR USER TOKEN HERE' -- Your user token, retrieve from settings inside pushover application for android or ios
-
- function pushover(title, message, sound, priority, retry, expire)
- if priority < -2 then priority = -2 end
- if priority > 2 then priority = 2 end
- if retry < 30 then retry = 30 end
- if retry > 86400 then retry = 86400 end
- if expire < retry then expire = retry end
- if expire > 86400 then expire = 86400 end
- if priority == 2 then prioritystring = ''.. priority .. '&retry=' .. retry .. '&expire=' .. expire ..'' else prioritystring = priority end
- now = os.date('*t')
- timestamp = string.format('%02d', now.day) .. '-' .. string.format('%02d', now.month) .. '-' .. now.year .. ' ' .. string.format('%02d', now.hour) .. ':' .. string.format('%02d', now.min) .. ':' .. string.format('%02d', now.sec)
- local data_str = 'user=' .. user .. '&message=' .. message .. ' ' .. timestamp .. '&token=' .. token .. '&title=' .. title .. '&sound=' .. sound .. '&priority=' .. prioritystring .. ''
- local res, code, headers, status = ssl.https.request(pushover_url, data_str)
- end
Event-based script
Add the following script which will send pushover notification with sound
- require("user.pushover")
- --Set title for message
- title = 'LogicMachine'
- --Set message to be send (current time and date will be added automaticly)
- message = 'Storing LBK1'
- --Set sound to be played on device
- --pushover(default), bike, bugle, cashregister, classical, cosmic, falling, gamelan, incoming, intermission, magic, mechanical, pianobar, siren, spacealarm, tugboat, alien, climb, persistent, echo, updown, none
- sound = 'updown'
- --Set priority (-2 = no notification only badge and message in app, -1 = notification without sound or vibration, 0 = default, 1 = bypass user quiet hours (set in App not iOS), 2 = bypass user quiet hours (set in App not iOS) + acknowledge required
- priority = 1
- --Seconds to retry when not acknowledged, minimum = 30 (only used with priority 2)
- retry = 30
- --Seconds to expire retry when not acknowledged, maximum = 86400 (24 hrs, only used with priority 2)
- expire = 3600
- --Activate Pushover with parameters above
- pushover(title, message, sound, priority, retry, expire)
Created by Erwin van der Zwart