JTK – Notes and Ramblings Things we have found …

1/14/2019

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.

12/23/2018

Seneye Home on the Pi

Filed under: General,Home Automation — taing @ 6:15 pm

The Seneye Home normally wants to be connected to a Windows PC to log its reading to the cloud. Naturally, I see no reason for the cloud to be involved. {Insert rant about unnecessary cloud connections for home devices here} Fortunately, Seneye has released at least a partial API for reading on a Raspberry Pi.

https://github.com/seneye/SUDDriver

There is a handy page describing compiling and testing the samples from the above: https://raspberrypidiyblog.wordpress.com/2018/01/17/seneye-suddriver-raspberrypi/

Compiling the code required I change line 464 of linux/hid.c from:

tmp = (hid_device_info*)malloc(sizeof(struct hid_device_info));

to

tmp = (struct hid_device_info *)malloc(sizeof(struct hid_device_info));

Over at https://doughall.me/2017/06/30/seneyemqttpt1/ is a discussion on using Python on the Pi to get the device readings. His code can be found at https://github.com/dhallgb/Seneye-MQTT.

Following these instructions I installed python modules pprint, pyusb, paho-mqtt and bitstring(not mentioned but required) using pip install. It was necessary to update the 10-local.rules file to indicate the correct idVendor and idProduct: idVendor=24f7 and idProduct=2204. These need to be in hex in the udev files. They are in decimal in the python source.

I have also updated the python script to not use bitstring and to use struct instead.

def mungReadings(p):
   s = {}
   scrap, scrap, TS, flag1, flag2, scrap, pH, NH3, thermo, scrap  = unpack('&lt;BBLBBHHHL46s', p)
   s['InWater']=bool(flag1 &amp; 0b00000100)
   s['SlideNotFitted']=bool(flag1 &amp; 0b00001000)
   s['SlideExpired']=bool(flag1 &amp; 0b00010000)
   s['pH']=float(pH)/100   # divided by 100
   s['NH3']=float(NH3)/1000  # divided by 1000
   s['Temp']=float(thermo)/1000 # divided by 1000
   j = json.dumps(s, ensure_ascii=False)
   return(j)

Still working on how to register a Seneye slide without the Windows PC. From the Seneye SUDDriver wiki:

Slide codes are retrieved from an API hosted on the seneye cloud. In order to use it, your account will need activating to allow permission. You can request access to this by E-mail by asking for “SUD Developer Access” and we will send you the terms and conditions to be sent to you for agreement.

https://github.com/seneye/SUDDriver/wiki/Activating-a-seneye-slide-for-your-SUD#retrieving-a-slide-code

Can’t access c$

Filed under: General,Router/PC Config — taing @ 5:54 pm

Recently I found on one of my systems that I was unable to access c$ even when using admin credentials. The solution can be found at https://support.microsoft.com/en-us/help/951016/description-of-user-account-control-and-remote-restrictions-in-windows The Fix It For Me feature of the article is no longer supported but the description of the manual fix via regedit works:

  1. Click Start, click Run, type regedit, and then press ENTER.
  2. Locate and then click the following registry subkey:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System
  3. If the LocalAccountTokenFilterPolicy registry entry does not exist, follow these steps: 
    1. On the Edit menu, point to
      New, and then click DWORD Value.
    2. Type
      LocalAccountTokenFilterPolicy, and then press ENTER.
  4. Right-click LocalAccountTokenFilterPolicy, and then click
    Modify.
  5. In the Value data box, type
    1, and then click OK.
  6. Exit Registry Editor.

8/14/2016

mythbuntu 16.04 on the NUC

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

The Gigabyte NUC GB-BXBT-1900 and Mythbuntu 16.04 have a few minor issues.

The first and biggest problem is the HDMI port shuts down after the monitor powers down. When the monitor is turned back on there is no display. Yikes.

The first part of the solution is a short shell script ~/screenfix.sh :

#!/bin/sh

export DISPLAY=:0
export XAUTHORITY=/home/taine/.Xauthority
sleep 8
/usr/bin/xrandr --verbose --display :0 --output HDMI1 --mode 1920x1080

Be sure to make the script executable with chmod u+x screenfix.sh

The second step is to make this a keyboard shortcut in the Keyboard Settings Shortcut tab. I chose Windows-S for my shortcut. The short cut command is:

xrandr --verbose --display :0 --output HDMI1 --mode 1920x1080

The final step is to automate this based a UDEV rule triggered when the display connects. Create /etc/udev/rules.d/95-monitor-hotplug.rules :

ACTION=="change", SUBSYSTEM=="drm", ENV{DISPLAY}=":0", ENV{XAUTHORITY}="/home/youruser/.Xauthority", RUN+="/home/taine/screenfix.sh"

The sleep line in the shell script was required to give the display time to actually be seen as “connected”.

The connected status of the display can be found with cat /sys/class/drm/card0-HDMI-A-1/status

The triggering UDEV event can be seen with udevadm monitor

Use xrandr -d :0 to display current display info.

Another minor annoyance was the failure of the CTRL-Escape keyboard shortcut to bring up the application menu. The shortcut appears to be set for xfce4-popup-menu. This has been around for quite a while. Change CTRL-Escape to run xfce4-popup-applicationsmenu in the Keyboard Settings Shortcut tab.

5/7/2016

Ubuntu 14.04LTS and Dropbox

Filed under: General,Router/PC Config — taing @ 11:08 pm

After recent update to 14.04LTS the dropbox status icon was gone. The installed version of dropbox is 2015.10.28.

After reading http://askubuntu.com/questions/732967/dropbox-icon-is-not-working-xubuntu-14-04-lts-64 I decided to use the option of editing /usr/bin/dropbox.

I added the line
os.environ['DBUS_SESSION_BUS_ADDRESS'] = ""
after the “import os” line.

Also of note is the dropbox command line interface. Simply type dropbox at the shell prompt for more info.

4/10/2016

NUT for Windows

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

I use NUT for all of my UPS on Linux machines. There is a beta Windows port available. I have it working for two Windows 7 Pro 64 bit boxes.

Documentation on getting it working under Windows is sparse.

Downloaded NUT Windows MSI installer 2.6.5-6. Installed.

Copy libgcc_s_dw2-1.dll from bin to sbin. it is required for upsmon to run.

Grabbed a copy of libeay32.dll and ssleay32.dll from my Nmap install and copied these to the bin and sbin folders. Without these two files upsc, upsd and upsmon throw error (0xc000007b).

Downloaded libusb-win32-bin-1.2.6.0.zip from SourceForge.

Used usb-lib bin/inf_wizard.exe to create the proper .inf file for the UPS and installed.

You can use bin/nut-scanner.exe to see is the UPS is detected.

Edit the config files: nut.conf, ups.conf, upsd,conf, uspd.users and upsmon.conf.

To fully integrate into the network, I edited(on the appropriate systems):
/etc/nut/host.conf to add the new system to the list displayed in the web status display.
/etc/nut/upsmon.conf to add the system to the list monitored for status with email/text warnings.

2/6/2016

Openhab zwave

Filed under: General,Home Automation — taing @ 11:44 pm

I added the zwave binding:
sudo apt-get install openhab-addon-binding-zwave

For the Aeon Labs Z-Stick Series 2 which appears as /dev/ttyUSB0 I had to add the openhab user to the dialout group:
sudo adduser openhab dialout

To bind devices I used Habmin – https://github.com/cdjackson/HABmin. I chose the complied release version – https://github.com/cdjackson/HABmin/releases. The alternative is to install source from the git and compile.

So far I have linked a RadioThermostat CT-80 with Z-wave interface and a Aoetec Home Energy Meter(2nd edition).

For the HEM it was necessary to set the mode properly for periodic updates.

The RadioThermostat only sends changes and only works in “dumb” mode when using zwave. I have not yet been able to read the humidity from the thermostat. The definition in the openhab zwave binding is imcomplete.

Radio Thermostat WiFi Module : http://ndgeek.com/ct-50/RTCOAWiFIAPIV1_3.pdf. The radio module I had was very unreliable and disconnected frequently. I did find some interesting discussions on using the WiFi module with Openhab – https://community.openhab.org/t/binding-radio-thermostat/5480 & https://community.openhab.org/t/how-to-return-current-temp-from-my-thermostat/3141

Radio Thermostat zwave Module: http://products.z-wavealliance.org/MarketCertification/File?folder=&filename=MarketCertificationFiles/1046/RTZW-02_module_IB_9jun14.pdf. The Openhab wiki does have some good examples for the zwave interface – https://community.openhab.org/t/collection-of-working-z-wave-configs/1407

Aoetec Home Energy Meter(2nd edition): https://docs.google.com/viewer?a=v&pid=forums&srcid=MDM3NTIwMDUwMTA4OTkyOTEwNDQBMTc2Mjg0MjUxOTM5MzgwNTU2ODABYXZNMEo0RUZVcllKATAuMQEBdjI.

« Newer PostsOlder Posts »

Powered by WordPress