A Pi Shack BASIC Year in Review
Happy New Year
I hope you had a blessed Christmas!
I haven't written anything on here since Thanksgiving. This being the "New Year" it seemed useful to look back at the things I've accomplished with Pi Shack BASIC (psBASIC). While I originally started on psBASIC purely for hardware manipulation it has grown to be my main tool in many Linux administration and data analysis tasks. There literally isn't a day that goes by that my psBASIC minions aren't helping me to keep an eye my clients' and my own systems. At just this instant it showed me that something called "zoominfobot" popped in to troll my web server.
I better go checkout what that thing is!
Beyond the animated light displays, responding to hardware events, triggering hardware actions and resurrecting antique computer games, it has helped me uncover SSD fraud, analyze the hard drive in a satellite receiver, search sector-by-sector for lost data on a hard drive, analyze website access logs, cross check TSV data with system files, automate changes to AWS S3 tanks and keep tabs on remote systems.
The SysAdmins Multi-tool
I don't think I have a system under my watch that I haven't installed it on. I run into some oddball problem and the first tool I now reach for is psBASIC. Bash, Dash, Python, iPython, IDLE, TCL, ... and others offer some of the interactive experience, but they are all missing parts of the interactivity that I came to expect having grown up on the pre-floppy personal computers of the 1970s.
psBASIC provides an interactive environment that has those missing features. Its easy to dynamically analyze things, develop recipes for dealing with them. Retry the analysis, refine, repeat, ... and then save your work for the start of another project. Your BASIC program and variables become your environment. And you don't have to hunt through history files to save your work or fight to get updated code into your operating environment.
Since BASIC is a full fledged language you don't have to fight bizarre syntax, eroded performance or go far out of your way to cobble together some missing common programming operation. You have a pretty complete suite of math operations and string manipulations available for processing data before deciding how to act on it. It also has the greatest flexibility in breaking text data tables down into their component fields than any other language I've seen. I know. I've had to write the field splitting logic in more than one language!
While psBASIC lacks some of the newer features of other languages it makes up for it in its ability to interact with other tools in the Linux environment. I was dealing with a list of a few hundred thousand files on an S3 bucket. I OPENed grep
to get me into my target ballpark, since grep
is heavily optimized for finding specific lines.
I can OPEN sort
to put things in order when producing results. Or I can OPEN
awk
to take advantage of its summary capabilities. The shell()
function and variations of the OPEN
command allow you to leverage the shell's and other programs' capabilities for use in your programs.
Oh! And did I mention that I used psBASIC to pre-process the bucket listing from the aws
command line tool to produce the list I was cross-checking against?
I think of psBASIC as the uber-agile glue to pull existing tools together to quickly get results. Its that perfect tool for when you need a bit more than BASH can reasonably provide and you need to actively manipulate data, code and hardware.
Programming your hardware
I was experimenting with using 74LS595 shift registers to expand the 4 SPI wires into a typical Hitachi character LCD style 12 wire interface. Of course with a pair of '595s you actually have 16 additional output lines (8 per chip daisy-chained). With psBASIC an OrangePi, breadboard, 74LS595s and an LCD display it was simple to send test signals from the command prompt and flesh out the idea.
I routinely use psBASIC to communicate with I2C devices to retrieve the current time from an RTC, read inputs and outputs from custom programmed ATMegas or even use an ATMega as an I2C attached LCD driver. It needs less pins and provides a more terminal like output. Or one could read the various sensors on their PC motherboard.
With GPIO pins psBASIC will automatically export and set directions based on the command you use. Of course, you need the appropriate rights for this to work. And if needed you can still fall back to raw file based I/O to access the Linux GPIO v1 interface (/sys/class/gpio...). I have needed to do that to read the last state of an output back during program startup.
The 8TB USB attached SSD scam
A friend of mine sent me an 8TB USB attached SSD. He claimed he bought it for an insanely cheap price off of Alibaba. Well... stories abound about cheap Chinese storage that are frauds. There are plenty of YouTube vids about them. I wondered if my friend had been "had". But... what the hay? Lets try to use it!
It was formatted in NTFS. The vendor claimed we had to use the format provided by them. That it couldn't be reformatted. I briefly wondered what they had been smoking. This felt extra scammy to me. I mean, from the computer perspective a disk is a stack of blocks to be used however it seems fitting. The storage could care less what filesystem you put on it or don't. A storage device that requires a specific vendor format?!?! NOT!
I don't use NTFS anyways. This is a Linux shop. NTFS doesn't work for us. So I formatted it and it eventually spouted errors. Various test procedures with mkfs
, dd
and badblocks
produced seemingly random results. I eventually thought I had ended up with a 1TB drive. OK, they lied, a little. But 1TB of USB attached SSD is still plenty useful, and I didn't buy it. But when trying to put small amounts of actual data on it, stuff was getting corrupted.
I broke out psBASIC and used it to do block-by-block testing with some different algorithms. I was able to rapidly change out diagnostics as I detected different patterns. I was having fun! What I found was that it seemed to be about 128GB of unreliable flash. This got me real curious. So I pried the case apart and took a look inside. There was a tiny PCB about half the size of a business card with two uSD sockets, one was filled with an unmarked card. 1TB uSD was unheard of at that time. I searched. I haven't looked since. It still may be.
I didn't press it any further. They obviously had a controller that reports 8TB regardless of the actual storage reported by the uSDs. It too was unmarked. And they carefully crafted a phony NTFS on the storage so it appeared to have 8TB of space. Then some poor unsuspecting sap will go and store some large quantity of important data on it just to have it vaporize.
I think this is how China handles uSD QC issues. Wrap the defective chips in shiny boxes, stamp outrageous capacities on them and sell them real cheap. Then they can be someone else's eWaste and they collect extra bucks in the process! What a deal!
Get the "Professional" Edition
It's only $50 for the full "professional" edition, the cost of a good meal out somewhere. Treat yourself to greater levels of productivity with this cool tool.