Added overlay with temperature data from OpenHAB
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d2e20753ae4907846a6cfba474a703a5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user