Rebooting ESP8266 after getting to ESP8266WebServer

Trying to establish communication between two ESP8266. One is the WebServer, the other is the client.

Server code:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const int ledPin = 2;

IPAddress apIP(192, 168, 4, 1);

//WEB интерфейс для устройства
ESP8266WebServer HTTP(80);


/* Установите здесь свои SSID и пароль */

String _ssid = " "; //Домашняя сеть
String _password =  " "; // Пароль домашней сети

String _ssidAP = "NodeMCU0";       // SSID
String _passwordAP = "123456789";  // пароль

//String host= "trainer-server"; // host

void setup() {
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  
  Serial.begin(115200);
  Serial.println("");
  Serial.println("Start 1-WIFI");
  //Запуск WiFi
  WIFI_init();
  //Настройка и запуск HTTP интерфейс
   Serial.println("Start 2-WEB server");
   HTTP_init();
}
void loop() {
  HTTP.handleClient();
  delay(100);
}

void HTTP_init(void){
  HTTP.onNotFound(handleNotFound); // сообщение, если нет страницы
  HTTP.on("/hit", handle_hitCounter); // рабочая функция http://192.168.4.1/hit?target=hit
  //Web server ON
  HTTP.begin();
  
}

// сообщение, если нет страницы
void handleNotFound (){
  String massage= "File Not Found \n\n";
  HTTP.send (404, "text/plain", massage); 
}

// рабочая функция

void handle_hitCounter (){
  String target = HTTP.arg ("target");
  if (target== "hit") {
    Serial.print ("taget HIT");
    digitalWrite(ledPin, LOW);   // turn the LED on (HIGH is the voltage level)
    delay(100);                       // wait for a 0,1 second
    digitalWrite(ledPin, HIGH);
  }
  HTTP.send(200, "text/plain", "OK");
}

oid WIFI_init(){
  //попытки подключения к точке доступа
  WiFi.mode(WIFI_STA);
  byte tries = 11;
  WiFi.begin(_ssid.c_str(), _password.c_str());

  while (--tries && WiFi.status()!=WL_CONNECTED)
  {
    Serial.print(".");
    delay (1000);
  }
  if (WiFi.status()!=WL_CONNECTED)  
  {
     Serial.println("...");
     Serial.println("WiFi up AP");
     StartAPMode();
  }
  else{
    Serial.println(".");
    Serial.println("WiFi connected");
    Serial.println("IP address: ");
    Serial.println(WiFi.localIP());
  }
}
bool StartAPMode(){
  WiFi.disconnect();
  WiFi.mode(WIFI_AP);
  WiFi.softAPConfig(apIP, apIP, IPAddress(255, 255, 255, 0));
  WiFi.softAP(_ssidAP.c_str(), _passwordAP.c_str());
  return true;
}

Client code (simplified to an example from the network):

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "NodeMCU0";
const char* password = "123456789";
 
void setup () {
 
  Serial.begin(115200);
 
  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
 
    delay(1000);
    Serial.print("Connecting..");
 
  }
 }
 
void loop() {
 
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
 
    HTTPClient http;  //Declare an object of class HTTPClient
 
    http.begin("http://192.168.4.1/hit?target=hit");  //Specify request destination
    int httpCode = http.GET();                                  //Send the request
 
    if (httpCode > 0) { //Check the returning code
 
      String payload = http.getString();   //Get the request response payload
      Serial.println(payload);             //Print the response payload
    Serial.println("kod tut 1");
    }
    Serial.println("kod tut 2");
    http.end();   //Close connection
    Serial.println("kod tut 3");
  }
   delay(30000);    //Send a request every 30 seconds
}

What does:
A GET request is sent, processed with a positive result from the server (and the server flashes the LED).

Code from the client's serial monitor:

ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3584, room 16 
tail 0
chksum 0xb0
csum 0xb0
v2843a5ac
~ld
Connecting..OK
kod tut 1
kod tut 2

What doesn't do is restart the esp266 client with this log (from Exception Decoder):

Exception 9: LoadStoreAlignmentCause: Load or store to an unaligned address
PC: 0x40206fe4: HTTPClient::connected() at /home/valerij/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 475
EXCVADDR: 0x00000139

Decoding stack results
0x40203a68: HardwareSerial::write(unsigned char const*, unsigned int) at /home/valerij/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/cores/esp8266/HardwareSerial.h line 164
0x40203d49: Print::write(char const*) at /home/valerij/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/cores/esp8266/Print.h line 62
0x402028b4: HTTPClient::disconnect(bool) at /home/valerij/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 434
0x40203658: HTTPClient::end() at /home/valerij/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp line 425
0x4020111a: loop() at /home/valerij/Загрузки/airsoft_trainer/client/client.ino line 39
0x40203d49: Print::write(char const*) at /home/valerij/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/cores/esp8266/Print.h line 62
0x40201078: setup() at /home/valerij/Загрузки/airsoft_trainer/client/client.ino line 13
0x40205128: loop_wrapper() at /home/valerij/snap/arduino/50/.arduino15/packages/esp8266/hardware/esp8266/2.7.4/cores/esp8266/core_esp8266_main.cpp line 197

How can you get away from this constant reboot?

Author: Valerij Tykhonov, 2020-12-11