HTTP service and ThingSpeak, Arduino and Roblox 2

Hello,
Im trying to make Roblox and Arduino talk to each other, i made series of atempst but failed…
Now i will use ThingSpeak as web server to send data.
How do i send data to ThingSpeak with HTTP service???
Can i send text data or just analog values to decode later?

Cheers from Serbia.

2 Likes

Hi again!
This might help you:

Hello again,
This is helping a bit, i can send any data i want and that is good, i dont have to use A/D converter,
but still im not best into HTTP service… Can you make some exmalple for me? Im trying to send text values (i have loop that reads data from table so its like
1 Wood
1 24
2 Sand
2 5
3 Iron
3 20)

for index, v in pairs(database2) do
print(index,v)
end
local HttpService = game:GetService("HttpService")
 
local dataFields = {
	["api_key"] = "FILL THIS WITH YOUR API KEY";
	["Wood"] = 52;
    ["Sand"] = 43;
}

dataFields = HttpService:JsonEncode(dataFields)
 
-- Make the request
local response = HttpService:PostAsync("https://api.thingspeak.com/update.json", data, Enum.HttpContentType.ApplicationUrlEncoded, false)

This code should work

1 Like

Its that simple? Let me test it please…

Wait, the code was wrong.

Correct code:

local HttpService = game:GetService("HttpService")
 
local dataFields = {
	["api_key"] = "FILL THIS WITH YOUR API KEY";
	["Wood"] = 52;
    ["Sand"] = 43;
}

dataFields = HttpService:JsonEncode(dataFields)
 
-- Make the request
local response = HttpService:PostAsync("https://api.thingspeak.com/update.json", data, Enum.HttpContentType.ApplicationJson, false)

uh… error appears:
JsonEncode is not a valid member of HttpService “HttpService”
so i replaced it with JSONEncode
and that

local response = HttpService:PostAsync("https://api.thingspeak.com/update.json", data, Enum.HttpContentType.ApplicationJson, false)

data value is table value?
edit:
i get 12:25:30.026 - Argument 2 missing or nil

JSONEncode returns string, JSONEncode do table to string covert

okay but i get error for last line:
12:25:30.026 - Argument 2 missing or nil

oh i was wrong, use this code:

local HttpService = game:GetService("HttpService")

local dataFields = {
	["api_key"] = "FILL THIS WITH YOUR API KEY";
	["Wood"] = 52;
	["Sand"] = 43;
}

local data = HttpService:JSONEncode(dataFields)

-- Make the request
local response = HttpService:PostAsync("https://api.thingspeak.com/update.json", data, Enum.HttpContentType.ApplicationJson, false)

hmmm… it did make some difrence,
value for entry got updated but nothing else,
wait that data value at last line, for what is it?

It means worked fine.

This part applies to the entry.

ok im confused right now, what should we add?
go to https:// thingspeak. com/channels /1176993/ to see what im talking about, and remove spaces, i just added them for fast reply
so if you can see im trying to send some data there but none appears,
should i try
“field1”: FIELD1_VALUE,
“field2”: FIELD2_VALUE,
“field3”: FIELD3_VALUE,
“field4”: FIELD4_VALUE,

I don’t know much about ThingSpeak, but I think I can get this entry from Arduino.

no, no entry from arduino is no problem, but from roblox a bit

should i try
“field1”: FIELD1_VALUE,
“field2”: FIELD2_VALUE,
“field3”: FIELD3_VALUE,
“field4”: FIELD4_VALUE,

I think so

да (yes) it is, YAY
we did it, thank you!

1 Like

I’m glad to help you!
Don’t forget to mark my reply as Solution!

1 Like

uh… text does not work… well #### i will have to use D/A and A/D converters…
here we go analog again

1 Like