Jump to content

Http.get update

computer networking help

4 replies to this topic

#1 MasterReaper

  • Members
  • 10 posts

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

  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 ^^

#2 MKlegoman357

  • Members
  • 1,170 posts
  • LocationKaunas, Lithuania

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.

#3 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

#4 MasterReaper

  • Members
  • 10 posts

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 ?

#5 Bomb Bloke

    Hobbyist Coder

  • Moderators
  • 7,099 posts
  • LocationTasmania (AU)

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.

1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users