6.04.2016

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=192.168.0.50
uci set network.wan.netmask=255.255.255.0
uci set network.wan.gateway=192.168.0.1
uci set network.wan.dns='8.8.8.8 8.8.4.4' # 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
wifi
ifup wan

Sources:
https://wiki.openwrt.org/doc/howto/clientmode
https://wiki.openwrt.org/doc/howto/internet.connection

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)

7.01.2014

How to install/set-up OpenWrt on a D-Link DIR-505L wireless router

OpenWrt wiki page for the D-Link DIR-505: https://wiki.openwrt.org/toh/d-link/dir-505

A. Basic setup and housekeeping:

Follow steps B thru E in this guide: https://dl.dropboxusercontent.com/u/57289645/blog/dir-505l_openwrt_setup_guide.txt

# ethernet/wan
uci set network.wan=interface
uci set network.wan.ifname=eth1
uci set network.wan.proto=dhcp
uci del network.lan.ifname
# wifi
uci set wireless.@wifi-device[0].disabled=0
uci set wireless.@wifi-device[0].channel=auto
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
wifi

Sources:
https://forum.openwrt.org/viewtopic.php?pid=230861#p230861
http://wiki.openwrt.org/doc/uci/wireless/encryption#configure.wpa2.psk
http://wiki.openwrt.org/doc/uci/system

B. USB storage support (assuming NTFS-formatted USB stick):

opkg update
opkg install kmod-usb-storage kmod-fs-ntfs ntfs-3g
mkdir -p /mnt/usb_drive
ntfs-3g /dev/sda1 /mnt/usb_drive -o rw,sync
# do stuff
umount /dev/sda1

Sources:
http://wiki.openwrt.org/doc/howto/usb.essentials
http://wiki.openwrt.org/doc/howto/usb.storage
http://wiki.openwrt.org/doc/howto/writable_ntfs

C. USB serial adapter support:

opkg update
opkg install kmod-usb-serial coreutils-stty
opkg install kmod-usb-serial-pl2303 # for Prolific PL2303-based devices
opkg install kmod-usb-acm # for devices using Abstract Control Model (ACM)
reboot
# device name will be /dev/ttyACM0 for ACM devices
cat /dev/ttyUSB0 # view data coming to the serial port
stty -F /dev/ttyUSB0 -a # view serial port settings

Source:
http://wiki.openwrt.org/doc/hardware/port.serial#usb.enabled.routers

D. Minimal Python install with pyserial support

opkg update
opkg install python-light python-pyserial
br/>