TP-Link MR3420 setup OpenWRT v18.06

OpenWrt is a powerful Linux distribution for embedded devices. Especially for routers with reduced memory and performance. This objective has contributed to an extreme level of optimization of this distribution, allowing also a high margin of flexibility and really easy setup.
This distribution usually fits on many embedded devices, the complete list can be found at this link: http://wiki.openwrt.org/toh/start

Don’t expect magics from this configuration, you can’t install all the available software, simply because we don’t have enough RAM / ROM memory. Sometimes it is possible to overcome some limitations, for example extending the RAM memory with the ZRAM or SWAP file, extending the root filesystem with a USB flash memory device. However, a stable and robust configuration requires a careful evaluation of the installed services and their impact on system resources. Software as imagemagick or ffmpeg, which tries to allocate a large amount of memory, will likely fail with the segmentation error.
However, everything comes from source and everything is customizable. You can even avoid to install web interface and configure everything by ssh console and UCI command line tool, or build your own web GUI or Service supported by a solid and flexible cross-build system.
Thanks to the excellent work of all OpenWrt team, time to time, we have a new and fresh release to build.
Check your system requirements first: http://wiki.openwrt.org/doc/howto/buildroot.exigence
This new release includes linux kernel updates, different security and bug fixes.

Clone v18.06 branche:

git clone -b openwrt-18.06 git://git.openwrt.org/openwrt/openwrt.git openwrt-18.06

Or master branche:

git clone git://git.openwrt.org/openwrt/openwrt.git openwrt

Next, update feeds:

cd openwrt-18.06/
./scripts/feeds update -a

Configure build system:

make menuconfig

Select router options:
Install LUCI web interface:

./scripts/feeds install luci

Select Luci web interface from menuconfig:

LuCI --->  1. Collections --->  <*> luci

Choose packages carefully, because we have only 4mb of storage. This amount of memory is enough for many specialized device with a limited set of features like a router or AP. In order to take advantage of many of the packages provided by OpenWrt, it is essential to extend the memory with external USB storage. Blockmount package and root overlay filesystem can do this trick: https://openwrt.org/docs/techref/block_mount

Select block-mount:

Base system --->  <*> block-mount
Kernel modules --->  USB Support --->  <*> kmod-usb-storage
Kernel modules --->  Filesystems --->  <*> kmod-fs-ext4

Another solution is to remove all ip-v6 support. Is configured by default and also supported from kernel side. Hacking on Kernel configuration is especially useful when support for specific hardware is required or simply to enable debugging features or disable something to save space. 

Linux kernel configuration:

make kernel_menuconfig

Careful with kernel settings, most of them are unsafe. Don’t touch things, if you are not aware about what are they really doing. At best, you’ll get a slow kernel with a lot of useless code.

Build firmware:

make -j8

Finally, we can find all binary files in “bin/targets/ar71xx/tiny/”

1,2K giu 13 12:04 config.seed
2,8K giu 13 12:07 openwrt-ar71xx-tiny-device-tl-mr3420-v1.manifest
2,7M giu 13 12:07 openwrt-ar71xx-tiny-root.squashfs
3,8M giu 13 12:07 openwrt-ar71xx-tiny-tl-mr3420-v1-squashfs-factory.bin
3,6M giu 13 12:07 openwrt-ar71xx-tiny-tl-mr3420-v1-squashfs-sysupgrade.bin
1,2M giu 13 12:07 openwrt-ar71xx-tiny-uImage-lzma.bin
3,5M giu 13 12:07 openwrt-ar71xx-tiny-vmlinux.bin
3,5M giu 13 12:07 openwrt-ar71xx-tiny-vmlinux.elf
1,2M giu 13 12:07 openwrt-ar71xx-tiny-vmlinux.lzma
1,2M giu 13 12:07 openwrt-ar71xx-tiny-vmlinux-lzma.elf
4,0K giu 13 12:07 packages
1,1K giu 13 12:07 sha256sums

To program the device for the first time is sufficient to upload “factory.bin” to the router, from it’s own classic web interface as usual. For subsequent upgrades from LUCI web interface use “sysupgrade.bin”.

Wait for the router to reboot, connect to “192.168.1.1” with any browser or ssh, then you will be able to set up root password. First Login: http://wiki.openwrt.org/doc/howto/firstlogin
 

Next topics:
1) Serial debug console
2) Customize your build
3) Remote development

Reference:
All documentation and howto: http://wiki.openwrt.org/doc/start
Multiple builds in one single checkout: http://wiki.openwrt.org/doc/devel/env
Detailed build instructions: http://wiki.openwrt.org/doc/howto/build
Easy patch management: http://wiki.openwrt.org/doc/devel/patches
Creating packages: http://wiki.openwrt.org/doc/devel/packages

TP-LINK MR3420 hardware

TL-MR3420 is Wireless N Router with USB 2.0 Port for UMTS/HSPA/EVDO USB Modem.

Model Name
TL-MR3420
Dimensions
6.9 x 4.4 x 1.2 in. (174 x 111 x 30 mm)
Power
9VDC / 0.85A
Ports
#1 – USB 2.0
#1 – Ethernet WAN 10/100Mbps
#4 – Ethernet LAN 10/100Mbps
Antennas
#2 – 3dBi Detachable Omni Directional Antennas
Wireless Transmit Power
20dBm (Max. EIRP)
CPU
Atheros AR7241@400MHz
RAM
32 MB
Flash
4 MB

Arduino Nano v3 internal temperature sensor

Calibration data:

Download data & formulas in excel.
Atmega documentation says:
The voltage sensitivity is approximately 1 mV/°C and the accuracy of the temperature measurement is +/- 10°C.
Measured temperature is a sum of ambient temperature and chip’s TDP.

In fact it rises up for few minutes after the chip is powered and may change in base of load.

// Read Atmega328P internal temperature sensor //
long read_temp()
{
  // Read temperature sensor against 1.1V reference
  ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX3);
  // Start AD conversion
  ADCSRA |= _BV(ADEN) | _BV(ADSC);
  // Detect end-of-conversion
  while (bit_is_set(ADCSRA,ADSC));
  // return raw data
  return ADCL | (ADCH &lt;&lt; 8);
}

// Convert raw temperature data to °C
double conv_temp(long raw_temp)
{
  // f(x) = (raw - offset) / coeff
  return((raw_temp - 324.31) / 1.22);
}

void setup()
{
  Serial.begin(115200);
}

void loop()
{
  Serial.println(conv_temp(read_temp()), 1);
  delay(500);
}

Datasheet Atmega 328P – https://www.microchip.com/wwwproducts/en/ATmega328p

It is a curious fact that putting chips in the freezer, after a few minutes when the temperature drops below zero, the chip stops working.

Gentoo default Python interpreter

Gentoo default Python interpreter is set to version 3.1:
~ # eselect python list
Available Python interpreters:
[1] python2.6
[2] python3.1 *

Command to change default interpreter:
~ # eselect python set 1
And now interpreter version is 2.6:
~ # eselect python list
Available Python interpreters:
[1] python2.6 *
[2] python3.1

Installing version 2.7:
~ # nano /etc/portage/package.accept_keywords
=dev-lang/python-2.7*
^X (Ctrl+X) --> exit & save
~ # emerge --ask =dev-lang/python-2.7*

Rebuild Python modules:
~ # python-updater
* Starting Python Updater...
* Main active version of Python: 2.7
* Active version of Python 2: 2.7
* Active version of Python 3: 3.1

Happy python coding!

Gentoo web2py daemon

Gentoo RC init script for web2py framework

Save as “/etc/init.d/web2py”

#!/sbin/runscript
# Gentoo web2py init script

WORK_PATH="/home/web2py"
WORK_FILE="web2py.py"

PYTHON="/usr/bin/python2.6"
PIDFILE="/var/run/web2py.pid"

PASSWORD="<recycle>"
SRV_ADDR="0.0.0.0"
SRV_PORT="8000"
SRV_CRT=""
SRV_KEY=""

depend(){
  need net
}

start() {
  ebegin "Starting web2py"
  start-stop-daemon --start --quiet --background --chdir "$WORK_PATH" \
                    --pidfile $PIDFILE --exec "$PYTHON" \
                    -- "$WORK_PATH/$WORK_FILE" \
                    --nogui --password="$PASSWORD" \
                    --pid_filename="$PIDFILE" \
                    --ip=$SRV_ADDR --port=$SRV_PORT \
                    --ssl_certificate="$SRV_CRT" --ssl_private_key="$SRV_KEY"
  eend $?
}

stop() {
  ebegin "Stopping web2py"
  start-stop-daemon --stop --pidfile $PIDFILE
  eend $?
}

To make a file executable:
chmode +x /etc/init.d/web2py
Add to default runlevel:
rc-update add web2py default
Start daemon:
rc-config start web2py

Remove Windows 7 password

This is the most easiest way to remove password of Windows system. Works on all Windows [NT/XP/Vista/Seven] – [32/64] versions.

DANGER!
If used on users that have EFS encrypted files, and the system is XP or newer, all encrypted files for that user will be UNREADABLE! If you don’t know if you have encrypted files or not, you most likely don’t have them. (except maybe on corporate systems)

It’s floppy based Linux distribution, partially derived from floppyfw.
Boot [CD/Floppy] downloads and instructions can be found at:
http://pogostick.net/~pnh/ntpasswd/

This floppy image is in the SYSRESCUECD, also instructions to make Boot USB Pen Drive: http://www.sysresccd.org/Sysresccd-manual-en_How_to_install_SystemRescueCd_on_an_USB-stick

Python GUI calc

Python GUI experiment. Simple calculator application made with Tk.
It’s a first choice because it’s integrated into Python, simple to use and powerful enough for most cases. It’s also cross platform like an interpreter.
However, there are many other libraries for GUI:
http://wiki.python.org/moin/GuiProgramming

#!/usr/bin/python

# Python GUI calculator 
# (C) 2011 - netquote.it
# Original code by Emanuele Chiabrera
# Enhanced by Toropov Ivan 

from Tkinter import *

# button text list
cmdlst = ['7', '8', '9', '+', '%',
          '4', '5', '6', '-', '**',
          '1', '2', '3', '*', '//',
          '.', '0', 'CL', '/', '=']

class MyButton(Button):
    
    backref = None
    
    def Click(self):
        # back reference
        self.backref.BtnCmd(self["text"])


class CalcApp:

    def __init__(self, master):
        frame = Frame(master)
        
        self.textbox = Entry(width=30, takefocus=1)
        self.textbox.pack(side=TOP)
        self.textbox.focus_force()

        self.buttons = []
        for n, c in enumerate(cmdlst):
            self.buttons.append(MyButton(frame, text=c, width=5))
            self.buttons[n]["command"] = self.buttons[n].Click
            self.buttons[n].backref = self
            self.buttons[n].grid(row=n/5, column=n%5)

        frame.pack()

    def BtnCmd(self, cmd):
        if cmd == '=':
            try:
                res = eval(self.textbox.get())
            except:
                res = "Error!"
            self.textbox.delete(0, END)
            self.textbox.insert(0, str(res))
        elif cmd == 'CL':
            self.textbox.delete(0, END)
        else:
            self.textbox.insert(END, cmd)

root = Tk()
root.title("EWCalc")

calcapp = CalcApp(root)
root.mainloop()

What comes out:

Voltage Drop Protection

DC motor drive circuit with automatic load regulation. Main concept is to cut off power from DC Motor and sustain the voltage in the circuit. Also detect low-battery state.

Components:
#1 – Dual Op-Amp CA158 (Like LM358)
#1 – Trimmer 4.7 kΩ (voltage limit regulator)
#1 – NPN-MOSFET IRF530 (14A, 100V)
#1 – Capacitor C 0,1 µF
#1 – Capacitor C 0,33 µF
#1 – Led (Green – Bat ok)
#1 – Led (Red – Bat low)
#2 – Resistor R 220 Ω
#3 – Resistor R 15 kΩ
#1 – Brushed DC-Motor Permax 400 (6V)

Fonera 2.0n hardware

Model Name

Fonera SDK is originally based on Ralink SDK, also derived from OpenWRT project.

Build instructions can be found on this pages:
http://wiki.fon.com/wiki/Fonera_2.0n
http://www.netquote.it/nqmain/2011/02/fonera-2-0n-hardware/
http://trac.fonosfera.org/fon-ng/wiki/build

Download and build sources:
svn co http://svn.fonosfera.org/fon-ng/tags/2.3.6.1/ fon-sdk
cd fon-sdk/
chmod +x install.sh
./install.sh
cd openwrt
make menuconfig


FON2303
Dimensions
30 mm x 157 mm x 127 mm (excluding antenna)
Power
12VDC, 1A (It seems to work with 6VDC)
Ports
#1 – USB 2.0/1.1
#1 – Ethernet WAN 10/100Mbps
#4 – Ethernet LAN 10/100Mbps
Antennas
#2 – 3dBi Dipole Fixed Antennas
CPU
SoC Ralink RT3052F 320/384 MHz MIPS24KEc
RAM
64 MB – (32 MB cpu internal + 2×16 MB external PSC A3V56S40ETP-G6)
Flash
8 MB – MX29LV640DBTC-90G

External links:
Product briefing
RT3052F CPU Ref.
Ralink ApSoC SDK 3301
SDK User’s manual
MX29LV640DBTC-90G

Fonera SDK is originally based on Ralink SDK, also derived from OpenWRT project.

Build instructions can be found on this pages:
http://wiki.fon.com/wiki/Fonera_2.0n
http://www.netquote.it/nqmain/2011/02/fonera-2-0n-hardware/
http://trac.fonosfera.org/fon-ng/wiki/build

Download and build sources:
svn co http://svn.fonosfera.org/fon-ng/tags/2.3.6.1/ fon-sdk
cd fon-sdk/
chmod +x install.sh
./install.sh
cd openwrt
make menuconfig

Dead after a few difficult years 🙁