Thursday, December 10, 2009
I updated my GitHub repo: http://github.com/nemik/arduinoponics with code I wrote for the OpenWRT firmware (version 8.09.1). It provides an AJAXy-updating page to OpenWRT’s Luci web-interface which displays the analog pin values from the Arduino which the Arduinoponics sketch runs on.
Here is a screenshot, notice the extra ‘Sensors’ link on the top right to access the info, the page does not require login

Monday, November 30, 2009
Lesson #1 of embedded development: don’t write all your code to your device and not backup/check-in. I did just that when writing some code for the hydroponics monitoring setup on my Fon2100 router running OpenWRT. After trying to opkg install ntpclient and getting a segfault and NTP not working, I restarted the network on it which restarted the router. For whatever reason, the router choked and each restart went into failsafe mode. When I telnet’d into it, dmesg told me the jffs2 partition had trouble mounting with an error in jffs2_link_node_ref.
I had written a bunch of Lua code to read the serial communications coming from the ATMega168 microcontroller (it was sending its analog input values) and store it into files in /tmp which were then read by some more Lua code in the (awesome) LuCI framework to make those sensors all cool and AJAXy on the router’s web-admin menu. This worked great until the NTP attempt. So I wanted all this code back. So in case anyone is as foolish as I was to lose their code in the router, here are the steps I took to recover it. David Woodhouse (dwmw2) and dedekind at #mtd on irc.ipv6.oftc.net were extremely helpful with all this and pointed me in all the right directions.
-
backup the jffs2 image from the router using dd. mine was coming up in failsafe mode so i had to telnet into 192.168.1.1 and then run command `dd if=/dev/mtdblock2 | gzip -c | ssh nemik@pillbox ‘dd of=/tmp/mtd2.gz’ bs=2048` but make sure you do the right mtdblock2 device. do `cat /proc/mtd` and choose the one that is for “rootfs_data”. pillbox is a Linux box on my network I transferred this all to.
-
`gunzip /tmp/mtd2.gz` on the Linux box and i got my 5.5MB partition.
-
-
`sudo mknod /dev/mtd0 c 90 0`
-
`sudo modprobe mtdblock`
-
`sudo dd if=/tmp/mtd2 of=/dev/mtd0 bs=2048`
-
`sudo mount -t jffs2 mtd0 /tmp/1/` THIS DIDN’T WORK! (right away). The Fon router and openWRT are big-endian and I was trying to mount this on a little-endian x86 box. I needed to recompile the jffs2 kernel module to be big-endian. David Woodhouse (creator of JFFS2) writes how here: [
http://www.infradead.org/pipermail/linux-mtd/2007-May/018227.html] I needed to get the kernel source and recompile the jffs2 module
-
get the kernel source `apt-get source linux-image-$(uname -r)`
-
go into the source and do `make prepare_modules`
-
copy /usr/src/linux-headers-2.6.27-14-generic/Module.symvers to the source. this will be different for you, but the Module.symvers is important otherwise the module won’t load properly
- Change the native_endian #define in fs/jffs2/nodelist.h to be little_endian as David writes in the infraread link on step 7.
-
do `make CONFIG_MODVERSIONS=y M=fs/jffs2`
-
if it compiled correctly, you then have a jffs2.ko module. load it via `sudo insmod /home/nemik/code/jffs2/linux-2.6.27/fs/jffs2/jffs2.ko`
-
now try `sudo mount -t jffs2 /dev/mtdblock0 /tmp/1/` and it worked for me!
I was now able to see all my lost files in /tmp/1/ !!! the whole filesystem was there and worked great. I extracted all the code I wrote and learned my lesson never to do development on a router and always backup and check in. Hopefully this helps someone out.
Saturday, November 7, 2009
So I started a new personal project in the past week or so. I built a very crude hydroponics setup using old Gatorade bottles and a Ford windshield washer pump to push nutrient-water through the system from a 2L Coke bottle as the “reservoir”. Ghetto. As. Hell. You can check out pics of it here: http://www.flickr.com/photos/nemik/sets/72157622608195083/
So I thought it would be cool to automatically control all this via the Arduino. I built a simple little circuit to control the pump so it runs for a few seconds every 10 minutes. However this could be expanded further so that the entire hydroponics setup can be automated via a computer that talks serially to the Arduino.
The Firmata (http://firmata.org/) firmware is designed to let a host computer talk to the Arduino in this way. So I modified it a little to for the project. It can use the Firmata functions of reading analog pins to get sensor readings but I wanted to have critical functionality like the turning on/off of the pump at specific intervals to be under the Arduino’s control. Just in case the host computer crashes or a connection is lost somehow, that a critical part of the plant’s needs such as water does not break as well.
The project is hosted here http://github.com/nemik/arduinoponics and licensed freely under and MIT license.
There is still a lot of work to do here. I should post schematics for my setup first I suppose. So I’ll do that once I find a decent software in Mac or Linux that can draw schematics, never done this before.
Also, I need to write host-software for the setup. I have a FON2100 Linux modem running the OpenWRT firmware and it has the Lua language on it. I’ve never used it before but it doesn’t seem too hard. I’m thinking to maybe write a Firmata implementation for Lua (probably based on the existing Java one used in Processing). I already got it talking serial to the Arduino so it might not be too bad. Or I could just use an old laptop and then maybe modify some existing Firmata host software rather than have to make the Lua one; I’ll have to see. The Fon router is just attractive now because it comes in such a small size and runs off 5V so it could share the power for the Arduino. Provided the 12V adapter I’m using for the pump and 7805 regulator to the Arduino can handle all this…it’s only rated for 1A. I may have to get a larger one.
Anyway, let me know what you think. I would love suggestions for this.
Monday, September 28, 2009
Finally got around to uploading pictures from my trip to Russia in September 2009. http://www.flickr.com/photos/nemik/collections/72157622345503563/
http://github.com/nemik/Pecha-Kucha-Timer
I wrote this for my girlfriend to practice her upcoming Pecha Kucha presentation with.
It is one of the ghetto-est J2ME apps I’ve come across. Since J2ME doesn’t have a font as large as I wanted for the numbers to display, I made each number into a PNG using MS Paint.
They’re even offset sometimes to keep your attention.
It also disables screensavers or the phone’s backlight from turning off so it can be used a constant timer. Just counts down from 20 to 1 over and over and over (20 seconds being the length of a Pecha Kucha slide).
Saturday, February 28, 2009
So the newest version of Ubuntu (8.10) kinda sucks. I didn’t notice this until I wanted to use bluetooth. I have the XBMC media center running on my home server attached to the TV and wanted to control it with a Nintendo Wiimote I had lying around. The computer REFUSED to pair with the wiimote. After messing around with the Bluez library and libbluetooth and all that shit thinking it was the problem…I finally found what was wrong.
Bluez and everything in userland were all fine, but in the 8.10 version, the Ubuntu team decided to compile the kernel with a new subsystem for Bluetooth, ‘btusb’. This is a new module compiled in to replace the older (and perfectly working, so WTF) ‘hci-usb’. So the new ‘btusb’ only works with some newer Bluetooth adapters. I had a cheapo little Chinese one (KY-BT100 is what lsusb says) that always worked in all previous Ubuntu’s just fine. New ‘btusb’ only seems to work for half or less of the adapters out there, and this didn’t concern anyone on the Ubuntu kernel team? Really?
So it was time to compile a new kernel. I copied the config from the default 8.10 one I had installed except I disabled ‘btusb’ and enabled ‘hci-usb’ back. After compiling and booting into the new kernel, everything worked perfectly again and Wiimote pairs nicely.
Thursday, January 29, 2009
crackheads broke my window.

before

after
So i decided to give making-openmoko-a-wifi-AP thing another go.
The USB wifi card I bought (ChiefMax RaLink RT73) needs some special cross-compiled drivers to put the wifi in master mode in order to act as an AP. So i gave up that route and tried making it an ad-hoc peer-to-peer access point.
This (kinda) worked! but only connecting with another Linux computer and even then, NetworkManager’s DHCP screwed up the subnet mask and that needed to be set manually.
Trying the same in Mac OS X and Windows XP was a colossal failure. Mac OS X refuses to even accept a DHCP offer from the openmoko (openmoko is using busybox’s udhcpd) and basically same for Windows: it gives itself some crazy nonsense IP.
So best option is still to get some magic USB wifi card that can be set to master mode from the openmoko using the drivers already in the kernel. I’m not really sure at this point which chipset would do that.
Either way, I think windows and mac have (very) flawed wifi ad-hoc implimentations. Linux’s is a little better but not by much. I guess it’s the ‘forgotten mode’ of 802.11b/g.