I'm making a project for the final year at the university and I can't make a connection between 2 esp to go right. First ESP have a accelerometer connected and I want that the other esp to read the values from the first one. Can anyone help me with a client code that I can use to read the values. Or tell me a simple way to do the connection between ESPs?
Server:
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU9150.h"
const char* ssid = "testserv";
const char* password = "12345678";
ESP8266WebServer server(80);
float p,y;
int16_t yaw, pitch, roll;
int16_t gx, gy, gz;
int16_t mx, my, mz;
String webString="";
MPU9150 accelGyroMag;
unsigned long previousMillis = 0;
unsigned long previousRate;
int sampleCount;
const long interval = 100; // interval at which to read sensor
void handle_root() {
getIMU(); // read sensor
webString="yaw "+String((int)y);
server.send(200, "text/plain", webString);
delay(100);
}
void setup() {
Serial.begin(115200);
Wire.begin();
Serial.println("Initializing I2C devices...");
accelGyroMag.initialize();
Serial.println("Testing device connections...");
Serial.println(accelGyroMag.testConnection() ? "MPU9150 connection successful" : "MPU9150 connection failed");
WiFi.begin(ssid, password);
Serial.print("\n\r \n\rWorking to connect");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("IMU Server");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
server.on("/", handle_root);
server.begin();
Serial.println("HTTP server started");
}
void loop() {
server.handleClient();
}
void getIMU()
{
unsigned long currentMillis = millis();
if(currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
accelGyroMag.getMotion9(&yaw, &pitch, &roll, &gx, &gy, &gz, &mx, &my, &mz);
y= yaw ;
p = pitch ;
// Check if any reads failed and exit early (to try again).
if (isnan(yaw) || isnan(pitch)) {
Serial.println("Failed to read from sensor!");
return;
}
}
}