Showing posts with label linux. Show all posts
Showing posts with label linux. Show all posts

Saturday, October 24, 2015

One minute tutorial: Getting started with a fresh NodeMCU ESP8266 (direct from eBay)

The NodeMCU / ESP8266 is a ridiculously cheap ($2) micro-controller that can talk to an 802.11N wireless network. This device is the herald of the "Internet of Things."

If you buy one on eBay, chances are it will NOT be flashed with NodeMCU firmware (it speaks Lua). This understandably confused the crap out of me. So, this serves as a guide to those running Manjaro (Arch) Linux:

  1. Download NodeMCU firmware
    "integer" versions will NOT understand floating point arithmetic, but save on system resources.
  2. Install minicom
    pacman -Ss minicom
  3. Install esptool from the AUR:
    yaourt esptool-git
  4. Make sure your Linux box recognizes the device
    tail -f /var/log/messages.log
  5. Plug in the NodeMCU device. You should see:
    kernel: usb whatever: ch341-uart converter now attached to ttyUSBX

    ch341-uart converter detected

    If this didn't happen, you cannot proceed and must troubleshoot.
  6. Flash the firmware. Make sure you have permission to read and write to the device in the command below. When in doubt, run as root:
    esptool.py --port /dev/ttyUSBX write_flash 0x00000 nodemcu_whatever.bin
    where:
    X corresponds to the device from the log file above, and
    nodemcu_whatever.bin corresponds to the firmware file in step 1.
  7. Unplug the USB cable after the flash command from the previous step is completed, and plug it back in.
  8. Fire up minicom, and talk to the board at 9600 baud:
    minicom -D /dev/ttyUSBX -b 9600
  9. Press the "enter" key a few times. In response, you should see:
    >
    >
  10. Try "hello world":
    > print ("hello world")
    hello world
    >

  11. Now you can configure wireless:
    > wifi.setmode(wifi.STATION)

    > wifi.sta.config("SSID", "PASSWORD")

    > ip, nm, gw=wifi.sta.getip()

    > print (ip, nm, gw)
    this   is   amazing
  12. Do some interesting things!

Saturday, September 26, 2015

Making old machines run a modern Linux distribution surprisingly well (using Zswap)

In between study sessions, I've been experimenting with some old hardware that I want to get rid of on eBay. I happen to have managed to get an old IBM A31 with 384 MB of RAM up and browsing the Web while using a modern operating system, namely: Manjaro Linux 0.8.13 (LXDE), kernel version 4.2.

The challenges here are plenty: low RAM, extremely slow and old rotational hard drive (20 GB), and the ever-increasing presence of complex multimedia and Javascript on the modern Web.

The key to my success has been the use of Zswap. In a nutshell, Zswap compresses pages that would be normally swapped out of RAM (and onto disk) into a separate storage area (in RAM) that is first compressed before being queued for swapping. This effectively increases the RAM of the computer in exchange for CPU time. With a system that is heavily I/O constrained, this is a very reasonable trade-off to make.

In order to make the default installation of Manjaro XFCE functional under such constraints:
  1. Edit /etc/default/grub and configure zswap to use the more space-efficient deflate compressor:
    1. Append "zswap.enabled=1 zswap.compressor=deflate zswap.max_pool_percent=90" to GRUB_CMDLINE_LINUX_DEFAULT
    2. update-grub
  2. Add the deflate module to the initial ramdisk by editing /etc/mkinitcpio.conf:
    1. Append "deflate" to MODULES
    2. Look inside of /etc/mkinitcpio.d/ to determine what profile to specify for rebuilding the ramdisk. If you are using the Linux 4.2 kernel (recommended):
      mkinitcpio -p linux42
  3. Uninstall the resource-hungry pulseaudio subsystem:
    1. pacman -R pulseaudio pulseaudio-ctl pulseaudio-alsa
  4. Install and use QupZilla as the default web browser
    1. pacman -Sy qupzilla
  5. For even better performance, change QupZilla's User-Agent string to an Android Webkit-based mobile device:
    1. Edit -> Preferences -> Other -> Change browser identification / User Agent Manager -> Change global User Agent

      I suggest:
      Mozilla/5.0 (Linux; U; Android 4.0.3; en-us; HTC Sensation Build/IML74K) AppleWebKit/538.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/538.1
Remarkably, these changes allow a full Web experience. Even Youtube videos seem to function.

On such a machine -- and in order to reduce slow disk I/O -- it might be advantageous to use a btrfs root filesystem mounted with gzip compression.

Tuesday, June 16, 2015

Linux BTRFS newbie thoughts: rolling back changes made to the root subvolume

If you're more intelligent than me, when you started using btrfs, you probably planned out how you are going to manage your data within a hierarchy of snapshots before using a btrfs filesystem. Let me state this more plainly, using more directive language: when using btrfs, consider mounting the root subvolume (subvolid=0) somewhere (e.g.: /media/btrfs/volume_name), for the sole purpose of managing snapshots.

Unfortunately, I wasn't that smart. I mounted my "root" btrfs volume on /backup, and willy-nilly copied files into the top level of /backup. Only later did I realize I wanted to use snapshots to allow granularity in changes made to /backup, so I created a directory /backup/snapshots/before_modification with the commands:
% mkdir /backup/snapshots
% su
# btrfs subvolume snapshot /backup /backup/snapshots/before_modification
I then made changes to the files inside of /backup, and messed something up, and then wanted to revert my changes. Okay, no problem; the btrfs system admin guide says that all I need to do is to mount the snapshot in question:
# btrfs subvolume list /backup
ID 666 Gen 5902 top level 5 path snapshots/before_modification
# umount /backup
# mount -o defaults,subvol=666 /dev/sdc1 /backup
Well, great! That worked fine; my ugly changes don't appear in /backup any more. But my btrfs filesystem is undoubtedly saving changes that I don't want to keep; these changes are associated with the 'root' subvolume (id=0). Surely, I can now delete these changes, right? (For the truly curious, you can measure the space used by a snapshot after you enable quota management). Can't I simply:
# btrfs subvolume delete 0 /backup
NOPE! Documentation says that the only argument to 'delete' is a path, and doesn't involve a subvolume ID. Uhhh... now I'm stuck. At this point, my puny brain imploded, and I had to visit #btrfs on freenode, where user darkling helped me out.

The solution? To release all of the space held by the root subvolume:
# mount -o defaults,subvol=0 /dev/sdc1 /media/btrfs/backup
# cd /media/btrfs/backup
# rm -rf dir1 dir2 dir3 dir4 ...
From there, I selectively deleted all subdirectories inside of /media/btrfs/backup -- and carefully excluded the /media/btrfs/backup/snapshots directory.

Note: even if you think you're clever, and decide to change permissions of the /media/btrfs/backup/snapshots directory itself, remember that the rm -rf command will still delete any accessible subdirectories with write permissions. In other words, DO NOT rely on permissions of the snapshot directory alone to keep your files safe.

And now, I have a directory structure very similar to that described in the btrfs system administration guide...







Tuesday, March 17, 2015

Rid thyself of that pesky PulseAudio daemon in Arch / Manjaro Linux

I have a very lightweight system -- a laptop from 2008 -- that usually works quite well until PulseAudio gets in the way of things.

Here are some tricks to disable PulseAudio:

  1. Edit /etc/pulse/client.conf and add the line:
    autospawn = no
  2. If you want to go "the whole nine yards" and uninstall PulseAudio entirely, you can build a Gnome package that does not depend on PulseAudio:
    yaourt -S gnome-settings-daemon-nopulse
  3. Next, you can entirely remove packages that depend on PulseAudio:
    pacman -R pulseaudio pulseaudio-alsa lib32-libcanberra-pulse lib32-libpulse manjaro-pulse xfce4-volumed-pulse skype
    Note that Skype 4.3 requires PulseAudio. Therefore, you have little choice but to remove it.

Wednesday, May 22, 2013

RTSP / Streaming Video with Foscam FI9821W pan/tilt camera under Linux (or any other operating system)

I purchased Foscam's 720P pan/tilt IP camera to use as a baby monitor, but was somewhat dismayed to discover that the camera didn't work well under FreeBSD... until I found the instructions at the following post.
rtsp://username:pwd@ip:port/videoMain  -- Main streaming
rtsp://username:pwd@ip:port/videoSub -- Sub streaming
rtsp://username:pwd@ip:port/audio -- Audio streaming
The camera works beautifully with VLC (VideoLan client)!

This feature very likely requires the latest firmware.

Now, I'm very pleased with this camera.

Tuesday, June 1, 2010

Correct Modelines for Panasonic TC-P42G10

Getting the picture from my Linux media box to be centered and clocked properly on my Panasonic plasma display has been quite challenging. This is because the TC-P42G10 furnishes incorrect EDID data to my computer through the DVI interface (shame on you, Panasonic!) that resulted in an off-center display and a vertical refresh rate ever so close to 60.01 Hz.

Centering the image in the display was not terribly challenging. The big mystery occurred when the television would cleanly display my Linux desktop; however, once a full-screen video started playing, the screen would go blank. It took me many hours to figure out that rounding errors in the calculated pixel clock caused the video refresh rate to be greater than 60 Hz. This, in turn, would cause the television's firmware to treat the video as invalid input -- resulting in a blank screen and no sound.

Furthermore, the latest Linux kernel drivers for ATI cards employ a new interface called kernel modesetting, or KMS. This means that, instead of the X server, the Linux kernel handles the probing of EDID information and configuration of all video timings. Because KMS is a new interface, there is no way for the user to easily specify his or her own timing information to the Linux kernel. Therefore, booting with the kernel option nomodeset is required to disable KMS and allow Xorg to handle mode changes.

Here is the modeline for Xorg:
Mode "1920x1080p"
DotClock 145
HTimings 1920 2016 2060 2200
# (67.5 kHz)
VTimings 1080 1084 1096 1125 # 60 Hz.
Flags "-hsync" "+vsync"
EndMode
Using this in the /etc/x11/xorg.conf had changed a little bit since the last time I had to do x11 hacking. Here's how we do it in 2010:
Section "Device"
Identifier "Configured Video Device"
Driver "radeon"
Option "NoDDC"
Option "IgnoreEDID" "on"
EndSection

Section "ServerFlags"
Option "AIGLX" "off" # Enabling this option seems to screw up firefox
EndSection

Section "Monitor"
Identifier "Configured Monitor"
HorizSync 15-68
VertRefresh 32-61
Mode "Original"
DotClock 148.50
HTimings 1920 2008 2052 2200
VTimings 1080 1084 1089 1125
Flags "-hsync" "+vsync"
EndMode
Mode "1920x1080p" # <60 Hz.
DotClock 145
HTimings 1920 2016 2060 2200
VTimings 1080 1084 1096 1125
Flags "-hsync" "+vsync"
# <(67.5 kHz)
EndMode
Mode "1920x1080i"
DotClock 72.5
HTimings 1920 2016 2060 2200
VTimings 1080 1084 1096 1125
Flags "-HSync" "-VSync" "Interlace"
EndMode
EndSection

Section "Screen"
Identifier "Default Screen"
Monitor "Configured Monitor"
Device "Configured Video Device"
DefaultDepth 24
SubSection "Display"
Depth 24
Modes "1920x1080p"
EndSubSection
EndSection
And there you have it.

Update: I found another test video that caused screen blanking, and had to back off the pixel clock even further to a value of "145."

Saturday, May 29, 2010

ath5k: Orinoco ComboCard 11A/B/G in Linux (Mint 9 'Isadora,' Ubuntu 10.04 'Lucid')

I discovered that my Orinoco ComboCard no longer worked when I upgraded from Ubuntu 9.10 to Linux Mint 9. The reason for this is that the ath5k kernel module does not recognize the ComboCard's PCI device ID. According to lcpci -nn:

03:00.0 Ethernet controller [0200]: Atheros Communications Inc. Device [168c:0200] (rev 01)

As of Linux kernel version 2.6.32, the ath5k driver does not seem to support 802.11g on the Orinoco ComboCard 11A/B/G. However, 802.11A works splendidly with this card, assuming that the driver is told to recognize it as a valid target.

In order to convince the Atheros driver to work with my card, I created the file /etc/modprobe.d/ath5k.conf :
install ath5k /sbin/modprobe --ignore-install ath5k && { echo '168c 0200' > /sys/bus/pci/drivers/ath5k/new_id ; }
I performed the following to append ath5k to the list of modules to be loaded at start-up:
echo ath5k >> /etc/modules
This is so much easier than modifying the kernel module code to recognize the PCI device ID of the card!