49 lines
1.4 KiB
C++
49 lines
1.4 KiB
C++
#include "headerFile.h"
|
|
|
|
void setup() {
|
|
//connect to internet and start sensor
|
|
connectivity.connectWiFi(ssid, pass);
|
|
sensorManager.sensorSetup();
|
|
Serial.begin(115200);
|
|
Serial.println("startup");
|
|
}
|
|
|
|
void loop() {
|
|
SensorManager::eulerAngles Rotation = sensorManager.getEulerAngles();
|
|
|
|
//static structure
|
|
// TODO: redo json for esp8266 and in android studio
|
|
struct acceleration {
|
|
float x = 9;
|
|
float y = 9;
|
|
float z = 9;
|
|
} accelData;
|
|
|
|
if (!ipAquired) {
|
|
serverIp = connectivity.fetchIPAddress(); //Fetch pepper ip address
|
|
ipAquired = true;
|
|
}
|
|
|
|
unsigned long lastTime = 0; // will store the last time the code was run
|
|
unsigned long currentTime = millis();
|
|
if (currentTime - lastTime >= 100) { // do everything inside every 100 ms
|
|
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,
|
|
Rotation.roll,
|
|
Rotation.pitch,
|
|
Rotation.yaw,
|
|
accelData.x,
|
|
accelData.y,
|
|
accelData.z,
|
|
"data");
|
|
// %d = int, %f = floatation, %s = string
|
|
connectivity.httpPost(serverIp, "/", 3445, buffer, strlen(buffer), "application/json");
|
|
Serial.println(serverIp);
|
|
Serial.println(buffer);
|
|
lastTime = currentTime;
|
|
}
|
|
}
|