// Não funcionou ...
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>
#define DEBUG false
LiquidCrystal_I2C lcd(0x27,16,2);
SoftwareSerial esp8266(2,3); // make RX Arduino line is pin 3, make TX Arduino line is pin 2.
// String retorno;
void setup() {
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Fac. Tecnologia");
lcd.setCursor(0,1);
lcd.print("Unicamp Limeira");
esp8266.begin(115200);
sendData("AT+RST\r\n",2000,DEBUG); // reset module
sendData("AT\r\n",2000,DEBUG); // reset module
sendData("AT+CWMODE=1\r\n",2000,DEBUG); // configure as Wireless Station mode
sendData("AT+CWJAP=\"Wokwi-GUEST\",\"\"\r\n", 6000, DEBUG); //Put Your SSID and password if activate as Station mode else comment down the line
}
void loop() {
Serial.println("Loop ...");
char payload[500];
String retorno;
sprintf(payload,"AT+HTTPCLIENT=2,0,\"http://disciplinasfatec.000webhostapp.com/base.txt\",\"disciplinasfatec.000webhostapp.com\",\"/base.txt\",1\r\n");
lcd.clear();
retorno = sendData(payload,2000,DEBUG);
retorno.trim();
int posicao = retorno.indexOf('|');
lcd.setCursor(0,0);
//lcd.print(retorno);
lcd.print(retorno.substring(posicao+1,posicao+5));
lcd.print(" ");
lcd.print(retorno.length());
delay(10000);
}
String sendData(String command, const int timeout, boolean debug) {
String retor = "";
char c = " ";
esp8266.print(command); // send the read character to the esp8266
long int time = millis();
while( (time+timeout) > millis()) {
while(esp8266.available()) {
c = esp8266.read();
//Serial.write(c);
retor += c;
//retor.concat(c);
//Serial.write(esp8266.read());
}
}
return retor;
}
Loading
esp-01
esp-01