Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,19 @@ curl -F "path=@settings.json" http://KRAKEN_IP:8081/upload\?path\=/

The DSP software would then notice the settings changes and apply them automatically.

#### Alternative via middleware

You can also use the middleware API to retrive and change the settings.json, the api is avaliable under `http://KRAKEN_IP:8042/settings` and works without enabling the remote mode mentioned in the software startup.

Use a simple GET request to the endpoint to retrive the current settings in json format.
To set a new settings file just send the json data as a POST request to the endpoint.

A typical use would be the following:

* GET request - retrive current settings
* modify settings in json
* POST request - save new settings to kraken


## For Contributors

Expand Down
1 change: 0 additions & 1 deletion _nodejs/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
node_modules/*
*.csv
56 changes: 48 additions & 8 deletions _nodejs/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// This is a Websocket server that is a middleware to interface wth the new Krakensdr app and future things
require('log-timestamp');
const express = require('express')
const cors = require('cors');
const ws = require('ws');
const fs = require('fs');
const crypto = require('crypto');
Expand Down Expand Up @@ -43,7 +44,7 @@ function loadSettingsJson (){
// check if Settings changed via Hash
if (settingsJson.center_freq) {
const oldHash = crypto.createHash('md5').update(JSON.stringify(settingsJson)).digest("hex")
// load ne Data and ten check if there are changes
// load new Data and then check if there are changes
try {
let rawdata = fs.readFileSync(settingsJsonPath);
let newSettings = JSON.parse(rawdata);
Expand Down Expand Up @@ -101,7 +102,7 @@ function websocketPing (){
}

function websocketConnect (){
wsClient = new ws(remoteServer);
wsClient = new ws(remoteServer, {rejectUnauthorized: false});

wsClient.onopen = () => {
// start ping interval
Expand Down Expand Up @@ -160,12 +161,52 @@ function checkForRemoteMode (){

checkForRemoteMode()

if(inRemoteMode){
websocketConnect();
} else {
// when not in Remote mode start websocket server for local connections
// Websocket that sends incomming Data to App
wsServer = new ws.Server({ noServer: true });
wsServer.on('connection', socket => {
console.log('Got websocket connection!')
socket.on('message', message => {
console.log("received: %s",message)
//socket.send('Connection works to KrakenSDR')
});
});

const server = app.listen(wsport);
server.on('upgrade', (request, socket, head) => {
wsServer.handleUpgrade(request, socket, head, socket => {
wsServer.emit('connection', socket, request);
});
});
}

app.use(express.json())
app.use(cors());
app.use(express.static('public'))

app.get('/', (req, res) => {
res.send('Hi, this is the KrakenSDR middleware server :)')
// get settings from settings.json as external API
app.get('/settings', (req, res) => {
res.send(JSON.stringify(settingsJson))
})

// set settings of settings.json from external API
app.post('/settings', (req, res) => {
console.log("Got new Settings over API")
try {
var newSettings = req.body
newSettings.ext_upd_flag = true
fs.writeFileSync(settingsJsonPath, JSON.stringify(newSettings, null, 2))

res.sendStatus(200)
} catch (error) {
console.error(error)
res.sendStatus(500)
}
});

app.post('/doapost', (req, res) => {
lastDoaUpdate = Date.now()
let vfo = req.body.freq.toString()
Expand All @@ -176,12 +217,11 @@ app.post('/doapost', (req, res) => {
wsTrySend(`{"apikey": "${settingsJson.krakenpro_key}", "data": ${JSON.stringify(req.body)}}`)
} else {
// sends data to all websocket clients
/*
wsServer.clients.forEach(function each(client) {
if (client.readyState === ws.OPEN) {
client.send(JSON.stringify(req.body));
}
})*/
})
}
res.sendStatus(200)
});
Expand All @@ -193,12 +233,12 @@ app.post('/prpost', (req, res) => {
wsTrySend(`{"apikey": "${settingsJson.krakenpro_key}", "type": "pr", "data": ${JSON.stringify(req.body)}}`)
} else {
// sends data to all websocket clients
/*

wsServer.clients.forEach(function each(client) {
if (client.readyState === ws.OPEN) {
client.send(JSON.stringify(req.body));
}
})*/
})
}
res.sendStatus(200)
});
Expand Down
1 change: 0 additions & 1 deletion _nodejs/node_modules/.bin/mime

This file was deleted.

Loading
Loading