This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
MasterReaper's profile picture

Http.get update

Started by MasterReaper, 03 March 2015 - 04:13 PM
MasterReaper #1
Posted 03 March 2015 - 05:13 PM
Hey this is my first post ont this forum,

First of all excuse me if I make some english mistakes (The fact is that I am French and learning english , but that's not what you want to know ^^ ).

So I reccently tried to make a program that uses 'http.get' to receive text from a webpage and then activate redstone.

Here is an example to show what it looks like :

while true do
local httpstatus = http.get("http://mywebsite.com/status")
local status = httpstatus.readAll()
print(status)

  if(status == "lights-on") then
   rs.setOutput("right", true)
  elseif (status == "lights-off") then
   rs.setOutput("right", false)
  end

sleep(1)
httpstatus.close()
end

The page 'status' is controlled by a PHP script and returns 2 possible values , here "lights-on" and "lights-off".

It's working actually, but I found that I had to refresh the webpage (status) myself ,using my webbrowser, for it to update !
For example :
1 - The status webpage shows "lights-off"
2 - My program prints "lights-off"
3 - I use my PHP script to change the status
4 - My program is still printing : "lights-off" until I refresh the webpage using my webbrowser


Is there any way to make it work properly ?
Am I doing something wrong ?


And if I made some mistakes feel free to correct me :)/>


Thanks for reading and hope to see your answers ^^
MKlegoman357 #2
Posted 03 March 2015 - 06:40 PM
I suspect it is happening because CC (or probably Java) is caching the webpage. I suggest to close the webpage handle ( httpstatus.close() ) before sleep(1), maybe that will make it return the non-cached version of your webpage.
Bomb Bloke #3
Posted 04 March 2015 - 12:02 AM
Hrm. If that were the case, then MasterReaper wouldn't be able to use a manual browser refresh as a workaround. This sounds like one of those times where you'd want to mess with your useragent.
MasterReaper #4
Posted 05 March 2015 - 06:42 PM
Thanks for replying :)/>

So I tested all you've said but I didn't work , in fact the problam is that my file isn't updating himself !
I searched for automatic webpage refresh but I didn't found how it was possible.
Is there any way to make LUA refresh a webpage ?
Bomb Bloke #5
Posted 05 March 2015 - 09:58 PM
Refresh it on the web server, you mean? That'd be up to the web server. ComputerCraft lets you POST and GET stuff but that's about it.