ESP8266 फास्ट HTTP GET प्रतिक्रिया दर


13

सर्वर से लगातार बदलते डेटा (कार की स्थिति) प्राप्त करने के लिए अपने ईएसपी 8266 की प्रोग्रामिंग शुरू करते समय, मुझे एक समस्या का सामना करना पड़ा: मुझे सर्वर से 3 गुना / सेकंड से अधिक डेटा प्राप्त करने के लिए ईएसपी 8266 नहीं मिल सकता है।

डेटा दर अधिमानतः 15 गुना / सेकंड होगी। प्राप्त डेटा 47 तत्वों की एक स्ट्रिंग है।

#include <ESP8266WiFi.h>
#include <WiFiClient.h>

// WiFi information
const char WIFI_SSID[] = "my-wlan";
const char WIFI_PSK[] = "123qwe123qwe";

// Remote site information
const char http_site[] = "10.13.137.144";
const int http_port = 8080;

// Pin definitions
const int LED_PIN = 16;

// Global variables
WiFiClient client;
String readString, readString1 ;
int x=0;
byte led_statuss = 0;
void setup() {

  // Set up serial console to read web page
  Serial.begin(115200);
  Serial.print("Thing GET Example");

  // Set up LED for debugging
  pinMode(LED_PIN, OUTPUT);

  // Connect to WiFi
  connectWiFi();
  }
//////////////////////////loop///////////////////////////////////////
void loop() {
  int time=millis();

    getPage();

    delay(100);
    // If there are incoming bytes, print them

     int lines_received = 0;

      while(client.available()) {
      String line = client.readStringUntil('\n');
      if (lines_received == 7) { 
      String k =(line.substring(0,line.length())); // removes headers from the server response

      Serial.println(k); // prints the raw data
      int time1 = millis()-time;
      Serial.print("Time is ");
      Serial.println(time1); // shows how much time the function takes    
      }
      lines_received++;

   }

     // Do nothing
    //Serial.println("Finished Thing GET test");
}

// Attempt to connect toFi///////////////////////////////////////////////////////////
void connectWiFi() {

  byte led_status = 0;

  // Set WiFi mode to station (client)
  WiFi.mode(WIFI_STA);

  // Initiate connection with SSID and PSK
  WiFi.begin(WIFI_SSID, WIFI_PSK);

  // Blink LED while we wait for WiFi connection
  while ( WiFi.status() != WL_CONNECTED ) {
    digitalWrite(LED_PIN, led_status);
    led_status ^= 0x01;
    delay(100);
  }

  // Turn LED on when we are connected
  digitalWrite(LED_PIN, HIGH);
}

// Perform an HTTP GET request to a remote page//////////////////////////////////////////
bool getPage() {

  // Attempt to make a connection to the remote server
  if ( !client.connect(http_site, http_port) ) {
    return false;
  }

  // Make an HTTP GET request
   //client.print("GET /cars" + "HTTP/1.1 \r\n" + "Host: " + "10.13.137.154" + "\r\n" + "Connection: close\r\n\r\n");
  client.println("GET /cars HTTP/1.1");
  client.print("Host: ");
  client.println(http_site);
  client.println("Connection: Close");
  client.println();
  delay(100); //some put delay, but why and how long?
  return true;
}

हम सर्वर से एक GET अनुरोध करते हैं और हम हेडर से कच्चे डेटा को फ़िल्टर करते हैं और प्रतिक्रियाएँ होती हैं:

Thing GET Example1;62.91;43.55;190.03;5.59;20.00;44.26;861503022
Time is 228
1;62.91;43.55;190.04;0.00;20.00;43.79;861503920
Time is 926
1;62.91;43.55;190.03;0.00;20.00;44.26;861504988
Time is 1050
1;62.91;43.55;190.08;5.76;20.00;43.83;861505980
Time is 1011
1;62.91;43.55;190.07;0.00;20.00;43.82;861506983
Time is 992
1;62.91;43.55;190.04;0.00;20.00;43.79;861508012
Time is 1036
1;62.91;43.55;190.11;0.00;20.00;43.86;861510045
Time is 2020
1;62.91;43.55;190.05;0.00;20.00;43.80;861510274
Time is 222
1;62.91;43.55;190.07;0.00;20.00;43.82;861511306
Time is 1026
1;62.91;43.55;190.07;0.00;20.00;43.82;861512410
Time is 1108
1;62.91;43.55;190.04;0.00;20.00;43.79;861512605
Time is 219
1;62.91;43.55;190.03;0.00;20.00;44.26;861512840
Time is 214
1;62.91;43.55;190.06;0.00;20.00;43.81;861513842
Time is 996

ऐसा लगता है कि ESP GET प्रतिक्रियाओं को तेज़ी से प्राप्त नहीं कर सकता है। समय एमएस में है। मैंने इसे 400 मीटर के आसपास देरी होने पर समान रूप से काम करने के लिए प्रबंधित किया।

प्रक्रिया की गति को बेहतर बनाने का सबसे अच्छा तरीका क्या होगा?


आपके getPageफ़ंक्शन में, यदि आप देरी को हटाते हैं या इसे कम करते हैं तो क्या होता है?
बेंस कौलिक्स 14

1
सामान्य तौर पर, यह प्रदर्शन में सुधार नहीं करता है, बस कुछ GET के लिए यह तेजी से बनाता है, लेकिन फिर आपके पास 900, 1000ms देरी है। मैंने दूसरे ईएसपी पर एक साधारण वेबसर्वर और अन्य ईएसपी पर एक क्लाइंट को दोहराने की कोशिश की, और इसने वहां बहुत अच्छा काम किया। प्रतिक्रियाएं लगभग 20-50ms थीं। तो मुझे लगता है कि यह नेटवर्क के साथ कुछ करने के लिए है।
रात्रि ē:

और संचार कार्यस्थलों पर किया जाता है आम वाई-फाई।
रायटिस बॉरज़िश

2
क्या आपको वास्तव में हर उस पृष्ठ को जोड़ने की आवश्यकता है जो आपको पृष्ठ की आवश्यकता है? क्या आप एक बार कनेक्ट नहीं कर सकते हैं और कनेक्शन रख सकते हैं, और कनेक्शन खो जाने या समाप्त हो जाने की स्थिति में फिर से कनेक्ट करें?
सांप सैंडर्स

2
क्या आपको इसके लिए HTTP का उपयोग करना है? यह इस उपयोग के मामले के लिए अविश्वसनीय रूप से अक्षम है, और सिर्फ इसलिए नहीं है कि रखने की समस्या के कारण।
दान हुलमे

जवाबों:


5

आप का उपयोग करके अपने getPage () विधि पर lenghtly कनेक्शन रीसेट से बचना चाहिए

Connection: Keep-Alive

के बजाय

Connection: Close

जिससे काफी बचत हो सकती है।

हमारी साइट का प्रयोग करके, आप स्वीकार करते हैं कि आपने हमारी Cookie Policy और निजता नीति को पढ़ और समझा लिया है।
Licensed under cc by-sa 3.0 with attribution required.