I learned on reddit the other day about the sudo “insults” capability where it throws shade at you when you mistype the password. I configured it everywhere I could, but I wanted more, so I came across cowsay and fortune.
$ fortune | cowsay
/ SHIFT TO THE LEFT! SHIFT TO THE RIGHT! \
\ POP UP, PUSH DOWN, BYTE, BYTE, BYTE! /
Oh this is exciting! I’ve been trying to figure out how to get motion events from my IP camera into my home-assistant instance running on my Raspberry Pi, and I just did a successful test! It works! Hooray. Briefly, I set up an email server on the Pi, have the camera email the Pi, have the email server trigger a script which parses the email for key words and sends MQTT signals as appropriate, at which point the home-assistant MQTT client sees them and triggers automations (like blinking a light to scare people off). Here’s how I did it.
You may have seen my earlier post about my new home automation setup. Well I just upgraded it! I just finished testing out a new infrared remote control send and receive capability and it is pure awesome. Here’s what I can do now from within home-assistant:
Turn on and off my new DeLonghi portable air conditioner from Costco, and set the temperature to whatever
Turn on and off the TV and press any buttons from its remote control
Turn on and off the stereo and virtually press any buttons from its remote control (which I never even had!)
Use an old random blueray remote control to set scenes, turn lights on and off, etc. (basically do anything under home-assistant’s control)
This post is about how I did it on my Raspberry Pi.
I went over to my friend’s house last night to help get home-assistant on a Raspberry Pi working for his z-wave door sensors and siren. The Ecotech sensor showed up fine but the Aeotech recessed one (Recessed Door Sensor Gen5 , ZW089-A) did not show up by default. After poking around in the logs for a while, we realized that it was sending BASIC_SET command classes instead of BinarySensor commands. Apparently (I thought I had fixed this already), home-assistant doesn’t recognize the BASIC_SET commands just yet. But looking at the config file for this device, we discovered that config item 121 changes which kind of report this sensor sends: Continue reading Using an Aeotech recessed door sensor in home-assistant
In this post, we’ll take a brief measurement of regular old FM radio stations and try to determine where we are. It’s like a GPS but with local FM transmitters instead of satellites. I did this just for fun. I wonder if it could be used for indoor location and stuff? It is nowhere near as accurate as GPS. But whatever.
Reading FM radio signal power
The first step is to get a reading of all the nearby radio stations. I used gnuradio and a HackRF One software defined radio. A simple flow-chart that takes the FFT and dumps it to a file is all I needed. I had to throttle the I/O or else my computer would freeze. I used 16M sample rate to have as wide a bandwidth as possible.
The file sink saves the FFT results in 4-byte integers and just has one 1024-length vector after the other. In a few seconds, I had a 50 MB of data. I did all the post-processing in an external Python script.
I’ve always dreamed of having a “smart-home.” There’s just something cool about being able to flip switches and read sensors and have a program turn a light on when you open the door, but only if it’s dark. This post is about home automation.
Sending and receiving text with Morse code light pulses across the room (or to your neighbor) is a fun and cheap project you can do on a Raspberry Pi or Arduino or any other microcontroller. This post explains how I did it, and how you can do it too.
The hardware is simple and cheap. Here’s my parts list:
Raspberry Pi B+ as the controller. This does the sending, receiving, and signal processing.
Photoresistor – Just a little guy that has variable resistance based on how much light is hitting it
A 220 Ohm resistor – to make a voltage divider with the photoresistor for reading the input signal
MCP3008 10-bit Analog-to-Digital Converter (ADC) – Since the RPi doesn’t come with an ADC, this is required for converting analog voltage from the photoresistor into a signal I can process on the RPi.
Laser module – to transmit with laser light. I got one from sunfounder.com for like 3 bucks.
You can learn how to use the ADC at this Adafruit tutorial. I decided to talk to the ADC with the RPi’s hardware SPI interface, which I had already enabled. I wanted to be able to go very fast. (You can alternatively do SPI off of GPIO ports with software, if you prefer.) The laser just hooks directly between a GPIO and +5V. Here’s the layout:
Sensors are fun!I wanted to keep an eye on the temperature of one of my home physics projects and realized I needed a thermocouple and a convenient way to read it. This post is about how I got one and wrote a Python program to send the data from a Raspberry PI over the network to my laptop, which plots the results in real time.
I bought a K-type thermocouple for several dollars that ranges from -100°C to 500°C. The Seebeck effect that makes it work only gives microvolts per degree so I needed a good amplifier for it. And since I wanted to read it on a Raspberry PI (which only has digital inputs), I’d need an analog-to-digital converter (ADC). Conveniently, the MAX31855 does amplification and ADC and is like $15, so I got one. Sweet. There’s even a Python library for it that makes it easy to access. Double-sweet.
Since I’m on a late 1800s physics kick, I’ve been staring at my Crookes radiometer a lot.
You might remember these from the hands-on museum. Today, these are just novelty items, but back in the 1800’s, there were actually scientific instruments that could quantitatively read out the amount of incoming radiation (like visible or infrared light). They were generally read out using a calibrated spinning disk with slots in it. It’s like when you have a fan spinning in a dark room, and you adjust a strobe light until it looks like the fan isn’t spinning. Then, if you know how fast the strobe is blinking, you know how fast the object is spinning. This is called a stroboscope.
Well, I don’t have a stroboscope. But I do have a digital camera and a computer. As it turns out, I can read the Crookes radiometer using that!
This post is about how I set up remote operation on my ham radio through a Wifi network, over a VPN, and around the world using a Raspberry Pi, like this:
This could be useful for people who travel a lot and want to be able to use their rig while away. Or for people who want to set up their radio and antenna far away from where they actually live (e.g. apartment dwellers who have friends or parents who live in the boonies and wouldn’t mind you erecting an antenna). If you want to skip the VPN and just control your ham shack from your kitchen, that’s even easier.
I did this all with an ICOM-7100 all-mode radio, a Raspberry Pi B+, a Buffalo DD-WRT router/VPN server, and a laptop running Ubuntu 15.04. This post focuses on the radio control and networked audio but not on setting up the VPN.
Linux is an open-source operating system that you can download and install on your computer to complement (or even replace) your current operating system (Windows or MacOS). It started out when some guy wrote some code and gave it to the world community for free. It has become huge, and now provides the engine of Android phones and tablets, runs about 40% of the servers that make up the internet, and powers 97% of the world’s supercomputers. It’s a stunning success in the social open-source experiment.
For home use, it is just now ditching a reputation of being only for nerds, scientists, and hobbyists like me, with lots of headaches getting software and hardware working nicely with it. Really, I’ve been using it at home on my laptop since 2007 and it’s evolved to a point where I think it’s totally usable for most people. It also has a focus on privacy, security, and stability. Since the code is open (everyone can see and change how and why it works), there’s less mystery about what anyone is doing with your computer and more control to get it to do what you want. It was the speed and low-resource requirements that brought me to Linux originally, and it’s the quality and open philosophy that has made me a real proponent.
I was doing some speed tests with cython in Windows and started wondering what the import precedence was between py, pyc, and pyd files (not to mention pyo). So I did a simple little test with two files, test.py and test2.py. Test.py just had a print statement in it and test2 just imported test1 (so it would create the pyc). I compiled test.py with cython into test.pyd and then changed test.py to print something else.
Conclusion: The pyd file was always imported if it was present. If it wasn’t there, then the new print statement from the new test.py was printed out. I’m sure this is documented somewhere but I’m not sure where. The conclusion holds if there are “optimized” pyo files present as well.
Just FYI, I was having a problem with ipython 0.12 running within Console, where pressing Ctrl-C to cancel an operation in a Python would actually just close the whole ipython window! It was horrible, since before I reinstalled everything it wouldn’t do that. Anyway, there’s an email chain talking about this here, but it’s irrelevant to this particular problem, since I’m using mainline (non-dev repo) versions and don’t know what an ETS is.
Thankfully, there’s a very simple solution (assuming you made my same mistake). Rather than setting the console tab to C:python27scriptsipython.exe, instead set it to C:python27python.exe C:python27scriptsipython-script.py and Ctrl+C will give a KeyboardInterrupt and leave you in ipython, just like the good old days!
Continuing the journey, the folks at work upgraded me to 64-bit Windows 7 and the Trilinos folks updated to 10.10. Needless to say, I had to rebuild. I can’t definitively say which of these steps is necessary but I can tell you that if you follow them, you can compile a C++ python extension that uses many aspects of Trilinos on this system. And not just a few packages from Trilinos either. In fact, I’m currently using all of the following:
To do this, first run the trilinos cmake system without shared libraries. Then build. This builds things like epetra.lib. Now, go back and turn on shared libraries and build again, this time with shared libraries turned on. This builds the dlls, which I believe are required to build a python extension. If one of the ones you needs fails, just go in to Visual Studio 2008 and open up the Trilinos solution. Right click the project. Change from a static library to a dynamic librray. Change Use of MFC to “Use MFC if a Shared DLL.” Change Use of ATL to “Dynamic Link to ATL.” The rebuild the package. The DLL should be created.
Once all the static and shared libraries are built, I didn’t even mess with environmental variables (being a grad student and all) so I just copied them all into the build directory of my Python extension. On import, it worked just fine. Amazing!
I have yet to try linking to MSMPI and running large reactor problems on Microsoft HPC but that will be coming someday.
Continuing my python extension project, I’ve now successfully built a toy python 2.7 extension in C++ that uses the Epetra package from Trilinos 10.8. I’ve built it on Ubuntu 11.10 (with gcc) and on Windows XP (with Visual Studio 2008) using distutils. It’s a bit of a hack, but it works and is a path forward for me.
I started with Linux, because I figured it would be easier. I learned a few things along the way. First, you have to have built Trilinos with shared libraries enabled. This is required for how Python handles things, I guess, and is made clear under the heading “Shared Libraries” in this file. The PyTrilinos package (which is effectively a professional set of python-trilinos extensions, btw. I needed a custom one!) needs them as well. So run your cmake-gui and check the shared libraries button. Besides the libepetra.a in the build folder, you’ll now also find a libepetra.so. In Windows, you’ll get >500 errors if you compile all of trilinos with shared libraries, but Epetra at least worked. Continue reading building a python extension with trilinos on linux and windows
I’m just embarking on a historic journey to learn a bit about the Trilinos math library. To get started, I’ve gone through the hands-on tutorial a bit and after a few tries, I’ve gotten something compiled.
Trilinos 10.4 is available in the repositories for Ubuntu (11.10 confirmed). But Trilinos 10.8 is out now, so I had to build my own. Their instructions with CMAKE were quite good and the build process didn’t have too many hiccups. I found that the cmake gui is the way to go. Make sure you enable Didasko (the tutorial) in the cmake gui. When you do this, a few more Didasko options show up so you have to go enable those too. Continue reading my experience compiling against Trilinos on Ubuntu
I just built ERANOS 2.1 reactor analysis suite from France on a 64-bit linux workstation with Red Hat 7. It wasn’t that bad, as the CEA has done a great job at automating the installation process. I’ll briefly discuss how things went.
iPython is a very nice way to fiddle around with Python interactively. Most beginners just use IDLE for this, since it comes with Python. But as you get to plotting stuff, you’ll find that IDLE just doesn’t cut it (it freezes every time you plot anything). So you try the regular python command line (on the black screen) but get frustrated that you can’t change directories or use tabbed completion or anything. You hear about ipython and try to use it but it’s not very obvious. Well all you have to do is make a shortcut and you’ll be off and running.By the way, if you had started on Linux in the first place, you wouldn’t have to deal with all this! Anyway, on Windows,
0. Make sure you have Python installed with matplotlib and numpy modules.
Yay. Now you have ipython on windows with matplotlib interactive capabilities! I suggest having your text editor open in one window and this ipython window in the other. Edit your code, save it, and then type “run mycode.py” to run it in the interpreter.