Last active
September 11, 2020 20:40
-
-
Save cpq/a89ba60a842ddbc2cac5414d16a74ff4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simulate mdash.net device. To run this script, install ws library first: | |
// $ npm -g i ws | |
// $ node devsim.js MDASH_DEVICE_TOKEN | |
const Websocket = require('ws'); // npm install -g ws | |
const pass = process.argv[2]; // Device password | |
const addr = 'wss://mdash.net/api/v2/rpc?access_token=' + pass; | |
const ws = new Websocket(addr, {origin: addr}); | |
ws.on('error', msg => console.log(msg.toString())); | |
ws.on('message', msg => { | |
const obj = JSON.parse(msg.toString()); | |
console.log('Got message:', obj); | |
if (obj.method == 'Sys.GetInfo') // Answer on Sys.GetInfo RPC call | |
ws.send(JSON.stringify({id: obj.id, result: {app: 'sim', arch: 'js'}})); | |
}); | |
// Send a HTTP.Request notification | |
setTimeout( | |
ev => ws.send(JSON.stringify({ | |
method: 'HTTP.Request', | |
params: { | |
url: 'http://HOST:PORT', | |
method: 'POST', | |
body: 'my data', | |
headers: {HDR1: 'custom header'} | |
} | |
})), | |
1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment