Example sketches for the new Arduino IDE for ESP8266

Moderator: igrr

User avatar
By markingle
#45754 Hello guys! ESP newbie here! I am having the exact same problem trying to get two ESP12E dev boards to communicate via http. My goal is to simply build my understanding and knowledge for a future project. I am using the MyAPServer and MyAPClient code from martinayoette (Thank you sir!). The MyAPClient code gets an IP address (192.168.4.2) from the ESP running in WIFI_AP mode but fails to connect to the http server.....at least that's how I think it should be working.

I don't think the client is even connecting to the http server since I dont see the same GET post in the serial monitor of the server. So my browser is connecting fine as I do see the GET post in the serial monitor. I have been troubleshooting this for about a week so I thought I would reach out after finding the post. I fear my problem may be a basic issue that I just cannot figure out.

Below is a section(s) of the code from MyAPClient...

#include <ESP8266WiFi.h>

const char *ssid = "MyESPAP";
const char *password = "MyPassword";
const char *host = "192.168.4.1";

..........

void loop() {
delay(8000);
if (rate_toogle == 0)
rate_toogle = 1;
else
rate_toogle = 0;
Serial.print("connecting to ");
Serial.println(host);
WiFiClient client;
const int httpPort = 80;
if (!client.connect(host, httpPort)) {
Serial.println("connection failed");
return;
}
.........

Here is the response from the serial monitor:

Connecting to MyESPAP
...........
WiFi connected
IP address:
192.168.4.2
connecting to 192.168.4.1
connection failed
connecting to 192.168.4.1
connection failed

Thanks in advance!
User avatar
By markingle
#45825 What a difference a day makes! I figured out what was wrong today at lunch time. There is a WiFi.printDiag(Serial) function that I found in the library on github. I added this to the code and it gives really good information (in red) about the WiFi instance.

Connecting to MyESPAP
.....
WiFi connected
IP address:
192.168.4.2
connecting to 192.168.4.1
Mode: STA
PHY mode: N
Channel: 1
AP id: 0
Status: 5
Auto connect: 1
SSID (7): MyESPAP
Passphrase (10): MyPassword
BSSID set: 0

Requesting URL: /srate
HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 174
Connection: close
Access-Control-Allow-Origin: *

<html><head><script>window.onload = function() { setInterval(function() {window.location.replace('/');}, 1000); };</script></head><body><h1>Slow Rate mode</h1></body></html>
closing connection

I was able to see that the client was running in STA+AP mode which will not work. Up until I saw the diagnostic info I was assuming the client was in WIFI_STAmode :(

marinayoette - I just saw your reply....so thank you for confirming. I never received an email on your reply so I need to check that out. Thanks again for your help!

Below is the update (in red)......My project is to create a security alarm system for my boat that is in public storage. I'll pull a GPIO low to trigger a "Raise Hell Alarm" with blue strobe LED. I will share the project here on ESP8266.com after I get the comms going using TCP.

void setup() {
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
WiFi.mode(WIFI_STA);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
}

........

String url = "/frate";
//if (rate_toogle == 0)
if (digitalRead(16) == 1)
url = "/srate";

.....
Last edited by markingle on Tue Apr 19, 2016 9:46 pm, edited 1 time in total.
User avatar
By martinayotte
#45834 Yes ! the WiFi.mode(WIFI_STA) call in MyAPClient sketch is mandatory !
Maybe it was missing there in my original ZIP file dated of almost 1 year, probably because it was the default behaviour at that time.
I should probably renew those ZIP files ...