h>
void setup()
Serial.begin(115200);
while (!Serial) {
wifiSerial.begin(115200);
while (!wifiSerial) {
void loop()
if(Serial.available()>0){
if(find(message,"debugEsp8266:")){
if(find(result,"OK"))
sendData("\nOK");
else
sendData("\nEr");
if(wifiSerial.available()>0){
if(find(message,"esp8266:")){
if(find(result,"OK"))
sendData("\n"+result);
else
}else
}else if(find(message,"LEDON")){
//sending ph level:
digitalWrite(13,HIGH);
}else if(find(message,"LEDOFF")){
//sending ph level:
digitalWrite(13,LOW);
else{
delay(responseTime);
/*
* Name: sendData
* Params:
* Returns: void
*/
String len="";
len+=str.length();
sendToWifi("AT+CIPSEND=0,"+len,responseTime,DEBUG);
delay(100);
sendToWifi(str,responseTime,DEBUG);
delay(100);
sendToWifi("AT+CIPCLOSE=5",responseTime,DEBUG);
/*
* Name: find
* Params:
*/
if(string.indexOf(value)>=0)
return true;
return false;
}
/*
* Name: readSerialMessage
* Params:
*/
String readSerialMessage(){
char value[100];
while(Serial.available()>0){
value[index_count]=Serial.read();
index_count++;
String str(value);
str.trim();
return str;
/*
* Name: readWifiSerialMessage
* Params:
* Returns: The response from the esp8266 (if there is a reponse)
*/
String readWifiSerialMessage(){
char value[100];
while(wifiSerial.available()>0){
value[index_count]=wifiSerial.read();
index_count++;
String str(value);
str.trim();
return str;
/*
* Name: sendToWifi
* Params: command - the data/command to send; timeout - the time to wait for a response; debug -
print to Serial window?(true = yes, false = no)
*/
while(wifiSerial.available())
// The esp has data so display its output to the serial window
response+=c;
if(debug)
Serial.println(response);
return response;
/*
* Name: sendToWifi
* Params: command - the data/command to send; timeout - the time to wait for a response; debug -
print to Serial window?(true = yes, false = no)
*/
while(Serial.available())
// The esp has data so display its output to the serial window
response+=c;
if(debug)
Serial.println(response);
return response;