Exemplo n.º 1
0
bool getWifiData() {
    content = ESPserial.readString();
    if (content != "") {
        return true;
    } else {
        return false;
    }
}
Exemplo n.º 2
0
int getState () {
    if( !wificmd("CIPSTART=\"TCP\",\"example.com\",8080", "OK")) { //start a TCP connection.
        return 0;
    }
    delay(1000);
    String getRequest = "STATE";

    ESPserial.print("AT+CIPSEND=");
    ESPserial.println(getRequest.length());
    delay(500);

    if(ESPserial.find(">")) {
        clearWifi();
        //Serial.println("Sending..");
        ESPserial.print(getRequest);

        if( ESPserial.find("SEND OK")) {
            //Serial.println("Packet sent");
            String tmpResp = "";
            while (ESPserial.available()) {
                tmpResp = ESPserial.readString();
            }
            // close the connection
            if(wificmd("CIPCLOSE", "OK")) {
                if (tmpResp.substring(11) == "1") {
                    return 1;
                } else {
                    return 0;
                }
            } else {
                Serial.println("Error closing connection");
            }
        } else {
            Serial.println("Error sending data");
        }
    }
    return 0;
}