I'm setting webserver with toggle led. I want to create global webserver. I`m mean hat use server with global ip. For it I must use port too. global ip/local ip:port. I want to create on 5000 port. I'm used for ESP-01f and connect it arduino. Communicating by SoftwareSerial. I used AT+CIPSTA for static ip. When I used AT+CIPSERVER=1,5000 it worked. But when I connect to it, it works, but in second connection it doesn't want to connect itor when I use digitalWrite it doesn't connect to this server. How can I solute this problem?
code:
#include <SoftwareSerial.h>
SoftwareSerial softSerial(10, 11);
String ssid = "ssid";
String ip = "staticip";
String gateway="gateway";
String sub="submask;
String password = "password";
String _response = "";
#define DEBUG true
void setup()
{
Serial.begin(115200);
pinMode(2,OUTPUT);
softSerial.begin(115200);
connectWifi();
}
void connectWifi() {
do {
sendData("AT+RESTORE\r\n", 5000, DEBUG);
} while (softSerial.find("OK"));
do {
sendData("AT\r\n", 2000, DEBUG);
} while (softSerial.find("OK"));
do {
sendData("AT+CWMODE=1\r\n", 1000, DEBUG);
} while (softSerial.find("OK"));
do {
sendData("AT+CWJAP=\"" + ssid + "\",\"" + password + "\"\r\n", 5000, DEBUG);
} while (softSerial.find("OK"));
do {
sendData("AT+CIPSTA=\"" + ip + "\",\"" + gateway +"\",\"" + sub + "\"\r\n", 2000, DEBUG);
} while (softSerial.find("OK"));
do {
sendData("AT+CIFSR\r\n", 1000, DEBUG);
} while (softSerial.find("OK"));
do {
sendData("AT+CIPMUX=1\r\n", 1000, DEBUG);
} while (softSerial.find("OK"));
do {
sendData("AT+CIPSERVER=1,5000\r\n", 1000, DEBUG);
} while (softSerial.find("OK"));
}
String sendData(String command, const int timeout, boolean debug)
{
String response = "";
softSerial.print(command); long int time = millis();
while ((time + timeout) > millis())
{
while (softSerial.available())
{
char c = softSerial.read();
response += c;
}
}
if (debug)
{
Serial.print(response);
}
return response;
}
void loop()
{
if(softSerial.available()){
if(softSerial.find("+IPD,"){
int connectionId = softSerial.read()-48;
softSerial.find("pin/");
int pin = softSerial.read()-48;
String htmlCode = "<label>"+String(pin)+"</label>";
digitalWrite(pin,HIGH);
sendData("AT+CIPSEND="+String(connectionId)+","+htmlCode.length()+"\r\n",1000,DEBUG);
sendData(htmlCode+"\r\n",1000,DEBUG);
sendData("AT+CIPCLOSE="+String(connectionId),3000,DEBUG);
}
}
}