optimization
This commit is contained in:
@@ -1,14 +1,18 @@
|
||||
#include "headerFile.h"
|
||||
|
||||
// SensorManager::Rotation offset;
|
||||
#define BUFFER_SIZE 1024
|
||||
|
||||
#define DEVICE_ID 1
|
||||
|
||||
char *buffer = (char *)malloc(sizeof(char) * BUFFER_SIZE);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
Serial.println("startup");
|
||||
// Serial.println("startup");
|
||||
//connect to internet and start sensor
|
||||
connectivity.connectWiFi(ssid, pass);
|
||||
sensorManager.sensorSetup();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
@@ -16,22 +20,26 @@ void loop() {
|
||||
SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration();
|
||||
unsigned long lastTime = 0; // will store the last time the code was run
|
||||
|
||||
Serial.print(eulerRotation.roll);
|
||||
Serial.print(" ");
|
||||
Serial.print(eulerRotation.yaw);
|
||||
Serial.print(" ");
|
||||
Serial.print(eulerRotation.pitch);
|
||||
Serial.println();
|
||||
|
||||
unsigned long currentTime = millis();
|
||||
if (currentTime - lastTime >= 100) { // 100 ms has passed
|
||||
String message = "{\"deviceId\": 1, \"rotationX\":\"" + String(eulerRotation.roll) + "\",\"rotationY\":\"" + String(eulerRotation.pitch) + "\",\"rotationZ\":\"" + String(eulerRotation.yaw) + "\",\"accelerationX\":\"" + String(rotationAcceleration.x) + "\",\"accelerationY\":\"" + String(rotationAcceleration.y) + "\",\"accelerationZ\":\"" + String(rotationAcceleration.z) + "\",\"type\":\"data\"}";
|
||||
Serial.println(connectivity.httpPost("192.168.137.146", "/", 3445, message.c_str(), message.length(), "json"));
|
||||
Serial.println(message);
|
||||
memset(buffer, 0, BUFFER_SIZE);
|
||||
sprintf(
|
||||
buffer,
|
||||
"{\"deviceId\": %d, \"rotationX\": %d, \"rotationY\": %d, \"rotationZ\": %d, \"accelerationX\": %d, \"accelerationY\": %d, \"accelerationZ\": %d, \"type\": %s}",
|
||||
DEVICE_ID,
|
||||
eulerRotation.roll,
|
||||
eulerRotation.pitch,
|
||||
eulerRotation.yaw,
|
||||
rotationAcceleration.x,
|
||||
rotationAcceleration.y,
|
||||
rotationAcceleration.z,
|
||||
"data");
|
||||
// Serial.println(connectivity.httpPost("192.168.137.45", "/", 3445, message.c_str(), message.length(), "json"));
|
||||
// Serial.println(message);
|
||||
connectivity.httpPost("192.168.137.45", "/", 3445, buffer, strlen(buffer), "application/json");
|
||||
lastTime = currentTime;
|
||||
}
|
||||
}
|
||||
}
|
||||
//acceleration.X
|
||||
//acceleration.Y
|
||||
//acceleration.Z
|
||||
|
||||
|
Reference in New Issue
Block a user