Disabled websocket in favour of other protocol
This commit is contained in:
@@ -20,4 +20,21 @@ void Connectivity::websocketSetup(char* ip, uint16_t port, char* adress){
|
|||||||
void Connectivity::sendData(float roll, float pitch, float yaw){
|
void Connectivity::sendData(float roll, float pitch, float yaw){
|
||||||
String message = "{\"Sensor\": 1, \"roll\":\"" + String(roll) + "\",\"pitch\":\"" + String(pitch) + "\",\"yaw\":\"" + String(yaw) + "\"}";
|
String message = "{\"Sensor\": 1, \"roll\":\"" + String(roll) + "\",\"pitch\":\"" + String(pitch) + "\",\"yaw\":\"" + String(yaw) + "\"}";
|
||||||
webSocket.sendTXT(message);
|
webSocket.sendTXT(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Send a POST request to a server with provided data */
|
||||||
|
int Connectivity::httpPost(const char *serverAddress, const char *serverSubPath, const unsigned short serverPort,
|
||||||
|
const char *data, const size_t dataLength, const char *contentType)
|
||||||
|
{
|
||||||
|
if ( wifi_client.connect(serverAddress, serverPort)) {
|
||||||
|
wifi_client.printf("POST %s HTTP/1.1\r\n", serverSubPath);
|
||||||
|
wifi_client.printf("Content-Type: %s\r\n", contentType);
|
||||||
|
wifi_client.printf("Content-Length: %d\r\n", dataLength);
|
||||||
|
wifi_client.printf("Host: %s\r\n\n", serverAddress);
|
||||||
|
wifi_client.println(data);
|
||||||
|
wifi_client.stop();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 1;
|
||||||
}
|
}
|
@@ -6,25 +6,25 @@
|
|||||||
#include <ArduinoWiFiServer.h>
|
#include <ArduinoWiFiServer.h>
|
||||||
#include <ESP8266WiFi.h>
|
#include <ESP8266WiFi.h>
|
||||||
#include <ESP8266WiFiGeneric.h>
|
#include <ESP8266WiFiGeneric.h>
|
||||||
#include <ESP8266WiFiGratuitous.h>
|
|
||||||
#include <ESP8266WiFiMulti.h>
|
#include <ESP8266WiFiMulti.h>
|
||||||
#include <ESP8266WiFiSTA.h>
|
#include <ESP8266WiFiSTA.h>
|
||||||
#include <ESP8266WiFiScan.h>
|
|
||||||
#include <ESP8266WiFiType.h>
|
|
||||||
#include <WiFiClient.h>
|
#include <WiFiClient.h>
|
||||||
#include <WiFiServer.h>
|
#include <WiFiClientSecure.h>
|
||||||
#include <WiFiServerSecure.h>
|
|
||||||
#include <WiFiUdp.h>
|
|
||||||
|
|
||||||
class Connectivity {
|
class Connectivity {
|
||||||
public:
|
public:
|
||||||
void connectWiFi(char* ssid, char* pass);
|
void connectWiFi(char* ssid, char* pass);
|
||||||
void websocketSetup(char* ip, uint16_t port, char* adress);
|
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);
|
||||||
|
int httpPost(const char *serverAddress, const char *serverSubPath, const unsigned short serverPort, const char *data, const size_t dataLength, const char *contentType);
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ESP8266WiFiMulti wifi;
|
ESP8266WiFiMulti wifi;
|
||||||
|
WiFiClient wifi_client;
|
||||||
WebSocketsClient webSocket;
|
WebSocketsClient webSocket;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@@ -10,9 +10,9 @@ void setup() {
|
|||||||
sensorManager.sensorSetup();
|
sensorManager.sensorSetup();
|
||||||
|
|
||||||
//ws server address, port and URL
|
//ws server address, port and URL
|
||||||
webSocket.begin("145.28.160.108", 8001, "");
|
// webSocket.begin("145.28.160.108", 8001, "");
|
||||||
// try every 500 again if connection has failed
|
// try every 500 again if connection has failed
|
||||||
webSocket.setReconnectInterval(500);
|
// webSocket.setReconnectInterval(500);
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
@@ -40,7 +40,7 @@ void loop() {
|
|||||||
sendData(eulerRotation.roll, eulerRotation.pitch, eulerRotation.yaw);
|
sendData(eulerRotation.roll, eulerRotation.pitch, eulerRotation.yaw);
|
||||||
|
|
||||||
Serial.println();
|
Serial.println();
|
||||||
webSocket.loop();
|
// webSocket.loop();
|
||||||
}
|
}
|
||||||
// if (Serial.available()) {
|
// if (Serial.available()) {
|
||||||
// String command = Serial.readStringUntil('\n');
|
// String command = Serial.readStringUntil('\n');
|
||||||
|
Reference in New Issue
Block a user