WiFi & IOT for home controllers/monitors using WR703N $20 routers and xx-WRT
Cluso99
Posts: 18,069
I thought it would be nice to setup a home control system using cheap WiFi routers such as the WR703N (~$20 on aliexpress or ~$24 on eBay).
These routers can be reprogrammed with OpenWRT or DD-WRT Linux.
There are a few GPIOs that can be accessed on the pcb as well as a serial (TX & RX) port and I2C.
http://wiki.openwrt.org/toh/tp-link/tl-wr703n
Before I start adding props to the WR703N to do all sorts of sensors/controls, I want to just get the basics working.
I have zero Linux experience, and I am not much better with WiFi.
But I am determined to get the basics working if at all possible.
So, does anyone here have any recommendations for OpenWRT or DD-WRT ?
And, does anyone have any ideas ?
BTW Could also be a nice way to download prop code via WiFi.
These routers can be reprogrammed with OpenWRT or DD-WRT Linux.
There are a few GPIOs that can be accessed on the pcb as well as a serial (TX & RX) port and I2C.
http://wiki.openwrt.org/toh/tp-link/tl-wr703n
Before I start adding props to the WR703N to do all sorts of sensors/controls, I want to just get the basics working.
I have zero Linux experience, and I am not much better with WiFi.
But I am determined to get the basics working if at all possible.
So, does anyone here have any recommendations for OpenWRT or DD-WRT ?
And, does anyone have any ideas ?
BTW Could also be a nice way to download prop code via WiFi.
Comments
Linux may not be a very big learning curve and there are lots of goodies to be had. But any home automation system that is really going to do it all will have to interface with the Mains at their distribution box and a CPU set up to arbitrate switching between human and automation.
I have looked into that and there are electrical boxes that can add 15 amp latching relays to all the house circuits. All the home light switches could then be converted to low voltage pulse switching and each and every outlet or other circuit could have automated control as well. Even individual on and off indicators could be provided in panels at certain locations. And the main CPU could connect via Wifi, LAN, CANbus, and any other means you desire.
I just have doubts that most people are ever going to desire to do a major home rewiring project. The latching relay panel itself is readily available, but for a complete one it is a few thousand USD.. and then there are the electrican labor and permits. After the panel is installed, the whole house would have low voltage wire (likely 24VDC) for the human override switching pulled to rooms throughout the home.
I suspect the best route to go would be to find an architect that has an interest in home automation and collaborate with him on doing all this for a client with deep pockets and a desire to have the latest in technology built into a new home.
++++++++++++++++
Nonetheless, OPENwrt opens up a wonderful world of customized routers that can also be used as servers. I have mine as a Wifi/LAN printer server that is on 24//7 due to its low power. So my wireless devices can print without plugging in a cable and any LAN computer can print without turning on another computer to read the printer.
You can also create special applications, such as a Wifi HOT SPOT for a small retail shop or restaurant. And there is much more. Of course, you do have to reload the firmware. And since the data storage is in SRAM, not hard disk -- there are a few things done differently than what we might think of as a conventional Linux OS.
Try to get a Wifi Router with lots of resources -- larger memory spaces, extra USB ports, RS232 ports, an internal hard disk -- and you will have more fun.
Personally, I would rather have the wifi router complete with chassic and power supply for about $60 to $100USD than to fool around with a bare board solution - but each to his own.
++++++++++
You could just take an old computer, add a wifi card and LAN ports and make it work as a combination router server -- but it wouldn't be low power.
Learning an Linux on an old computer first might be helpful. Here is my favorite Linux text
====> http://www.nostarch.com/howlinuxworks2
To that end installing Linux on an old PC or laptop is a great idea. Then you can try out developing your own code for Linux easily.
Of course one of the smallest cheapest and easiest ways to get up to speed with Linux today is the oft mentioned Raspberry Pi. There are the Cubie boards and Beagle Bones etc, which are fine systems, but I believe you will find the greatest support community around the Raspi.
When you have your creations up and running on a Raspi, using ethernet, WIFI, GPIO etc you may well decide it's easier just to use the Raspis as the finished product and forget those router boxes!
Having said all that, there are other ways to go for home automation. For example this : http://www.espruino.com/ coupled with this : http://www.adafruit.com/products/1469 and or this : http://www.espruino.com/NRF24L01P and or this : http://www.espruino.com/WIZnet Then you can have your simple control applications up and running in JavaScript in no time. No need to learn a new OS at all!
Soon we will be able to do all that in Python as well: http://micropython.org/
I do know some of the cheap router boards you are talking about, but this tiny one is really just a Wifi to USB node. When you start comparing them and what needs to be added against a complete wifi router with antennas, power supply, chassis, and ports.. they are not so cheap. Also, I find that a GPIO port tends to be over-rated. Most of the time there are only a small fraction of the i/o pins deployed for anything.
For actual home automation, I really like CANbus and a hardwire network that cannot be easily snooped or hacked into. Using a wireless network means anyone with Wifi snooping software can likely break in over a day or so.
About the ONLY reason I would bother with a GPIO port is to have a third i/o pin with my Rx and Tx to program a Propeller. But one can easily program a Propelelr with just Rx and Tx in Forth (which I happen to enjoy). So the basic question is "What are you really expecting out of that GPIO?".
Home automation without complete control of the Main is just not attractive to me. I am gobsmacked that Google spent 2 billion on a thermostat company for home automation. Seems so absurd. One has to control the power distribuition completely to really control HVAC.
The Pi only has one network port, but if it's a "leaf node" on the network that is fine. A five dollar USB WIFI dongle can also be used.
It's not clear that Cluso want's to build routers as such. I not sure what you mean by that. A Propeller chip is nothing but GPIO! On the edge of your network you need to interact with the physical things you want to control. A GPIO pin is often essential.
I agree a wired network is preferred but WIFI can be made pretty safe by limiting what software is running on each end of the links and adding some encryption of your own to your application code. For example if someone can hack into your WIFI they might still find they have nothing to do but hack into my SSH to get anywhere.
Well, you can call the Propeller all GPIO, but I DO NOT!
What I am referring to is the term GPIO in SOC chips that require an OS such as Windows, Android, Linux, and so on. In the SOC chips, these i/o pins do have 'first choice' dedicated functions and 'potentially' any open use as a second choice. But getting through an OS and to those second choice abilities can be nightmarish.
Like those on the SoCs they can also be used for dedicated hardware, like programming the Propeller, driving video or being used with the counters.
GPIO pins on SoCs do not require an OS to use them.
There need not be a nightmare to use GPIO on a Soc. For example it can be done as simply as:
Just sayin'
Agreeing with Heater.
I already have WiFi (hotspot) at home now. Later I will want to use this if I am remote over internet.
But for now, I just want to use one of my routers as a router/hotspot, and use the serial port as the controller. I am hoping that a script can do this - read the serial and send via wifi an on/off command.
On the slave wifi router box (there will be multiples later) it will receive a wifi command to turn a gpio pin on/off. Initially, this will just be a LED.
OpenWRT and DD-WRT will both work on the WR703N -these are nice 2x2x0.8" boxes with minimal hw and low power.
BTW I do have a RaspberryPi but other than load debian? I have done nothing with it.
I am really wanting to have most devices on their own wifi, not on a bus - otherwise I would use CAN but with a subset of the protocol and perhaps 5V.
I don't intend wiring 240V in the house. I have seen new 240v wifi orbluetooth adapters in the retail shops here. They can be controlledby smartphones.
I also want to keep my options open ashopefully wemaymove back onto our boat in thefuture. All the lightingon the boat are individually switched 12v halogen. But I will be replacing all light with LEDs. Currently I am considering how I will switch thes leds individually - maybe i will rewire with low current 4 wire and use can to one wifi box.
There are other items on the boat to monitor and control.
But my aimis to initially come to grips with getting this network running simply.
I certainly understand the generic sense, but I am just sayin' Buyer Beware -- not all mentions of GPIO are as user friendly as the Propeller.
========
@Cluso
I suppose your vision of home automation is to have something able to be moved from house to house. I guess you can see that premise pretty much conflicts with my vision of what home automation should be. I figure a system should comprehensively fit the dwelling one calls 'home' and left there for the life of the building.
A marine application for monitoring a moored pleasure vessel is an excellent niche market and just maybe the addition of a Propeller to one of these would be ideal for that. But it is just as feasible to use a Raspberry Pi or my personal favorite -- the CubieBoard. (The CubieBoard has more GPIO open to use, and an IR remote control interface installed, you would have to add a wifi dongle -- but those have dropped to less than $3 of late.)
Even on a boat, I would go for a central switching panel with latching relays for each and every circuit would be ideal. The panel may be cheaper to buy and install as it would be mostly low voltage. In that panel would sit a CPU that would handle timed switching, sensor controlled switching, over-rides, and channels of communication (wired and/or wireless) for remote switching and configuration.
The idea is that if and when an emergency situation does occur, you can always jump into that panel and override anything that you need to. You would also keep spare latching relays that could just be swapped out quickly if one were to fail. And as a last result, there would be switches that over-ride the relays completely and also you to do without.
The little device you are looking at is pretty much just a portal for wifi. You add a Propeller and that pretty much begins to be the CPU for your central switching panel or it could just monitor your boat's bilge pumps with 24/7 internet access via a wifi jump to shore.
If you don't want to go with a centralized scheme, I suspect whatever you do will be of limited utility and more of a study project. Nothing wrong with starting out that way. But bear in mind that my more ambitious modular approach will likely allow for a system that is easier to maintain and manage in the future... no requiring a complete rebuilt from the ground up when you are inspired to add features or change something.
The Electric Imp is amazing but it seems to rely on a connection to the companies "cloud" servers in order to control it from the internet. Might not be so useful on a boat far away from an internet connection.
Jim
You should be able to use sensors and RTC with enough programming to the point where remotes are a thing of the past. Maybe it could notify you via phone or internet should something go wrong but I'd have a lot more faith knowing that it was setup in a way where my interaction wasn't needed at all.
There are a few specifics that I am after...
1. Low power (rules out R-Pi)
2. Cheap WiFi module
3. Wireless - WiFi (need the distance over Bluetooth 4.0)
4. Lots of sensors/controllers
5. 1x Gateway controller WiFi that can be connected to the internet (hot spot) - via Ethernet or direct to mobile phone
6. Can be locally monitored/controlled by smartphone
A lot of what I am after is just proof of concept and can be expanded upon later.
On a boat, power is paramount. By using cheap standard modules, spares can be carried onboard. Any controller needs to be able to be bypassed to manual in case of failure.
Hence, a cheap low power standard type module needs to be the basis of the IOT devices. That's my reason for choosing the WR703N and it's readily available. If anyone knows of anything better, please let me know. BTW there are slightly cheaper WR701N and WR702N but they have smaller memories so I am unsure whether they will do the job.
Loopy: I think it's too early to wire a house for full control yet. There are modules now on the market that just plug into power points with their own switched sockets. They can be controlled by WiFi or their own remotes. Prices are coming down. They are just like the timer switches you can buy.
I can see that the main controller for the home will become the smartphone with an app (Android or iOS) and this can be done whether at home or away via the internet.
FYI: My son uses XBMC and a Raspberry Pi for his media centre. He can remotely login and play a recorded show on his TV. I was looking after his boys and they wanted to see a specific show on TV. I had no idea how to find it, so he just connected via the internet and found and started playing it.
It wasn't so long ago that we lit a candle or keroscene lamp and carried it from room to room.
But the day is coming when people will become aware that cluttering up outlets with piggy-back devices is not really a good fix. It may be a handy gadgety way to patch in a convienence, but that is about all. Failure rates are going to be higher and reliablity is going to be low (Your house cat might knock the thing out of whack.)
But I still believe that anything really good comes with a centralized integration of the switching with the power distribution and that the use of latching relays (mechanical or solid state) are the low-power relay solution. I have seen homes and offices with this set up since the 1960s. The technology is nothing new. But the installation is best done when the building is built as it is a costly retrofit.
There may come a day when building codes with require new installations should provide all this, or the luxury home market might popularize the right solution... years and years away.
+++++++++++
I can appreciate the need for low power and for wifi. At $20 for one of these, I will look around and see if I can get one locally to refit with Linux. The larger memory choice is always wise as you are likely to desire more features than your memory will allow anyway.
You can plug in a memory still to the USB port and have that operate as an additional memory resource.
It looks like getting to the Tx, the Rx, and any additional GPIO is going to be micro-surgery... not for a first-time hacker.
My Asus wl-500gp is much easier to deal with... but it wants a 3 amp power supply.
Your desire for low power may also conflict with the actual range of the wifi. Nothing is clearly stated about how much power goes into the radio communications.
The wifi feature in a normal router set up in Linux uses a 'bridge configuration'. It takes a bit of understanding about LANs and Routers and Bridges to graps what is going on. But the Wifi side of things is pretty much an automated blackbox that can handle a wifi login and provide a seamless transistion to the equivalent of a conventional wired LAN to web link.
I am not sure how firewall services and all the other stuff is going to work in such a small device with just one LAN port and wifi. So at best, I need to get one and hack it to see how it compares to a 'real wifi router' experience.
SSH and related encryption services are relatively simply. A Linux terminal application such as PuTTY offers all that.
http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
You can even get PuTTY for Windows if you want to evaluate it without yet learning Linux.
I went out and purchased a WR702n for a mere $17.50USD locally with Ver1.1 firmware... only to discover that I should have checked first.
I need a WR703n for OpenWrt support and the price is a bit higher. They were sitting right next to the WR702n devices, but I opted for what I thought was the cheapest device to hack into.
You not only have to get the right device, you have to get the correct firmware version to hack. My error is quite typical of fooling around with OpenWRT....
it all starts with getting the exactly right device. DO NOT OPEN the package until you have checked OPENwrt.
The WR702n comes with a USB 5V 1 amp power supply, a USB to USB cable, and a short LAN cable. I have a dedicated use for this (the Landlady provided a second internet service that I have not used but is active), so I may not return it and just go back for the wr703n to hack.
++++++++==
In any event the first phase of hacking is to see what the device does without hacking it. If you like it just the way it is, why bother?
So far it is a rather brainless Plug and Play. You locate 'dlink' in your wireless and select, and then enter the Password on the rear of the device. I am using it right NOW and off my regular internet wifi router. Seems to respond well.
It certainly wouldn't hurt download a copy of the User's Manual (nearly 190 pages) before you buy. It appears that TP-LINK has yet to publish the TP-WR703n Manual, so the TP-702n Manual will have to do.
It comes with all the documents on a tiny 3" CD.
http://www.tp-link.com/resources/document/TL-WR702N_V1_User_Guide_1910010880.pdf
Here is the second WR703N that I purchased for US$19.51 (note it's now dearer)
http://www.aliexpress.com/item/3G-TAX-FREE-150Mbps-Wireless-Portable-Mini-Wi-Fi-Wireless-Router-Travel-TP-LINK-TL-WR703N/1713957427.html
My first was this one for A$19.70+A$4.99 shipping (again now more expensive)
http://www.ebay.com.au/itm/TP-LINK-TL-WR703N-150Mbps-150M-Nano-Mini-Portable-WiFi-3G-Wireless-Router-AP-TR-/141075805085?pt=LH_DefaultDomain_15&hash=item20d8c5f39d
Don't worry about the current firmware as you will be reloading it. If you brick the device, you will need to add the serial port connections to the main board which I suggest you do anyway. You can always start with loading dd-wrt first. There are lots of information to do this.
Note I have added the Tx & Rx pins to the mini microUSB connector on my first unit and seen the bootup info. But I haven't reloaded the firmware yet.
As long as you have a small tip iron, its quite easy for experienced solderers to add these wires. I use kynar wire.
I will add a pic here shortly. Note I marked one end where the box lid clip is located to make it easier to re-open, and I also ground/cut off the side retaining catches (opposite the RJ45).
I think you can still use the WR702N but it comes with less memory so you have to remove some things from the package. There is a difference discussion - search google.
BTW For the IOT device ends, I don't intend to ever use the Ethernet port. Support could be removed from Linux.
Here is a pic of my first modified WR703N
As soon as I know what I want inside the box I can make a pcb to fit.
Version numbers in some of these products reflect much more than a change in firmware, they can be a completely different wifi board or chip. So they may become very very significant.
OPENwrt is very diligent at keep a good data base of what can be hacked easily and what is not presently available. So I don't think ignoring the Version is a wise thing to do. This has been a part of the hacking environment for routers since the start of it all.
It will be a day or two before I go back for a 703. Isn't it annoying that the Web will actually bump up the price when you go back for more of the same? I try to buy locally unless it is obviously impossible.
Mine is also the microUSB to USB. I just wasn't clear in saying so. The 702 has only a microUSB plug for power and potentially a USB link. I want that very much to add a 4Gbyte filesystem it that will work. But providing power to the unit seems to imply that I have to create some sort of splitter cable or hack for an independent +5V barrel plug interface.
http://wiki.openwrt.org/toh/tp-link/tl-wr702n
OPENwrt will not support the wr-702 due to the lesser FLASH memory. It is really not worth my trouble to hack it if OPENwrt is wary. That extra FLASH memory will matter. ... not to be confused with RAM
I see that the 702 is missing the full size USB connector and a few components, in addition to the smaller flash.
The power is supplied via the microUSB. If you don't add the serial port to that connector, then this is how you supply the 5V power. IIRC you could also provide it via the full sized USB connector.
The 3.5mm (or 2.5mm) connector is usually added to bring out the serial port rather than on the microUSB.
I have an FT232RL board where I can also provide the 5V from the USB side, so I can use this with a breakout to supply the router and connect the serial port.
You still need to get a GPIO output to toggle the Propeller's Reset through a transistor or a MOSfet to be able to do direct Propeller binary loads to the Propeller EEPROM.
That would require downloading a binary file wirelessly into the wr703n's own Linux file system. And also, having properly loaded the Linux version of the Propeller binary loader properly cross-compiled for whatever the processor is.
That is a bit much for me. But having Forth on the Propeller can download Forth programs as a simple .txt file. My gut feeling is that using Forth makes this a whole lot easier. Locating and learnung a cross-compiler and tool chain for GCC may take up a lot of time.
http://www.dd-wrt.com/phpBB2/viewtopic.php?t=61112http://www.dd-wrt.com/phpBB2/viewtopic.php?t=61112
Of course, with the GCC cross-compile you might even load the wr-703 with SimpleIDE and not work from the command line. My ASUS wl500g has an HTML interface that works quite nicely.
How ambitious are you? I really do like hack these devices as a better means to deploying the Propeller.
So, initially I am just going to get the WR703N (device end) working to my FT232RL / USB to PC and PST.
WiFi downloading to the prop would be nice to get working...
It ought to be possible to write a downloader that can toggle the GPIO to do the reset as part of the download so that the transistor cct would not be required.
Perhaps RossH's payload that comes with Catalina could be modified to do this. There are a few things to be sorted but I am sure they can be overcome.
IIRC we can use the reset sw on the WR703N as an input to Linux, and the LED as an output. So we should be able to get a simple I/O device working once OpenWRT is running correctly. I think we need an ssh script running to do the I/O. This will be my biggest part of the learning curve - running Linux.
BTW none of my WR703N's came with RJ45 cables (Ethernet). Do you know if they are 1:1 pinout (or cross-over)?
PuTTY is probably the easiest way to deploy SSH scripts in Linux, but there are other ways that I either don't bother with or don't know about.
Find out how to install PuTTY as your first software addition. You won't regret it.
It seems you have TTL RS233 from the WR703n that is going through a level shifter to become true RS232. It could just as easily gone through RS422 devices to convert to that for a serial wire connection that can work better in a noisy environment and reach further distances.
That only provides the Rx and Tx. and you desire a Reset as well (regardless of how it is wired. that comes later). I expect you to have to write something in GCC to get that Reset working when you want to program a Propeller binary. Of course, someone else might have a better understanding of how that will come about. Heater seems to thing these things are easy to do..... ;-)
So it seems that you either have NO USB active on the WR703n (which is what I think I am reading) or you have some USB capablities.
This is important to me... because my Asus wl500gp provides two USB host ports. and these allow me to connect to a printer and use it as a printer server, to a USB to RS232 to Telnet with the device, to a USB hard disk for massive additional storage, or to a USB memory stick for up to 32Gbytes of storage.
So I am just trying to figure out if you have a USB slave, a USB host, or both, or none.
++++++++++++
Next item...
The RS232 port can be very useful without any USB. I previously mentioned PuTTY terminal software that you will need to download and install in the WL703n and unlike Parallax software, it is likely that OPENwrt has already compiled a copy for your Antheros chip.
Ideally you could turn on your wireless notebook, find the Admin login for the WR703n, login to PuTTY and then just use it to transfer files or keyboard input directly to a Propeller.
Even if you don't like Forth, it is an active serial interface that will send you a Prompt and respond to your keyboard input. So I think it is worth loading either Tachyon, Pfth, or PropForth on a Propeller and seeing if it works well with your RS232 port. .... later you can get that GPIO activated. You will be more motivated if you know the Propeller has already talked to you in the way you hope for.
Not having an SDmemory stick feasible as an add-on, restricts your ability to install added programs. So it is why it seems so important to me.
=========
I do like the WL702n after using it all afternoon. It is fast, as fast as my other older wifi. And it has a lot of features mentioned in the 190 page manual. It can serve as a repeater if you get too far from your main wifi installation, and maybe as a private wireless link to your main wifi router when you want to have a computer in your out-house or on your private golf course.
Lots of fun to be had here without a lot of soldering and hacking. More fun to be had if you also solder and hack.
==========
Though people are do such, I really don't want to mess with swapping out the on-board SRAM and FLASH chips with bigger devices to add more space. These things are possible, but are rather hardcore mods that should be left to people that really understand what they are doing and can easily get the memory chips. It could also get more expensive than it is really worth.
IOW, use the device until you are convinced you need to upgrade with more memory. And expect the upgrades to force you into learning more deeply about how to reconfigure your system. The firmware needs to be told that there is more space and how to use. It isn't just going to scream "Oh! WOW... I have more memory." This is low level stuff.
I didn't really check, but it seems like it was just a 1:1 pinout, no cross-over. I just assumed is was straight through, pluged it into my service and it worked.
It is very rare to need a cross-over cable these days... only for PC to PC LAN ports.
It seems that the WR702N had all the promotional goodies, and the WR703N has just more power. I am wondering if we will ever see a User Manual written for it.
Now I'm confused. What are SSH scripts? Why would anyone install putty on a Linux box? How would you use a GUI program, putty uses X Windows, on router that has no graphics capability?
Seems more likely to me that one would run putty on a Windows box so as to be able to log into the the router and get a command line terminal. With that one can run shell scripts on the router.
If one has a Propeller connected via serial to such a router with reset connected to a GPIO it should be possible to reset the Propeller by simply writing to a "magic" special file located in /sys. Or at least that is how it is done on every other ARM Soc I have seen recently. That is how the Propeller loader works from the Raspberry Pi.
Taken from here: http://elinux.org/RPi_Low-level_peripherals#Bash_shell_script.2C_using_sysfs.2C_part_of_the_raspbian_operating_system
The above extroot feature will extend memory storage to really get the full use of the WR703n.
@Heater
Yeah, I guess you are just keeping me honest once again.
What one really wants is a SSH daemon running on the wr703n. I guess I got this backwards.
What is needed is Dropbear.
http://wiki.openwrt.org/doc/uci/dropbear on the wr703n and PuTTY on your computer of any sort - Windows, Linux, or Apple can use PuTTY and this is free.
my slave(s) 703s will initially connect via the ttl serial to my propplug equiv tomy pc which will run a terminal program. for simple terminal use, PST is nice and simple. i wont have propsconnected initially, nor will i have anything connectedto the usb port, nor the ethernet port. i have a usb plug with microsd socket (more than 1) so i can use this for file transfer or data logging.
i am not sure what hw config i will have for the master end. perhaps i might be able to use my existing wifi hot spot, which in reality is my xoom with mobile 3G data connection to the internet - i dont have a wired adsl/cable internet connection. i havent had a landline for almost 10 years.
heater,
thanks. once i get openwrt loaded iwillgive the ssh and shell script a go. i actually am not familiar with this but i am hopingits not that difficult. I believe the reset sw and the led can be usd as an input and output respectively. hopefully i can get a script working that can read the sw and set the led accordingly. this will prove the preliminary. then i can expand this to do this remotely, etc.
i am not intending to add the props until i get the basics working. just trying to keep it simple for starters, and learning as i go.
BTW the usb to uSD are $1 on ebay. Cheap usb hubs can also be used. the Sydneyuser group made some usb hub boards a while back.
Hope to getsome time tomorrow to load openwrt.