The code I used was from online and I tried using it to send data to firebase through web server. But the ouput I get from serial monitor was just "ATE0" which means there's something wrong. Hence, I can't proceed in solving this issue.
I tried several resources online to match my current problem.
I hope someone can help me
Thank you :)
#include <SoftwareSerial.h>;
SoftwareSerial Serial1(10, 11);
#include "DHT.h"
#define Terra "terra1"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
//const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2; eyagagana soy
int j=0;
int prev=0;
int pres=0;
String status="";
String buff(64);
String getStr(128);
void setup() {
Serial.begin(9600);
Serial1.begin(9600);
// Serial.println(F("Humiture and Soil Moisture Sensors"));
delay(2000);
Serial1.setTimeout(5000);
dht.begin();
if (!connectWiFi()) {
Serial.println("Can not connect to the WiFi.");
while (true)
; // do nothing
}
Serial.println("OK, Connected to WiFi.");
sendCommand("AT+CIPSTA?");
sendCommand("AT+CIPDNS_CUR?");
sendCommand("AT+CIPSTAMAC?");
}
void loop() {
j=analogRead(A0);
j=map(j,0,982,148,0);
pres=j;
if(j>100)
j=100;
else if(j<0)
j=0;
prev=j;
delay(1000);
float h = dht.readHumidity();
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
// Check if any reads failed and exit early (to try again).
// if (isnan(h) || isnan(t) || isnan(f)) {
// Serial.println(F("Failed to read from DHT sensor!"));
// return;
// }
// Compute heat index in Fahrenheit (the default)
float hif = dht.computeHeatIndex(f, h);
// Compute heat index in Celsius (isFahreheit = false)
float hic = dht.computeHeatIndex(t, h, false);
// Serial.print(F("Humidity: "));
// Serial.print(h);
// Serial.print(F("% Temperature: "));
// Serial.print(t);
// Serial.print(F("°C "));
// Serial.print(("Soil Moisture: "));
// Serial.print(j);
// Serial.println("%");
// connect to server
if (sendCommand("AT+CIPSTART=\"TCP\",\"https://terraduino.000webhostapp.com\",80")) {
Serial.println("connected to Cloud");
// build HTTP request
getStr = "GET /upload.php?terra=";
getStr += Terra;
getStr += "&j=";
getStr += j;
getStr += "&t=";
getStr += t;
getStr += "&h=";
getStr += h;
getStr += " HTTP/1.1\r\n";
//WEBSERVER
getStr += "Host: https://terraduino.000webhostapp.com\r\n\r\n";
// open send buffer
buff = "AT+CIPSEND=";
buff += getStr.length();
if (sendCommand(buff.c_str()) && Serial1.find(">")) { // AT firmware is ready to accept data
// send HTTP request
Serial.println(getStr);
Serial1.print(getStr);
// print HTTP response
if (Serial1.find("+IPD,")) { // response received
int l = Serial1.parseInt();
while (l > 0) {
if (Serial1.available()) {
Serial.write(Serial1.read());
}
}
Serial.println("--------------");
} else {
Serial.println("no response");
}
} else {
Serial.println("send error");
}
sendCommand("AT+CIPCLOSE");
} else {
Serial.println("Error connecting");
}
}
bool connectWiFi() {
if (!sendCommand("ATE0")) // echo off
return false;
if (!sendCommand("AT+CIPMUX=0")) // set single connection mode
return false;
if (!sendCommand("AT+CWMODE=1")) // set STA mode
return false;
return sendCommand("AT+CWJAP=\"I Pronounce you Man and Wifi\",\"-PX?*[email protected]\"");
}
bool sendCommand(const char* cmd) {
Serial.println(cmd);
Serial1.println(cmd);
while (true) {
buff = Serial1.readStringUntil('\n');
buff.trim();
if (buff.length() > 0) {
Serial.println(buff);
if (buff == "OK" || buff == "SEND OK" || buff == "ALREADY CONNECTED")
return true;
if (buff == "ERROR" || buff == "FAIL" || buff == "SEND FAIL")
return false;
}
}
}
-
ESP boards are definitely nothing for beginners. The problem with them is that they might have very different Firmware versions on them. You can for example not be sure what baud rate they are using. So, you have to find out which baud rate the Serial interface uses. You configured 9600 Bit/sec but most of the boards need 115200. Event ESP Gurus do flushing the ESP with a well define firmware: e.g. medium.com/@aallan/…Peter Paul Kiefer– Peter Paul Kiefer2019年10月29日 15:20:36 +00:00Commented Oct 29, 2019 at 15:20
-
It would be a good idea to also add the complete output of the arduino to the question. The output helps us to follow the program and how it executes.Peter Paul Kiefer– Peter Paul Kiefer2019年10月29日 15:23:45 +00:00Commented Oct 29, 2019 at 15:23
-
did you set the baud rate of AT firmware to 9600 baud? (btw, I wrote this version of sendCommand function)Juraj– Juraj ♦2019年10月29日 17:16:12 +00:00Commented Oct 29, 2019 at 17:16
-
not yet sir, awsome!Warren Paulino– Warren Paulino2019年10月30日 12:54:49 +00:00Commented Oct 30, 2019 at 12:54
-
It doesn't workWarren Paulino– Warren Paulino2019年10月30日 13:27:14 +00:00Commented Oct 30, 2019 at 13:27
1 Answer 1
I would say you are trapped in the sendCommand
function. You print the cmd
(cmd="ATE0") variable to the terminal and then send the command to the ESP over Serial1 = software serial. Serial1 is configured with a baud rate of 9600 (Serial1.begin(9600)
) it depends on your ESP but that might be wrong. A common value is 115200 (Serial1.begin(115200)
). But because that can vary from board to board, it could also be wrong.
If I'm right and you configured a wrong baud rate, the command can not be understood by the ESP and even the newline after the command might be missing for it.
So the ESP send nothing back and the 'buff.length()' equals to 0. Then the while(true)
runs and runs and runs ... .
-
yes, this was the idea. But I can't go back with the AT Commands, I checked all the wires and process done well. output are just some internal information and unknown random symbols printed in serial monitorWarren Paulino– Warren Paulino2019年10月30日 13:51:57 +00:00Commented Oct 30, 2019 at 13:51
Explore related questions
See similar questions with these tags.