#include "Connectivity.h" void Connectivity::connectWiFi(char* ssid, char* pass){ WiFi.mode(WIFI_STA); WiFi.begin(ssid, pass); while (WiFi.status() != WL_CONNECTED) { delay(1000); } } void Connectivity::websocketSetup(char* ip, uint16_t port, char* adress){ //ws server address, port and URL webSocket.begin(ip , port, adress); // try every 500 again if connection has failed webSocket.setReconnectInterval(500); } void Connectivity::sendData(float roll, float pitch, float yaw){ String message = "{\"Sensor\": 1, \"roll\":\"" + String(roll) + "\",\"pitch\":\"" + String(pitch) + "\",\"yaw\":\"" + String(yaw) + "\"}"; 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; }