Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //tambahin fungsi:
- //fungsi send data to esp
- boolean sendData(String command, char response[], const int timeout) {
- esp8266.print(command); // send the read character to the esp8266
- Serial.println(">"+command);
- long int time = millis();
- while( (time+timeout) > millis()) {
- while(esp8266.available()) {
- if(esp8266.find(response)){
- Serial.println("Response found");
- return true;
- }
- else if(esp8266.find("busy")){ //If device is busy...
- Serial.println("busy...");
- wifi_reset();
- waitResponse("ready",5000);
- return false;
- }
- }
- }
- Serial.println("Response NOT found");
- return false;
- }
- //## reset the esp8266 by digitalwrite pin
- void wifi_reset(){
- digitalWrite(RST,LOW);
- delay(100);
- digitalWrite(RST,HIGH);
- delay(1000);
- Serial.println("##### ESP8266 Reset #####");
- }
- //kode untuk kirim data di main:
- main(){
- ...
- String cmd="AT+CIPSEND=";
- cmd+= getStr.length();
- cmd+= "\r\n";
- //timeout 10000
- if(sendData(cmd,">",10000)){
- //berhasil
- } else {
- //gagal
- Serial.println("connection timeout");
- sendData("AT+CIPCLOSE\r\n","OK",1000);
- return;
- }
- ...
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement