Hi,
I am struggling with this and lost a lot of hair. Hoping someone can help:
What I am trying to do: Make an HTTP request from another app to change the value of a cloud variable ("todo" int variable on arduino cloud) for my arduino device.
I have a variable called "todo" (int variable)...I am trying to figure out what the structure of the Arduino API should be so that I can use the code below to pass different variables through the arduino cloud API to my arduino device:
local HttpService = game:GetService("HttpService")
-- Replace with your Arduino Cloud API endpoint and token
local url = "YOUR_ARDUINO_CLOUD_API_ENDPOINT"
local token = "YOUR_AUTH_TOKEN"
local function updateArduinoCloudVariable(value)
local headers = {
["Content-Type"] = "application/json",
["Authorization"] = "Bearer " .. token
}
local body = {
-- Replace 'variableName' with the name of your variable in Arduino Cloud
variableName = value
}
local data = HttpService:JSONEncode(body)
local success, response = pcall(function()
return HttpService:RequestAsync({
Url = url,
Method = "PUT", -- or "POST", depending on the API requirement
Headers = headers,
Body = data
})
end)
if success then
print("Request successful: ", response.Body)
else
warn("Request failed: ", response)
end
end
-- Example usage
updateArduinoCloudVariable(true) -- or false
I have the auth token, but now what exactly goes inside of "YOUR_ARDUINO_CLOUD_API_ENDPOINT" to pass values to that device's variable?