You are here

Risharde's Blog

Setting up TP-LINK TL-WN725N on Raspberry PI 2 #755

The Raspberry PI 2 (Raspbian - Debian Wheezy 2015) will not detect the TP-LINK TL-WN725N on a fresh install. Even lsusb will not show the TP-LINK WIFI device until you install the drivers. It was a lot of running around to figure this out and while the guys at the Raspberry forums are very technically inclined, they were not able to explain this in over 29 pages of chatter.

wget https://dl.dropboxusercontent.com/u/80256631/8188eu-v7-20150212.tar.gz
tar xzf 8188eu-v7-20150212.tar.gz
./install.sh
reboot

Go to GUI and look for WIFI manager and set up your network accordingly :)

Good luck!

Adding a second disk to server

# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb

# su -
# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd1082b01.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').

Command (m for help):

Command (m for help): c
DOS Compatibility flag is not set
Command (m for help): u
Changing display/entry units to sectors

Command (m for help): p

Disk /dev/sdb: 34.4 GB, 34359738368 bytes
255 heads, 63 sectors/track, 4177 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xd1082b01

Device Boot Start End Blocks Id System

Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4):

Partition number (1-4): 1
First sector (2048-67108863, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-67108863, default 67108863):
Using default value 67108863

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

# ls /dev/sd*
/dev/sda /dev/sda1 /dev/sda2 /dev/sdb /dev/sdb1

# /sbin/mkfs.ext4 -L /backup /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=/backup
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2097152 inodes, 8388352 blocks
419417 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
256 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 36 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

# mkdir /backup

# mount /dev/sdb1 /backup

# mount
/dev/mapper/vg_CentOS6-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/sr0 on /media/CentOS_6.0 x86_64 Disc 1 type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=500,gid=500,
iocharset=utf8,mode=0400,dmode=0500)
/dev/sdb1 on /backup type ext4 (rw)

LABEL=/backup /backup ext4 defaults 1 2

Create Linux Swap File

Instructions found from DigitalOcean Tutorial

Create and Enable the Swap File
Now it’s time to create the swap file itself using the dd command :

sudo dd if=/dev/zero of=/swapfile bs=1024 count=512k
“of=/swapfile” designates the file’s name. In this case the name is swapfile.

Subsequently we are going to prepare the swap file by creating a linux swap area:

sudo mkswap /swapfile
The results display:

Setting up swapspace version 1, size = 536866 kB
Finish up by activating the swap file:

sudo swapon /swapfile
You will then be able to see the new swap file when you view the swap summary.

swapon -s
Filename Type Size Used Priority
/swapfile file 524280 0 -1
This file will last on the server until the machine reboots. You can ensure that the swap is permanent by adding it to the fstab file.

Open up the file:

sudo nano /etc/fstab
Paste in the following line:

/swapfile swap swap defaults 0 0

Setup GRE Tunnel

lsmod

modprobe ip_gre
Now set it to start at boot.

echo "/sbin/modprobe ip_gre > /dev/null 2>&1" > /etc/sysconfig/modules/ip_gre.modules && chmod 755 /etc/sysconfig/modules/ip_gre.modules
Create ifcfg-tun0 Configuration Files
We need to create the configuration files for the GRE tunnel. These files live alongside your CentOS network device files in /etc/sysconfig/network-scripts/

grebos.centoshowtos.org

Create ifcfg-tun0 file. Please note, the internal and external interfaces must already be configured and plugged into the correct ports for each network.

vi /etc/sysconfig/network-scripts/ifcfg-tun0
The file should look like this (except your IPs will be different)

DEVICE=tun0
BOOTPROTO=none
ONBOOT=no
TYPE=GRE
PEER_OUTER_IPADDR=216.52.2.41
PEER_INNER_IPADDR=192.168.77.253
MY_INNER_IPADDR=192.168.77.254
gresea.centoshowtos.org

Create ifcfg-tun0 file where the network interface scripts are.

vi /etc/sysconfig/network-scripts/ifcfg-tun0
The file should look like this (except your IPs will be different)

DEVICE=tun0
BOOTPROTO=none
ONBOOT=no
TYPE=GRE
PEER_OUTER_IPADDR=141.136.108.122
PEER_INNER_IPADDR=192.168.77.254
MY_INNER_IPADDR=192.168.77.253
Bring tun0 interfaces online and verify
Now that we have the configuration files setup, we will need to bring up the tunnel interfaces and verify that they came online properly.

grebos.centoshowtos.org

We’ll just use the ifup command to bring up the interfaces.

ifup tun0
Now we can verify with the ifconfig command.

ifconfig tun0
gresea.centoshowtos.org

We’ll just use the ifup command to bring up the interfaces.

ifup tun0
Now we can verify with the ifconfig command.

ifconfig tun0
Test the connection
At this point the tunnel should be online, and the machines should be able to reach one another via internal IP addresses. Lets ping each other and make sure everything looks ok – make sure your firewall isn’t dropping ICMP packets if it doesn’t work.

grebos.centoshowtos.org

Ping gresea.centoshowtos.org internal address

ping 192.168.77.253
gresea.centoshowtos.org

Ping grebos.centoshowtos.org internal address

ping 192.168.77.254

TCP Forwarding to next server

These rules should work, assuming that iptables is running on server 192.168.12.87 :

#!/bin/sh

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables -F
iptables -t nat -F
iptables -X

iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to-destination 192.168.12.77:80
iptables -t nat -A POSTROUTING -p tcp -d 192.168.12.77 --dport 80 -j SNAT --to-source 192.168.12.87

Possible priorities to solve health issues

1. Reduce / remove acid reflux (Possibly Probiotics and Yogurt (Yogurt is okay but it will take much more... while you can overdose on probiotics which could cause over active immune response), reduction of oily foods, reduction of pepper, reduction of MSG)
2. Reduce over indulgence of sugar. Look at food that keeps sugar at bay (perhaps cabbages? - Eating Subway related diet will help with sugar and colesterol)
3. Solve sinusitis and reoccurant lung infections (reduce sugar, reduce dust, reduce allergens from air like dust, concrete, sand etc, reduce food allergens like fish, green peppers, sulphur if you are allergic to them)
4. Possibly Vitamin B, Selenium and there's one more I can't remember. Vitamin B12 in particular seems to increase immune function but remember also that if the immune system is defective, high immunity can also cause unwanted inflammation if the immune system isn't doing it properly.
5. Exercise but this is dependent on overall health as well. If exercise is making you sick, half it and keep halfing it until you feel ok. Then gradually increase as health increases (this is based on logic).
6. Reduce weight to good level to reduce stress on body especially during sleep apnea + reducing acid reflux (a prime cause of infection issues according to research) + reducing colesterol in many cases

DNS Poisoning?

I could be wrong but the site has been up and down for the past month and it seems to be some sort of DNS poisoning that was occurring. It's very weird because nothing changed on the webserver architecture yet the DNS was simply not resolving even though I can confirm bind was answering. Anyways, we're back up and if you're the attacker, it seems I didn't care that much... :) lol

pyUSB on Raspberry Pi

sudo python setup.py install

http://stackoverflow.com/questions/29345325/raspberry-pyusb-gets-resourc...

https://pixiescorner.wordpress.com/2009/09/05/utilityconvert-x10-to-inst...

This isn't too bad, but there are a couple quirks to be aware of. One limitation is that sending X10 codes breaks if you go too fast. I added a Wait subroutine (see the end of this page). The PLM seems to need a 500 millisecond pause between X10 commands. Lower delays didn't seem to work.

Also, the indexes are odd. I set up two arrays with the necessary values (see below).

The following also assumes that

house = the X10 house code as an integer, 0 = A, etc
device = the X10 device code as an integer

Put this in the declarations area of your form/module:

Public PLM_X10_House(16) as Byte
Public PLM_X10_Device(16) as Byte

Set the values for those areas somewhere convenient (like Form1.Load):

PLM_X10_House(1) = 96 ' House code A
PLM_X10_House(2) = 224 ' House code B
PLM_X10_House(3) = 32 ' House code C
PLM_X10_House(4) = 160 ' House code D
PLM_X10_House(5) = 16 ' House code E
PLM_X10_House(6) = 144 ' House code F
PLM_X10_House(7) = 80 ' House code G
PLM_X10_House(8) = 208 ' House code H
PLM_X10_House(9) = 112 ' House code I
PLM_X10_House(10) = 240 ' House code J
PLM_X10_House(11) = 48 ' House code K
PLM_X10_House(12) = 176 ' House code L
PLM_X10_House(13) = 0 ' House code M
PLM_X10_House(14) = 128 ' House code N
PLM_X10_House(15) = 64 ' House code O
PLM_X10_House(16) = 192 ' House code P

PLM_X10_Device(1) = 6
PLM_X10_Device(2) = 14
PLM_X10_Device(3) = 2
PLM_X10_Device(4) = 10
PLM_X10_Device(5) = 1
PLM_X10_Device(6) = 9
PLM_X10_Device(7) = 5
PLM_X10_Device(8) = 13
PLM_X10_Device(9) = 7
PLM_X10_Device(10) = 15
PLM_X10_Device(11) = 3
PLM_X10_Device(12) = 11
PLM_X10_Device(13) = 0
PLM_X10_Device(14) = 8
PLM_X10_Device(15) = 4
PLM_X10_Device(16) = 12
To send an X10 On command:

Dim data(3) as Byte

data(0) = 2 ' start first message: send X10 address only
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + PLM_X10_Device(device) ' X10 address (house + device)
data(3) = 0 ' flag = this is the address
SerialPLM.Write(data, 0, 4)
Wait(500)
data(0) = 2 ' start second message: send X10 house + command
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + 2 ' X10 address (house + command)
data(3) = 128 ' flag = this is house + address
SerialPLM.Write(data, 0, 4)
To send an X10 Off command:

Dim data(3) as Byte

data(0) = 2 ' start first message: send X10 address only
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + PLM_X10_Device(device) ' X10 address (house + device)
data(3) = 0 ' flag = this is the address
SerialPLM.Write(data, 0, 4)
Wait(500)
data(0) = 2 ' start second message: send X10 house + command
data(1) = 99 ' 0x063 = Send X10
data(2) = PLM_X10_House(house + 1) + 3 ' X10 address (house + command)
data(3) = 128 ' flag = this is house + address
SerialPLM.Write(data, 0, 4)

import usb.core
import usb.util

# find our device
dev = usb.core.find(idVendor=0xfffe, idProduct=0x0001)

# was it found?
if dev is None:
raise ValueError('Device not found')

# set the active configuration. With no arguments, the first
# configuration will be the active one
dev.set_configuration()

# get an endpoint instance
cfg = dev.get_active_configuration()
intf = cfg[(0,0)]

ep = usb.util.find_descriptor(
intf,
# match the first OUT endpoint
custom_match = \
lambda e: \
usb.util.endpoint_direction(e.bEndpointAddress) == \
usb.util.ENDPOINT_OUT)

assert ep is not None

# write the data
ep.write('test')

Pages