I have been trying to build a programme where it would get information from web server through ESP-01 and turn on a LED connect to the Arduino board. I have been following the tutorial I found here, with the exact same wiring at 5:52 except RST briefly connected to ground before uploading code. But when I upload any code other than completely blank one to Arduino board after switching the wiring to 9:36 in the video after removing the Arduino from power, I get nothing from serial and the blue LED on the ESP-01 stops blinking when I made it to retrieve information constantly from the web server. Here is the code.
#include <ESP8266HTTPClient.h>
#include<ESP8266WiFi.h>
void setup() {
Serial.begin(9600);
WiFi.begin("WIFI", "PW");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
//Serial.println("Waiting for connection");
}
Serial.println("Connected...");
delay(1000);
if (WiFi.status() == WL_CONNECTED) {
//Serial.println("Wi-Fi Connected!");
}
delay(2000);
}
char data[] = {'a', 'r', 'd', '0', '\0'};
void loop() {
delay(100);
if(oc() == '1'){
Serial.println("HIGH");
} else {
Serial.println("LOW");
}
}
char oc() {
String res = query("returnlasttask", "");
if(res != "Failed"){
return res[res.length() - 1];
} else {
//Serial.println("Failed!");
}
}
String query(String s, String data){
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
String url = "http://website.com/" + s + ".php?" + data;
http.begin(url);
http.addHeader("Content-Type", "text/plain");
int httpCode = http.GET();
String str = http.getString();
http.end();
return str;
} else {
return "Failed";
}
}
Here is the code for Arduino board:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
String incomingByte;
void setup() {
pinMode(13, OUTPUT);
Serial.begin(9600);
}
void loop() {
if (Serial.available() > 0) {
Serial.println("Receiving");
incomingByte = Serial.readString();
if(incomingByte.substring(0, 3) == "ard"){
if(incomingByte[3] == '1'){
Serial.println("ON");
digitalWrite(13, HIGH);
} else {
Serial.println("OFF");
digitalWrite(13, LOW);
}
}
}
}
I know the code isn't good, but my prime objective is to get it working. Anyway, when I upload the first code to ESP-01 module with blank code uploaded to Arduino board, it retrieves information well and prints "HIGH" and "LOW" to the serial properly. When I upload Arduino board code, the blue LED stops blinking, and nothing is printed on the serial, not even "Receiving". How can I fix this? If I can't for whatever reason, what are the alternative methods?
Also, is it normal that when I need to upload code to ESP-01, I need to have the board uploaded with empty code and ESP-01's RST pin briefly connected to ground? Because this was never mentioned in any tutorials, and this was the only way to get my modules to work. Not doing both simply gets me this error:
warning: espcomm_sync failed
error: espcomm_open failed
error: espcomm_upload_mem failed
Edit: Crossed out things I just fixed, but I still don't get anything through serial.