• 前言
透過GPS裝置定位,雖然方便,但是往往因為在室內收不到GPS訊號,會造成定位失效。而透過Wi-Fi AP定位是室內定位的一種不錯的另外方式(當然啦,2D bar code其實也可以做到),不過其實原理都是一樣的,就是有人先幫你量好位置,你走到附近的位置,根據前人的資訊,你就可以知道你現在的位置可能在哪。


  • GPS的定位方式
1.拿到建築物的平面圖,並將此圖可以數位化。

2.先擷取幾個特徵點n(1),n(2),.....n(m),在行走間測量其wi-fi AP的訊號特徵。

n(1)=地圖位置(x1,y1)=>wi-fi-signal1(ap1_mac訊號強度,ap2_mac訊號強度,.....)
n(2)=地圖位置(x2,y2)=>wi-fi-signal1(ap1_mac訊號強度,ap2_mac訊號強度,.....)
n(3)=地圖位置(x3,y3)=>wi-fi-signal1(ap1_mac訊號強度,ap2_mac訊號強度,.....)
...............................................

3.擷取完特徵點後,在沒有擷取的位置需要有估計方法,可以用各種不同的方式(內差法、外差法、類神經網路、基因演算法...等)


  • 如何在windows平台上,抓到Wi-Fi AP訊號強度

在講完學理的問題之後,現在問題來了,該怎樣在windows平台上抓取Wi-Fi AP的訊號呢?
其實網路上已經存在許多Wi-Fi API,這邊就用SourceForge上的windows wi-fi API說明
  1. 首先透過TortoiseSVN checkout  source code
      checkout the wi-fi-api
   
      2. 這邊以windows sp2為例說明
     
      3. sp2目錄裡面檔案的說明(我是用VS2003開啟編輯的)
     
         
4. 本來的專案只有提供 API,我另外加上一個 GUI的選項


5.  編譯過後執行程式的結果(有網路卡可以抓到所有AP訊號強度,剩下的就是看你要用怎樣的數學去定位了)


GUI的程式碼,請見以下,也些住解釋測試的部分

using System.Management;
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using WPSAPI_SP2;
namespace GUITEST
{
    /// <summary>
    /// Summary description for Form1.
    /// </summary>
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.Button button1;
        private System.Windows.Forms.TextBox textBox1;
        /// <summary>
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.Container components = null;

        public Form1()
        {
            //
            // Required for Windows Form Designer support
            //
            InitializeComponent();

            //
            // TODO: Add any constructor code after InitializeComponent call
            //
        }

        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        protected override void Dispose( bool disposing )
        {
            if( disposing )
            {
                if (components != null)
                {
                    components.Dispose();
                }
            }
            base.Dispose( disposing );
        }

        #region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.textBox1 = new System.Windows.Forms.TextBox();
            this.SuspendLayout();
            //
            // button1
            //
            this.button1.Location = new System.Drawing.Point(8, 8);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(280, 56);
            this.button1.TabIndex = 0;
            this.button1.Text = "Get the AP signals";
            this.button1.Click += new System.EventHandler(this.button1_Click);
            //
            // textBox1
            //
            this.textBox1.Location = new System.Drawing.Point(8, 80);
            this.textBox1.Multiline = true;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new System.Drawing.Size(656, 432);
            this.textBox1.TabIndex = 1;
            this.textBox1.Text = "";
            this.textBox1.TextChanged += new System.EventHandler(this.textBox1_TextChanged);
            //
            // Form1
            //
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 15);
            this.ClientSize = new System.Drawing.Size(680, 530);
            this.Controls.Add(this.textBox1);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);

        }
        #endregion

        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.Run(new Form1());
        }

        private void button1_Click(object sender, System.EventArgs e)
        {
            int i=0;
            methods s = new methods();
            int a = 0;
            s.TotalNumNIC(out a);
            string g="";
            s.GetNICGuid(0,out g);
            //s.AuthPEAP(g, "WPA");
            //s.DisableEAPMSCHAP(g,"WPA");
            //s.ReSetConnect(g,"ITRI02750963");           
            textBox1.Text = "NICnumber:" + a.ToString() + Environment.NewLine;
            textBox1.Text = textBox1.Text + "GUID:" + g + Environment.NewLine;
            ArrayList aplist;
            s.QueryAPs(g,out aplist);
            foreach (AP_Datas ap in aplist)
            {
            textBox1.Text = textBox1.Text +"MAC="+ap.MacAddress.ToString()+ " ssid:" + ap.Ssid.ToString() + ",rssi=" + ap.Rssi.ToString() + ",channel=" + ap.channel.ToString() + ",auth_mode=" + ap.AuthenticationMode.ToString() + Environment.NewLine;
            }
            string curssid;
            if(s.QueryCurConnect(g,out curssid))
                textBox1.Text = textBox1.Text+"Current connection:"+curssid+Environment.NewLine;
            else
                MessageBox.Show(s.ErrorMessage);
            textBox1.Text = textBox1.Text+"Current BSSID connection:"+s.QueryCurConnectAPMAC(g);
        //WZCERRORMESSAGE result=(WZCERRORMESSAGE)s.AuthOpen(g, "TEST");
        //textBox1.Text = textBox1.Text+"Create Profile result:"+result.ToString()+Environment.NewLine;
        //s.AuthPEAP(g, "WPSTest");//新增WPSTEST profeil
        //s.AuthShare(g, "Shared",1,"abcde"); //新增Shared
        //int profiles=s.TotalNumProfile(g);
        //textBox1.Text = textBox1.Text+"total Profiles result:"+profiles.ToString()+Environment.NewLine;
        //string s_=s.GetSSID(1,g);//砍掉第一個profile ->shared
        //bool result_=s.DeleteProfile(g,s_);
        //if (result_)
        //textBox1.Text = textBox1.Text+"刪除成功profile:"+s_+Environment.NewLine;
        //else
        //textBox1.Text = textBox1.Text+"刪除失敗profile:"+s_+Environment.NewLine;

    }

        private void textBox1_TextChanged(object sender, System.EventArgs e)
        {
       
        }

        private void button2_Click(object sender, System.EventArgs e)
        {
           
           
           

        }

        private void button2_Click_1(object sender, System.EventArgs e)
        {
           
        }
    }
}



arrow
arrow
    全站熱搜

    questioner 發表在 痞客邦 留言(4) 人氣()