Merge branch 'main' of ssh://gitlab.fdmci.hva.nl/propedeuse-hbo-ict/onderwijs/2023-2024/out-a-se-ti/blok-4/muupooviixee66

This commit is contained in:
Niels Gras
2024-06-03 14:32:00 +02:00
12 changed files with 47 additions and 93 deletions

View File

@@ -23,7 +23,7 @@ void Connectivity::connectWiFi(char* ssid, char* pass){
const char* getServerURL = "http://145.92.8.132:443/get-ip";
String ipAddress = ""; // string that will hold the server's IP address
String Connectivity::fetchIPAddress() {
const char* Connectivity::fetchIPAddress() {
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http;
WiFiClient client;

View File

@@ -19,7 +19,7 @@ public:
void websocketSetup(char* ip, uint16_t port, char* adress);
void sendData(float roll, float pitch, float yaw);
int httpPost(const char *serverAddress, const char *serverSubPath, const unsigned short serverPort, const char *data, const size_t dataLength, const char *contentType);
String fetchIPAddress();
const char* fetchIPAddress();
private:
ESP8266WiFiMulti wifi;

View File

@@ -7,8 +7,6 @@ void setup() {
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();
@@ -19,6 +17,11 @@ struct acceleration {
float z = 9;
} accelData;
if (!ipAquired) {
serverIp = connectivity.fetchIPAddress();
ipAquired = true;
}
unsigned long lastTime = 0; // will store the last time the code was run
unsigned long currentTime = millis();
if (currentTime - lastTime >= 100) { // 100 ms has passed
memset(buffer, 0, BUFFER_SIZE);
@@ -34,10 +37,10 @@ struct acceleration {
accelData.z,
"data");
// %d = int, %f = floatation, %s = string
connectivity.httpPost(connectivity.fetchIPAddress(), "/", 3445, buffer, strlen(buffer), "application/json");
connectivity.httpPost(serverIp, "/", 3445, buffer, strlen(buffer), "application/json");
lastTime = currentTime;
}
}
//acceleration.X
//acceleration.Y
//acceleration.Z
//acceleration.Z

View File

@@ -15,3 +15,5 @@ WebSocketsClient webSocket;
#define IP_ADDRESS "192.168.137.12"
char *buffer = (char *)malloc(sizeof(char) * BUFFER_SIZE);
const char* serverIp = NULL; // Declare serverIp here
bool ipAquired = false;