-->
Page 1 of 2

Wierd connection issues

PostPosted: Tue Jul 21, 2020 3:09 pm
by flagtrax
Hi All,
If this has been addressed I couldn't find anything specific to my experience so I decided to post hoping I'm not being redundent.
I have a couple Lolin developement boards, and some generic ESP8266 -12's I'm playing with. I have the same sketch on both types, which is an asynchronous webserver on AP mode, serving a temperature reading from an 18b20 sensor. If I access the network access point with any of my android devices, I can log into the webserver page, and view the readings, and they do update.
HOWEVER:
If I try to access the AP via my LAPTOP running Windows 10, the first thing I notice is that the Lolin seems to have difficulty connecting. If it does, when I try to access the webservers page via a browser the connection is dropped. Several times, while attempting, I left the connection open to the android device and it never dropped to that device. If I leave the laptop browser open (I've tried Chrome, Firefox, Safari, and Opra) and try reconnecting via the Windows10 connection icon, it will sometimes connect long enough to display one reading, then drop, all the time maintaining connection to the android device. Removing that device has no effect. One time, and only one time, Windows reported that the network selected was using an "older" security set up and may leave me vulnerable.
But:
When accessing the same webserver loaded onto the generic ESP8255, it links up and holds the connection fine. Both the modules are labeled ESP8266-MOD
So I guess the question is, Is this a windows issue? Is anyone else experiencing this? I have an older Laptop with Ubuntu on it, I may dust it off and see what happens with it.
Any feed back greatly appreciated.

Re: Wierd connection issues

PostPosted: Tue Jul 21, 2020 7:18 pm
by pangolin
Seeing the code might help.

Re: Wierd connection issues

PostPosted: Tue Jul 21, 2020 8:44 pm
by flagtrax
Thanks pangolin, can do, keep in mind right now it's start-up and crude, just to get some temporary readings and make some tests. The ultimate goal will be to monitor the cooling system temperature between a radiator and shroud. Then adjust air flow accordingly by adjusting fan speed. In this simple sketch, I'm just monitoring temperature.
It does that, at least to android connected devices like my phone, wife's phone and my tablet all using Chrome as a browser. But the connection issues happen with the Laptop (Lenovo Ideapad320 running Windows10 Home v101941).

Code: Select all/*********
  Modified from Rui Santos' wifi Temperature monitor in STA mode
  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

// 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 = "12345678";  //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: 4.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();
}, 2000) ;
</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();

   WiFi.softAP(ssid, password);
  WiFi.softAPConfig(local_ip, gateway, subnet);
  delay(100);
 
  // Start up the DS18B20 library
  sensors.begin();
 
  // 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(){
 
}

Re: Wierd connection issues

PostPosted: Wed Jul 22, 2020 2:38 am
by pangolin
I'm glad I said "might help" as at first glance the code seems fine... but I have a question:
You say "lolin" - thats too general a term: is it a lolin D32 with an ESP32 processor or a lolin wemos d1 mini with an ESP8266? I notice your code compiles for both using the (incorrect) PlatformIO #ifdef ESP32.

That's not you, its PlatformIO that is incorrect...on Arduino the correct way is #ifdef ARDUINO_ARCH_ESP32, but that's a side issue compared with the target MCU type. Also I'm guessing that "generic ESP8255" you mean ESP8285...the thing is different boards have different FLASH modes (as well as different sizes) so the problem may depend on the build settings you choose.

For example I had some terrible problems with ESPAsyncWebserver, similar to yours when I had incorrectly used QIO mode in error. Selecting DOUT instead seemed to fix it. However I dont remember trying to access with mobile devices, all was Win10 / Chrome. Bottom line is you need to check / change build settings for each different type of target even though source code and basic MCU may be identical.

One way of getting further insight would be to look at a Wireshark trace of the connection - but that may be difficult with WiFi - some adapters can't do it...if your pc is wired, you may have more luck.