Robofun 機器人論壇

 找回密碼
 申請會員
搜索
熱搜: 活動 交友 discuz
查看: 16838|回復: 21
打印 上一主題 下一主題

[請教]arduino wifi shield

[複製鏈接]
跳轉到指定樓層
1#
發表於 2011-9-9 14:35:34 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
各位大大,不好德思,想請教一下,我現在想要試看看,怎麼用iphone去控制有用wifi的arduino,目前想要先去控制led而已(做實驗用的),我想用在網路上找到的code下去改,但現在我不知我要怎麼去抓網路上傳回來的參數,如人家打192,168,5,40/?L=x(x是變數),我去判斷人家打的x是幾,再去決定要亮幾個led,想請問,這一段要用什麼函數去做?




/*
* Web Server
*
* A simple web server example using the WiShield 1.0
*/

#include <WiShield.h>


#define WIRELESS_MODE_INFRA    1
#define WIRELESS_MODE_ADHOC    2

// Wireless configuration parameters ----------------------------------------
unsigned char local_ip[] = {192,168,5,40};    // IP address of WiShield
unsigned char gateway_ip[] = {192,168,5,1};    // router or gateway IP address
unsigned char subnet_mask[] = {255,255,255,0};    // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"jimmy-test"};        // max 32 bytes

unsigned char security_type = 0;    // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2

// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};    // max 64 characters

// WEP 128-bit keys
// sample HEX keys
prog_uchar wep_keys[] PROGMEM = {    0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,    // Key 0
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00,    // Key 1
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00,    // Key 2
                                    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00    // Key 3
                                };

// setup the wireless mode
// infrastructure - connect to AP
// adhoc - connect to another WiFi device
unsigned char wireless_mode = WIRELESS_MODE_INFRA;

unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

void setup()
{
    WiFi.init();
}

// This is the webpage that is served up by the webserver
const prog_char webpage[] PROGMEM = {"HTTP/1.1 200 OK\r\nContent-Type: text/html\r\n\r\n<center><h1>Hello TEST!!!</h1><form method=\"get\" action=\"0\">Toggle LED:<input type=\"submit\" name=\"0\" value=\"LED1\"></input></form></center>"};

void loop()
{
    WiFi.run();
}
2#
發表於 2011-9-19 08:50:17 | 只看該作者
建議你可以用WiShield example 中的 SimpleServer. 然後sendpage改一下即可, 我寫了一個例子如下

boolean  controlpage(char* URL)
{
//    Serial.println(URL);
    if (strcmp(URL, "/") == 0)
    {
          sendpage();  
         return true;
    }
    else
    {
         if(URL[1] == '?')
         {
           if((URL[2] == 'V') && (URL[3] == '='))
           {
              switch(URL[4])
              {
                 case 'F':
                           forward(0, 0);
                          break;
                 case 'B':
                           back(0, 0);
                          break;
                 case 'L':
                           left(0, 0);
                          break;
                 case 'R':
                           right(0, 0);
                          break;
                 case 'S':
                           motorstop(0, 0);
                          break;
               
              }
            
           }
          sendpage();  
          return true;         
         }      

    }
}

可以參考我的Blog. http://sinocgtchen.blogspot.com
3#
 樓主| 發表於 2011-9-19 10:32:41 | 只看該作者
sinocgt大大,謝謝你的幫忙,想請問一下,為什麼我用WiShield example 中的 SimpleServer,什麼都還沒有改,按compiling就出現一堆錯誤,這是找不到WiServer那個檔的意思嗎?


SimpleServer.cpp.o: In function `loop':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:74: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:74: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:74: undefined reference to `Server::server_task()'
SimpleServer.cpp.o: In function `setup':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:64: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:64: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:64: undefined reference to `Server::init(unsigned char (*)(char*))'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:68: undefined reference to `Server::enableVerboseMode(unsigned char)'
SimpleServer.cpp.o: In function `sendMyPage(char*)':
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:50: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:50: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:51: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:51: undefined reference to `WiServer'
C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:52: undefined reference to `WiServer'
SimpleServer.cpp.o:C:\DOCUME~1\ADMINI~1\LOCALS~1\Temp\build2630776630530569053.tmp/SimpleServer.cpp:52: more undefined references to `WiServer' follow
4#
 樓主| 發表於 2011-9-19 10:54:57 | 只看該作者
sinocgt大大,謝謝,我上面的問題已經解開了,原來是要到apps-conf.h裡把
imply comment out the #define for APP_WEBSERVER and uncomment the #define for APP_WISERVER as shown here:
小弟英文不好,因為都沒有中文網站在說明,只好硬著頭皮去把英文網頁看完,^^,才發現原來是這麼簡單的問題
5#
發表於 2011-9-19 11:02:15 | 只看該作者
要去修改WiShield 目錄下的apps-conf.h, 把#define APP_WEBSERVER 打開(其他remark), 這個檔案是config檔,看你是要用哪一個應用程式例如APP_SOCKAPP, UIP_DHCP,.... 不是很難看了你就知道如何設定.
6#
發表於 2011-9-19 11:04:04 | 只看該作者
抱歉, 你現在改用SimpleServer,所以把#define APP_WISERVER打開即可.
7#
發表於 2011-10-7 21:34:28 | 只看該作者
用了很久終於可以把範例的程式燒進去Arduino了!!
真是超感動的!!><
真是感謝前輩啊!!~

不過~
我想請問一下~這些範例檔的功用是什麼??該怎麼測試可用呢??
抱歉或許這問題有點蠢~不顧我真的不知道><

然後我看網路上寫好多跳線的東西
是說他的硬體須要做一些跳線嗎??
那些腳位不能用??不太懂那些

例如:
Slave select (SS) : Arduino pin 10 (port B, pin 2)
是說~要使用主從關西要把WiShield的地10隻腳拉出來接到Arduino主板的第2隻腳嗎??
那port B又是在說什麼呢??
好多類似的都不太瞭解!!
可以請哪位大大幫忙解釋一下嗎??
十分感謝!!^^
8#
發表於 2011-10-8 21:21:37 | 只看該作者
本帖最後由 vegewell 於 2011-10-8 21:23 編輯

回復 7# Eason


   請問你的Arduino板是否有連接 網路擴充板 Arduino Ethernet Shield ?
你不是zero7386 大大嗎 ?
9#
發表於 2011-10-8 22:45:20 | 只看該作者
有的,我是用UNO板接上wishield V2.0 板
這樣的話有需要不同的接線嗎@@?
如果要測試是要怎麼做呢??
看網路上好像有人是打上網址會顯示HELLO和BYEBYE
可是我打網址連不上@@"
10#
發表於 2011-10-9 11:13:52 | 只看該作者
本帖最後由 vegewell 於 2011-10-9 11:23 編輯

回復 9# Eason

這句話<從機選擇(SS) : Arduino pin 10 (端口B, pin 2)>
(端口B, pin 2)是指給比較低階的Arduino板如  (the ATmega8 and ATmega168) have three ports
所以你不用管端口B
    用UNO板接上wishield V2.0 板
接線引腳使用
‧SPI
◦從機選擇(SS) : Arduino pin 10
◦時鐘(SCK) : Arduino pin 13
◦主機進,從機出(MISO) : Arduino pin 12
◦主機出,從機進(MOSI) : Arduino pin 11
‧中斷引腳(根據跳針,選擇下面其中的一種)
◦INT0 : Arduino pin 2
◦DIG8 : Arduino pin 8
‧LED : Arduino pin 9 ◦要重新使用這個引腳,移掉LED跳投帽
‧5V功率
‧GND

要測試的話到下列往址照著做:
The best place to start would be to install the WiShield drivers using the instructions on the Async Labs wiki, and test out one or two example sketches to make sure you have the driver and shield working correctly.
http://asynclabs.com/wiki/index.php?title=AsyncLabsWiki
Test the "SimpleServer" example sketch and make sure you can access the demo page in your browser.
--------------------
Compatible with Asynclab wifi shield!」  This would have led me to the AsyncLabs Wiki and would have saved me a lot of time.
==========================
一步一步的做, 有問題再提出來討論,
11#
發表於 2011-10-11 15:36:25 | 只看該作者
可以了可以了!!!!~~~感謝各位大大!!!

抱歉再問個問題!!他是用什麼去寫顯示網頁那一塊的啊??
我應該是要用他的語法寫吧!?是HTML嗎??
想要知道是什麼感快去學一下!!~再次感謝各位大大!!^^
12#
發表於 2011-10-11 23:29:45 | 只看該作者
回復 11# Eason


   是的! 可以用HTML寫,會比較容易!
13#
發表於 2011-10-12 11:35:08 | 只看該作者
本帖最後由 Eason 於 2011-10-12 11:36 編輯

好的!!~感謝各位大大的回答!!^^
我會好好努力做~
希望之後也可以幫到別人!!^^
14#
發表於 2011-11-21 11:45:22 | 只看該作者
我想在問一下~
我現在用 WISERVER
我使用的IP已經ping的到了
可是為何網頁就是無法顯示出來呢??
15#
發表於 2011-11-21 13:18:57 | 只看該作者
程式貼出來看看! 通常webpage or http 沒寫好.
16#
發表於 2011-11-22 15:29:06 | 只看該作者
抱歉抱歉!!!~原來是我搞錯了!!

WISERVER的東西放在WEBSERVER的資料夾中
沒有改conf.h的註解卻可以燒進去@@"
後來才發現做了蠢事= ="
不過這算是BUG嗎??XD
17#
發表於 2011-11-30 14:19:43 | 只看該作者
請問zero7386 大大     您用的arduino版子 跟wifi 各是哪一塊?
     小弟最近看到arduino,想要來試試.不知有何建議?

     另外小弟跟您有相似的構想.最終想利用iphone遙控家中的anduino自走車.(或偵測狀況後,通知iphone...........漫漫長路.......)
18#
發表於 2011-12-20 09:10:46 | 只看該作者
我手上有2片,要的人可以pm我
19#
發表於 2012-1-1 17:44:17 | 只看該作者
用html寫會容易一點  上面基本都改動好了                               lv     prada ROLEX 勞力士         Chanel 香奈兒      
Cartier 卡地亞     lv代購     Gucci       lv圍巾         NIKE運動鞋
20#
 樓主| 發表於 2012-1-9 10:26:37 | 只看該作者
回復 17# kevin6010
         我買的是arduino uno(ATMEGA168 )和 wifi就普通的.我也沒有什麼經驗,我玩東西都是先把我要做的東西拆開,如你想做自走車,你可以先從arduno 怎麼控制 馬達開始,可以控制後,在加上網路的部份,板上高手很多,可以問板上的高手
您需要登錄後才可以回帖 登錄 | 申請會員

本版積分規則

小黑屋|手機版|Archiver|機器人論壇 from 2005.07

GMT+8, 2024-4-29 22:14 , Processed in 0.233330 second(s), 7 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表