Sprinkler control project: Part 1 (Setting up OpenWrt on a DIR-505L to connect to an Arduino UNO)

This is part 1 of a multi-part series I'll be doing on a sprinkler control project I'm working on.

The basic idea is that I'll be using a D-Link DIR-505 connected to an Arduino UNO connected to a small relay board, which in turn will trigger the sprinkler solenoid valves.

The D-Link DIR-505 will be running OpenWrt Linux, and the UNO will have a small/simple program to receive commands from the DIR-505 to trigger the different relays/valves.

The basic setup steps for installing OpenWrt on the DIR-505 have been skipped; refer to my previous post: How to install/set-up OpenWrt on a D-Link DIR-505L wireless router

A. Basic setup and housekeeping:

# this time the DIR will connect to my home wifi router as a client so it has internet access and can host a server
# wan
uci set network.wan=interface
uci set network.wan.ifname=wlan0
uci set network.wan.proto=static
uci set network.wan.ipaddr=
uci set network.wan.netmask=
uci set network.wan.gateway=
uci set network.wan.dns='' # use Google DNS servers
# wifi
uci set wireless.@wifi-device[0].disabled=0
uci set wireless.@wifi-device[0].channel=auto
uci set wireless.@wifi-iface[0].mode=sta
uci set wireless.@wifi-iface[0].network=wan
uci set wireless.@wifi-iface[0].ssid=your_ssid_name
uci set wireless.@wifi-iface[0].encryption=psk2
uci set wireless.@wifi-iface[0].key=your_password
# system
uci set system.@system[0].hostname=your_hostname
uci set system.@system[0].timezone=PST8PDT,M3.2.0,M11.1.0 # Los Angeles
# commit changes
uci commit
ifup wan


B. Allow SSH through WAN:

uci add firewall rule
uci set firewall.@rule[-1].src=wan
uci set firewall.@rule[-1].target=ACCEPT
uci set firewall.@rule[-1].proto=tcp
uci set firewall.@rule[-1].dest_port=22
uci commit firewall
/etc/init.d/firewall restart

Source: https://forum.openwrt.org/viewtopic.php?id=24683

C. Install necessary packages:

# we'll need support for ACM devices, as the UNO appears as /dev/ttyACM0, and Python to communicate to the UNO through this device
opkg update
opkg install kmod-usb-serial kmod-usb-acm python-light python-pyserial
reboot # to detect /dev/ttyACM0 (UNO)