Extracting Connection Information For Display Elsewhere

Post your tips and tricks here
Post Reply
NQ4T
Posts: 51
Joined: Mon Aug 06, 2018 11:48 pm

Extracting Connection Information For Display Elsewhere

Post by NQ4T »

Hi,

So I had this crazy idea of slapping my current connection information in to a format I could embed it in some of my other pages/profiles. Since I'd done some work a couple years ago scraping information from Pi-Star dashboard for some APRS-IS stuff; I decided to just stick with that general idea. Unlike my previous stuff that ran a bash script on pi-star and required some additional stuff; this runs on the webserver and now requires absolutely nothing special except access to the pi-star dashboard.

This is making the assumption that you self-host a webserver. You can probably do this using remote access to the dashboard depending on your level of paranoia. So far all I have working is the bash script portion:

Code: Select all

#!/bin/bash
#.006 alpha

dmr=$(curl -s http://192.168.1.10/mmdvmhost/bm_links.php| sed 's/<[^>]\+>/\n/g' | grep '^TG' |  sed 's/TG/#/g'| sed 's/(.)//g' | sed ':a;N;$!ba;s/\n/ /g')
[ -z "$dmr" ] && dmr="No Talkgroups Found"
dstar=$(curl -s http://192.168.1.11/mmdvmhost/repeaterinfo.php | egrep "REF|XRF|DCS|XLX" | sed 's/<[^>]\+>//g' | sed 's/L/l/'| cut -b 1-8)
[ -z "$dstar" ] && dstar="Not Linked"
printf "%s\n" "BM TG: $dmr"
printf "%s\n" "DStar: $dstar"
For DMR; I do the hacky thing of pulling a copy of bm_links.php and strip the HTML tags out by converting them to line breaks. This makes for a stupid number of lines....but efficiency isn't a concern on the webserver. This allows me to grab the groups by filtering by lines that start with TG rather than using a modified copy of bm_links on pistar. TG is converted to #, timeslot information is stripped (since I run duplex), and line breaks are converted to spaces to put the talk groups back on a single line. If no groups are returned, a message is used instead.

Same thing for DStar....except we just egrep for a reflector prefix, strip the HTML, and cut the protocol (i.e "DPlus/OUT"). This is hacky. If you happen to connect to a repeater directly and not a reflector; it won't register. That's something I'm going to work on. But since 99.9% of my activity is on a reflector....this will work. Again...if I'm not linked to a reflector a message is used instead.

Code: Select all

dewdude@ovh:/media/html/qth-nq4t$ ./hotspots.sh
BM TG: #3151 #98003
DStar: DCS216 E

dewdude@ovh:/media/html/qth-nq4t$ ./hotspots.sh
BM TG: #3151 #98003
DStar: Not Linked

dewdude@ovh:/media/html/qth-nq4t$ ./hotspots.sh
BM TG: No Talkgroups Found
DStar: DCS216 E

dewdude@ovh:/media/html/qth-nq4t$ ./hotspots.sh
BM TG: No Talkgroups Found
DStar: Not Linked
I was attempting to get this to display using PHP, but I'm probably tired and not understanding something because while I can get PHP at command-line to work; the browser gets nothing. [s]I'll figure that out tomorrow.[/s]

Update: I apparently forgot to update nginx config for this server directive when I upgraded PHP. https://qth.nq4t.com/hotspots.php now actually displays some text.

73 de Jay/NQ4T
NQ4T
Posts: 51
Joined: Mon Aug 06, 2018 11:48 pm

Re: Extracting Connection Information For Display Elsewhere

Post by NQ4T »

So after figuring out the stupid mistake that was keeping PHP from displaying anything; I can get some basic output with PHP using just a little bit of code:

Code: Select all

<?php
$output = shell_exec('bash /media/html/qth-nq4t/hotspots.sh');
echo "<pre>$output</pre>";
?>
Now it's just a matter of figuring out how I want to integrate it in to pages/profiles.
NQ4T
Posts: 51
Joined: Mon Aug 06, 2018 11:48 pm

Re: Extracting Connection Information For Display Elsewhere

Post by NQ4T »

More improvements? Yes! With most of the code working I started on making it "look nicer". I decided the easiest thing would be to format everything before it's outputted. There's probably a way I can make PHP break everything down in to individual variables for later rendering; like breaking it up in to two scripts and running them back to back, each one spitting out data to a variable. It seemed easier to figure out how to format and just let the bash script spit out my HTML.

So that's what we do!

Code: Select all

#!/bin/bash
#.010 alpha

dmr=$(curl -s http://192.168.1.10/mmdvmhost/bm_links.php| sed 's/<[^>]\+>/\n/g' | grep '^TG' |  sed 's/TG/#/g'| sed 's/(.)//g' | sed ':a;N;$!ba;s/\n/ - /g')
[ -z "$dmr" ] && dmr="No Talkgroups Found"
dstar=$(curl -s http://192.168.1.11/mmdvmhost/repeaterinfo.php | egrep "REF|XRF|DCS|XLX" | sed 's/<[^>]\+>//g' | sed 's/L/l/'| cut -b 1-8)
[ -z "$dstar" ] && dstar="Not Linked"
#printf "%s\n" "BM TG: $dmr"
#printf "%s\n"
#printf "%s\n" "DStar: $dstar"
printf "<td style=\"vertical-align: top; width: 54px; font-family: Verdana; font-weight: bold; text-align: right;\"><small>BM TG:</small></td>\n<td style=\"vertical-align: top;\"><small style=\"font-style: italic;\">&nbsp $dmr</small><br></td></tr>\n<tr><td style=\"vertical-align: top; width: 54px; font-family: Verdana; font-weight: bold; text-align: right;\"><small>D-Star:</small></td>\n<td style=\"vertical-align: top;\"><small style=\"font-style: italic;\">&nbsp $dstar</small><br></td>\n"
The basic change here is spitting out a bunch of HTML for table cells. The PHP contains the accompanying code for the table:

Code: Select all

<html><head><meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
<title>NQ4T Hotspot Info</title></head><body>
<div style="width: 225px; margin-right: auto; font-family: Verdana; text-align: left;">
<small style="font-weight: bold; font-style: italic;">NQ4T Pi-Star Hotspot Network<br><br></small>
<small><small style="font-weight: bold;">Current Connections:<br></small></small>
<table style="text-align: left; width: 100%; border-collapse: collapse; border: 1px solid black;" cellpadding="2"
cellspacing="0"><tbody><tr>
<?php
$output = shell_exec('bash /media/html/qth-nq4t/hotspots.sh');
echo "$output";
?>
</tr></tbody></table><small>
<br><small style="font-weight: bold; font-style: italic;">
<br>Listed connections do not mean I have a radio on or am at a radio. This is especially true for Brandmeister.<br> For informational purposes only.
<br><br>73 de NQ4T</small>
<br><small style="font-style: italic;">
<?php
echo date("Y-m-d") . " @ " . date("H:i:s") . "z";
?>
</small></div></body></html>
The new result can be viewed in the link in the first post.
NQ4T
Posts: 51
Joined: Mon Aug 06, 2018 11:48 pm

Re: Extracting Connection Information For Display Elsewhere

Post by NQ4T »

Well...now it can auto-size. Rather than specifying all the widths and limiting it in a div; I instead just use viewport CSS commands to make it adapt to whatever window it's in. Rather than post all the code, I'll note the changes that need to be made

Code: Select all

PHP File:

remove the "width: 225px" CSS in the initial <div style=> statement entirely and replace with  "font-size: 6vw"

remove "width: 100%" from the table code and replace with "font-size: 6vw"

Shell Script:

Remove "width: 54px;" both times it appears
Now it will only be as wide as whatever is displaying it, be it an iframe or whatever; but everything will resize. So if I embed it in a 250px iframe, it'll look about how it's designed. Bump that up to 500px and it scales everything up.

Using a value of 6vw is probably excessive. I need to sit down, delete all text sizing that exists, and reformat for viewport.
NQ4T
Posts: 51
Joined: Mon Aug 06, 2018 11:48 pm

Re: Extracting Connection Information For Display Elsewhere

Post by NQ4T »

I have created a repository for this project. You can track it's changes there.

https://gitlab.com/dewdude/pistar-scrape
NQ4T
Posts: 51
Joined: Mon Aug 06, 2018 11:48 pm

Re: Extracting Connection Information For Display Elsewhere

Post by NQ4T »

I pushed an update to this on Thursday night. The primary change is that the PHP was "rewritten from scratch" to fix the hacky formatting I used before. Also attempted to make some adjustments so things look better when you have a large number of talkgroups connected and the cell becomes more than 1 line tall. This still doesn't work right and is probably a limitation of HTML/rendering. At least it's no longer 600% zoom by default if you load the page directly while still looking fine on mobile and as part of iframes.
NQ4T
Posts: 51
Joined: Mon Aug 06, 2018 11:48 pm

Re: Extracting Connection Information For Display Elsewhere

Post by NQ4T »

This has been running silently as an iframe on my QRZ page for months with zero issues. There have been some changes.
  • There are preliminary instructions on how to do this with remote SSH access
You will still need to have a PHP server the ability to execute local bash scripts, and key based authentication. Not a problem if you run your own server; probably a major limitation if you're using simple web-hosting.

I'm getting ready to head to Dayton; so I'll also be reviving my previous project which pulled the group information and pushed it out over APRS-IS as a comment. The new version uses the updated method of grabbing info; so no more having to actually poke in the OS (which the devs don't like). I largely just have to update it to make use of the new group extraction method and make sure my GPS parsing still works.
Post Reply