Post topics, source code that relate to the Arduino Platform

User avatar
By paolovr70
#84945 Hi,
I'm adding wifi access to an ARDUINO MEGA project. I would like to use ESP8266 both in AP and CLIENT MODE. For CLIENT mode I want to choose a specific PORT (in spite of the usual 80). The code under reported WORKS ONLY if I maintain the PORT 80. If I change the PORT number to any other number than 80 after the first "AT+CIPSEND" the connection is closed (and I cannot BUILD the page). Where is the mistake? SOLUTIONS? Thanks.
p.

Code: Select allvoid setup() {
  Serial.begin(9600);
  Serial3.begin(115200); // esp's baud rate might be different
  sendData("AT+RST\r\n",2000,DEBUG); // reset module
  Serial.println("Set mode 1/3");// was 1
  sendData("AT+CWMODE=3\r\n",1000,DEBUG); // configure as both mode 3000
  Serial.println("Setting for multiple connection");
  sendData("AT+CIPMUX=1\r\n",1000,DEBUG); // configure for multiple connections 2000
  Serial.println("define fixed IP");
  sendData("AT+CIPSTA=\"192.168.178.151\"\r\n",1000,DEBUG); //SET STA IP ADDED
  Serial.println("joining AP");
  //sendData("AT+CWJAP=\"DWR-116_PR\",\"1234_abcd_!_9876\"\r\n", 8000, DEBUG); // connect to wifi 8000
  sendData("AT+CWJAP=\"FRITZ!Box7490_PR\",\"1234_abcd_!_9876\"\r\n", 10000, DEBUG); // connect to wifi 8000
  Serial.println("Testing CIFSR");
  sendData("AT+CIFSR\r\n",2000,DEBUG); // get ip address 7000
  Serial.println("Set AP name, pw");
  sendData("AT+CWSAP=\"ESP8266\",\"1234567890\",5,3,1,0\r\n",1000,DEBUG); // turn on server on port 80 1000
  Serial.println("set port for server");
  sendData("AT+CIPSERVER=1,80\r\n",1000,DEBUG); // turn on server on port 80 1000
}


For sending the pages to ESP I use the following code:

Code: Select allString webpage = "<h1>PR Smart Home</h1><button>LED1</button><button>LED2</button><button>LED3</button>"
      "<button>LED4</button><button>LED5</button>";
      String cipSend = "AT+CIPSEND=";
      cipSend += connectionId;
      cipSend += ",";
      cipSend +=webpage.length();
      //cipSend += ",192.168.178.151,5556";
      cipSend +="\r\n";
      sendData(cipSend,1000,DEBUG);
      sendData(webpage,1000,DEBUG);