Ho un Arduino Uno e un server scritto in C ++. Ho collegato correttamente l'ESP8266 al mio router usando il seguente codice:
#include <SoftwareSerial.h>
SoftwareSerial esp8266(3, 2);
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
while (!Serial) {
; // wait for serial port to connect. Needed for native USB port only
}
Serial.println("Started");
// set the data rate for the SoftwareSerial port
esp8266.begin(115200);
esp8266.write("ATrn");
}
void loop() {
if (esp8266.available()) {
Serial.write(esp8266.read());
}
if (Serial.available()) {
esp8266.write(Serial.read());
}
}
Ora, voglio che ESP8266 si colleghi al mio server come client nella stessa LAN (ho IP del server). Come posso farlo con SoftwareSerial? C'è un altro modo per farlo?
risposte:
2 per risposta № 1Devi inviarlo comandi AT per creare una richiesta HTTP. Questo si collegherebbe ad un server a 192.168.88.35 sulla porta 80
// Connect to the server
esp8266.write("AT+CIPSTART="TCP","192.168.88.35",80rn"); //make this command: AT+CPISTART="TCP","192.168.88.35",80
//wait a little while for "Linked"
delay(300);
//This is our HTTP GET Request change to the page and server you want to load.
String cmd = "GET /status.html HTTP/1.0rn";
cmd += "Host: 192.168.88.35rnrn";
//The ESP8266 needs to know the size of the GET request
esp8266.write("AT+CIPSEND=");
esp8266.write(cmd.length());
esp8266.write("rn");
esp8266.write(cmd);
esp8266.write("AT+CIPCLOSErn");
Questo link dovrebbe essere d'aiuto se hai bisogno di maggiori dettagli: http://blog.huntgang.com/2015/01/20/arduino-esp8266-tutorial-web-server-monitor-example/