So you're a Noob? Post your questions here until you graduate! Don't be shy.

User avatar
By flagtrax
#88548 I've used the ESP8266 mostly in station mode, and only recently had a (convenience) need to use one in AP mode. I could select it from my android phone's list of networks, and tablet, but not my laptop, with Chrome on Windows 10 reporting that it was an insecure website. I'm not sure when but at some upgrade point, I was able to log on to it, but still with the message that it was insecure. I tried with my older laptop currently running Ubuntu 20.04 and Firefox, with the same results. I've searched the internet and found vague information on the subject but don't fully understand what is being said. Can anyone tell me if there is a work - around for this issue or do we just live with it?
User avatar
By atefth
#88573 Hello.

What are you trying to access from the browser?
If you are hosting a web page in the ESP device can you share the source code?

Thank you.
User avatar
By flagtrax
#88620 Yes @ atefth exactly that. I have a small page that simply at this point reports a temperature from an 18B20 sensor. And it does serve it. But all but the android devices report an insecure connection, when establishing a connection to the ESP8266 as an access point. Not the page itself.

Code: Select all/*********
  Built on the base of Rui Santos 18b20 Async webserver sketch
  Complete project details at https://RandomNerdTutorials.com 
*********/

// Import required libraries
#ifdef ESP32
  #include <WiFi.h>
  #include <ESPAsyncWebServer.h>
#else
  #include <Arduino.h>
  #include <ESP8266WiFi.h>
  #include <Hash.h>
  #include <ESPAsyncTCP.h>
  #include <ESPAsyncWebServer.h>
#endif
#include <OneWire.h>
#include <DallasTemperature.h>

// Data wire is connected to GPIO 4
#define ONE_WIRE_BUS 4
int ledPin =5;

// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);

// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);

/* Put your SSID & Password */
const char* ssid = "tempprobe";  // Enter SSID here
const char* password = "********";  //Enter Password here

/* Put IP Address details */
IPAddress local_ip(192,168,1,1);
IPAddress gateway(192,168,1,1);
IPAddress subnet(255,255,255,0);


// Create AsyncWebServer object on port 80
AsyncWebServer server(80);

 
String readDSTemperatureF() {
  // Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
  sensors.requestTemperatures();
  float tempF = sensors.getTempFByIndex(0);

  if(int(tempF) == -196){
    Serial.println("Failed to read from DS18B20 sensor");
    return "--";
  } else {
    Serial.print("Temperature Fahrenheit: ");
    Serial.println(tempF);
  }
  return String(tempF);
}

const char index_html[] PROGMEM = R"rawliteral(
<!DOCTYPE HTML><html>
<head>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <style>
    html {
     font-family: Arial;
     display: inline-block;
     margin: 0px auto;
     text-align: center;
    }
    h2 { font-size: 3.0rem; }
    p { font-size: 8.0rem; }
    .units { font-size: 2.2rem; }
   
  </style>
</head>
<body>
  <h2>Temperature</h2>
 
  <p>
    <span id="temperaturef">%TEMPERATUREF%</span>
    <sup class="units">&deg;F</sup>
  </p>
</body>
<script>

setInterval(function ( ) {
  var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
      document.getElementById("temperaturef").innerHTML = this.responseText;
    }
  };
  xhttp.open("GET", "/temperaturef", true);
  xhttp.send();
}, 5000) ;
</script>
</html>)rawliteral";

// Replaces placeholder with DHT values
String processor(const String& var){
  //Serial.println(var);
  if(var == "TEMPERATUREF"){
    return readDSTemperatureF();
  }
  return String();
}

void setup(){
  // Serial port for debugging purposes
 
  Serial.begin(115200);
  Serial.println();
Serial.println("");
Serial.println("Starting AP mode");
   WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
  pinMode(ledPin,OUTPUT);
  // Start up the DS18B20 library
  sensors.begin();
  Serial.println("sensor started");
 
  // Route for root / web page
  server.on("/", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/html", index_html, processor);
  });
 
  server.on("/temperaturef", HTTP_GET, [](AsyncWebServerRequest *request){
    request->send_P(200, "text/plain", readDSTemperatureF().c_str());
  });
  // Start server
  server.begin();
}
 
void loop(){
 sensors.requestTemperatures();
  float cTemp = sensors.getTempFByIndex(0);

  if(int(cTemp) == -196){
    Serial.println("Failed to read from DS18B20 sensor");
  } else {
    Serial.print("cTemp : ");
    Serial.println(cTemp);
  }
    if(int(cTemp >85)){
      digitalWrite(ledPin,HIGH);
    }
    else{
      digitalWrite(ledPin,LOW);
    }
    delay (2000);
}
User avatar
By atefth
#88630 Hello Flagtrax,

I think the issue is happening because you are using xhttp.onreadystatechange function in the web page.
Try to use the socket instead, it will allow you to update certain fields in the web page without refreshing it and data from the sensor will be sent in real time.
Also I've experienced that storing the webpade inside the Programm partition is causing it to load slower later.
so better to define it as a local variable then use .send function not .sendP.