README
IoT Platform
Lynxari Websocket Feed Application
Install
Lynxari Server App for streaming sensor data on a websocket server
<script type="module">
import agilatechLynxariWsfeedApplication from 'https://cdn.skypack.dev/@agilatech/lynxari-wsfeed-application';
</script>
IoT Platform
gt; npm install @agilatech/lynxari-wsfeed-application
Install in the same directory in which lynxari is installed. Create a config.json file to suit.
The purpose of this application is to feed data from devices to a websocket. Remote clients which are allowed by the app configuration may connect to the websocket to receive the data feed. This provides a more direct method to get data while at the same time having such data data automatically pushed to the client.
This application runs on the Agilatech® Lynxari IoT platform. As such, it is not applicable for other environments.
To use it with Lynxari, simply insert its object definition as an element in the apps array in the applist.json file. On startup, the Lynxari server reads applist.json and starts all applications found there.
A config.json configuration file must be present in the module's main directory. For this module, that will be within the Lynxari home directory in node_modules/@agilatech/lynxari-wsfeed-application/config.json
The config.json file contains objects which define the security parameters, what hosts are allowed to connect, and the devices which are monitored. A sample config file is provided to give an example.
First, the security object:
Next is an array of allowed clients. If the hostname or IP address is not a member of the array, then it's request will be ignored. Only those clients whose domain or IP appear in the allow array will be served.
The devices array contains device definitions which will be served to Websocket receivers.
Note that each device starts its own server, and listens on the given port. Devices may be duplicated with different ports.
There is no limit to the number of device objects which may appear in the devices array. The config.json file must be valid JSON.
A sample config file:
{
"security": {
"autoAccept": false,
"usePlatformTLS": false
},
"allow": [
"192.168.44.100",
"192.168.44.155",
"agilatech.com",
"10.0.248.*"
],
"devices": [
{
"name": "VL6180",
"port": 8082,
"values": ["range"]
},
{
"name": "MPU9250",
"port": 8084,
"values": ["accelx", "accely", "accelz"]
}
]
}
A typical minimum client-side program might look like this:
<script>
const wss = new WebSocket(`wss://localhost:8082`, 'wsfeed-protocol');
wss.onmessage = function(evt) {
console.log(`Received new wss data ${evt.data}`);
const data = JSON.parse(evt.data);
message.innerHTML = data.value;
}
</script>
Note that the Lynxari wsfeed app uses the protocol 'wsfeed-protocol'. This protocol string must be present in the websocket constructor. If missing or different, the connection will be refused by the server.
Unless the secure certificate loaded into Lynxari is signed by an industry trusted certificate authority contained in the Web broswer, a client-side Web program connecting to a wss websocket will likely fail. To overcome this error, the signing authority certificate must be loaded into the browser and trusted. Different browsers have different mechanisms for doing this, and the top three are covered here:
macOS Utilities contains a Keychain Access program which handles all the certificates for the operating system. Safari uses this system-wide access rather than loading certificates into the browswer itself. To load an Certificate Authority certificate in the Keychain Access:
On a Mac, Google Chrome accesses the system keychain, so the above instructions for Safari also apply when running Chrome on macOS. On other systems:
Copyright © 2018-2019 Agilatech®. All Rights Reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.