Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Arduino.h>
- #include <PLDuino.h>
- #define ESP_BAUD 115200
- #define BAUD3 9600
- String getResponse()
- {
- String response = "";
- for(int i=0; i<10; ++i)
- {
- while(Serial3.available())
- response += char(Serial3.read());
- delay(100);
- }
- return response;
- }
- String getESPResponse()
- {
- String response = "";
- for(int i=0; i<10; ++i)
- {
- while(Serial2.available())
- response += char(Serial2.read());
- delay(100);
- }
- return response;
- }
- bool waitUntilStringReceived (String ptn, int timeout)
- {
- String response = "";
- long start_time = millis();
- while(millis() - start_time < timeout)
- {
- if (Serial2.available())
- {
- response += (char)Serial2.read();
- if (response.length() >= ptn.length())
- {
- response = response.substring(response.length() - ptn.length());
- if (response == ptn) return true;
- }
- }
- }
- return false;
- }
- void cancelWiFiTestStartup()
- {
- if (waitUntilStringReceived("type \"qw\"", 10000))
- {
- Serial.println("sending qw...");
- Serial2.println("qwqwqw;\n");
- Serial.flush();
- }
- Serial2.flush();
- }
- void setup()
- {
- using namespace PLDuino;
- PLDuino::init();
- enableESP();
- Serial2.begin(ESP_BAUD);
- Serial.begin(ESP_BAUD);
- Serial3.begin(BAUD3);
- cancelWiFiTestStartup();
- }
- void loop()
- {
- String response = "";
- String ESPResponse = "";
- response = getResponse();
- ESPResponse = getESPResponse();
- if(response != "")
- {
- Serial2.println(response);
- //Serial2.println("12345");
- Serial.println(response);
- Serial.flush();
- Serial2.flush();
- Serial3.flush();
- }
- if(ESPResponse != "")
- {
- Serial.println(ESPResponse);
- Serial.flush();
- Serial2.flush();
- Serial3.flush();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement