Friday, June 17, 2016

Delete Duplicate data in database (MYSQL)

DELETE a
FROM tpcap_dailycheck as a, tpcap_dailycheck as b
WHERE
          (a.partno   = b.partno OR a.partno IS NULL AND b.partno IS NULL)
      AND (a.del_date = b.del_date OR a.del_date IS NULL AND b.del_date IS NULL)
      AND (a.qty = b.qty OR a.qty IS NULL AND b.qty IS NULL)
      AND a.no > b.no;

Wednesday, June 1, 2016

Openwrt with 3g usb modem DWM-156


opkg update
opkg install comgt kmod-usb-serial kmod-usb-serial-option kmod-usb-serial-wwan
usb-modeswitch luci-proto-3g 

APN internet
phone *99***1#

cat /sys/kernel/debug/usb/devices
to check vender xxxx pid xxxx

echo "2001 7d00" > /sys/bus/usb-serial/drivers/option1/new_id

vi /etc/chatscripts/3g.chat


ABORT   BUSY
ABORT   'NO CARRIER'
ABORT   ERROR
REPORT  CONNECT
TIMEOUT 20
""      "AT+CSQ"
""      "AT&F"
OK      "ATE1"
OK      'AT+CGDCONT=1,"IP","$USE_APN"'
SAY     "Calling UMTS/GPRS"
TIMEOUT 60
OK      "ATD$DIALNUMBER"
CONNECT ' '


vi /etc/config/network

config interface '3G_wan'
        option ifname 'ppp0'
        option proto '3g'
        option service 'umts'


vi /etc/hotplug.d/usb/20-usbmode
#!/bin/sh


BINARY="gcom -d /dev/ttyUSB1"
RTL8188SU_PRODID="2001/7d00/200"

if [ "${PRODUCT}" = "${RTL8188SU_PRODID}" ]; then
    if [ "${ACTION}" = "add" ]; then
        ${BINARY}
        logger -t Hotplug DWM-156 Regiter network
    fi
fi


vi /etc/hotplug.d/usb/10-usb_debug

#!/bin/sh

logger -t DEBUG "hotplug usb: action='$ACTION' devicename='$DEVICENAME' devname='$DEVNAME' devpath='$DEVPATH' product='$PRODUCT' type='$TYPE' interface='$INTERFACE'"



Start up openwrt

echo "2001 7d00" > /sys/bus/usb-serial/drivers/option1/new_id

echo "$(date "+%m%d%Y %T") : boot" >> log 2>&1

exit 0

vi /bin/test.sh

wget -s http://www.google.com
if [[ $? -eq 0 ]]; then
 echo "$(date "+%m%d%Y %T") : 3g online" >> /log 2>&1
else
 echo "$(date "+%m%d%Y %T") : 3g down" >> /log 2>&1
 # turn off USB power
 echo 0 > /sys/devices/virtual/gpio/gpio8/value
 # let things settle
 sleep 2
 # turn on USB power
 echo 1 > /sys/devices/virtual/gpio/gpio8/value
 # restart the interface
fi

chmod 777 /bin/test.sh

schedule task

*/2 * * * * test.sh