2017年5月5日 星期五

Bluetooth GPS Tracer

一個簡單有趣的 GPS 應用,可以拿來用在尋機…

結合現成的三種模組 GPS Module、HC12 RF Module、HC-05 Bluetooth Module 再加上簡單的 App 解 MNEA GPS 格式,就能實現遠距 GPS 追蹤,類似防丟器的概念,但即時距離可達 1 公里。

Combine "CRIUS GPS Module"、"HC12 - Long Range RF Wireless SERIAL Module" and "HC-05 Bluetooth Module",make remote location trace with 433mhz RF and Bluetooth comunication

App...
https://play.google.com/store/apps/details?id=com.longfellowchen.bluetoothgpstracer

系統架構 - System Architecture…
GPS--[UART]-->HC12-->~~[RF433MHZ]~~-->HC12-->HC-05-->~~[BT2.4G]-->SmartPhone

硬體線路 - Hardware circuit...
基本上只是把模組 UART 線路全串在一起…

Remote device...
GPS-TX ---------------->HC12-RX
GPS-RX ---------------->HC12-TX (option)

Local device
HC05-TX ---------------->HC12-RX(option)
HC05-RX ---------------->HC12-TX

All Module..
VCC ----------------> +5V
GND ----------------> GND

注意事項…
*All module should set the same baud-rate (default is 9600)
*HC12 Module can set transmit power to what you want. (see it's documents)


2017年4月15日 星期六

Convert NMEA format data to latitude and longitude for GMap Latlng


Reference...
http://aprs.gids.nl/nmea/

Format...
$GPRMC,hhmmss.ss,A,llll.ll,a,yyyyy.yy,a,x.x,x.x,ddmmyy,x.x,a*hh
1    = UTC of position fix
2    = Data status (V=navigation receiver warning)
3    = Latitude of fix
4    = N or S
5    = Longitude of fix
6    = E or W
7    = Speed over ground in knots
8    = Track made good in degrees True
9    = UT date
10   = Magnetic variation degrees (Easterly var. subtracts from true course)
11   = E or W
12   = Checksum

Formula...
Latitude / Longitude = ddmm.mmmm = dd + (mm.mmmm/60) (* -1 for W and S)

Java code...
String str = "$GPRMC,182807.036,A,3731.9404,N,10601.6986,W,0.078542,40.74,050107,,*20"
if( str.startsWith( "$GPRMC" ) )
{
    String[] tags = str.split(",");
    if( tags[2].equals("A") ) {
        String lotdd = tags[3].substring( 0, tags[3].indexOf(".") - 2 );
        String lotmm = tags[3].substring( tags[3].indexOf(".") -2 );
        float lot = Float.valueOf( lotdd ) + Float.valueOf( lotmm )/60;
        if( tags[4].equals("S") )
            lot = -lot;
        String lngdd = tags[5].substring( 0, tags[5].indexOf(".") - 2 );
        String lngmm = tags[5].substring( tags[5].indexOf(".") -2 );
        float lng = Float.valueOf( lngdd ) + Float.valueOf( lngmm )/60;
        if( tags[6].equals("W") )
            lng = -lng;
        LatLng pos = new LatLng( lot, lng );
    } else {
        // Invalid $GPRMC
    }
}

2017年3月26日 星期日

python 透過 google smtp server 發信的方法

python code‧‧‧

import smtplib
    to = 'where@gmail.com'
    server = "smtp.gmail.com"
    #port = 465 # ssl
    port = 587 # tls
    gmail_user = 'youraccount@gmail.com'
    gmail_pwd = 'yourpassword or application password'
    #smtpserver = smtplib.SMTP_SSL(server, long(port)) # ssl
    smtpserver = smtplib.SMTP(server, long(port)) # tls
    smtpserver.ehlo()
    smtpserver.starttls() # tls
    smtpserver.login(gmail_user, gmail_pwd)
    header = 'To:' + to + '\n' + 'From: ' + gmail_user + '\n' + 'Subject:test \n'
    print header
    msg = header + '\n this is test \n\n'
    smtpserver.sendmail(gmail_user, to, msg)
    print 'done!'
    smtpserver.quit()

*如果你有使用兩階段驗證,必須先到 google 個人設定頁,增加應用程式密碼,smtp 才會驗證通過…
    https://myaccount.google.com/apppasswords

2017年3月1日 星期三

網頁後台使用 php 執行 python 操作 serial (uart) 權限的設定




uart0.php... (透過 shell_exec 執行 python 碼)
===============================================
$cmd = escapeshellcmd ( '/usr/bin/python uart0.py' );
$output = shell_exec ( $cmd );
echo $output;
===============================================

uart0.py... (console下執行沒問題,但透過 php 執行沒結果)
===============================================
import serial
serialport = serial.Serial("/dev/ttyAMA0", 9600, timeout=0.5)
serialport.write( "TEST" )
response = serialport.readlines(None)
print response
===============================================

解決… (需要設定裝置的權限 ttyAMA0 屬於 dialout 群組)
=1=暫時-reboot後無效==============================
sudo chmod 777 /dev/ttyAMA0
=2=============================================
sudo adduser youruser dialout
usermod -aG dialout youruser
===============================================


2016年10月18日 星期二

AFS ReVersiNG


AFS ReVersiNG Guide


-working with MAZDA CX5、Cadillac ATS


STEP0. Hardware Analyze - connector defination、power line、data line…
STEP1. Use Linbus/Canbus Analyzer
STEP2, Stage by stage mining Linbus data records, in the meantime watch over AFS's action
  • ACC OFF
  • ACC ON
  • ENGINE START
  • TURN ON THE HEADLIGHT
  • GEAR SHIFT TO P/N/D/R/...
  • TURN WHEEL LEFT/RIGHT
  • TURN OFF THE HEADLIGHT
  • STOP ENGINE
  • ACC OFF
STEP3. Find out the valuable changing with wheel turning
STEP4. Figure out which record is writing and which is reading and what is there meaning
STEP5. Is there any initial progress at beginning ?
STEP6. Hardware implement
STEP7. Firmware implement
STEP8. Cut off KD module and replace with reversing one
  • Attention: Do not run to this step until you figure out the ECU's every read / write procedure
STEP9. See what happens :)


2016年4月26日 星期二

Xilinx Virtual Download Cable using Raspberry Pi

based on this project below…( Thanks this great project )
https://github.com/tmbinc/xvcd

just replacement following function calls…

======== gipo.c ========
#include

#define GPIO_TDI 3       /// JTAG TDI pin
#define GPIO_TDO 12   /// JTAG TDO pin
#define GPIO_TCK 13   /// JTAG TCK pin
#define GPIO_TMS 14   /// JTAG TMS pin

void gpio_init(void)
{
if (wiringPiSetup() == -1)
return;
gpio_output(GPIO_TDI, 1);
gpio_output(GPIO_TMS, 1);
gpio_output(GPIO_TCK, 1);
gpio_output(GPIO_TDO, 0);
}

void gpio_close(void)
{
}
================

======== gipo_inline.h ========
static inline void gpio_output(int i, int dir)
{
if (dir)
pinMode (i, OUTPUT);
else
pinMode (i, INPUT);
}

static inline void gpio_set(int i, int val)
{
if (!val)
digitalWrite (i, 0) ; // Off
else
digitalWrite (i, 1) ; // On

}

static inline int gpio_get(int i)
{
return (digitalRead( i )!=0);
}
================

Tested with NetBeans IDE 8.1 + Raspberry Pi 1 & 2 + Xilinx XC3S400AN



2016年4月22日 星期五

NETBEANS 開發 RASPBERRY PI APP

使用 NETBEANS 開發 RASPBERRY PI APP
非常方便,可遠端開發、執行偵錯

請參考此篇…
http://www.raspberry-projects.com/pi/programming-in-c/compilers-and-ides/netbeans-windows/installing-netbeans-for-c-remote-development-on-a-raspberry-pi

主要需增加一個遠端 HOST 的設定

若有使用 WIRING PI 等 I/O 底層服務,則需以 ROOT 身份進行遠端操作
可參考此篇…
http://www.raspberry-projects.com/pi/programming-in-c/compilers-and-ides/netbeans-windows/creating-a-new-project

主要為了打開 ROOT 帳戶
sudo passwd root
sudo nano /etc/ssh/sshd_config
PermitRootLogin and change it to yes (the default "without-password" won't work – change it to "yes"
存檔後 reboot

VirtualBox 空間減肥

sdelete64 -z c: VBoxManage  modifymedium  disk  "/Users/fellow/VirtualBox VMs/Win10/Win10.vdi"  --compact *.vdi 路徑可以在 VirtualBox 儲...