Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By burkmurray
#21281
Oh, one last thing....are you using the entire library from
https://github.com/esp8266/Arduino/tree ... /libraries
or from
https://github.com/knovoselic/Arduino/t ... /libraries


I'm using the library from your second link, Knovoselic's repo. It's marked as version 1.1.0, and has two example sketches.

I've attached the libraries as a zip.
You do not have the required permissions to view the files attached to this post.
User avatar
By burkmurray
#21282 I'm not familiar with Android, but IOS has an info page for your WiFi connection, which lists your IP, subnet, router IP and DNS. If you have something like that, it would be handy to check that your DNS is the same as your AP IP, and that there aren't any other DNS servers listed.
User avatar
By SwiCago
#21286
burkmurray wrote:
Oh, one last thing....are you using the entire library from
https://github.com/esp8266/Arduino/tree ... /libraries
or from
https://github.com/knovoselic/Arduino/t ... /libraries


I'm using the library from your second link, Knovoselic's repo. It's marked as version 1.1.0, and has two example sketches.

I've attached the libraries as a zip.


OK, I'll try just using knovoselics repo as soon as I get home..

Again, thanks for helping me try to figure out why it isn't working on Android.
User avatar
By SwiCago
#21296 OK, the demo as I posted works perfectly with iOS. Tested with my iPad. As soon as I am connected to my AP, my ON/OFF page is loaded.
On Android it fails. I checked my wifi Settings as set by the AP on android.
MAC: AC:22:0B:43:XX:XX (ommitting last 4)
SSID: esp8266
Hidden: NO
Link Speed: 54Mbps
RSSI: -42dBm
IP: 192.168.1.3
Netmask: 0.0.0.0 (for some reason this is not 255.255.255.0 as set by code)
Gateway: 192.168.1.1
DNS1: 192.168.1.1
DNS2: 0.0.0.0
DHCP Server: 192.168.1.1
DHCP Lease: 86400s

So it looks like the DNS server does not work correctly for Android 5.1.1
Tested also with an older version of Android (4.1.2), same result...does not work.

Can any one else please test on Android?

Posting my sketch as it currently is. tested using latest IDE and git sources for ESP. As said, works perfectly for iOS, but not for Android...direct access via IP works from all OS
Code: Select all#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <DNSServer.h>

const char* ssid     = "esp8266";
boolean LEDstate[] = {LOW, false, LOW};

const char* html = "<html><head><style>.bt{display:block;width:250px;height:100px;padding:10px;margin:10px;"
                    "text-align:center;border-radius:5px;color:white;font-weight:bold;font-size:70px;text-decoration:none;} "
                    "body{background:#000;} .r{background:#933;} .g{background:#363;} .y{background:#EE0;height:100px;"
                    "width:100px;border-radius:50px;} .b{background:#000;height:100px;width:100px;border-radius:50px;} "
                    ".a{font-size:35px;} td{vertical-align:middle;}</style>"
                    "</head><body><table><tr><td><div class='TGT0'></div></td><td><a class='bt g' href='/L0?v=1'>ON</a></td>"
                    "<td><a class='bt r' href='/L0?v=0'>OFF</a></td></tr><tr><td><div class='TGT2'></div></td><td>"
                    "<a class='bt g' href='/L2?v=1'>ON</a></td><td><a class='bt r' href='/L2?v=0'>OFF</a></td></tr>"
                    "<tr><td>&nbsp;</td><td><a class='bt g a' href='/ALL?v=1'><br/>ALL ON</a></td><td>"
                    "<a class='bt r a' href='/ALL?v=0'><br/>ALL OFF</a></td></tr></body></html>";

const byte DNS_PORT = 53;
IPAddress apIP(192, 168, 1, 1);
IPAddress netMsk(255, 255, 255, 0);
DNSServer dnsServer;
ESP8266WebServer server(80);

void setup() {
  pinMode(0, OUTPUT);
  pinMode(2, OUTPUT);
  digitalWrite(2, LEDstate[0]);
  digitalWrite(2, LEDstate[2]);
  Serial.begin(115200);
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(apIP, apIP, netMsk);
  WiFi.softAP(ssid);
  Serial.print("Started as ");
  Serial.println(ssid);
  Serial.print("IP address: ");
  Serial.println(WiFi.softAPIP());
  dnsServer.start(DNS_PORT, "*", apIP);
  Serial.println("USP Server started");
 
  server.on("/", handle_root);
  server.on("/L0", handle_L0);
  server.on("/L2", handle_L2);
  server.on("/ALL", handle_ALL);
  server.onNotFound(handle_root);
  server.begin();
  Serial.println("HTTP server started");

}

void loop() {
  dnsServer.processNextRequest();
  server.handleClient();
}

void handle_root() {
  Serial.println("Page served");
  String toSend = html;
  toSend.replace("TGT0", LEDstate[0] ? "y" : "b");
  toSend.replace("TGT2", LEDstate[2] ? "y" : "b");
  server.send(200, "text/html", toSend);
  delay(100);
}

void handle_L0() {
  change_states(0);
  handle_root();
}

void handle_L2() {
  change_states(2);
  handle_root();
}

void handle_ALL() {
  change_states(0);
  change_states(2);
  handle_root();
}

void change_states(int tgt) {
  if (server.hasArg("v")) {
    int state = server.arg("v").toInt() == 1;
    Serial.print("LED");
    Serial.print(tgt);
    Serial.print("=");
    Serial.println(state);
    LEDstate[tgt] = state ? HIGH : LOW;
    digitalWrite(tgt, LEDstate[tgt]);
  }
}