Template

Send SIA events by Notify My Android
Post Reply
gol
Webbplatsadministratör
Posts: 72
Joined: Sun 01 Jun 2014, 19:38

Template

Post by gol »

This is program template written in Javascript that can be used to send SIA-events from the SPC panel by Notify My Android. You need to have a NMA account and a API-key from http://www.notifymyandroid.com.

To be able to run the program you need to install NodeJS and some NodeJS addon modules.

Install NodeJS

Code: Select all

sudo apt-get update
sudo wget http://node-arm.herokuapp.com/node_latest_armhf.deb
sudo dpkg -i node_latest_armhf.deb
Check the installation with: node -v

Install required addon modules

Code: Select all

cd <INSTALL_DIR>
sudo npm install websocket
sudo npm install nma
Install spc-notify-nma

Code: Select all

cd <INSTALL_DIR>
tar xzvf spc-notify-nma.tar.gz
cd spc-notify-nma
Modify the settings in config.json according your environment and NMA API-key.
In spc-notify-nma.js, function manageSiaEvent() you have to add all SIA-event types you want to be managed by the program. Look in the SPC documentation for definitions of the SIA-event types.

Run the program with: ./spc-notify-nma.js
Attachments
spc-notify-nma-1.0.tar.gz
(1.39 KiB) Downloaded 685 times
BigSwede
Posts: 4
Joined: Tue 09 Aug 2016, 08:11

Re: Template

Post by BigSwede »

The script (node-spc-notify-nma.js) did not work for me. I had to change the last function nmaMessage(subject, text).

I got an "TypeError: callback is not a function" until I changed the nma command.
It seems like the nma command is expecting an callback at the end which I set to null in the code below.
https://github.com/randallagordon/node-nma

This code worked for me.

Code: Select all

/**********************************************************************
* nmaMessage  - Send message by using NMA push
**********************************************************************/
function nmaMessage(subject, text){

   // Send message
   // nma(config.api_key, 'spc-notify', subject, text, 0, "http://www.lundix.se/");

        nma({
          "apikey": config.api_key,
          "application": "SPC Notify",
          "event": subject,
          "description": text,
          "priority": 0, // Priority
          "url": "http://www.lundix.se/",
          "content-type": "text/plain"
        }, null);

}

Last edited by BigSwede on Tue 09 Aug 2016, 13:29, edited 1 time in total.
BigSwede
Posts: 4
Joined: Tue 09 Aug 2016, 08:11

Re: Template

Post by BigSwede »

Here is my example of SystemD startup script for notify nma script.
Please adjust path's to match your system.

Create file in /etc/systemd/system

Code: Select all

cd /etc/systemd/system
touch spc-notify-nma.service
chmod 664 spc-notify-nma.service
nano spc-notify-nma.service

Code: Select all

[Unit]
Description=SPC Notify NMA plugin
After=spc-web-gateway.service

[Service]
ExecStart=/usr/bin/node /opt/spc-web-gateway/plugins/node-spc-notify-nma-master/node-spc-notify-nma.js
Restart=always
RestartSec=10
User=pi

[Install]
WantedBy=multi-user.target
Update SystemD, install and start.

Code: Select all

systemctl daemon-reload
systemctl enable spc-notify-nma.service
systemctl start spc-notify-nma.service
Good luck.
Post Reply