Added overlay with temperature data from OpenHAB

This commit is contained in:
ftc
2021-02-22 10:17:22 +03:00
parent fbc829ba33
commit 6e63d6de99
4 changed files with 226 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
public class OpenHabItemView : MonoBehaviour
{
[SerializeField]
private string itemUrl;
[SerializeField]
private Text text;
[SerializeField]
private float refreshInterval;
// Start is called before the first frame update
void Start()
{
CultureInfo.CurrentCulture = new CultureInfo("en-US");
StartCoroutine(LoadAndSet());
}
private IEnumerator LoadAndSet()
{
while (true)
{
var www = UnityWebRequest.Get(itemUrl);
yield return www.SendWebRequest();
if (!www.isNetworkError && !www.isHttpError)
{
float result = float.NaN;
if (float.TryParse(www.downloadHandler.text, out result))
{
text.text = string.Format("{0:F2}", result);
}
}
yield return new WaitForSeconds(refreshInterval);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: d2e20753ae4907846a6cfba474a703a5
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: