<acronym id="xonnx"></acronym>
      <td id="xonnx"></td>
    1. <pre id="xonnx"></pre>

      1. 專注電子技術學習與研究
        當前位置:單片機教程網 >> Arduino >> 瀏覽文章

        如何使用Arduino 制作 串口(UART)轉WiFi的服務器

        作者:huqin   來源:本站原創   點擊數:  更新時間:2014年04月02日   【字體:

        1. 所需要硬件
        A. Netgear WiFi Router
        B. Arduino USB board
        C. Arduino WiFi Shield


         

         

        2. 所需要軟件

        下載
        http://www.thefapper.com/f/WiShield.zip

        放到
        arduino-0018\hardware\libraries\WiShield 下.

         

        3. CuteDigi 串口(UART)轉WiFi Sketch

        (以下代碼:)

        #include <WiShield.h>

        #define WIRELESS_MODE_INFRA   1
        #define WIRELESS_MODE_ADHOC   2

        // Wireless configuration parameters ----------------------------------------
        byte local_ip[]    = {10,0,0,3};   // IP address of WiShield
        byte gateway_ip[]  = {10,0,0,1};   // router or gateway IP address
        byte subnet_mask[] = {255,255,255,0};   // subnet mask for the local network
        prog_char ssid[] PROGMEM    = {"cutedigi"};      // 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 = {"big_secret"};   // 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;
        //---------------------------------------------------------------------------


        Server server(5000);
        Client client;

        unsigned long last_serial;

        void setup()
        {
          Serial.begin(9600);

          WiFi.begin(local_ip, gateway_ip, subnet_mask);
          server.begin();
          Serial.begin(9600);
         
        }


        void loop()
        {


        if(!client.connected()) {
             server.available(&client);
          } else {
         
           

             if (Serial.available() > 0)
             {
               client.print((char)Serial.read());
               last_serial=millis();
             }
             else
             {
               if ( millis()-last_serial > 10 )
                 client.sendnow();
             }
         
             while(client.available()) {
               char c = (char)client.read();
               Serial.print(c);
            }
         
          }
         


        }

        測試:
        我們需要下載一個串口監視器:http://www.thefapper.com/f/LinkSprite-NEC-serial-v1.0.rar

        TCP/IP調試器


         

         

        關閉窗口

        相關文章

        欧美性色欧美精品视频,99热这里只有精品mp4,日韩高清亚洲日韩精品一区二区,2020国自产拍精品高潮