In this section, we will move the application developed in the previous section and set it up to run as a service on the SmartServer IoT. Here is what needs to be done.
- Move the application and npm package files to a location on the SmartServer IoT.
- Install the application with npm.
- Run the application from an SSH session.
- Set the application up to run as a service under supervisorctl.
Moving the Application to the SmartServer
In this step, you will copy this application to the folder
- Connect to the SmartServer as user apollo using winscp or other sftp client.
- Create a new folder called /var/apollo/data/apps/point-monitor as shown in the following screenshot.
- Copy these files from the point-monitor project directory to the folder you just created.
Installing the NPM Packages
You have moved the application files (pointmonitor.js) along with the package.json file that describes the modules used by the application. The following procedure only works if your SmartServer IoT is connected to a network that can reach the internet. This is required for npm to complete installation of dependent modules.
- Use putty.exe to connect to the ssh console as user apollo.
- After about 30 seconds, npm install will add 73 packages that comprise the mqtt.js, and collections.js modules used in this example.
- Run the application by typing:
- The application will report operation as observed in the debugger to the console as shown above.
- Type <cntrl>+c to terminate the application.
Setting Up pointmonitor to Run as a Service
Many of the software modules that make up the SmartServer IoT, are managed by supervisorctl. In this section, we will create a conf file to run the pointmonitor.js application under supervisorctl.
sudo nano /etc/supervisor/conf.d/pointmonitor.conf
- The following lines need to be added to this file:
<cntrl>+oto write the file.
<cntrl>+xto exit nano.
Now you can reboot the SmartServer IoT, and the pointmonitor.js application will run as a service in the following steps, you will understand how to confirm this.
- After the SmartServer IoT reboot, use putty.exe to connect to the SSH console.
- The pointmonitor application is show in the list of services running on your SmartServer IoT along with the other services and modules that implement the SmartServer IoT. Type
exitto return to the bash shell.
- If you want to monitor the standard output stream for the pointmonitor application running as a service, type
tail -f /var/log/supervisor/stdout-pointmonitor.log
- You can use
sudo supervisorctlto issue commands to stop and restart the pointmonitor application.
This application as written is reporting the results of every network variable poll request that is done by the lon:echlte engine. Here are some explorations you should try.
- You can control the state of the pointmonitor application by typing
sudo supervisorctland using supervisorctl commands like
Modify the monitorSpecs object array so the monitoring object for the points of interest generate data events on 'change' as shown in the following source code fragment.
- Observe how the application responds when the monitored devices are power down. You will see monitor rate adjustments being made to leave only a single active point. This type of behavior is most critical in a bandwidth limited channel, like a power line. You could improve this application by leaving only a single actively polled point when a device goes down, and setting up the monitoring when the device health changes to "normal".
- Modify the application to work with your own LON devices.
- Bonus points if you can modify the application to publish an update to
- This last point is a detail you need to understand. An XIF file defines the implementation name for network variables on a devices interface. When dealing with interfaces in the IAP/MQ, you need to use the names as defined by the functional block definition in the resource file. For example, if you use the Open CT browser to browse the temperature sensor function block. You will see the network variable listed by its program name as defined in the XIF file (nvoTemperature), but the topic to access this point in IAP/MQ is nvoHVACTemp as defined in the resource file as shown here. The actual program name for the variable is part of the label property within the lon.cfg object within the datapoint object.
You have successfully run this application as a service. You will need to remove or change the conf file extension of the
/etc/supervisor/conf.d/pointmonitor.conf file to prevent the application from running as a service.