JTK – Notes and Ramblings Things we have found …

1/26/2019

PICkit3, Acer Switch 5, Windows 10

Filed under: General — taing @ 2:13 pm

This is why having the source code and a bit of Google is awesome. I was unable to get my Microchip PICkit3 to work on an Acer Switch 5 with Windows 10 when using the Microchip standalone PICkit3 application. The PICkit3 worked on my Windows 7 HP laptop or on the Acer with MPLAB X 5.10 but refused to connect in the standalone application. After a bit of googling about for the issue and many false leads I found https://www.microchip.com/forums/m908976.aspx.

The issue seems to be a a loop in the USB.Find_This_Device () function that is too short. After reading the thread I attempted to connect the PICkit3 with the Acer keyboard disconnected and was successful each time. This supported the theory.

Fortunately the source for the standalone application is included in the package. After downloading and installing Visual Studio Express 17 I was able to follow along with the steps in the discussion.

I opened PICkit2V2.sln from PICkit3 Programmer Application Source v3.10/PICkit2V2 in Visual Studio. After finding the file USB.cs and changing line 203 to read:

for (int l_loop = 0; l_loop < 64; l_loop++)

I was able to rebuild, resulting in a new PICkit3.exe. For more context the surrounding code is:

MyDeviceInterfaceData.cbSize = Marshal.SizeOf(MyDeviceInterfaceData);
for (int l_loop = 0; l_loop < 64; l_loop++)
{
Result = SetupDiEnumDeviceInterfaces(
DeviceInfoSet,
0,
ref HidGuid,
l_loop,
ref MyDeviceInterfaceData);
if (Result != 0)
{

1/14/2019

Further Weather Alerts

Filed under: General,Home Automation — taing @ 8:48 am

The code at https://github.com/K2DLS/noaacap looks like a good start on grabbing the relevant Weather Alerts from https://alerts.weather.gov.

For my current location I am using https://alerts.weather.gov/cap/wwaatmget.php?x=OHC055&y=1 or https://alerts.weather.gov/cap/wwaatmget.php?x=OHZ013&y=1. Changing the parameter y=1 to y=0 will yield the atom/xml feed instead of the html.

Weather Radio Part 2

Filed under: General,Home Automation,RTL-SDR — taing @ 8:40 am

Continuing from http://jtkdev.com/wp/2019/01/03/pi-weather-radio-w-same/.

Using the code from http://jtkdev.com/wp/2019/01/03/pi-weather-radio-w-same/ to decode the SAME alerts in the broadcast. The current current script:

rtl_fm -f 162298000 -s 22050 -p 14 | tee >(multimon-ng -t raw -a EAS /dev/stdin | python ~/dsame/dsame.py --text >> alerts.txt) | lame --bitwidth 16 --signed -s 22050 --lowpass 3500 --abr 64 --scale 8 -r -m m - - |ezstream -c ezstream.xml

Notice the sample rate has been reduced to match what is expected by multimon-ng.

It was necessary to download and install multimon-ng. We also installed sox (sudo apt-get install sox) to test the dsame code with the included sample.

1/6/2019

Nut vs my UPS

Filed under: General,Router/PC Config — taing @ 1:38 am

Nut has been setup and running mostly successfully on the LAN for a few years. Most of the small units are APC, larger unit in the basement is a CyberPower. I replaced one of the units with a small CyberPower CP1500AVR. It refused to cooperate via usb. According to the everything I could find online it should use the same usbhid-ups driver the previous unit had. Instead, I get a myriad of usb errors in dmesg.

I followed the recommendations of several online guide for configuring nut to see what I had missed previously to no avail. Several writer indicated they had similar and other issues with CyberPower usb connections.

Both http://tedfelix.com/software/nut-network-ups-tools.html and https://nmaggioni.xyz/2017/03/14/NUT-CyberPower-UPS/ had helpful pointers.

The most significant being the proper udev rules(from /lib/udev/rules.d/52-nut-usbups.rules) and the potential need to increase the pollinterval and deadtime.

Refer to my earlier post for configuring Nut on Windows.

1/5/2019

Centos FTP server – vsftpd

Filed under: General,Router/PC Config — taing @ 9:33 pm

Using tutorials from https://linuxize.com/post/how-to-setup-ftp-server-with-vsftpd-on-centos-7/ and https://www.tecmint.com/install-ftp-server-in-centos-7/.

Install vsftpd:

yum install vsftpd

Edit /etc/vsftpd/vsftpd.conf:

anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
listen=YES
listen_address=192.168.0.1
# ip address of the server
listen_ipv6=NO
pam_service_name=vsftpd
userlist_enable=YES
userlist_file=/etc/vsftpd/vsftpd.userlist
userlist_deny=NO
chroot_local_user=YES
user_sub_token=$USER
local_root=/home/$USER/ftp
tcp_wrappers=YES

Create a ftp user, add it to /etc/vsftpd/vsftpduserlist and create directories:

adduser newftpuser
passwd newftpuser

echo "newftpuser" | sudo tee -a /etc/vsftpd/user_list

mkdir -p /home/newftpuser/ftp/upload
chmod 550 /home/newftpuser/ftp
chmod 750 /home/newftpuser/ftp/upload
chown -R newftpuser: /home/newftpuser/ftp

usermod newftpuser -s /bin/nologin

Start the server and enable it to run as a daemon at startup:

systemctl start vsftpd
systemctl enable vsftpd

Things should be up and running. This is not a secure server. We did not create a certificate or enable TLS. User credentials will be sent as plain text. The server is only listening on the one specified interface. We did not make any firewall adjustments.

1/4/2019

Debouncing events in Javascript

Filed under: General — taing @ 11:15 am

https://css-tricks.com/debouncing-throttling-explained-examples/ pointed me to http://unscriptable.com/2009/03/20/debouncing-javascript-methods/.

If you are already using jQuery, underscore.js or Lodash you have versions of this in your framework. The simplest version not embedded in a library or framework which doesn’t use prototypes was:

 
var debounce = function (func, threshold, execAsap) {
  var timeout;
  return function debounced () {
  var obj = this, args = arguments;
  function delayed () {
  if (!execAsap)
func.apply(obj, args);
timeout = null;
};
  if (timeout)
clearTimeout(timeout);
  else if (execAsap)
func.apply(obj, args);
timeout = setTimeout(delayed, threshold || 100)
};
}

func is the function to call, threshold is the interval expressed in milliseconds and execAsap determines if the function is called at the beginning or end of the interval. The function will only be called once per interval.

 
document.onmousemove = debounce(function (e) {
  /* do something here, but only once after mouse cursor stops */
}, 250, false);

1/3/2019

Pi Weather Radio w/SAME

Filed under: General,Home Automation,RTL-SDR — taing @ 11:35 pm

So I have been planning to use the SDR dongle as a weather radio for some time. The goal was to stream the audio AND capture the digital SAME messages to signal weather alerts.

I found several useful references online: https://github.com/tim273/weather_radio_scripts, https://github.com/cuppa-joe/dsame, https://www.dynode.nl/streaming-radio-receivers-with-the-raspberry-pi/ and https://www.wxforum.net/index.php?topic=31396.msg314826#msg314826.

I installed rtl-sdr, lame, icecast2 and ezstream.

sudo apt-get install rtl-sdr lame icecast2 ezstream

I created 20.rtlsdr.rules in /etc/udev/rules.d/

SUBSYSTEM=="usb", ATTRS{idVendor}=="0bda", ATTRS{idProduct}=="2838", GROUP="adm", MODE="0666", SYMLINK+="rtl_sdr"

I created /etc/modprobe.d/rtlsdr-blacklist.conf

blacklist dvb_usb_rtl28xxu
blacklist rtl2832
blacklist rtl2830

After rebooting I was able to use rtl_test successfully. Using the NOAA website I was able to look up the require frequency for my location. It took a bit of fiddling to get the proper frequency setting for the dongle to actually tune the desired channel. The desired frequency for me is 162.55Mhz. I ended up using 162.298M to truly tune 162.55M.

rtl_fm -f 162298000 -s 48000 -p 14

Piping this to lame results in an MP3 stream.

rtl_fm -f 162298000 -s 48000 -p 14 | lame --bitwidth 16 --signed -s 48000 --lowpass 3500 --abr 64 --scale 8 -r -m m - - > test.mp3

The next step was to create a config XML file to ezstream and test the stream. A little touch-up is required for the sample below.

exstream.xml
<ezstream>
<url>http://your-ip:8000/weather</url>
<sourcepassword>xxxxxxxx</sourcepassword>
<format>MP3</format>
<filename>stdin</filename>
<!--
Important:
For streaming from standard input, the default for continuous streaming
is bad. Set <stream_once /> to 1 here to prevent ezstream from spinning
endlessly when the input stream stops:
-->
<stream_once>1</stream_once>
<!--
The following settings are used to describe your stream to the server.
It's up to you to make sure that the bitrate/quality/samplerate/channels
information matches up with your input stream files.
-->
<svrinfoname>Weather test stream</svrinfoname>
<svrinfourl>your-ip</svrinfourl>
<svrinfogenre>weather</svrinfogenre>
<svrinfodescription>Weather test stream</svrinfodescription>
<svrinfobitrate>32</svrinfobitrate>
<svrinfoquality>2.0</svrinfoquality>
<svrinfochannels>1</svrinfochannels>
<svrinfosamplerate>48000</svrinfosamplerate>
<!-- Turn off YP directory advertising -->
<svrinfopublic>0</svrinfopublic>
</ezstream>
rtl_fm -f 162298000 -s 48000 -p 14 | lame --bitwidth 16 --signed -s 48000 --lowpass 3500 --abr 64 --scale 8 -r -m m - - | ezstream -c ezstream.xml

The test icecast2 stream can be found at http://your-ip:8000/weather. The icecast2 config can be edited at /etc/icecast2/icecast.xml. Documentation for the config file can be found at http://icecast.org/docs/icecast-2.4.1/config-file.html.

Next I’ll be working to integrate the python from https://github.com/cuppa-joe/dsame handle the digital side of the stream. For now we have the stream going to the icecast2 stream and also piping to the next thing.

rtl_fm -f 162298000 -s 48000 -p 14 | lame --bitwidth 16 --signed -s 48000 --lowpass 3500 --abr 64 --scale 8 -r -m m - - |tee >(ezstream -c ezstream.xml) | cat >test1.mp3

Seneye Home on the Pi – Part 2

Filed under: General,Home Automation — taing @ 10:52 pm

After getting the Python sorted out to read the Seneye Home it was time resolve a few outstanding issues with the unit. Seneye has only released the partial API discussed previously. This API lacks the ability to 1) register a slide 2) clear the “offline” readings stored in the unit.

Following ideas found online I setup VirtualHere. There is a Raspberry Pi server and a Windows 10 client. The free version will allow for a for sharing a single device. The free version also doesn’t support running the client as a service on Windows 10. Neither of these limitation was a problem for our setup.

I setup a cron job to run every 30 minutes. It calls a shell script which stops the VirtualHere server, runs the Seneye Python code to send reading to Openhab via MQTT and restarts the VirtualHere server.

crontab -e
*/30 * * * * ~/fish.sh
fish.sh
date >>~/Seneye-MQTT/suddriver.log
sudo killall vhusbdarm
sleep 10
python ~/Seneye-MQTT/suddriver.py >>~/Seneye-MQTT/suddriver.log
sleep 10
sudo ~/VirtualHere/vhusbdarm -b

It would be nice not to need sudo in this script but at the moment I haven’t noodled out the permissions required to get the VitrualHere server to run without sudo.

Powered by WordPress