snik3 Δημοσ. 3 Ιουλίου 2018 Δημοσ. 3 Ιουλίου 2018 Καλησπέρα στη παρέα. Χρησιμοποιώ ένα wemos d1 r2 σε συνδυασμό με ένα MPU6050 module για να καταγράφω accelerometer και gyroscope data για ένα project. Έχω επίσης εγκαταστήσει έναν Apache - MySQL (XAMPP) Server με σκοπό να στέλνω τα δεδομένα εκεί. Ενώ συνδέομαι κανονικά με τη database, δεν αποστέλλονται τα δεδομένα. Ο κώδικας μου είναι ο παρακάτω, υποθέτω πως κάποιο λάθος έχω κάνει και θα ήθελα τα φώτα σας. #include <ESP8266WiFi.h> #include <MySQL_Connection.h> #include <MySQL_Cursor.h> #include <ESP8266WiFi.h> #include <WiFiClient.h> #include <math.h> #include <Wire.h> #include <SPI.h> const int MPU_addr=0x68; // I2C address of the MPU-6050 int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ; double AcXN,AcYN,AcZN,GyXN,GyYN,GyZN; //SSID of your network char ssid[] = "SKYEB5A9"; //SSID of your Wi-Fi router char pass[] = "12349999"; //Password of your Wi-Fi router byte mac[6]; WiFiServer server(80); WiFiClient client; MySQL_Connection conn((Client *)&client); MySQL_Cursor* cursor; char INSERT_SQL[] = "INSERT INTO test.testdata(AcX, AcY, AcZ, GyX, GyY, GyZ) VALUES (AcXN, AcYN, AcZN, GyXN, GyYN, GyZN)"; char query[128]; IPAddress server_addr(192, 168, 0, 5); // MySQL server IP char user[] = "wemos"; // MySQL user char password[] = ""; // MySQL password void setup(){ Serial.begin(115200); // Connect to Wi-Fi network delay(100); Serial.println(); Serial.println(); Serial.print("Connecting to Selected Wi-Fi..."); Serial.println(ssid); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } WiFi.macAddress(mac); Serial.print("MAC: "); Serial.print(mac[5],HEX); Serial.print(":"); Serial.print(mac[4],HEX); Serial.print(":"); Serial.print(mac[3],HEX); Serial.print(":"); Serial.print(mac[2],HEX); Serial.print(":"); Serial.print(mac[1],HEX); Serial.print(":"); Serial.println(mac[0],HEX); Serial.println(""); Serial.println("Wi-Fi connected successfully"); Serial.println(WiFi.localIP()); // Connect to MySQL DB1 Serial.println("Connecting to database"); while (conn.connect(server_addr, 3306, user, password) != true) { delay(200); Serial.print ( "." ); } Serial.println(""); Serial.println("Connected to SQL Server!"); cursor = new MySQL_Cursor(&conn); //Setup MPU Wire.begin(); Wire.beginTransmission(MPU_addr); Wire.write(0x6B); // PWR_MGMT_1 register Wire.write(0); // set to zero (wakes up the MPU-6050) Wire.endTransmission(); Wire.beginTransmission(0b1101000); //I2C address of the MPU Wire.write(0x1B); //Accessing the register 1B - Gyroscope Configuration (Sec. 4.4) Wire.write(0x00000000); //Setting the gyro to full scale +/- 250deg./s Wire.endTransmission(); Wire.beginTransmission(0b1101000); //I2C address of the MPU Wire.write(0x1C); //Accessing the register 1C - Acccelerometer Configuration (Sec. 4.5) Wire.write(0b00000000); //Setting the accel to +/- 2g Wire.endTransmission(true); delay(5000); } void loop(){ //Read Raw Data Wire.beginTransmission(MPU_addr); Wire.write(0x3B); // starting with register 0x3B (ACCEL_XOUT_H) Wire.endTransmission(false); Wire.requestFrom(MPU_addr,14,true); // request a total of 14 registers AcX=Wire.read()<<8|Wire.read(); // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L) AcY=Wire.read()<<8|Wire.read(); // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L) AcZ=Wire.read()<<8|Wire.read(); // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L) Tmp=Wire.read()<<8|Wire.read(); // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L) GyX=Wire.read()<<8|Wire.read(); // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L) GyY=Wire.read()<<8|Wire.read(); // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L) GyZ=Wire.read()<<8|Wire.read(); // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L) //Normalize Raw Data AcXN=((AcX)/1638.4)/10; AcYN=((AcY)/1638.4)/10; AcZN=((AcZ)/1638.4)/10; GyXN=(GyX)/131; GyYN=(GyY)/131; GyZN=(GyZ)/131; //Print Normalized Data Serial.print("AcX = "); Serial.print(AcXN,4); Serial.print(" | AcY = "); Serial.print(AcYN,4); Serial.print(" | AcZ = "); Serial.print(AcZN,4); Serial.print(" | Tmp = "); Serial.print((Tmp/340.00)+36.53); //equation for temperature in degrees C from datasheet Serial.print(" | GyX = "); Serial.print(GyXN); Serial.print(" | GyY = "); Serial.print(GyYN); Serial.print(" | GyZ = "); Serial.println(GyZN); //delay(100); if (conn.connected()) cursor->execute(INSERT_SQL); //delay(1000); }
Προτεινόμενες αναρτήσεις