Fix automatic ip adress esp
This commit is contained in:
@@ -33,8 +33,12 @@ const char* Connectivity::fetchIPAddress() {
|
||||
int httpCode = http.GET();
|
||||
if (httpCode > 0) {
|
||||
if (httpCode == HTTP_CODE_OK) {
|
||||
// If successful (code 200), read the response body and store the IP address
|
||||
ipAddress = strdup(http.getString().c_str());
|
||||
// If successful (code 200), read the response body and parse the IP address
|
||||
String response = http.getString();
|
||||
StaticJsonDocument<200> doc;
|
||||
deserializeJson(doc, response);
|
||||
const char* ip = doc["ip"]; // Extract the IP address
|
||||
ipAddress = strdup(ip);
|
||||
}
|
||||
} else {
|
||||
Serial.printf("GET request failed, error: %s\n", http.errorToString(httpCode).c_str());
|
||||
|
@@ -11,6 +11,8 @@
|
||||
#include <ESP8266WiFiSTA.h>
|
||||
#include <WiFiClient.h>
|
||||
#include <WiFiClientSecure.h>
|
||||
#include <ArduinoJson.h>
|
||||
|
||||
|
||||
|
||||
class Connectivity {
|
||||
|
@@ -4,11 +4,12 @@ void setup() {
|
||||
//connect to internet and start sensor
|
||||
connectivity.connectWiFi(ssid, pass);
|
||||
sensorManager.sensorSetup();
|
||||
Serial.begin(9600);
|
||||
Serial.begin(115200);
|
||||
Serial.println("startup");
|
||||
}
|
||||
|
||||
void loop() {
|
||||
SensorManager::eulerAngles eulerRotation = sensorManager.getEulerAngles();
|
||||
SensorManager::RotationQuaternions Rotation = sensorManager.getQuaternions();
|
||||
// SensorManager::acceleration rotationAcceleration = sensorManager.getAcelleration();
|
||||
|
||||
struct acceleration {
|
||||
@@ -18,9 +19,10 @@ struct acceleration {
|
||||
} accelData;
|
||||
|
||||
if (!ipAquired) {
|
||||
serverIp = connectivity.fetchIPAddress();
|
||||
serverIp = connectivity.fetchIPAddress(); // Assign the value here
|
||||
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
|
||||
@@ -29,15 +31,17 @@ struct acceleration {
|
||||
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,
|
||||
Rotation.i,
|
||||
Rotation.j,
|
||||
Rotation.k,
|
||||
Rotation.w,
|
||||
accelData.y,
|
||||
accelData.z,
|
||||
"data");
|
||||
// %d = int, %f = floatation, %s = string
|
||||
connectivity.httpPost("192.168.137.30", "/", 3445, buffer, strlen(buffer), "application/json");
|
||||
connectivity.httpPost(serverIp, "/", 3445, buffer, strlen(buffer), "application/json");
|
||||
Serial.println(serverIp);
|
||||
Serial.println(buffer);
|
||||
lastTime = currentTime;
|
||||
}
|
||||
}
|
||||
|
@@ -22,14 +22,17 @@ public:
|
||||
eulerAngles getEulerAngles();
|
||||
acceleration getAcelleration();
|
||||
bool sensorTap();
|
||||
private:
|
||||
struct RotationQuaternions {
|
||||
|
||||
struct RotationQuaternions {
|
||||
float i;
|
||||
float j;
|
||||
float k;
|
||||
float w;
|
||||
};
|
||||
RotationQuaternions getQuaternions();
|
||||
|
||||
private:
|
||||
|
||||
BNO080 myIMU;
|
||||
};
|
||||
|
||||
|
@@ -8,8 +8,8 @@ Connectivity connectivity;
|
||||
WebSocketsClient webSocket;
|
||||
#define USE_SERIAL Serial
|
||||
|
||||
#define ssid "1235678i"
|
||||
#define pass "12345678"
|
||||
#define ssid "msi 5556"
|
||||
#define pass "abc12345"
|
||||
#define BUFFER_SIZE 1024
|
||||
#define DEVICE_ID 1
|
||||
#define IP_ADDRESS "192.168.137.12"
|
||||
|
Reference in New Issue
Block a user