Monday, November 23, 2015

Control Led on Arduino using OpenWRT (TP Link MR-3020) serial com




1. Install modem driver on openwrt

root@OpenWrt:~# opkg install kmod-usb-serial kmod-usb-serial-ftdi

2. Attach Arduino to OpenWRT, and check on dmesg

[ 5182.260000] usb 1-1: new full-speed USB device number 3 using ehci-platform
[ 5182.430000] cdc_acm 1-1:1.0: ttyACM0: USB ACM device

3. Install coreutils-stty

root@OpenWrt:~# opkg install coreutils-stty

4. run coreutils

stty -F /dev/ttyACM0 cs8 9600 ignbrk -brkint -icrnl -imaxbel -opost -onlcr -isig -icanon -iexten -echo -echoe -echok -echoctl -echoke noflsh -ixon -crtscts

5. upload the sketch to Arduino.


int ledPin3 = 3;

int ledPin2 = 2;

int incomingByte;          // a variable to read incoming serial data into



void setup() {   

   Serial.begin(9600);     

   pinMode(ledPin3, OUTPUT);              

   pinMode(ledPin2, OUTPUT);              

}



void loop() {    

    if (Serial.available() > 0) {        // see if there's incoming serial data:

        incomingByte = Serial.read();     // read the oldest byte in the serial buffer

                                        //Preform the code to switch on or off the leds

        if (incomingByte == '1') {

            digitalWrite(ledPin3, HIGH);     //If the serial data is 0 turn LED 1 on

        }

        if (incomingByte == '2') {

            digitalWrite(ledPin3, LOW);     //If the serial data is 1 turn LED 1 off

        }

        if (incomingByte == '3') {

            digitalWrite(ledPin2, HIGH);     //If the serial data is 2 turn LED 2 on

        }

        if (incomingByte == '4') {

            digitalWrite(ledPin2, LOW);     //If the serial data is 3 turn LED 2 off

        }

    }

}

6. run this command on Openwrt terminal.

-- to turn on LedPin3

echo "1" >/dev/ttyACM0

-- to turn off Led 

echo "2" >/dev/ttyACM0



Image result for smiley face








Wednesday, November 11, 2015

Automatic Wifi Connection on Openwrt (MR3020)


1. Set MR3020 as Client and Master AP from luci menu,
     - As client of  APMaster1 and as APMaster -- save configuration with nama apmaster1, put in /etc/config folder.. and so on.

2. Create file /etc/init.d/wireless_auto

#!/bin/sh
#As client APMaster1
iwinfo wlan0 scan | grep "APMaster1" &> /dev/null
if [ $? == 0 ]; then
cp /etc/config/apmaster1 /etc/config/wireless
wifibssid=$(iwinfo wlan0 scan|grep "APMaster1" -B 1|head -n 1|awk '{print $NF'})
uci set wireless.@wifi-iface[0].bssid="$wifibssid"
uci commit wireless
        /etc/init.d/network reload ;

#As client APMaster2
elif [ $? == 1 ]; then
iwinfo wlan0 scan | grep "APMaster2" &> /dev/null
if [ $? == 0 ]; then
cp /etc/config/apmaster2/etc/config/wireless
wifibssid=$(iwinfo wlan0 scan|grep "APMaster2" -B 1|head -n 1|awk '{print $NF'})
        uci set wireless.@wifi-iface[0].bssid="$wifibssid"
        uci commit wireless
        /etc/init.d/network reload ;
#As APMaster
elif [ $? == 1 ]; then
cp /etc/config/APMaster /etc/config/wireless
fi
fi



2. Reboot.


Sunday, November 8, 2015

Basic input/output gpio pin GL-INET








1. Export first the gpio pin (example port 21), type command

echo "21" >/sys/class/gpio/export

2. Define gpio port 21 (example as output)

echo "out" >/sys/class/gpio//gpio21/direction

if as input type,

echo "in" >/sys/class/gpio//gpio21/direction



3. Fire up the led on gpio port 21

echo "1" >/sys/class/gpio/gpio21/value


Wednesday, November 4, 2015

Mounting USB on OpenWRT (barrier breaker)

langkah langkahnya


1. install driver
opkg update
opkg install kmod-usb-storage block-mount block-hotplug kmod-fs-ext4 kmod-fs-vfat kmod-nls-cp437 kmod-nls-iso8859-1
mkdir -p /mnt/usb
mount -t vfat /dev/sda1 /mnt/usb
 
22




Tuesday, November 3, 2015

Exroot OpenWRT on TPLink MR3020

Langkah langkah exroot

1. siapkan usb flashdisk, buat 2 partisi, partisi 1 buat swap file besarnya 500M saja,
   partisi 2 jenisnya ext4 besarnya sisa dari partisi yg ada.
2. siapkan MR3020 dengan firmware barrier breaker dan sudah tersetting konek ke internet.
3. masuk ssh ke ip router
4. ketik perintah update
opkg update
5. install driver usb storage
opkg install block-mount kmod-usb-storage kmod-fs-ext4

kalau ada error
kmod: failed to insert /lib/modules/3.10.49/ext4.ko
biarin aja

6. reboot
7. cek apakah usbnya sudah terdeteksi

root@OpenWrt:~# dmesg|grep sda
[   10.410000] sd 0:0:0:0: [sda] 15820800 512-byte logical blocks: (8.10 GB/7.54 GiB)
[   10.410000] sd 0:0:0:0: [sda] Write Protect is off
[   10.420000] sd 0:0:0:0: [sda] Mode Sense: 43 00 00 00
[   10.430000] sd 0:0:0:0: [sda] No Caching mode page found
[   10.430000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   10.450000] sd 0:0:0:0: [sda] No Caching mode page found
[   10.450000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   10.480000]  sda: sda1 < sda5 sda6 >
[   10.510000] sd 0:0:0:0: [sda] No Caching mode page found
[   10.510000] sd 0:0:0:0: [sda] Assuming drive cache: write through
[   10.520000] sd 0:0:0:0: [sda] Attached SCSI removable disk

8. install paket untuk exroot
opkg install block-mount kmod-fs-ext4 kmod-usb-storage kmod-usb-ohci

9. cek partisi yg ada di flash disk
block info

root@OpenWrt:~# block info
/dev/mtdblock2: UUID="20ad40ea-d33a421e-785b7d2d-ada99230" VERSION="4.0" TYPE="squashfs"
/dev/mtdblock3: TYPE="jffs2"
/dev/sda1: VERSION="2" TYPE="swap"
/dev/sda2: UUID="f5e53d37-b516-d101-70e5-3d37b516d101" NAME="EXT_JOURNAL" VERSION="1.0" TYPE="ext4"

yg sda1 --> swap  yg sda2 --> ext4

10. copy file system ke sda2

langkah langkahnya

mkdir -p /mnt/sda2
mount /dev/sda2 /mnt/sda2
mkdir -p /tmp/cproot
mount --bind / /tmp/cproot
tar -C /tmp/cproot -cvf - . | tar -C /mnt/sda2 -xf -
umount /tmp/cproot
umount /mnt/sda2

11. Buat router boot melalui flashdisk

Jalankan perintah ini

block detect > /etc/config/fstab


Edit file /etc/config/fstab

config global
        option anon_swap '0'
        option anon_mount '0'
        option auto_swap '1'
        option auto_mount '1'
        option delay_root '5'
        option check_fs '0'

config swap
        option device '/dev/sda1'
        option enabled '1'

config mount
        option target '/'
        option uuid '78e2ef58-6318-d101-7022-e4586318d101'
        option enabled '1'

11. reboot

12. cek

root@OpenWrt:~# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                    5.5G     16.0E      5.2G 100% /
/dev/root                 2.3M      2.3M         0 100% /rom
tmpfs                    14.1M    564.0K     13.5M   4% /tmp
/dev/sda2                 5.5G     16.0E      5.2G 100% /
tmpfs                   512.0K         0    512.0K   0% /dev

root@OpenWrt:~# mount
rootfs on / type rootfs (rw)
/dev/root on /rom type squashfs (ro,noatime)
proc on /proc type proc (rw,noatime)
sysfs on /sys type sysfs (rw,noatime)
tmpfs on /tmp type tmpfs (rw,nosuid,nodev,noatime)
/dev/sda2 on / type ext4 (rw,relatime,data=ordered)
tmpfs on /dev type tmpfs (rw,relatime,size=512k,mode=755)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
debugfs on /sys/kernel/debug type debugfs (rw,noatime)


13. DONE!