wifi and websocket connection added

This commit is contained in:
2024-05-12 18:42:40 +02:00
parent 29ed7e57c7
commit c7c3ebe1c2
3 changed files with 44 additions and 22 deletions

View File

@@ -2,23 +2,16 @@
SensorManager sensorManager; SensorManager sensorManager;
ESP8266WiFiMulti wifi; ESP8266WiFiMulti wifi;
WebSocketsClient webSocket;
#define USE_SERIAL Serial
void setup() { void setup() {
Serial.begin(9600); Serial.begin(9600);
Serial.println("startup"); Serial.println("startup");
delay(5000); delay(5000);
connectWiFi();
//Wifi
WiFi.mode(WIFI_STA);
wifi.addAP(ssid, pass);
while (WiFi.status() != WL_CONNECTED) {
Serial.println("connecting to wifi");
delay(1000);
}
Serial.println(WiFi.localIP());
Wire.setClockStretchLimit(150000L); // Default stretch limit 150mS
sensorManager.sensorSetup(); sensorManager.sensorSetup();
websocketSetup();
} }
void loop() { void loop() {
@@ -39,6 +32,35 @@ void loop() {
Serial.print(pitch); Serial.print(pitch);
Serial.print(" "); Serial.print(" ");
Serial.print(yaw); Serial.print(yaw);
sendData(String(roll));
sendData(String(pitch));
sendData(String(yaw));
Serial.println(); Serial.println();
webSocket.loop();
}
void connectWiFi(){
WiFi.mode(WIFI_STA);
wifi.addAP(ssid, pass);
WiFi.begin();
while (WiFi.status() != WL_CONNECTED) {
Serial.println("connecting to wifi");
delay(1000);
}
Serial.println(WiFi.localIP());
}
void websocketSetup(){
//ws server address, port and URL
webSocket.begin("192.168.178.118", 8001, "");
// try every 500 again if connection has failed
webSocket.setReconnectInterval(500);
}
void sendData(String textString){
webSocket.sendTXT(textString);
} }

View File

@@ -4,21 +4,19 @@
SensorManager::SensorManager() {} SensorManager::SensorManager() {}
void SensorManager::sensorSetup() { void SensorManager::sensorSetup() {
Serial.println(); Wire.setClockStretchLimit(150000L); // Default stretch limit 150mS
Serial.println("BNO080 Read Example");
delay(1000); // Wait for BNO to boot
Wire.begin(); Wire.begin();
//wait for the sensor to start before continue
if (myIMU.begin() == false) { if (myIMU.begin() == false) {
delay(1000); delay(1000);
Serial.println("."); Serial.println(".");
} }
//start sensorfunction and start autocalibration
//once calibration is enabled it attempts to every 5 min
Wire.setClock(400000); //Increase I2C data rate to 400kHz Wire.setClock(400000); //Increase I2C data rate to 400kHz
myIMU.calibrateAll(); //Turn on cal for Accel, Gyro, and Mag myIMU.calibrateAll(); //Turn on cal for Accel, Gyro, and Mag
myIMU.enableGyroIntegratedRotationVector(100); myIMU.enableGyroIntegratedRotationVector(100); //send data every 100ms
myIMU.enableMagnetometer(100); //Send data update every 100ms myIMU.enableMagnetometer(100); //Send data update every 100ms
myIMU.saveCalibration(); //Saves the current dynamic calibration data (DCD) to memory myIMU.saveCalibration(); //Saves the current dynamic calibration data (DCD) to memory
myIMU.requestCalibrationStatus(); //Sends command to get the latest calibration status myIMU.requestCalibrationStatus(); //Sends command to get the latest calibration status

View File

@@ -1,3 +1,5 @@
#include <WebSocketsClient.h>
#include <ArduinoWiFiServer.h> #include <ArduinoWiFiServer.h>
#include <ESP8266WiFi.h> #include <ESP8266WiFi.h>
#include <ESP8266WiFiGeneric.h> #include <ESP8266WiFiGeneric.h>
@@ -11,8 +13,8 @@
#include <WiFiServerSecure.h> #include <WiFiServerSecure.h>
#include <WiFiUdp.h> #include <WiFiUdp.h>
#define ssid "LAPTOP3028043" #define ssid "ObsidianAmstelveen"
#define pass "619#5gJ5" #define pass "drijversstraatmaastricht"
//custom classes //custom classes
#include "SensorManager.h" #include "SensorManager.h"