有人可以帮我吗,当我分别运行此代码时,没有发现任何问题,但是当我将其融合在一起时,只能将模糊的工作和数据发送到我的服务器,对不起我的英语
我已经尝试通过功能将它们分开,并延迟了时间来发布数据,但这也许不是真正的问题
#include "SoftwareSerial.h"
#include <dht.h>
#include <Fuzzy.h>
#define DEBUG true
#define dht_apin A1 // Analog Pin sensor is connected to
SoftwareSerial esp(6, 7);// RX, TX
String ssid = "BU SIS";
String password = "Bismillah";
dht DHT;
// Fuzzy
Fuzzy *fuzzy = new Fuzzy();
// FuzzyInputKudara
FuzzySet *urendah = new FuzzySet(0, 50, 50, 50);
FuzzySet *usedang = new FuzzySet(45, 60, 60, 75);
FuzzySet *utinggi = new FuzzySet(70, 70, 100, 100);
// FuzzyInputKtanah
FuzzySet *trendah = new FuzzySet(0, 50, 50, 50);
FuzzySet *tsedang = new FuzzySet(45, 60, 60, 75);
FuzzySet *ttinggi = new FuzzySet(70, 70, 100, 100);
// FuzzyInputSudara
FuzzySet *srendah = new FuzzySet(20, 27, 27, 31);
FuzzySet *stinggi = new FuzzySet(30, 35, 40, 40);
// FuzzyOutputKondisi
FuzzySet *tidak = new FuzzySet(0, 25, 25, 50);
FuzzySet *siram = new FuzzySet(50, 80, 100, 100);
String data;
String server = "192.168.100.11";
String uri = "/web/insertx.php";
String temp , hum;
int ftemp, fhum;
int tanah;
void setup() {
Serial.begin(9600);
esp.begin(9600);
// Reset modul
sendCommand("AT+RST\r\n", 1000, DEBUG);
// Konfigurasikan sebagai Akses poin & Wifi
sendCommand("AT+CWMODE=3\r\n", 1000, DEBUG);
// Sesuaikan dengan SSID dan Password
sendCommand("AT+CWJAP=\"BU SIS\",\"Bismillah\"\r\n", 10000, DEBUG);
// Mendapatkan IP adress
sendCommand("AT+CIFSR\r\n", 1000, DEBUG);
// Konfigurasikan untuk multiple connection
sendCommand("AT+CIPMUX=1\r\n", 1000, DEBUG);
// FuzzyInput
FuzzyInput *kudara = new FuzzyInput(1);
kudara->addFuzzySet(urendah);
kudara->addFuzzySet(usedang);
kudara->addFuzzySet(utinggi);
fuzzy->addFuzzyInput(kudara);
// FuzzyInput
FuzzyInput *ktanah = new FuzzyInput(2);
ktanah->addFuzzySet(trendah);
ktanah->addFuzzySet(tsedang);
ktanah->addFuzzySet(ttinggi);
fuzzy->addFuzzyInput(ktanah);
// FuzzyInput
FuzzyInput *sudara = new FuzzyInput(3);
sudara->addFuzzySet(srendah);
sudara->addFuzzySet(stinggi);
fuzzy->addFuzzyInput(sudara);
// FuzzyOutput
FuzzyOutput *kondisi = new FuzzyOutput(1);
kondisi->addFuzzySet(tidak);
kondisi->addFuzzySet(siram);
fuzzy->addFuzzyOutput(kondisi);
// Building FuzzyRule 3
FuzzyRuleAntecedent *a3 = new FuzzyRuleAntecedent();
a3->joinWithAND(urendah, tsedang);
FuzzyRuleAntecedent *ktanah3 = new FuzzyRuleAntecedent();
ktanah3->joinSingle(srendah);
FuzzyRuleAntecedent *aa3 = new FuzzyRuleAntecedent();
aa3->joinWithAND(a3, ktanah3);
FuzzyRuleConsequent *maka3 = new FuzzyRuleConsequent();
maka3->addOutput(siram);
FuzzyRule *fuzzyRule3 = new FuzzyRule(3, aa3, maka3);
fuzzy->addFuzzyRule(fuzzyRule3);
// Building FuzzyRule 5
FuzzyRuleAntecedent *a5 = new FuzzyRuleAntecedent();
a5->joinWithAND(urendah, ttinggi);
FuzzyRuleAntecedent *ktanah5 = new FuzzyRuleAntecedent();
ktanah5->joinSingle(srendah);
FuzzyRuleAntecedent *aa5 = new FuzzyRuleAntecedent();
aa5->joinWithAND(a5, ktanah5);
FuzzyRuleConsequent *maka5 = new FuzzyRuleConsequent();
maka5->addOutput(siram);
FuzzyRule *fuzzyRule5 = new FuzzyRule(5, aa5, maka5);
fuzzy->addFuzzyRule(fuzzyRule5);
// Building FuzzyRule 9
FuzzyRuleAntecedent *a9 = new FuzzyRuleAntecedent();
a9->joinWithAND(usedang, tsedang);
FuzzyRuleAntecedent *ktanah9 = new FuzzyRuleAntecedent();
ktanah9->joinSingle(srendah);
FuzzyRuleAntecedent *aa9 = new FuzzyRuleAntecedent();
aa9->joinWithAND(a9, ktanah9);
FuzzyRuleConsequent *maka9 = new FuzzyRuleConsequent();
maka9->addOutput(siram);
FuzzyRule *fuzzyRule9 = new FuzzyRule(9, aa9, maka9);
fuzzy->addFuzzyRule(fuzzyRule9);
// Building FuzzyRule 11
FuzzyRuleAntecedent *a11 = new FuzzyRuleAntecedent();
a11->joinWithAND(usedang, ttinggi);
FuzzyRuleAntecedent *ktanaha11 = new FuzzyRuleAntecedent();
ktanaha11->joinSingle(srendah);
FuzzyRuleAntecedent *aa11 = new FuzzyRuleAntecedent();
aa11->joinWithAND(a11, ktanaha11);
FuzzyRuleConsequent *maka11 = new FuzzyRuleConsequent();
maka11->addOutput(siram);
FuzzyRule *fuzzyRule11 = new FuzzyRule(11, aa11, maka11);
fuzzy->addFuzzyRule(fuzzyRule11);
// Building FuzzyRule 12
FuzzyRuleAntecedent *a12 = new FuzzyRuleAntecedent();
a12->joinWithAND(usedang, stinggi);
FuzzyRuleAntecedent *ktanaha2 = new FuzzyRuleAntecedent();
ktanaha2->joinSingle(ttinggi);
FuzzyRuleAntecedent *aa12 = new FuzzyRuleAntecedent();
aa12->joinWithAND(a12, ktanaha2);
FuzzyRuleConsequent *makaa2 = new FuzzyRuleConsequent();
makaa2->addOutput(siram);
FuzzyRule *fuzzyRule12 = new FuzzyRule(12, aa12, makaa2);
fuzzy->addFuzzyRule(fuzzyRule12);
// Building FuzzyRule 15
FuzzyRuleAntecedent *a15 = new FuzzyRuleAntecedent();
a15->joinWithAND(utinggi, srendah);
FuzzyRuleAntecedent *ktanaha5 = new FuzzyRuleAntecedent();
ktanaha5->joinSingle(tsedang);
FuzzyRuleAntecedent *aa15 = new FuzzyRuleAntecedent();
aa15->joinWithAND(a15, ktanaha5);
FuzzyRuleConsequent *makaa5 = new FuzzyRuleConsequent();
makaa5->addOutput(siram);
FuzzyRule *fuzzyRule15 = new FuzzyRule(15, aa15, makaa5);
fuzzy->addFuzzyRule(fuzzyRule15);
// Building FuzzyRule 17
FuzzyRuleAntecedent *a17 = new FuzzyRuleAntecedent();
a17->joinWithAND(utinggi, ttinggi);
FuzzyRuleAntecedent *ktanaha7 = new FuzzyRuleAntecedent();
ktanaha7->joinSingle(srendah);
FuzzyRuleAntecedent *aa17 = new FuzzyRuleAntecedent();
aa17->joinWithAND(a17, ktanaha7);
FuzzyRuleConsequent *makaa7 = new FuzzyRuleConsequent();
makaa7->addOutput(siram);
FuzzyRule *fuzzyRule17 = new FuzzyRule(17, aa17, makaa7);
fuzzy->addFuzzyRule(fuzzyRule17);
delay(10000);
}
void dataku() {
DHT.read11(dht_apin);
fhum = DHT.humidity;
ftemp = DHT.temperature;
tanah = analogRead(A0);
tanah = map(tanah, 1023, 36, 100, 0);
hum = String(fhum);
temp = String(ftemp);
fuzzy->setInput(1, fhum);
fuzzy->setInput(2, tanah);
fuzzy->setInput(3, ftemp);
fuzzy->fuzzify();
Serial.println(fhum);
Serial.println(ftemp);
Serial.println(tanah);
Serial.print("\n\nKondisi: ");
if (siram->getPertinence() > tidak->getPertinence()) {
Serial.println("Siram\n");
pinMode(10, OUTPUT);
digitalWrite(10, LOW);
} else {
Serial.println("Tidak Siram\n");
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
};
float output1 = fuzzy->defuzzify(1);
data = "suhu=" + temp + " & udara=" + hum + " & tanah=" + tanah;// data sent must be under this form //name1=value1&name2=value2.
// data = "suhu=10 & udara=20 & tanah=30";
Serial.println(data);
}
void loop() {
esp.println("AT+CIPSTART=0,\"TCP\",\"" + server + "\",80");//start a TCP connection.
if ( esp.find("OK")) {
Serial.println("Koneksi siap");
};
Serial.println("=>======================================");
dataku();
httppost();
delay(5000);
}
void httppost () {
String postRequest =
"POST " + uri + " HTTP/1.1\r\n" +
"Host: " + server + "\r\n" +
"Connection: close\r\n" +
"Content-Type: application/x-www-form-urlencoded\r\n" +
// "Content-Type: application/json;charset=UTF-8\r\n"+
"Content-Length: " + data.length() + "\r\n" +
"\r\n" + data;
String sendCmd = "AT+CIPSEND=0";//determine the number of caracters to be sent.
//Serial.println(postRequest);
esp.print(sendCmd);
esp.print(",");
esp.println(postRequest.length());
delay(200);
if (esp.find(">")) {
Serial.println("Sending.."); esp.print(postRequest);
if ( esp.find("SEND OK")) {
Serial.println("Packet sent");
while (esp.available()) {
String tmpResp = esp.readString();
Serial.println(tmpResp);
}
// close the connection
delay(3000);
esp.println("AT+CIPCLOSE");
Serial.println("PUTUS");
}
// Serial.println(postRequest);
}
delay(4000);
// Serial.println(sendCmd + postRequest.length() );
}
String sendCommand(String command, const int timeout, boolean debug) {
String response = "";
esp.print(command);
long int time = millis();
while ( (time + timeout) > millis()) {
while (esp.available()) {
char c = esp.read();
response += c;
}
}
if (debug) {
Serial.print(response);
}
return response;
}
草图使用17524字节(54%)的程序存储空间。最大为32256字节。 全局变量使用832字节(占40%)的动态内存,为本地变量保留1216字节。最大为2048个字节。