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 setup OpenWRT

This post is outdated, please refer to next one

http://www.netquote.it/nqmain/2019/06/tp-link-mr3420-setup-openwrt-v18-06/

OpenWrt is a powerful Linux distribution for embedded devices. Main target is various router boards, but also other small devices like GuruPlug, ALIX Boards, OLPC.

List of all supported hardware: http://wiki.openwrt.org/toh/start

Using this distribution require little Linux skills and lot of time…
All documentation and howto: http://wiki.openwrt.org/doc/start

Check system prerequisites: http://wiki.openwrt.org/doc/howto/buildroot.exigence

Next quick setup and build instruction for MR3420 router with 3g/UMTS USB Dongle for WAN connection.

Get source (Chaos Calmer 15.05):

~ $&amp;gt; git clone git://git.openwrt.org/15.05/openwrt.git openwrt

Update source:

~ $&amp;gt; cd openwrt
~/openwrt $&amp;gt; git pull

Update all feeds:

~/openwrt $&amp;gt; ./scripts/feeds update -a

Install useful feeds:

~/openwrt $&amp;gt; ./scripts/feeds install luci luci-proto-3g

Configure buildsystem:

~/openwrt $&amp;gt; make menuconfig

Select router:

menuconfig

Select block-mount:

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

Select Luci web interface:

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

Select Dongle kernel support:

Kernel modules ---> USB Support ---> <*> kmod-usb-serial
Kernel modules ---> USB Support ---> <*> kmod-usb-serial-option
LuCI ---> 6. Protocols ---> <*> luci-proto-3g
Utilities ---> <*> usb-modeswitch

Build:

make -j4

Finally, we can find all in “bin/ar71xx/”

~/openwrt $&amp;gt; ls -hgG bin/ar71xx/
totale 23M
-rw-r--r-- 1  827 apr 17 16:59 md5sums
-rw-r--r-- 1 2,7M apr 17 16:59 openwrt-ar71xx-generic-root.squashfs
-rw-r--r-- 1 2,6M apr 17 16:59 openwrt-ar71xx-generic-root.squashfs-64k
-rw-r--r-- 1 3,8M apr 17 16:59 openwrt-ar71xx-generic-tl-mr3420-v1-squashfs-factory.bin
-rw-r--r-- 1 3,4M apr 17 16:59 openwrt-ar71xx-generic-tl-mr3420-v1-squashfs-sysupgrade.bin
-rw-r--r-- 1 1,3M apr 17 16:59 openwrt-ar71xx-generic-uImage-gzip.bin
-rw-r--r-- 1 903K apr 17 16:59 openwrt-ar71xx-generic-uImage-lzma.bin
-rwxr-xr-x 1 2,7M apr 17 16:59 openwrt-ar71xx-generic-vmlinux.bin
-rwxr-xr-x 1 2,8M apr 17 16:59 openwrt-ar71xx-generic-vmlinux.elf
-rw-r--r-- 1 1,3M apr 17 16:59 openwrt-ar71xx-generic-vmlinux.gz
-rw-r--r-- 1 960K apr 17 16:59 openwrt-ar71xx-generic-vmlinux.lzma
-rwxr-xr-x 1 973K apr 17 16:59 openwrt-ar71xx-generic-vmlinux-lzma.elf
drwxr-xr-x 2  16K apr 17 16:58 packages

Reference:
Working with Feeds: http://wiki.openwrt.org/doc/devel/feeds
Multiple targets 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
First Login: http://wiki.openwrt.org/doc/howto/firstlogin
Configuration files: http://wiki.openwrt.org/doc/uci

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 << 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);
}

Atmega 328P – Datasheet

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)