{"id":704,"date":"2014-12-13T22:34:41","date_gmt":"2014-12-13T21:34:41","guid":{"rendered":"http:\/\/pinguino.walii.es\/?p=704"},"modified":"2020-07-02T11:20:39","modified_gmt":"2020-07-02T10:20:39","slug":"wifi-to-serial-module-esp2866","status":"publish","type":"post","link":"https:\/\/pinguino.walii.es\/?p=704","title":{"rendered":"WIFI to Serial module ESP2866"},"content":{"rendered":"

This is a new module, that will help us to communicate with our ARDUINOS or PINGUINOS modules.<\/p>\n

Is like a modem, by all the people that use some time ago the well know US-ROBOTIC, know the AT commands, and the easy way to use it.<\/p>\n

The module showed is a BASIC model, but the distance that reach is perfect for domotic or smart home.<\/p>\n

\"Unknown-9\"<\/a><\/p>\n

 <\/p>\n

The PINOUT<\/p>\n

\"esp8266_schematic\"<\/a><\/p>\n

The power supply never will be UP of 3,62Volts<\/p>\n

After of some days testing I will say that is recommended that you install a resistor from VCC to CH_PD, to make UP this pin. With an 1k resistor will be perfect.<\/p>\n

 <\/p>\n

 <\/p>\n

The next example code only make a GET of a WEBPAGE, if we run a TCPDUMP in the middle of the NETWORKS we will capture the request.<\/p>\n

This code will be compatible with any project ARDUINO or PINGUINO<\/p>\n

#define SSID \u00abWalii\u00bb \/\/your wifi ssid here
\n#define PASS \u00abffffffffff\u00bb \/\/your wifi wep key here<\/p>\n

#define DST_IP \u00ab164.138.31.203\u00bb \/\/baidu.com
\n#define HOST \u00abpinguino.walii.es\u00bb<\/p>\n

char myChar;<\/p>\n

void setup()
\n{
\npinMode(9, OUTPUT);
\npinMode(13, OUTPUT);<\/p>\n

\/\/blink led13 to indicate power up
\nfor(int i = 0; i<15; i++)
\n{
\ndigitalWrite(13,HIGH);
\ndelay(50);
\ndigitalWrite(13,LOW);
\ndelay(50);
\n}<\/p>\n

\/\/ Open serial communications for WiFi module:
\nSerial.begin(115200);
\n\/\/ Set time to wait for response strings to be found
\nSerial.setTimeout(5000);
\ndelay(100);<\/p>\n

\/\/test if the module is ready
\nSerial.println(\u00abAT+RST\u00bb);
\nif(Serial.find(\u00abready\u00bb))
\n{
\ndelay(1000);
\n\/\/connect to the wifi
\nboolean connected=false;
\nfor(int i=0;i<5;i++)
\n{
\nif(connectWiFi())
\n{
\nconnected = true;
\nbreak;
\n}
\n}
\nif (!connected)
\n{
\n\/\/die
\nwhile(1);
\n}<\/p>\n

delay(5000);
\n\/\/set the single connection mode
\nSerial.println(\u00abAT+CIPMUX=0\u00bb);
\n}
\nelse
\n{
\ndelay(100);
\n}
\n}<\/p>\n

void loop()
\n{
\nString cmd = \u00abAT+CIPSTART=\\\u00bbTCP\\\u00bb,\\\u00bb\u00bb;
\ncmd += DST_IP;
\ncmd += \u00ab\\\u00bb,80″;
\nSerial.println(cmd);
\nif(Serial.find(\u00abError\u00bb)) return;
\ncmd = \u00abGET \/status HTTP\/1.0\\r\\nHost: \u00ab;
\ncmd += HOST;
\ncmd += \u00ab\\r\\n\\r\\n\u00bb;<\/p>\n

Serial.print(\u00abAT+CIPSEND=\u00bb);
\nSerial.println(cmd.length());
\nif(Serial.find(\u00ab>\u00bb))
\n{
\n}
\nelse
\n{
\nSerial.println(\u00abAT+CIPCLOSE\u00bb);
\ndelay(1000);
\nreturn;
\n}<\/p>\n

Serial.print(cmd);<\/p>\n

delay(500);
\n\/\/Serial.find(\u00ab+IPD\u00bb);
\nwhile (Serial.available())
\n{
\nchar c = Serial.read();
\ndelay(50);
\n}<\/p>\n

delay(1000);
\n}<\/p>\n

boolean connectWiFi()
\n{
\nSerial.println(\u00abAT+CWMODE=1″);
\nString cmd=\u00bbAT+CWJAP=\\\u00bb\u00bb;
\ncmd+=SSID;
\ncmd+=\u00bb\\\u00bb,\\\u00bb\u00bb;
\ncmd+=PASS;
\ncmd+=\u00bb\\\u00bb\u00bb;
\nSerial.println(cmd);
\ndelay(2000);
\nif(Serial.find(\u00abOK\u00bb))
\n{
\nreturn true;
\n}
\nelse
\n{
\nreturn false;
\n}
\n}<\/p>\n

 <\/p>\n

 <\/p>\n

TCPDUMP capture.<\/p>\n

22:25:46.492679 IP 10.10.10.127.60604 > 164.138.31.203.80: Flags [.], ack 5761, win 638, options [nop,nop,TS val 108106608 ecr 2454109009], length 0
\n22:25:46.493147 IP 164.138.31.203.80 > 10.10.10.127.60604: Flags [.], seq 5761:7201, ack 73, win 905, options [nop,nop,TS val 2454109009 ecr 108106599], length 1440<\/p>\n

 <\/p>\n

 <\/p>\n

 <\/p>\n

 <\/p>\n

Specifications and Features<\/h3>\n