Creating a Custom SSGSCP Server

For production environments using SSGSCP, you will need to run your own server to receive and process measurements. We provide an easy-to-use Node.js module for this purpose. An open-source implementation is available on GitHub.

Installation

1. Create a new project folder and initialize a Node.js project:
npm init
2. Follow the prompts, then set the project type to "module":
npm pkg set type="module"
3. Install the
ssgs
package:
npm i ssgs

Basic Server Example

Create an
index.js
file with the following code. This server listens on the default SSGSCP UDP port 1818 and prints any received sensor data to the console.
import SSGS from 'ssgs'; // Create a server listening on the default SSGSCP port (UDP 1818) const server = new SSGS(1818, client => { // Fired when a new gateway connects and is authorized const uidStr = SSGS.uidToString(client.gatewayUID); console.log(`Gateway ${uidStr} connected.`); // Fired when a sensor measurement is received from this gateway client.onupdate = update => { console.log(`\nSensor Seal ${SSGS.uidToString(update.sensorSealUID)}:`); console.log(` Temperature: ${update.temperature}°C`); console.log(` Vibration: ${update.vibration} mm/s^2`); console.log(` Speed: ${update.rpm} rpm`); }; // Fired when the gateway disconnects client.ondisconnect = () => { console.log(`Gateway ${uidStr} disconnected.`); }; }); console.log('SSGSCP server started on UDP port 1818.');

Authorizing Gateways

To accept a connection, your server must know the gateway's unique ID (UID) and its Pre-Shared Key (PSK). The PSK is generated by the gateway when you run the ssgscpsetup command.

Option 1: Using
authorized.json
(Simple)

Create an
authorized.json
file in your project's root directory. The server will automatically load these credentials. This file must be kept confidential.
{ "authorized_gateways": [ { "description": "Example Gateway on Conveyor A", "uid": "4d ec 5d fa", "key": "67 82 60 ef 97... Paste full key from ssgscpsetup command" } ] }

Option 2: Using a Callback (Advanced)

For dynamic lookups (e.g., from a database), set the
onconnectionattempt
callback.
server.onconnectionattempt = async (gatewayUID) => { // Your logic to check if the gateway is authorized const isAuthorized = await myDatabase.isGatewayAuthorized(gatewayUID); if (isAuthorized) { // Return the key from your database to authorize the connection return await myDatabase.getGatewayKey(gatewayUID); } // Return null to reject the connection return null; };