Chat freely about anything...

User avatar
By RICARDO PACHECO
#71684 Hello people!

I have a project that have one ESP8266 as AP and others ESP8266 as STA.
As it is obvious, the ESP stations conect on ESP AP.

When the station start and conect to AP, it send a hello with some parameters behind httpClient.
Look this:

Code: Select all#include "Arduino.h"
#include <EEPROM.h>
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <FS.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include "AsyncJson.h"
#include "ArduinoJson.h"
#include <StreamString.h>
#include "TimeLib.h"
#include <ESP8266HTTPClient.h>
#include <stdio.h>

#include "lib.h"
#include "version.h"
#include "wifihwtypes.h"


void WiFiDCC::hello() {
#ifndef RELEASE
  Serial.printf_P( pgm_INFunction, "hello()", ESP.getFreeHeap() );
#endif

  HTTPClient http;
  String payload;
  String url;

  url = "http://" + wifi.gateway.toString() + "/gsr?qt=run&q=hello&hwType=" + hw.HW.Type + "&hwSN=" + lib.urlencode(searchSN()) + "&IP=" + wifi.IP.toString() + "&hwName=" + lib.urlencode(hw.hwName);

#ifndef RELEASE
  Serial.println(url);
#endif

  if ( WiFi.status() == WL_CONNECTED ) {
    http.begin(url);
    int httpCode = http.GET();
#ifndef RELEASE
    if (httpCode < 0) {
      Serial.printf("\n[HTTP] GET... failed, error: %s\n", http.errorToString(httpCode).c_str());
    }
#endif

    payload = http.getString();
    http.end();

#ifndef RELEASE
    Serial.print("payload: ");
    Serial.println( payload );
#endif

    DynamicJsonBuffer jsonBuffer(32);
    JsonObject& root = jsonBuffer.parseObject(payload);
    IPWiFiStation = lib.strToIP(root["ip"]);
  } else {
#ifndef RELEASE
    Serial.println( F("Desconectado enquanto iniciava hello()") );
#endif
  }

  payload = String();
  url = String();


#ifndef RELEASE
  Serial.printf_P( pgm_OUTFunction, "hello()", ESP.getFreeHeap() );
#endif
}



The problem is: The hello() function works perfectly at the first time that is called.
Next call of hello(), I receive: -1 Connection Refused

Somebody have a tip, trick, a magic, or who know the answer for this?
User avatar
By RICARDO PACHECO
#71740 Look the serial debug.
First time I call hello() works fine.
Second time, does'not work :/
Why???!?!

Code: Select all
--------------------------------------------
WiFi Iniciado!
--------------------------------------------
SSID: WiFiStation
Password: wifistation
IP: 192.168.2.101
Gateway: 192.168.2.1
DNS1: 192.168.2.1
DNS2: 0.0.0.0
--------------------------------------------
bcn 0
del if1
pm open,type:2 0
add if1
pm close 7
dhcp server start:(ip:192.168.3.1,mask:255.255.255.0,gw:192.168.3.1)
bcn 100

--------------------------------------------
Access Point Iniciado!
--------------------------------------------
SSID: WiFiLocomotive
Password: wifilocomotive
--------------------------------------------
hostName: wifilocomotive
--------------------------------------------
OUT: startWiFi() - Free Heap: 29000
IN:  hello() - Free Heap: 27536
IN:  searchSN() - Free Heap: 27232
Sizeof SN: 15
SN: B9C977-186AE/BR
OUT: searchSN() - Free Heap: 27232
http://192.168.2.1/gsr?qt=run&q=hello&hwType=2&hwSN=B9C977%2D186AE%2FBR&IP=192.168.2.101&hwName=WiFiLocomotive
payload: {"ip":"192.168.2.1"}
OUT: hello() - Free Heap: 27232
OUT: startOperation() - Free Heap: 27672

Free Heap: 27648
IN-> tMaiinCallback
IN:  hello() - Free Heap: 27672
IN:  searchSN() - Free Heap: 27368
Sizeof SN: 15
SN: B9C977-186AE/BR
OUT: searchSN() - Free Heap: 27368
http://192.168.2.1/gsr?qt=run&q=hello&hwType=2&hwSN=B9C977%2D186AE%2FBR&IP=192.168.2.101&hwName=WiFiLocomotive

[HTTP] GET... failed, error: connection refused
payload:
OUT: hello() - Free Heap: 27008
OUT-> tMaiinCallback
IN-> tMaiinCallback
IN:  hello() - Free Heap: 27672
IN:  searchSN() - Free Heap: 27368
Sizeof SN: 15
SN: B9C977-186AE/BR
OUT: searchSN() - Free Heap: 27368
http://192.168.2.1/gsr?qt=run&q=hello&hwType=2&hwSN=B9C977%2D186AE%2FBR&IP=192.168.2.101&hwName=WiFiLocomotive

[HTTP] GET... failed, error: connection refused
payload:
OUT: hello() - Free Heap: 27008
OUT-> tMaiinCallback
IN-> tMaiinCallback
IN:  hello() - Free Heap: 27672
IN:  searchSN() - Free Heap: 27368
Sizeof SN: 15
SN: B9C977-186AE/BR
OUT: searchSN() - Free Heap: 27368
http://192.168.2.1/gsr?qt=run&q=hello&hwType=2&hwSN=B9C977%2D186AE%2FBR&IP=192.168.2.101&hwName=WiFiLocomotive


User avatar
By RICARDO PACHECO
#71742 Hi!

Thanks for repply.
The frequency is low, every 10 seconds. Just one client.
I will try log the server side and post the results.