找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 3431|回復(fù): 1
打印 上一主題 下一主題
收起左側(cè)

esp8266關(guān)于arduino的一些測試文件

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:229133 發(fā)表于 2018-11-19 17:52 | 只看該作者 |只看大圖 回帖獎勵 |倒序瀏覽 |閱讀模式
  1. void setup() {
  2.   inputString.reserve(20);
  3.   swSerial.begin(9600);
  4.   Serial.begin(9600);
  5.   while (!Serial)
  6.     ;
  7.   Serial.println("Starting wifi");
  8.   wifi.setTransportToTCP();// this is also default
  9.   // wifi.setTransportToUDP();//Will use UDP when connecting to server, default is TCP
  10.   wifi.endSendWithNewline(true); // Will end all transmissions with a newline and carrage return ie println.. default is true
  11.   wifi.begin();
  12.   //Turn on local ap and server (TCP)
  13.   wifi.startLocalAPAndServer("MY_CONFIG_AP", "password", "5", "2121");
  14.   wifi.connectToAP("wifissid", "wifipass");
  15.   wifi.connectToServer("192.168.0.28", "2121");
  16.   wifi.send(SERVER, "ESP8266 test app started");
  17. }


  18. void loop() {
  19.   //Make sure the esp8266 is started..
  20.   if (!wifi.isStarted())
  21.     wifi.begin();
  22.   //Send what you typed in the arduino console to the server
  23.   static char buf[20];
  24.   if (stringComplete) {
  25.     inputString.toCharArray(buf, sizeof buf);
  26.     wifi.send(SERVER, buf);
  27.     inputString = "";
  28.     stringComplete = false;
  29.   }
  30.   //Send a ping once in a while..
  31.   if (millis() > nextPing) {
  32.     wifi.send(SERVER, "Ping ping..");
  33.     nextPing = millis() + 10000;
  34.   }
  35.   //Listen for incoming messages and echo back, will wait until a message is received, or max 6000ms..
  36.   WifiMessage in = wifi.listenForIncomingMessage(6000);
  37.   if (in.hasData) {
  38.     if (in.channel == SERVER)
  39.       Serial.println("Message from the server:");
  40.     else
  41.       Serial.println("Message a local client:");
  42.     Serial.println(in.message);
  43.     //Echo back;
  44.     wifi.send(in.channel, "Echo:", false);
  45.     wifi.send(in.channel, in.message);
  46.     nextPing = millis() + 10000;
  47.   }
  48.   //If you want do disconnect from the server use:
  49.   // wifi.disconnectFromServer();
  50. }


復(fù)制代碼


ESP8266wifi-master.zip

14.72 KB, 下載次數(shù): 13, 下載積分: 黑幣 -5

評分

參與人數(shù) 1黑幣 +50 收起 理由
admin + 50 共享資料的黑幣獎勵!

查看全部評分

分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復(fù)

使用道具 舉報

沙發(fā)
ID:425007 發(fā)表于 2018-11-20 09:36 來自手機 | 只看該作者
這個是有什么用的?
回復(fù)

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復(fù) 返回頂部 返回列表