/*
https://ikkholis27.wordpress.com/2020/06/01/arduino-with-esp01-esp8266-wifi-module-webclient-for-internet-of-things-tutorial/
AT Firmware simulation example
Use the serial monitor to interface with the AT firmware. For instance, to scan for WiFi:
AT+CWMODE=1
AT+CWLAP
Connect to WiFi:
AT+CWJAP="Wokwi-GUEST",
Show the current IP address:
AT+CIFSR
Show firmware version
AT+GMR
To show list list of available commands:
AT+CMD?
AT
AT+CWMODE=1
AT+CWLAP
AT+CWJAP="Wokwi-GUEST",
AT+CIFSR
AT+CIPMUX=1
AT+CIPSERVER=1,80
*/
//Programa: Comandos AT com ESP8266
//Guia do Usuario do ESP8266
#include "WiFiEsp.h"
#include <SoftwareSerial.h>
//RX pino 2, TX pino 3
/*
* Adaptador Arduino
* RX -> 3(TX)
* TX -> 2(RX)
*/
SoftwareSerial esp8266(2, 3);
#define DEBUG true
int status = WL_IDLE_STATUS; // the Wifi radio's status
char server[] = "disciplinasfatec.000webhostapp.com";
WiFiEspClient client;
void setup() {
Serial.begin(9600);
esp8266.begin(115200); // baud rate padrão do ESP8266
Serial.println("** Verificando conexao **");
Serial.println();
delay(1000);
// Reinicializar parametros ...
sendData("AT\r\n", 2000, DEBUG); // rst
delay(1000);
// Ativar mode de operação para estação ...
sendData("AT+CWMODE=1\r\n", 1000, DEBUG);
delay(1000);
// Conectar a rede wireless ...
sendData("AT+CWJAP=\"Wokwi-GUEST\",\r\n", 2000, DEBUG);
delay(3000);
// Mostrar o endereco IP ...
sendData("AT+CIFSR\r\n", 1000, DEBUG);
//sendData("AT+CWLIF\r\n", 1000, DEBUG);
delay(3000);
Serial.println();
Serial.println("** Final **");
// you're connected now, so print out the data
Serial.println("You're connected to the network");
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
if (client.connect(server, 80)) {
delay(3000);
Serial.println("Connected to server");
// Make a HTTP request
client.println("GET /gerador_trafego.txt HTTP/1.1");
client.println("Host: disciplinasfatec.000webhostapp.com");
client.println();
}
}
void loop() {
/*
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
*/
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
String sendData(String command, const int timeout, boolean debug)
{
// Envio dos comandos AT para o modulo
String response = "";
esp8266.print(command);
long int time = millis();
while ( (time + timeout) > millis())
{
while (esp8266.available())
{
// The esp has data so display its output to the serial window
char c = esp8266.read(); // read the next character.
response += c;
}
}
if (debug)
{
Serial.println(response);
}
return response;
}