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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user