Repaired the websocket connector
for some reason it doesnt wannar in a class
This commit is contained in:
@@ -10,9 +10,9 @@ void Connectivity::connectWiFi(char* ssid, char* pass){
|
|||||||
Serial.println(WiFi.localIP());
|
Serial.println(WiFi.localIP());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Connectivity::websocketSetup(){
|
void Connectivity::websocketSetup(char* ip, uint16_t port, char* adress){
|
||||||
//ws server address, port and URL
|
//ws server address, port and URL
|
||||||
webSocket.begin("192.168.137.1", 8001, "");
|
webSocket.begin(ip , port, adress);
|
||||||
// try every 500 again if connection has failed
|
// try every 500 again if connection has failed
|
||||||
webSocket.setReconnectInterval(500);
|
webSocket.setReconnectInterval(500);
|
||||||
}
|
}
|
||||||
|
@@ -19,7 +19,7 @@
|
|||||||
class Connectivity {
|
class Connectivity {
|
||||||
public:
|
public:
|
||||||
void connectWiFi(char* ssid, char* pass);
|
void connectWiFi(char* ssid, char* pass);
|
||||||
void websocketSetup();
|
void websocketSetup(char* ip, uint16_t port, char* adress);
|
||||||
void sendData(float roll, float pitch, float yaw);
|
void sendData(float roll, float pitch, float yaw);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@@ -5,11 +5,14 @@ SensorManager::Rotation offset;
|
|||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("startup");
|
Serial.println("startup");
|
||||||
delay(5000);
|
|
||||||
|
|
||||||
connectivity.connectWiFi(ssid, pass);
|
connectivity.connectWiFi(ssid, pass);
|
||||||
sensorManager.sensorSetup();
|
sensorManager.sensorSetup();
|
||||||
connectivity.websocketSetup();
|
|
||||||
|
//ws server address, port and URL
|
||||||
|
webSocket.begin("145.3.245.22", 8001, "");
|
||||||
|
// try every 500 again if connection has failed
|
||||||
|
webSocket.setReconnectInterval(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -36,7 +39,7 @@ void loop() {
|
|||||||
Serial.print(pitch);
|
Serial.print(pitch);
|
||||||
Serial.print(" ");
|
Serial.print(" ");
|
||||||
Serial.print(yaw);
|
Serial.print(yaw);
|
||||||
connectivity.sendData(roll, pitch, yaw);
|
sendData(roll, pitch, yaw);
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
webSocket.loop();
|
webSocket.loop();
|
||||||
@@ -52,3 +55,8 @@ void loop() {
|
|||||||
void setZeroPoint() {
|
void setZeroPoint() {
|
||||||
offset = sensorManager.readLoop();
|
offset = sensorManager.readLoop();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void sendData(float roll, float pitch, float yaw){
|
||||||
|
String message = "{\"Sensor\": 1, \"roll\":\"" + String(roll) + "\",\"pitch\":\"" + String(pitch) + "\",\"yaw\":\"" + String(yaw) + "\"}";
|
||||||
|
webSocket.sendTXT(message);
|
||||||
|
}
|
Reference in New Issue
Block a user