Intel物联网开发者专区
直播中

dvd1478

12年用户 586经验值
擅长:可编程逻辑 电源/新能源 MEMS/传感技术 测量仪表 嵌入式技术 制造/封装 模拟技术 连接器 EMC/EMI设计 光电显示 存储技术 EDA/IC设计 处理器/DSP 接口/总线/驱动 控制/MCU RF/无线
私信 关注
[经验]

【Intel Edison试用体验】使用arduino wifi telnet

注意添加自己的WIFI SSID与密码


  1. #include
  2. #include

  3. char ssid[] = "SSID"; //  your network SSID (name)
  4. char pass[] = "PASSWORD";    // your network password (use for WPA, or use as key for WEP)

  5. int keyIndex = 0;            // your network key Index number (needed only for WEP)

  6. int status = WL_IDLE_STATUS;

  7. WiFiServer server(23);

  8. boolean alreadyConnected = false; // whether or not the client was connected previously

  9. void setup() {
  10.   //Initialize serial and wait for port to open:
  11.   Serial.begin(9600);
  12.   while (!Serial) {
  13.     ; // wait for serial port to connect. Needed for Leonardo only
  14.   }
  15.   
  16.   // check for the presence of the shield:
  17.   if (WiFi.status() == WL_NO_SHIELD) {
  18.     Serial.println("WiFi shield not present");
  19.     // don't continue:
  20.     while(true);
  21.   }

  22.   String fv = WiFi.firmwareVersion();
  23.   if( fv != "1.1.0" )
  24.     Serial.println("Please upgrade the firmware");
  25.   
  26.   // attempt to connect to Wifi network:
  27.   while ( status != WL_CONNECTED) {
  28.     Serial.print("Attempting to connect to SSID: ");
  29.     Serial.println(ssid);
  30.     // Connect to WPA/WPA2 network. Change this line if using open or WEP network:   
  31.     status = WiFi.begin(ssid, pass);

  32.     // wait 10 seconds for connection:
  33.     delay(10000);
  34.   }

  35.   // start the server:
  36.   server.begin();
  37.   // you're connected now, so print out the status:
  38.   printWifiStatus();
  39. }


  40. void loop() {
  41.   // wait for a new client:
  42.   WiFiClient client = server.available();


  43.   // when the client sends the first byte, say hello:
  44.   if (client) {
  45.     if (!alreadyConnected) {
  46.       // clead out the input buffer:
  47.       client.flush();   
  48.       Serial.println("We have a new client");
  49.       client.println("Hello, client!");
  50.       alreadyConnected = true;
  51.     }

  52.     if (client.available() > 0) {
  53.       // read the bytes incoming from the client:
  54.       char thisChar = client.read();
  55.       // echo the bytes back to the client:
  56.       server.write(thisChar);
  57.       // echo the bytes to the server as well:
  58.       Serial.write(thisChar);
  59.     }
  60.   }
  61. }


  62. void printWifiStatus() {
  63.   // print the SSID of the network you're attached to:
  64.   Serial.print("SSID: ");
  65.   Serial.println(WiFi.SSID());

  66.   // print your WiFi shield's IP address:
  67.   IPAddress ip = WiFi.localIP();
  68.   Serial.print("IP Address: ");
  69.   Serial.println(ip);

  70.   // print the received signal strength:
  71.   long rssi = WiFi.RSSI();
  72.   Serial.print("signal strength (RSSI):");
  73.   Serial.print(rssi);
  74.   Serial.println(" dBm");
  75. }

连接成功会显示连接后的IP地址
1.png

2.png

3.png

更多回帖

发帖
×
20
完善资料,
赚取积分