Help - Search - Members - Calendar
Full Version: How do I send a HTTP request from button
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
goingbush
I'd like to make a webpage interactive and include a button or link in my chicken cam webpage http://chookcam.com so that users can click to activate a chicken feeder in the cameras view.

I have the hardware set up so that if I enter url = server adress/axis-cgi/io/output.cgi?action=1:/1000\ in my browser or via a link a 12volt io relay will turn on for 1000ms then turn off ( / =on, 1000 = time, \ =off )

I will use the relay to control a solenoid to dispense bird seed.

Problem is the hardware server http request opens a new blank page which I am unable to edit , closing the page gets me back to chickencam.com but I simply want users to push a button & the relay activates without any fuss

best i can do so far is http://www.chookcam.com/test.html which opens a popup window that must be closed by the user, rest assured the hardware side is good as I have a buzzer connected & everytime I activate the request the buzzer goes off !!

As you can tell I'm new to this & only know basic html / css have tried searching in vain for a few days to no avail.

cheers ..Don
Darin McGrew
If I understand you correctly, then you could just delete the onClick attribute.
Barons
I really love this idea. I'd like to get some info on your hardware setup if you have a chance. I'd like to get something like that setup for my tarantulas. Prob not the feeding part. They don't eat very often. But the live feed would be cool.

As for your question. I think you need the onClick.

I'm in the process of playing with JavaScript and Ajax. I think Ajax is the stuff that lets you do stuff while staying on the current page.

I'm going to search around abit and see if I can come up with something more detailed. Somthing to the effect of...

function .......code here

$feed = function();
<a href="#" onclick="$function" target="_blank">Feed Em!</a>
goingbush
QUOTE(Darin McGrew @ Feb 21 2011, 01:44 AM) *

If I understand you correctly, then you could just delete the onClick attribute.


Thanks Darin, I tried that but no joy, instead of a popup the whole browser just goes to the http request url and the user has to press the back button.

I uploaded this, it might help explain what I need http://www.chookcam.com/feedtest.html
the problem is in the white css container,
Pressing the link does activate the relay, tho you can't see any result as yet on the webcam

thanks ..Don
goingbush
QUOTE(Barons @ Feb 21 2011, 02:12 AM) *

I really love this idea. I'd like to get some info on your hardware setup if you have a chance. I'd like to get something like that setup for my tarantulas. Prob not the feeding part. They don't eat very often. But the live feed would be cool.

As for your question. I think you need the onClick.

I'm in the process of playing with JavaScript and Ajax. I think Ajax is the stuff that lets you do stuff while staying on the current page.

I'm going to search around abit and see if I can come up with something more detailed. Somthing to the effect of...

function .......code here

$feed = function();
<a href="#" onclick="$function" target="_blank">Feed Em!</a>


Thanks Barons, there is some info on the hardware setup in the About menu button on the page, another issue with my setup is some visitors complain that the video does not display in IE, not a biggie with me, Thnks for the code tip will have a play with it.
cheers ..Don
Christian J
QUOTE(goingbush @ Feb 21 2011, 06:03 AM) *

best i can do so far is http://www.chookcam.com/test.html which opens a popup window that must be closed by the user

Seems the javascript should close the popup automatically, but doesn't. Try this:

CODE
<script type="text/javascript">
function popup(mylink, relay)
{
    var popup=window.open(mylink.href, relay, 'width=50px,height=50px,scrollbars=no,left=400,top=300');
    popup.close();
    return false;
}
</script>


Another method might be to put a form (using method POST) on the "output.cgi" page itself, and let the server-side script feed only when the form's submitted but not when the form page is first loaded. But that way you may accidentally feed by reloading the submitted form page.
goingbush
QUOTE(Christian J @ Feb 21 2011, 07:17 AM) *


Seems the javascript should close the popup automatically, but doesn't. Try this:

CODE
<script type="text/javascript">
function popup(mylink, relay)
{
    var popup=window.open(mylink.href, relay, 'width=50px,height=50px,scrollbars=no,left=400,top=300');
    popup.close();
    return false;
}
</script>




Thanks so much Christian, That almost works, only issue now is it runs a little fast, Have included your code in http://chookcam.com/feedtest2.html for testing, I'll rig a lightbulb in front of the camera tomorrow to demonstrate, Relay triggers about 1 out of 3 clicks, a subsequent click works, is there a way to slow down the popup closing, say about 1 second would be just perfect , perhaps issue is due to latency? either way its great.
pandy
Actually, clicking that link crashes my browser (K-Meleon, a gecko browser).

Regarding your previous try, with the popup, since you open the window with JavaScript you could let JavaScript close it after an adequate number of seconds. Would that work? If you make the window small it wouldn't be disturbing.

Were are you? I'm guessing Australia. When will the chickens wake up? I want to see them. Boy, will those chooks get fat when you get this working! biggrin.gif
Christian J
At least in theory it shouldn't matter how fast the popup closes once the HTTP request has been made, but if the browser somehow messes up with the HTTP request anyway you might instead try closing the popup once it has loaded from a script in the actual popup page. Alas I can't remember the details on how to do this without a closing confirmation window.

Perhaps it's easier to use an iframe instead of a popup? Then you don't need to close anything.
pandy
Yeah, an invisible iframe should work.

I didn't follow what you said about a script in the popup page. Isn't that on another server? And I think goingbush said it can't be edited.
pandy
They are awake now! This is fun! biggrin.gif
Christian J
QUOTE(pandy @ Feb 21 2011, 09:06 PM) *

I didn't follow what you said about a script in the popup page. Isn't that on another server?

In that case I guess it will not work.

To the OP: are any visitors from the web allowed to feed the chickens? I'm sure you're aware that this might lead to excessive feeding...
goingbush
QUOTE(pandy @ Feb 21 2011, 02:08 PM) *

Actually, clicking that link crashes my browser (K-Meleon, a gecko browser).

Regarding your previous try, with the popup, since you open the window with JavaScript you could let JavaScript close it after an adequate number of seconds. Would that work? If you make the window small it wouldn't be disturbing.

Were are you? I'm guessing Australia. When will the chickens wake up? I want to see them. Boy, will those chooks get fat when you get this working! biggrin.gif


Hey Pandy, when you said your browser crashed I downloaded Camino, a Gecko browser for OSX, It works Ok & whats more the timing issue is gone, The popup works perfect, I tried a few other browsers, Safari crashes on my Intel macbook but is fine on my older PPC Mac, and The timing issue is on Google Chrome, It works flawless in Firefox, Camino and SeaMonkey

yes, Im in Australia, Ill set the Feeder so it only dispenses a small amount of seed & will only fire once every 10 mins, Its mainly to get the chooks in front of the camera for the viewer rather than to actualy feed them because they already have a pellet hopper
pandy
The time of day in the hen house and your use of the word chook made me think so. wink.gif

FF doesn't crash for me, only K-Mel, but K-Mel is behind in gecko versions and I don't even have the latest. What make browsers crash though? Have you figured that out?
goingbush
QUOTE(pandy @ Feb 21 2011, 03:06 PM) *

Yeah, an invisible iframe should work.



Duh!

So Ive spent days trying to get this to work, I even thought iframe but got sidetracked ,

I frame works perfect , thanks Christian and Pandy. I'll just tidy up the css positioning and make a button for the link & jobs done , Even the button dissapears after the user feeds the chooks and it does not crash anything .

test page at http://chookcam.com/feedtest3.html

Will have to spend some time in the shed now making the feeder , might take a few days, once I'm done I'll crank it up on the index page , cheers & thanks heaps !!
pandy
Hey, K-Mel actually crashes when I click any link on that page, except the one in that's now in the iframe.
Christian J
Windows Vista often shows a crash message for Chrome (I use the Iron version) and Safari when I leave the page, yet Chrome is still there (while Safari goes down for real). This happens both when closing window and following links.

Also the web cam images don't load properly in Opera.

(This based on http://chookcam.com/feedtest3.html )
pandy
K-Mel just disappears and it there is a delay before it happens. Just goes poof, no lookup or anything. I didn't understand it had crashed at first and thought I had minimized it by accident.

Tell us when you find out what causes the crashes.
Darin McGrew
The difference between Chrome and Safari when they crash is that Chrome keeps each window or tab in a separate process, so when a process crashes, it takes out only that window or tab. Safari runs everything as a single process, so crashes take out everything.
goingbush
QUOTE(Christian J @ Feb 22 2011, 09:22 AM) *

Windows Vista often shows a crash message for Chrome (I use the Iron version) and Safari when I leave the page, yet Chrome is still there (while Safari goes down for real). This happens both when closing window and following links.

Also the web cam images don't load properly in Opera.

(This based on http://chookcam.com/feedtest3.html )


I blew the I/O output relay on the video server so changed out to an earlier model that uses activeX instead of J video, can you try this link instead http://chookcam.com/IE.html it should render the video properley.

meanwhile I'll replace the relay in the original server and re install.

Also will download Opera & try to find K-Mel for osx to install & if I find what causes the crashing I'll let y'all know.
pandy
You can't find K-Mel for anything else than Windows. It's just a gecko browser with a native Windows interface which I happen to like better than FF and XUL. An older version of FF would probably do for testing.

What's different on the new test page? K-Mel doesn't crash when I click the links - hallelujah!

OMG I got a closeup of its ass! How rude! tongue.gif
goingbush
QUOTE(pandy @ Feb 22 2011, 04:07 PM) *

You can't find K-Mel for anything else than Windows. It's just a gecko browser with a native Windows interface which I happen to like better than FF and XUL. An older version of FF would probably do for testing.

What's different on the new test page? K-Mel doesn't crash when I click the links - hallelujah!

OMG I got a closeup of its ass! How rude! tongue.gif

(yikes ! )

I just cranked up an old XP Laptop and installed K-Mel, Hey I really like that browser !!
chookcam.com works fine in it & all the links too.

The diference in the IE.html test page is that the video is in Iframes & is the exact display size coming from the video server.
the index.htm & other test pages use a enlarged video to fill the image of an imac screen.

Thanks for helping find the bug, I'll sort it out.
cheers ..Don
pandy
Can they reach the camera? First an enormous chicken head came at me and it stared vilely with one eye and then I got the rear view. It looked like it was really up close. The head covered the whole viewfield. I may get nightmares now. ohmy.gif

Yup, K-Mel is nice. Faster than FF.

I don't know if we have helped you with the bug really, but if it's gone all is well.
goingbush
It all seems to be good now, Have taken down the test pages before google indexes them.

feed Button works good

Not crashing safari here anymore. Have got the video in iframes which displays a little smaller, I could change it to 704x576 but that might be a bit large ??.

http://chookcam.com

thanks for all help , cheers ..Don


pandy
The feed button disappears when I have clicked it and after a second or two K-Mel crashes. sad.gif
Barons
@ Pandy Try to uninstall K-Mel and see if that works better =P

I just made the light come on I thought they were going to do something when it flashed... They were all standing around it... but they didn't seem to notice it =(

Yea food is going to be good! That will get their attention.
Christian J
Chrome still crashes for me (not every time), and Opera still only shows a flicker of an image. I wouldn't bother too much about Opera though, since few people use it.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2018 Invision Power Services, Inc.