Professional Documents
Culture Documents
h>
#include <ESP8266WiFi.h>
#include <ESPAsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <AsyncElegantOTA.h>
#include "DHT.h"
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Wire.h>
#include "I2Cdev.h"
#include "MPU6050.h"
bool connect_wifi = 1;
float acc_total_first;
void acc_setup() {
/*
Wire.beginTransmission(0x68); //Start communicating with the MPU-6050
Wire.write(0x6B); //Send the requested starting register
Wire.write(0x00); //Set the requested starting register
Wire.endTransmission(); //End the transmission
//Configure the accelerometer (+/-8g)
Wire.beginTransmission(0x68); //Start communicating with the MPU-6050
Wire.write(0x1C); //Send the requested starting register
Wire.write(0x10); //Set the requested starting register
Wire.endTransmission();
*/
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
accelgyro.initialize();
}
void setup(void) {
Serial.begin(9600);
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
Serial.println("");
uint16_t count_delay = 0;
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
count_delay++;
if (count_delay >= 30) {
connect_wifi = 0;
dht.begin();
acc_setup();
radio.begin();
radio.openWritingPipe(address);
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
return;
}
}
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
//or use this for auto generated name ESP + ChipID
//wifiManager.autoConnect();
//if you get here you have connected to the WiFi
Serial.println("connected...yeey :)");
server.on("/", HTTP_GET, [](AsyncWebServerRequest* request) {
request->send(200, "text/plain", "Hello! This is a simple text message sent
from ESP8266. Microcontrollerslab");
});
void loop(void) {
if (connect_wifi == 1) AsyncElegantOTA.loop();
static uint8_t state = 0;
static unsigned long time_ = millis();
imu_cal2();
if (millis() - time_ > 50) {
time_ = millis();