Some time ago, we were approached by one potential customer with his own idea of a “smart home” project. We are always glad for customers, especially if they have a more or less intelligible idea and enough money to implement it (I’ll say right away that this customer is still the ideal for a spherical customer in a vacuum, we are lucky with him). So after a couple of meetings, a general description of the project was born, and we began to look for options for technical implementation. We needed an inexpensive controller with WiFi and USB support, low power consumption and, most importantly, with an open enough architecture so that we could make our own customized solution on its basis.
And then a very good
article caught our eye. Wow, what things happen, it turns out! I myself have used the mini-router TP-LINK TL-WR702N, bought rubles for 700, as a mobile access point for traveling around China (where until now the RJ-45 socket in the room with no WiFi is quite common) the fact that a decent single board computer lives inside with a bunch of extra features was a pleasant surprise for me. And since we are tightly tied with China in our main business (and Chinese electronics manufacturers in particular), it became interesting to us - how much will our own board based on SoC AR9331 cost, if the whole is a complete solution in the package, in the box, with wires and block food costs 700r in Russia ($ 22 at the time) in retail?

1. What is so attractive about SoC AR9331?
For a start, what is the basis of all these extremely cheap mini-routers? This is a SoC (system-on-chip) Atheros AR9331 (
datashit ). In one small chip (12x12mm) are concentrated:
- MIPS 400MHz 32-bit processor
- memory interfaces (DRAM and serial Flash)
- five-port Ethernet switch
- 2.4 GHz WiFi interface 802.11b / g / n (up to 130 Mbps)
- USB 2.0 controller (host / client)
- UART, I2S / SPDIF, SLIC interfaces
- up to 28 GPIO (!!!).
This all works (in addition to proprietary firmware) under control of
OpenWRT . But the most interesting thing is that this chip in China is wholesale in the region of 5-6 USD! But…
')
2. Give two!
I really wanted to look at this miracle alive, to conduct a couple of inhuman experiments. It turned out that in the "walking distance" there are two options for the CPU board based on the AR9331. These are Lithuanian
Carambola2 and Chinese
EL-M150 boards . Of course, for convenience we ordered a development board for a couple or three (
this one and
this one , respectively).


It is clear that we ordered Chinese motherboards through our own channels in Shenzhen, and they were much cheaper (65 USD with delivery). At the same time, the Chinese have acquired several pieces of processor boards to find out how much their production actually costs? (Chinese retail sells them for $ 25). Here are these:

3. Carambola2 development board
Lyrical digression.I can not share my memories of the first time when I came across this funny word - “carambola”. At the dawn of perestroika, the USSR began to publish a local version of the magazine "Burda Fashion". It was an unconditional hit, our women (in my case - mother) stood in a queue to get acquainted with the advanced Western ideas of cutting and sewing. At that time, I was not interested in rags, but now there were all sorts of interesting recipes (and I always loved to devour, and now ... oh ...), which I always read with pleasure and the extreme degree of curiosity. Painfully, all this glossy splendor was noticeably different from the beloved desktop “Books about tasty and healthy food” of 1976 edition. So, in one of the recipes I met the golden words: "... take two cannons." To say that I fell into a stupor is to say nothing. Not only did I have absolutely no idea
where they could be taken in the late 80s in Leningrad? To my deepest shock, I could not even imagine -
what is it all about ?! Vegetable? Fruit? Nut? Seasoning? Spice? And, alas, there was no photo of a magical object with the miraculous (or miraculous) name of "carambola" ... That's how I had to live in ignorance until the Internet appeared.


What well:
- inexpensive (33 Euro)
- miniUSB connector (connect to computer and immediately get power plus console)
- small (84x63x12mm with connectors)
- ceramic WiFi antenna plus connector for a small external antenna
- 16MB of flash memory
- developed community of enthusiasts.
What is not very good:
- few things: connectors, buttons, LEDs, etc.
- WiFi is disabled by default, SCP and console are inaccessible, out of the box - only WEB access via Ethernet
- non-informative indication of the current state
- I got a version with some kind of a very truncated firmware
- It is not clear that with accessibility: I bought before the New Year, but now the site is only available pre-order.
Since the power is from the computer via miniUSB, the power consumption has not yet been measured.
4. EL-M150 development board

What well:
- Dofig total on the board (14 LEDs, two relays, three Ethernet connectors, three USB (full-sized), SD card slot, power button with latching, three buttons without latching (including Reset), 16 jumpers), connector for a large WiFi antenna
- the firmware is completely full at once, it was not necessary to reflash right away
- WiFi is included out of the box in the “access point” mode - initial setup without problems
- The SCP and console are available immediately (if the buyer is sufficiently quick to guess the “admin” password for the “root” user).
What is not very good:
more expensive and more Carambola (this is not a drawback - see the list of opportunities a little higher)- need a separate power supply (7-12V)
- flash memory - 8Mb
- Built-in WiFi antenna (track on the board) - not a fountain (although it works)
- Initially, the WEB-interface is in Chinese (oh, how can I use foul language !)
- 2 relays of the magic brand “HUI KE” for some reason in nominal 1A 125V (which prevented 230V from supplying - it is not clear)
- Chinese specifics - technical support will not wait
- I somehow managed to turn one board into a brick.
Power consumption (without external connected devices) is about 1.1 W.
5. Processor board EL-M150
As I already mentioned, it was very interesting to us - what is the cost price of the product of our Chinese friends (I remind you that they sell this board for an average of $ 25 at retail)? We counted. So, in circulation in 1000 pcs. The cost of the card goes a little less than $ 12:
SoC AR9331 $ 5.4
RAM DDR2 64Mb $ 1.5
Serial flash 8Mb $ 1.1
PCB fabrication (4 layers) plus installation - $ 3.2
Plus small things, testing and firmware.


Our own payment will turn out to be a bit more expensive in the cost than the Chinese, because we make a 5V power input (the Chinese have 3.3V) so that we can directly connect USB clients to the processor board (and feed it from the same USB). In general, $ 20 retail in Russia is quite real. Again, the Chinese friends made the bottom surface smooth
like a baby's ass , in order to use their favorite way of mounting on the "carrier board" - hardworking yesterday's peasants with hot (
very hot - solder, everyone already has lead-free!) Soldering irons in their callused hands. We want to make the fee "two-way" and reduce the size of one and a half times. How to make prototypes - open all documentation for the board.
By the way. The processor board "assembled" consumes about 0.4W and is not heated (in general!).
Well, now, as an experiment, we will try to do with each of these two development boards and the cheapest USB WEB-camera (some Logitech was in the nightstand, bought sometime later 500r) IP-camera with video broadcasting via local network via WiFi. Need to start somewhere?

1. EL-M150
Let's start with the Chinese board, because everything is easier with her.
1. Turn on the power. Seconds 20 board flashes lights like a Christmas tree, after which a pair of LEDs start to burn constantly. The board is ready for experiments.
2. Look at the available WiFi networks. We find something like "Unsafe Wireless Network OpenWRT_el-m150_020020". We cling to it, we get an IP address.
3. We climb the browser to 192.168.1.1. Enter the password "admin". We see the unearthly beauty and rejoice, damn it.

4. Switch the language to English, rejoice again, but much stronger. (I found a
video on YouTube , where a
slightly different OpenWRT interface was switched, and compared hieroglyphs, ... !!!). At the same time, we set the date / time and save all configs. You can also go to the tab "LEDX / RELAYX", look at the flashing LEDs and listen to relay clicks.
5. Transfer the card from the “access point” mode to the client mode of your (home or work) WiFi network. How to do it - is written in detail
here . We remember the board's IP address.
6. Connect the camera to the USB port.
7. Go to the board already at the new IP-address in your own local network. In the WEB interface, select the usbd / webcam tab and check the box “enable or disable mjpg-streamer webcam”. Save the changes - voila, the green LED lights up on the camera, we're on the air!
Now you can watch the video (for example, in the VLC player) at http: // <board IP address>: 8080 /? Action = stream, or catch screenshots at http: // <board IP address>: 8080 /? action = snapshot.
2. Carambola2
There is more work here (well, at least there are no adventures with the Chinese language).
1. Connect the board to the computer with a USB-miniUSB lanyard. The board blinks happily (once) with a green LED. There is nothing in the console. No new WiFi networks. Only gently (and constantly!) Green LEDs on two RJ-45 connectors are lit. What is going on?!
2. Cling the twisted pair port J4 on Karambol to the computer network card. Yeah, the computer got an IP address! Go to 192.168.1.1, we see LuCI, hurray!

3. Set a password for root. Now the board is "visible" in the console and on the SCP. Cool.

4. Turn on WiFi, change the mode from "access point" to "client". We cling to a payment in a local network through WiFi - hurray! Now the board can go online (needed for the next item).
5. We want to put the package mjpg-streamer. Bummer !!! There is no such package in the repository! Gosha…

6. Download
the latest firmware
from the site , reflash the board via the WEB-interface with saving the settings.

Cheers, mjpg-streamer appeared in the list of packages! Install.
7. Connect the camera to USB.
8. Everything is cool, only mjpg_streamer does not start. Error "Init v4L2 failed". Compare the installed packages on the M150 (where the video works) and on Karambol. It turns out that there is not enough package kmod-video-videobuf2. Installing the package, restarting the streamer - hurray! It worked.
There are no problems with connecting and using USB flash drives. Now we are slowly torturing GPIO, connecting a 3G modem, building our own OpenWRT firmware, etc. For this money, I believe both development boards are just a gift. And the processor board itself is a fairy tale.
How suitable is the AR9331 solution as a smart home controller? In my opinion, perfect. It integrates into the local network without any problems (if you want - via Ethernet cable, and PoE has not been canceled, if you want - via WiFi). The power of 400 MHz MIPS processor is more than enough. OpenWRT allows you to do anything with this board without any special programming difficulties; a lot of packages are available from the repository as a finished product. Peripherals connect easily. It is worth quite reasonable money. In general, if you do not need hardware encoding / decoding video - in my opinion, just a plague.