HTTP/1.1 404 Not Found

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);
            }
        }
    }
}

You should remove your auth token! :hushed:

Use secure https. Likely the issue because insecure http is getting blocked up and down the road, for good reasons.

If that’s not the fix note that 404 means you are accessing a URL that doesn’t exist. Compare it with your endpoint. It’s also curious that the authToken is part of the URL, I find that unusual but web dev crap isn’t my thing.

Also rather than checking for errors, check for success and then do your thing while in all other cases you log that error, including its type because you want to know that it failed because you weren’t connected to the Internet rather than going through an hours long phantom bug hunt.

1 Like