Stream Aircraft AM ATC to Broadcastify using RTL-SDR

Status
Not open for further replies.

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Feedid are the numbers at the end of your links posted two posts above.

23831
And
25781

Userid and password are your user name and password used to sign in to use the RR forums. jack26 and your password.

Got the link working thanks to your help. It works with chrome in win 7 but if I try a wget command on the rpi it returns a 403 error. Exact same link. Do I need to apply for an api key to get this working with linux?

i.e this works with win7 and chrome:
https://api.broadcastify.com/owner/?a=feed&feedId=23831&type=json&u=jack26&p=MyPassword

This returns a 403 error on the rpi (debian):
wget https://api.broadcastify.com/owner/?a=feed&feedId=23831&type=json&u=jack26&p=MyPassword

TIA :)
 

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Back to thinking that the rpi uptime problem is the internet connection and not a code problem. I can stream locally to my intranet for over 24 hours and no problems. I can't stream to broadcastify for more than about 10 hours before the rpi starts streaming "no more data..." problem and lost connection.

Until I solve this problem, I'm streaming to Bcstfy from a win8 mini pc with similar USB sdr sticks and no connection problems with that configuration but does not sound as good as the rpi.

ps: post above, it does work as stated with the correct password with Win7 chrome but throws a 403 error with debian linux on rpi :).
 
Last edited:

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
Back to thinking that the rpi uptime problem is the internet connection and not a code problem. I can stream locally to my intranet for over 24 hours and no problems. I can't stream to broadcastify for more than about 10 hours before the rpi starts streaming "no more data..." problem and lost connection.

Until I solve this problem, I'm streaming to Bcstfy from a win8 mini pc with similar USB sdr sticks and no connection problems with that configuration but does not sound as good as the rpi.

ps: post above, it does work as stated with the correct password with Win7 chrome but throws a 403 error with debian linux on rpi :).

Using the curl command will return the json data on the pi:

$ curl 'https://api.broadcastify.com/owner/?a=feed&feedId=14693&type=json&u=dc31&p=XXXXX'

{
"Feed" : [
{"id":14693, "status": 1, "listeners": 1, "descr": "Franklin County Fire and EMS Dispatch 1", "genre": "Public Safety", "mount": "/136068518", "bitrate": 16, "Counties" : [{"ctid":1218,"name": "Franklin","type": "County", "stid":"25", "stateCode": "MA", "stateName": "Massachusetts", "countryName": "United States", "countryCode": "US", "coid": "1", "countyDetails": "", "lat": "42.582748", "lon": "-72.606354"}
],"Relays" : [{"host": "relay.broadcastify.com", "port": "80"}]}
]
}


Now you are as far along as I am.
 

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
DC31 I just copied and pasted your comment on my PC for future ref :) So far not making that work yet. But sure it will work eventually :)
 
Last edited:

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Almost sent an alarm today when some idiot called in burglary event at large warehouse. The Milpitas cops spent around 3 hours surrounding the place only to find out it was just a janitor who was scheduled to clean the place.
I think it ended with a request to interview the reporting person :).

To those who are interested and have the access, it's all logged on my archives here
https://www.broadcastify.com/listen/feed/23831
https://www.broadcastify.com/listen/feed/25781
 
Last edited:

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Having some level of success here :) This does work in an executable called checkonline2.sh:

#get online status
sudo curl 'https://api.broadcastify.com/owner/?a=feed&feedId=23831&type=json&u=jack26&p=MyPassword' > status.txt
#strip quotes
sudo sed 's/\"//g' status.txt > status2.txt
#strip white space
sudo sed -r 's/\s+//g' status2.txt > status.txt
#Test for online status. Reboot if offline
sudo grep status:0 status.txt > status2.txt
sudo grep -q status:0 status2.txt && reboot

DC31, you are right about the lag with offline status with Broadcastify and the status message. It would be nice to fix that problem. :)

ps I know this is rookie code and can be improved but it does work :)

pps to everyone else interested, you have to use ssh to edit the long url link. It gets corrupted if you try to use the raspberry pi pixel gui.
 
Last edited:

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
Having some level of success here :) This does work in an executable called checkonline2.sh:

#get online status
sudo curl 'https://api.broadcastify.com/owner/?a=feed&feedId=23831&type=json&u=jack26&p=MyPassword' > status.txt
#strip quotes
sudo sed 's/\"//g' status.txt > status2.txt
#strip white space
sudo sed -r 's/\s+//g' status2.txt > status.txt
#Test for online status. Reboot if offline
sudo grep status:0 status.txt > status2.txt
sudo grep -q status:0 status2.txt && reboot

DC31, you are right about the lag with offline status with Broadcastify and the status message. It would be nice to fix that problem. :)

ps I know this is rookie code and can be improved but it does work :)

pps to everyone else interested, you have to use ssh to edit the long url link. It gets corrupted if you try to use the raspberry pi pixel gui.
Some more rookie code for you to try. Install jq $ sudo apt install jq

then try running:

curl -s 'https://api.broadcastify.com/owner/?a=feed&feedId=14693&type=json&u=dc31&p=PWD' | jq '.Feed[].status'

That should return just the 1 or 0 depending on whether you are on line or not. then pipe the output from that on to your script, etc.
 

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Some more rookie code for you to try. Install jq $ sudo apt install jq

then try running:

curl -s 'https://api.broadcastify.com/owner/?a=feed&feedId=14693&type=json&u=dc31&p=PWD' | jq '.Feed[].status'

That should return just the 1 or 0 depending on whether you are on line or not. then pipe the output from that on to your script, etc.

That doesn't look like rookie code compared to mine :).
Now struggling to get my script to work as a cron job. Following the tutorials but so far no luck.
The script file works and available to any user to execute. I've tried "crontab -e" and "sudo crontab -e" to edit scheduled tasks but nothing works so far.

Task I'm trying to create:
#!/bin/sh -e
#get online status
5 * * * * ./checkonline.sh 2>&1 /tmp/testlog.log

If I run checkonline.sh from a terminal window it runs with no errors and updates some text files. But it never runs as a scheduled task.

So far it did create the testlog.log but it just echoed the cron script as follows:
#!/bin/sh -e
#get online status
5 * * * * ./checkonline.sh 2>&1 /tmp/testlog.log "

The task itself (checkonline.sh) does not seem to be running periodically.

I've tried:
sudo systemctl daemon-reload
sudo /etc/init.d/cron restart
Any ideas? TIA :).
 

DC31

Member
Feed Provider
Joined
Feb 19, 2011
Messages
1,547
Location
Massachusetts
That doesn't look like rookie code compared to mine :).
Now struggling to get my script to work as a cron job. Following the tutorials but so far no luck.
The script file works and available to any user to execute. I've tried "crontab -e" and "sudo crontab -e" to edit scheduled tasks but nothing works so far.

Task I'm trying to create:
#!/bin/sh -e
#get online status
5 * * * * ./checkonline.sh 2>&1 /tmp/testlog.log

If I run checkonline.sh from a terminal window it runs with no errors and updates some text files. But it never runs as a scheduled task.

So far it did create the testlog.log but it just echoed the cron script as follows:
#!/bin/sh -e
#get online status
5 * * * * ./checkonline.sh 2>&1 /tmp/testlog.log "

The task itself (checkonline.sh) does not seem to be running periodically.

I've tried:
sudo systemctl daemon-reload
sudo /etc/init.d/cron restart
Any ideas? TIA :).

Try simplifying your line in cron

When you enter crontab -e you should get a whole bunch of lines of instructions that are all commented out (start with #)

After all those lines, try simply putting in 5 * * * * ./checkonline.sh

Nothing more nothing less. That will run it on the 5th minute of every hour. If you change the 5 to /2, that will run it every even numbered minute.

EDIT: that /2 needs to be */2. If you want every minute it is simply *
 

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Troubleshooting this problem is painfully slow as I need a sleep 90 command with these scripts to avoid an unrecoverable boot problem which means the task schedule has to have at least 5 minutes between tasks.

So far the cron tasks are not running as far as I can tell.

ps: I just saw your reply after I posted this comment. Update:

Result of "crontab -e" file contains the following:
#!/bin/sh -e
#get online status
5 * * * * ./checkonline.sh 2>&1 /tmp/testlog.log

Result of "sudo crontab -e" file contains the following:

lot of comments and this at the bottom:'
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
5 * * * * ./checkonline.sh

Still it doesn't seem to work.
 
Last edited:

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Update: Not sure what I did, but it is running now. May take a few days to see how reliable it is.
This is a total bandaid fix for now. There should be a better way to monitor the traffic in real time and restart based on what the rtl-fm is doing. The Broadcastify api status has about 90 seconds lag when connection is lost. Not sure how much lag it has when connection is back on yet.

Back online with the rpi3 and 2 sdr usb sticks only for now. :)
https://www.broadcastify.com/listen/feed/23831
https://www.broadcastify.com/listen/feed/25781
 

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Try simplifying your line in cron

When you enter crontab -e you should get a whole bunch of lines of instructions that are all commented out (start with #)

After all those lines, try simply putting in 5 * * * * ./checkonline.sh

Nothing more nothing less. That will run it on the 5th minute of every hour. If you change the 5 to /2, that will run it every even numbered minute.

EDIT: that /2 needs to be */2. If you want every minute it is simply *

Still doesn't work. Thought it was working but not. Both pi user and sudo user cron files updated but still not running.

Update: This might be working but it's like watching paint dry to see the results :).
 
Last edited:

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Update, the task seems to be running but I had to change period from 5 mininutes to 10 minutes because of the lag in the online status from the api link. This api link is not that useful for detecting offline status. But better than nothing for now :).
Oh yeah, and added the */ to make the interval recurrent. :)
 
Last edited:

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Seriously though, that online status data from the api link has a huge time lag. It even lags the website status. Would be nice to fix that. :)

Would be nice if this code was opened up to the public.
 
Last edited:

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Update: Very limited success so far. Mistake in the bash script above.

This code works:
sudo grep -q status:0 status2.txt && sudo reboot

This doesn't work as reboot needs the root superuser to execute:
sudo grep -q status:0 status2.txt && reboot.

Worked a couple of times then something got corrupted and the cron job disappeared from the task tree.
Starting over with a backed up SD card image. Back online with the HP windows 8 PC using scannercast and SDR# and the 2 backup SDR USB sticks.

The loss of connection to Broadcastify is definitely due to internet connectivity. Scannercast and Windows OS can deal with re-establishing connection but the rpi code with rtl_fm and the rtl-sdr library doesn't have a way to deal with the lost connection.
 

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
Ezstream is the problem with reconnection. There is something wrong with that code if connection is lost.

Still working on a bandaid fix. When connection is lost the rpi cpu usage goes from around 5% or less to over 20% and keeps increasing.

Thinking about greping that as a condition for a reboot to get the feeds back online. :)
 

ki6ptn

Newbie
Feed Provider
Joined
May 22, 2014
Messages
3
Location
Oceanside, CA
@JACK26 and @DC31 i just spent my morning working my way through this thread and finally made it to page 10.

I too followed the wiki instructions with little modifications along the way.

I've lightly dabbled in Linux over the years, but i'm a windows sysadmin type by trade, so I feel mostly lost when trying to troubleshoot.

I've been struggling with audio quality and your comments caused me to take another look at my gain settings. I had it cranked up pretty high and I think that was the problem. I feel like I still have some tweaking to do, but the feeds are at least audible now.

I'm using rpi 2B with 2x NooElec R802T2 SDR & DVB-T NESDR Mini 2

Here's what I have in my /etc/rc.local

/usr/local/bin/rtl_fm -d 0 -M fm -f 144.505M -p 6 -l 65 -g 20.7 -t 2 -E pad -s 12k | /usr/bin/lame -r -s 12 --resample 22.05 -m m -b 16 -F --cbr --lowpass 2.8 - - | /usr/bin/ezstream -c /etc/ezstream_bcfy.xml 2>&1 &

/usr/local/bin/rtl_fm -d 1 -M fm -f 145.540000M -p 6 -l 75 -g 38.6 -t 2 -E pad -s 12k | /usr/bin/lame -r -s 12 --resample 22.05 -m m -b 16 -F --cbr --lowpass 2.8 - - | /usr/bin/ezstream -c /etc/ezstream_bcfy2.xml 2>&1 &

Here are links to the 2 feeds I'm running.
WF6OCS 144.5050 MHz Oceanside CERT Repeater
145.5400 MHz Amateur Simplex

If you are Ham, the first feed is also on EchoLink, search WF6OCS. connect then listen to the bcfy feed to hear yourself. I think its delayed by about 30 seconds

Side note: I'm using PuTTY for connecting. No VNC running on my pi.
 

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
ki6ptn,
Nice to see someone else is interested in making this work. Using putty ssh versus VNC will save you from numerous pitfalls with the compatibility problems between linux and windows. I'm using both VNC and putty ssh in parallel and it's easy to mess up with short cut control characters that work with VNC and have completely different affects with putty.
VNC is nice for shortcuts to quickly look at log files and other things but causes compatibility problems with copy and paste if using windows to VNC to the rpi.

The sox audio tool works much better than lame and more powerful, but I'm using raspberry pi 3 and don't know how well it works for other rpi's. Lame is a minimal audio tool.
This startup code works for me and sounds really well:

#!/bin/bash
sleep 65 s
sudo rtl_fm -d 0 -f 482.8624M -s 16000 -g 29.7 \
-p 0 -l 95 -t 5 -E dc -E pad |
sudo sox -v 0.95 -t raw -r 16000 -b 16 \
-e signed -c 1 - -t .mp3 -c 1 -C 64 \
- sinc -n 3000 280-3.5k : - sinc -n 1000 325-55 |
#sudo /usr/bin/ezstream -q -c /etc/ezstream_bcfy.xml |
sudo /usr/bin/ezstream -q -c /etc/Ezstream |
sleep 5 s |
sudo rtl_fm -d 1 -f 460.624M -s 16000 -g 28.0 \
-p 0 -l 95 -t 5 -E dc -E pad |
sudo sox -v 0.95 -t raw -r 16000 -b 16 \
-e signed -c 1 - -t .mp3 -c 1 -C 64 \
- sinc -n 3000 280-3.5k : - sinc -n 1000 325-55 |
#sudo /usr/bin/ezstream -q -c /etc/ezstream_bcfy_FireMilp1.xml
sudo /usr/bin/ezstream -q -c /etc/Ezstream2

Note: Ezstream and Ezstream2 are local instances for offline testing.

The tuned frequency and ppm offset (-p parameter in rtl_fm command line) that works best with SDR# on a windows computer for a specific rtl-sdr dongle also works with the rpi. The best squelch (-l) parameter can be much higher (in my case it can be no higher than 78 on the windows pc whereas the best number for the rpi turned out to be 95). Gain values from SDR# are a starting point but need to be tweaked on and very sensitive to physical setup and hardware.

Still working on the connectivity reliability issue. It looks like Ezstream goes to 100% cpu usage when it happens so I'm looking at grepping Ezstream and killing and restarting Ezstream. rtl-fm and sox for the specific channel when it happens instead of rebooting the rpi.

It's going to take awhile to figure out how to do that so in the mean time I'm feeding from the mini win8 pc.
Using the online status api has too much lag to use that as a condition to restart.
 
Last edited:

JACK26

Member
Joined
Dec 7, 2016
Messages
298
Location
Milpitas, CA
One other thing, don't put all your startup script in the rc.local file as that's dangerous and can lead to an unrecoverable boot loop (learned the hard way).
Put all your code in a file called something like "/etc/startup.sh" and put "sudo /etc/startup.sh" in the rc.local file.
Also the first couple of lines in the "startup.sh" script file should look like this:

#!/bin/bash
sleep 65 s

sleep 65 seconds gives you time to correct an error in the startup.sh file if it causes a boot up loop.
 
Last edited:
Status
Not open for further replies.
Top