Sending notifications from raw websocket


In extending the nodejs simulater device:

I need to send notification and send DB.Store commands through the websocket. I searched the forum and the docs but i am unable to get it working.

Here is a sample of what i have so far:

    import Websocket from "ws";   
    import fetch from 'node-fetch'; 
    import chalk from "chalk";

    let connRPC = null;
    const RPC = 'wss://' + accessToken;

    connRPC = new Websocket(RPC, {origin: RPC});
    connRPC.on('message', msg => {
        let req = JSON.parse(msg), resp = {};  // request and response RPC frames
        if (req.method === 'Sys.GetInfo') {
            resp = {id:, result: {arch: 'nodejs', app: 'app1'}};
        } else if (req.method === 'RPC.Describe') {
            resp = {id:, result: null};
        } else if (req.method === 'RPC.List') {
            resp = {id:, result: ['Sys.GetInfo', 'RPC.List', 'RPC.Describe', 'RPC.Command']};
        } else if (req.method === 'RPC.Command') {
            resp = {id:, result: {success: true}};
        } else {
            resp = {id:, error: {code: -32601, message: 'method not found'}};
        console.log(chalk.magenta('RPC:'), JSON.stringify(req), '->', JSON.stringify(resp));
        connRPC.send(JSON.stringify(resp));  // Send reply to mDash

    connRPC.on('error', error => {
        console.error('Websocket error'), error);

    setInterval(() => {
        const msg = {
            name: "rpc.out.MyStat", // "rpc.out.EVENT_NAME", in our case rpc.out.MyStat
            data: {temperature: 12.34}  // Your event payload - arbitrary

        // This is not working. Nothing is saved in the database i mdash. I have tried to use the DB.Store as well but with any luck.
        console.log(chalk.bgYellow('Send sensor readings')), msg);
    }, 5000)

Can anyone give a pointer? I think it is related to the json format i am sending, but the documentation does not help formatting raw messages - only how to use the mongoose os methods.

Thanks in advance