mirror of
https://github.com/Mukheem/TwinTurbine.git
synced 2025-05-11 16:50:33 +02:00
Added WebSocketController script
This commit is contained in:
parent
10c019bd83
commit
f1ef6cfe31
Assets/SharedSpatialAnchors/Scripts
ProjectSettings
64
Assets/SharedSpatialAnchors/Scripts/WebSocketController.cs
Normal file
64
Assets/SharedSpatialAnchors/Scripts/WebSocketController.cs
Normal file
@ -0,0 +1,64 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using System.IO.Ports;
|
||||
using System;
|
||||
using WebSocketSharp;
|
||||
|
||||
public class WebSocketController : MonoBehaviour
|
||||
{
|
||||
|
||||
String esp32IPAddress = "10.204.0.245";
|
||||
String esp32WebsocketPort = "81";
|
||||
// Websocket Service
|
||||
public WebSocket ws;
|
||||
|
||||
|
||||
// Serial Port to which Arduino is connected
|
||||
SerialPort arduinoPort = new SerialPort("COM4", 115200);
|
||||
|
||||
|
||||
public void Start(){
|
||||
ConnectWithESP32();
|
||||
//narrationController.GetComponent<NarrationController>();
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// Method to connect ESP32
|
||||
public void ConnectWithESP32()
|
||||
{
|
||||
Debug.Log("Connecting Unity with ESP32 via Websockets...");
|
||||
ws = new WebSocket("ws://" + esp32IPAddress + ":" + esp32WebsocketPort);
|
||||
ws.OnOpen += (sender, e) =>
|
||||
{
|
||||
Debug.Log("WebSocket connected");
|
||||
ws.Send("Hello from Unity!");
|
||||
//ws.Send("Need input");
|
||||
};
|
||||
ws.OnMessage += (sender, e) =>
|
||||
{
|
||||
Debug.Log("Received message: " + e.Data);
|
||||
if(e.Data.Equals("Start Narration", StringComparison.OrdinalIgnoreCase)){
|
||||
// narrationControllerScript.startNarration = true;
|
||||
}
|
||||
|
||||
};
|
||||
ws.Connect();
|
||||
Debug.Log("Websocket state - " + ws.ReadyState);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Closing websocket upon application quit
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
ws.Close();
|
||||
Debug.Log("WebSocket closed on application exit");
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3c468066257183f4eb657f07381143b7
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@ -1201,7 +1201,7 @@ PlayerSettings:
|
||||
luminVersion:
|
||||
m_VersionCode: 1
|
||||
m_VersionName:
|
||||
apiCompatibilityLevel: 6
|
||||
apiCompatibilityLevel: 3
|
||||
activeInputHandler: 2
|
||||
windowsGamepadBackendHint: 0
|
||||
cloudProjectId:
|
||||
|
Loading…
x
Reference in New Issue
Block a user