Hi All,
I am trying to get Unity to fetch data from the blynk cloud from the virtual pins assigned. Below is the code. But whenever I try to run it. It gives me the following error. Not sure what to do here.
Need URGENT HELP.
Error fetching Blynk data: HTTP/1.1 404 Not Found
UnityEngine.Debug:LogError (object)
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System;
using System.Collections;
using UnityEngine.Networking;
public class SmartTshirt : MonoBehaviour
{
string authToken = "OAu4M69S3xP_92ymKqomJ6eUqU4M0fpR"; // Replace with your Blynk auth token
string serverIP = "blynk.cloud"; // Replace with your Blynk server IP
int updateInterval = 1; // Update interval in seconds
public TMP_InputField InputFieldTEMP; // Specify the type of the input field
public TMP_InputField InputFieldHB; // Specify the type of the input field
public TMP_InputField InputFieldSP; // Specify the type of the input field
string temperature;
string heartbeat;
string spo2;
private void Start()
{
StartCoroutine(FetchData());
}
private IEnumerator FetchData()
{
while (true)
{
// Fetch temperature data
yield return StartCoroutine(FetchBlynkData("V0", (value) =>
{
temperature = value;
}));
// Fetch heartbeat data
yield return StartCoroutine(FetchBlynkData("V1", (value) =>
{
heartbeat = value;
}));
// Fetch SpO2 data
yield return StartCoroutine(FetchBlynkData("V2", (value) =>
{
spo2 = value;
}));
// Update input fields with fetched data
InputFieldTEMP.text = temperature;
InputFieldHB.text = heartbeat;
InputFieldSP.text = spo2;
yield return new WaitForSeconds(updateInterval);
}
}
private IEnumerator FetchBlynkData(string virtualPin, Action<string> callback)
{
string url = "http://" + serverIP + "/" + authToken + "/get/" + virtualPin;
Debug.Log("Fetching data from URL: " + url);
using (UnityWebRequest request = UnityWebRequest.Get(url))
{
yield return request.SendWebRequest();
if (request.result == UnityWebRequest.Result.ConnectionError || request.result == UnityWebRequest.Result.ProtocolError)
{
Debug.LogError("Error fetching Blynk data: " + request.error);
}
else
{
callback(request.downloadHandler.text);
}
}
}
}