44 lines
1.3 KiB
C++
44 lines
1.3 KiB
C++
#include "headerFile.h"
|
|
|
|
void setup() {
|
|
//connect to internet and start sensor
|
|
connectivity.connectWiFi(ssid, pass);
|
|
sensorManager.sensorSetup();
|
|
Serial.begin(9600);
|
|
}
|
|
|
|
unsigned long lastTime = 0; // will store the last time the code was run
|
|
|
|
void loop() {
|
|
SensorManager::eulerAngles eulerRotation = sensorManager.getEulerAngles();
|
|
// SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration();
|
|
|
|
struct acceleration {
|
|
float x = 9;
|
|
float y = 9;
|
|
float z = 9;
|
|
} accelData;
|
|
|
|
unsigned long currentTime = millis();
|
|
if (currentTime - lastTime >= 100) { // 100 ms has passed
|
|
memset(buffer, 0, BUFFER_SIZE);
|
|
sprintf(
|
|
buffer,
|
|
"{\"deviceId\": %d, \"rotationX\": %f, \"rotationY\": %f, \"rotationZ\": %f, \"accelerationX\": %f, \"accelerationY\": %f, \"accelerationZ\": %f, \"type\": %s}",
|
|
DEVICE_ID,
|
|
eulerRotation.roll,
|
|
eulerRotation.pitch,
|
|
eulerRotation.yaw,
|
|
accelData.x,
|
|
accelData.y,
|
|
accelData.z,
|
|
"data");
|
|
// %d = int, %f = floatation, %s = string
|
|
connectivity.httpPost(connectivity.fetchIPAddress(), "/", 3445, buffer, strlen(buffer), "application/json");
|
|
lastTime = currentTime;
|
|
}
|
|
}
|
|
//acceleration.X
|
|
//acceleration.Y
|
|
//acceleration.Z
|