標(biāo)題: esp8266關(guān)于arduino的一些測(cè)試文件 [打印本頁(yè)]

作者: 橙小亮    時(shí)間: 2018-11-19 17:52
標(biāo)題: esp8266關(guān)于arduino的一些測(cè)試文件
  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


作者: lscc    時(shí)間: 2018-11-20 09:36
這個(gè)是有什么用的?




歡迎光臨 (http://www.torrancerestoration.com/bbs/) Powered by Discuz! X3.1