←  Ask a Pro

ComputerCraft | Programmable Computers for Minecraft


Http.get update

MasterReaper's Photo MasterReaper 03 Mar 2015

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()

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


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's Photo MKlegoman357 03 Mar 2015

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's Photo Bomb Bloke 04 Mar 2015

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's Photo MasterReaper 05 Mar 2015

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's Photo Bomb Bloke 05 Mar 2015

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.