Urgent help gurus, OTA no working

The code below compiled and run successfully but I can see the data on the serial monitor but nothing shows when I open the IP address. The task is to visualize the data on the IP not the serial monitor. Please what am I doing wrong?

#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;


#ifndef STASSID
#define STASSID "kicky"
#define STAPSK  "12341234"
#endif

const char* ssid = STASSID;
const char* password = STAPSK;

void setup() {
  Serial.begin(2000000);
  Serial.println("Booting");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Connection Failed! Rebooting...");
    delay(5000);
    ESP.restart();
  }

  // Port defaults to 8266
  // ArduinoOTA.setPort(8266);

  // Hostname defaults to esp8266-[ChipID]
  // ArduinoOTA.setHostname("myesp8266");

  // No authentication by default
   //ArduinoOTA.setPassword("admin");

  // Password can be set with it's md5 value as well
  // MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
  // ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

  ArduinoOTA.onStart([]() {
    Serial.println("Start");
    String type;
    if (ArduinoOTA.getCommand() == U_FLASH) {
      type = "sketch";
    } else { // U_FS
      type = "filesystem";
    }

    // NOTE: if updating FS this would be the place to unmount FS using FS.end()
    Serial.println("Start updating " + type);
  });
  ArduinoOTA.onEnd([]() {
    Serial.println("\nEnd");
  });
  ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
    Serial.printf("Progress: %u%%\r", (progress / (total / 100)));
  });
  ArduinoOTA.onError([](ota_error_t error) {
    Serial.printf("Error[%u]: ", error);
    if (error == OTA_AUTH_ERROR) {
      Serial.println("Auth Failed");
    } else if (error == OTA_BEGIN_ERROR) {
      Serial.println("Begin Failed");
    } else if (error == OTA_CONNECT_ERROR) {
      Serial.println("Connect Failed");
    } else if (error == OTA_RECEIVE_ERROR) {
      Serial.println("Receive Failed");
    } else if (error == OTA_END_ERROR) {
      Serial.println("End Failed");
    }
  });
  ArduinoOTA.begin();
  Serial.println("Ready");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
  //pinMode(2, OUTPUT);
   if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(1);
    }
  }
}
bool ota_flag = true;
uint16_t time_elasped = 0;

void loop() {
  if(ota_flag)
  {
    while(time_elasped < 1000)
   {
     ArduinoOTA.handle();
     time_elasped = millis();
     delay(10);
   }
   ota_flag = false;
  }

  //digitalWrite(2,!digitalRead(2));
  delay(100);
  sensors_event_t a, g, temp;
  mpu.getEvent(&a,&g, &temp);

  /* Print out the values */
  //Serial.print("Acceleration X: ");
  Serial.print(a.acceleration.x);
  Serial.print(",");
  Serial.print(a.acceleration.y);
  Serial.print(",");
  Serial.println(a.acceleration.z);
  delay(100);
}

This is the serial monitor
IP address: 192.168.157.180
-1.39,0.79,8.16
-1.18,0.96,8.01
-1.01,1.00,7.72
-1.12,1.03,7.82
-1.18,0.89,7.92
-1.04,0.91,7.88
-1.07,0.98,7.91
-1.06,0.98,7.77
-1.04,0.96,7.93
-1.08,0.98,7.88


Arduino OTA is only for OTA upload, not for Monitor

Hey, It's not for monitor... You can try to upload on another way...

Thanks for your response. So can I visualise the accelerometer data from the IP address? When I tried that, the page didn't load. please help

Thanks, please in what way(s) ?

You need to host a Web Page on the ESP8266 that displays the results. There are Web Page examples built into the Arduino IDE (when the selected board is ESP8266-based). You can find many others with a Google search.

You need to do some research.

did this compile?? Never seen such a thing before

Yes, it compiled.

Lambda Expression

Hi gfvalvo,

thank you for naming it. I looked up the link and started reading ... --- ... -- ?????

Well the usual standard-encryption-level of explaining it in a too short way with too many new details included where I do not know if these details are just some additional bells and whistles or substantial for the use of lambda-expressions. Nor giving an overview or comparing it with a non-lambda example.

But I don't want to hijack this thread. So if I will be interested some day I will open a thread asking again.

Like Mick Jagger noted ... You Can't Always Get What You Want

The explanation at the link I posted is pretty accessible. You're welcome to Google for one you like better ... now that you know what to call the construct. This One is far more pedantic.

I have checked google and tried available libraries in Arduino, all to no avail.

Please, assist me.

I want to connect my mpu6050 and esp8266 nodemcu with batteries and get the output accelerometer data on a webpage in real-time. The data should look like that of a serial monitor.

maybe you can use my TelnetStream library

Thanks for your swift response. let me install the library and manipulate the MPU6050 library alongside. Get back soon.

I have editted the code and hooked it on putty. Below is the code and the output.

Thanks guys for your contribution.

Finally, how can I increase the speed?
How do I know the delay?

#include <ESP8266WiFi.h>
#include <TimeLib.h>
#include <TelnetStream.h>
#include <sntp.h>
#include <TZ.h>
#include <Adafruit_MPU6050.h>
#include <Adafruit_Sensor.h>
#include <Wire.h>

Adafruit_MPU6050 mpu;

//#define TIME_ZONE TZ_Europe_London

#include "arduino_secrets.h"
///////please enter your sensitive data in the Secret tab/arduino_secrets.h
const char ssid[] = SECRET_SSID;    // your network SSID (name)
const char pass[] = SECRET_PASS;    // your network password (use for WPA, or use as key for WEP)

void setup() {
  Serial.begin(115200);
  if (!mpu.begin()) {
    Serial.println("Failed to find MPU6050 chip");
    while (1) {
      delay(10);
    }
  }

  Serial.print("Attempting to connect to WPA SSID: ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  if (WiFi.waitForConnectResult() != WL_CONNECTED) {
    Serial.println("Failed to connect.");
    while (1) {
      delay(10);
    }
  }

 /* configTime(TIME_ZONE, "pool.ntp.org");
  time_t now = time(nullptr);
  while (now < SECS_YR_2000) {
    delay(100);
    now = time(nullptr);
  }
  setTime(now);*/

  IPAddress ip = WiFi.localIP();
  Serial.println();
  Serial.println("Connected to WiFi network.");
  Serial.print("Connect with Telnet client to ");
  Serial.println(ip);

  TelnetStream.begin();
}

void loop() {
  switch (TelnetStream.read()) {
    case 'R':
    TelnetStream.stop();
    delay(100);
    ESP.reset();
      break;
    case 'C':
      TelnetStream.println("bye bye");
      TelnetStream.flush();
      TelnetStream.stop();
      break;
  }

  static unsigned long next;
  if (millis() - next > 5000) {
    next = millis();
    log();
  }
}

void log() {
 // static int i = 0;

 // char timeStr[20];
 // sprintf(timeStr, "%02d-%02d-%02d %02d:%02d:%02d", year(), month(), day(), hour(), minute(), second());

 // TelnetStream.print(i++);
 // TelnetStream.print(" ");
 // TelnetStream.print(timeStr);
 // TelnetStream.print(" A0: ");
 // TelnetStream.println(analogRead(A0));
   sensors_event_t a, g, temp;
  mpu.getEvent(&a, &g, &temp);

  /* Print out the values */
 //TelnetStream .print("Acceleration X: ");
  TelnetStream.print(a.acceleration.x);
  TelnetStream.print(",");
  TelnetStream.print(a.acceleration.y);
  TelnetStream.print(",");
  TelnetStream.println(a.acceleration.z);
  //TelnetStream.println(" m/s^2");
}

-3.14,-1.75,7.36
-3.15,-1.51,7.27
-3.27,-1.58,7.08
-3.16,-1.53,7.30
-3.23,-1.57,7.24
-3.23,-1.57,7.30
-3.19,-1.55,7.34
-3.19,-1.54,7.29
-3.25,-1.56,7.29
-3.20,-1.49,7.30
-3.21,-1.62,7.28
-3.28,-1.53,7.18
-3.15,-1.52,7.35
-3.14,-1.44,7.21
-3.21,-1.53,7.26
``

the 5000 is 5 seconds

Many thanks, all done.

[quote="harrrry, post:18, topic:1016534, full:true"]
The newbie is here again.

I have successfully transmitted the data via wifi hooked with putty. The transmitting ( ESP8266 + MPU6050 + 3.7v Battery) sends the data to the receiver (laptop).
How do I know, calculate or code the delay or latency between the two ends? For example, how long does it take for the transmitted data to get to the laptop?

it depends on the WiFi. no guaranteed time.

Thanks for your response.
Are you referring to the ESP8266 WiFi module or the hotspot I am using?