Ask Your Question
0

Using JS / PHP to query BrandMeister last heard data [closed]

asked 2017-06-14 01:12:35 +0200

W7CIA gravatar image

updated 2017-06-20 12:53:46 +0200

Is it possible to issue a PHP query to obtain filtered last heard data of a specific source ID so that that data can be posted to another web-page? For example, I'd like to issue a query for 311602 and/or 311603, add my own post processing (i.e. limit to the last 10-entries) so that the last heard data for these source ID values can be posted on another page.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by f4bwg
close date 2017-06-20 12:54:05.279244

Comments

Moved comment to Oliver's response below...

W7CIA gravatar imageW7CIA ( 2017-06-16 22:54:15 +0200 )edit

2 Answers

Sort by ยป oldest newest most voted
0

answered 2017-06-16 05:28:54 +0200

updated 2017-06-20 12:52:03 +0200

It's absolutely do-able and several people have done that already. If you look at the page

https://brandmeister.network/?page=lh...

you will see that the calls are web services call made by your browser for your specific ID. The data comes back JSON formatted and is then displayed in a pretty format. You can use this as a base to query the data for process it in any way you'd like.

====Edit 06/20/2017====

Hello ! Here are some samples for you to get started. The below code can be run in NodeJS and will get you the lastheard data:

var options = {
  'path':'/lh',
  'secure':true
}

var activeCallCount = 0
var activeCalls = {}
var dup = false
var history = [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]

var CLI = require('clui'),
    clc = require('cli-color');

var Sparkline = require('clui').Sparkline;

var Line          = CLI.Line,
    LineBuffer    = CLI.LineBuffer;

var outputBuffer = new LineBuffer({
  x: 0,
  y: 0,
  width: 'console',
  height: 'console'
});

var socket = require('socket.io-client')('api.brandmeister.network',options);
socket.on('connect', function(){
  activeCallCount = 0
  activeCalls = {}
  dup = false
  console.log("Connected")
  socket.on('mqtt', function (msg) {
    var data = JSON.parse(msg.payload);
    if (data['Event'] == "Session-Start" && data['Stop'] == 0)
    {
      if (activeCalls[data['SessionID']] != undefined) {
        dup = true
        return
      }
      activeCalls[data['SessionID']] = data
      if (dup) console.log("Duplicated session")
    }
    if (data['Stop'] != 0)
    {
      if (activeCalls[data['SessionID']] != undefined)
      {
        delete(activeCalls[data['SessionID']])
      }
    }
  })
});
socket.on('event', function(data){

});
socket.on('disconnect', function(){
  activeCallCount = 0
  activeCalls = {}
  dup = false
});

setInterval(function () {
  redrawDisplay()
}, 1000);

function redrawDisplay()
{ 
  console.log('\033[2J');

  history.push(Object.keys(activeCalls).length)
  if (history.length > 30) history.shift()

  var outputBuffer = new LineBuffer({
    x: 0,
    y: 0,
    width: 'console',
    height: 'console'
  });
  var message = new Line(outputBuffer)
    .column('LH CLI', 20, [clc.green])
    .fill()
    .store();
  var message = new Line(outputBuffer)
    .column(Sparkline(history, ' calls active'))
    .fill()
    .store();
  var header = new Line(outputBuffer)
    .column('',4)
    .column('Session ID', 37, [clc.cyan])
    .column('Source', 8, [clc.cyan])
    .column('', 9, [clc.cyan])
    .column('Destination', 20, [clc.cyan])
    .column('LinkName', 25, [clc.cyan])
    .fill()
    .store();
  for (index in activeCalls) {
    var reflector = ""
    if (activeCalls[index]['ReflectorID']) reflector = "("+activeCalls[index]['ReflectorID']+")"
      line = new Line(outputBuffer)
        .column((Math.floor(Date.now() / 1000) - activeCalls[index]['Start']) + '',4)
        .column(index, 37)
        .column(activeCalls[index]['SourceCall'] + "",8 )
        .column(activeCalls[index]['SourceID'] + "", 9)
        .column(activeCalls[index]['DestinationID']+" "+reflector, 20)
        .column(activeCalls[index]['LinkName'], 25)
        .fill()
        .store();
  }
  outputBuffer.output();
}

The code above has the following dependencies: socket.io-client , clui , cli-color

Here is an example that will allow you to only get the historical data from the last heard database:

// LastHeard
    var lhCount=0;
    var filter = {'ContextID':""+repeater.repeaterid};
    lhSocket.on('connect', function (msg) {
        lhSocket.emit("searchMongo", {'query': filter, 'amount': 5})
            lhSocket.on('mqtt', function (msg) {
                if (msg.topic != "LH-Startup")
                    return;
                var lastraw = JSON.parse(msg.payload);
            })
    })

Happy Coding !

edit flag offensive delete link more

Comments

Hi Oliver. Thanks for responding. Unfortunately, every time I go looking for documentation, I come up wanting. Many of the pages even indicate that the documentation needs to be updated. Do you have a URL to documentation or sample code? Thanks much!

W7CIA gravatar imageW7CIA ( 2017-06-18 16:36:21 +0200 )edit

The page you referenced shows an example of the output. What is needed is an example of how to post the query, or documentation describing how to do it.

W7CIA gravatar imageW7CIA ( 2017-06-18 16:40:33 +0200 )edit

Hello! The comments are limited to a few hundred characters - see today's edit in my answer. this should get you started in the right direction.

f4bwg gravatar imagef4bwg ( 2017-06-20 12:52:54 +0200 )edit
0

answered 2017-06-20 21:41:33 +0200

PD0MZ gravatar image

There are plenty PHP Socket.IO clients such as https://github.com/ephp/socketio that should give you the Last Heard stream as described.

edit flag offensive delete link more

Comments

Thank you to all!

W7CIA gravatar imageW7CIA ( 2017-06-23 00:11:53 +0200 )edit

Question Tools

1 follower

Stats

Asked: 2017-06-14 01:12:35 +0200

Seen: 71 times

Last updated: Jun 20