PDA

View Full Version : Idiot simple webserver question



Mastiff
January 11th, 2012, 01:45 PM
From an idiot, I must add. Because I'm embarassed... I am going to start using webserver again to turn on radio channels and a bit more stuff in the house, and I can't remember how to do it! The simple stuff I want to do isn't in the example web pages or anywhere else I can find it. All I want to do is to have a few pages where klicking a link triggers a regular event in Girder. I tried to search here, but only found questions about the advanced stuff. :( I think there was something about doing it through a payload hook or something within the GML, but I can't remember how it was done. Also it's been so long since I used it that it may have been on Girder 4, and maybe stuff changed to Girder 5?

So basically: How do I code a html page so that klicking the link "hello" triggers the event "hello" in girder, which then again trigges an action?

Ron
January 11th, 2012, 01:51 PM
No worries. Look at events.html and send_event.lhtml in the httpd subdir of Girder.

Mastiff
January 11th, 2012, 01:55 PM
I guess I'm still stoopid, since I can only find the events.html (where you must know the name of an event to send it, instead of just cliking on a link) and ajax_sendevents.lhtml. No send_event.lhtml anywyere, as far as I can see.

Ron
January 11th, 2012, 02:03 PM
I meant ajax_sendevent.lhtml

look at line 90 of events.html it shows you have to pre-program the event string.

Mastiff
January 11th, 2012, 02:12 PM
OK, if I counted correctly this is it:


<a href="" OnClick='return SendEvent("PREVIOUS", "4000");' OnMouseDown='return SetImage("PrevButton", "img/prev_hi.gif");' OnMouseUp='return SetImage("PrevButton", "img/prev.gif");' onmouseout='return SetImage("PrevButton", "img/prev.gif");'><IMG src="img/prev.gif" border="0" id="PrevButton"></a>&nbsp;

So I tried to copy that to my own setup in the correct directory, and in the log display I see "WebServer" as source and / as Details. But no Payload, which I would assum would be what triggered the event. Right?

I apologize for being thick but as you probably remember from when I still tried coding isn't my strong side...

Ron
January 11th, 2012, 02:22 PM
try changing the event number from 4000 to 18. And click it again (after reloading). You should see two events. The webserver event plus a Girder event with the name "PREVIOUS"

Mastiff
January 11th, 2012, 02:29 PM
You mean like this:


<a href="" OnClick='return SendEvent("PREVIOUS", "18");' OnMouseDown='return SetImage("PrevButton", "img/prev_hi.gif");' OnMouseUp='return SetImage("PrevButton", "img/prev.gif");' onmouseout='return SetImage("PrevButton", "img/prev.gif");'><IMG src="img/prev.gif" border="0" id="PrevButton"></a>&nbsp;

That gives me two entries in the log marked "WebServer", probably one for mouse down and one for mouse up, but no Girder events. Maybe I need to copy some files from the httpd directory for this to work?

shaun5
January 11th, 2012, 04:35 PM
If you want to do it the same way as the events.html example, you need to load a jquery library. The default install uses jquery.min.js, but you can use a newer release as well.
1) Make sure the following is in between the <head> </head> tags:
<SCRIPT src="jquery.min.js" type="text/javascript"></SCRIPT>
function SendEvent( Event, Device )
{
$.get("ajax_sendevent.lhtml?event="+escape(Event)+"&device="+escape(Device));
return false;
}
2) drop the jquery.min.js and ajax_sendevent.lhtml from the default install in the same directory as your new html or lhtml file.
3)have javascript enabled on the web browser you are using.

Also you can make almost any tag fire with by adding: OnClick='return SendEvent("PREVIOUS", "18");' example: <div OnClick='return SendEvent("PREVIOUS", "18");'>PREVIOUS</div>

Mastiff
January 11th, 2012, 04:37 PM
Thanks, I'll try to get my head around that stuff tomorrow, when I'm a bit more awake. So there is no way to fire simple events without using advanced stuff like javascript, which may or may not work on moile browsers? I would very much prefer the simplest method, if there is one.

shaun5
January 11th, 2012, 05:00 PM
You need javascript, but I would be surprised if this was a problem on any current device...
There is a way to not use jQuery using a using strictly javascript. If I remember correctly, the girder.js file has no jQuery dependencies. So you would just

1)stick <SCRIPT src="girder.js" type="text/javascript"></SCRIPT> between the <head> </head> tags.
2) drop the girder.js and ajax_sendevent.lhtml from the default install in the same directory as your new html or lhtml file.
3)add <div OnClick='SendEvent("PREVIOUS", "18");'>PREVIOUS</div> between the <BODY> </BODY> tags... (I skipped this step on the last set of instructions because you already had it)
4)have javascript enabled on the web browser you are using.

Mastiff
January 12th, 2012, 03:06 AM
OK, no I have this.
Girder-styring PREVIOUS
http://www.promixis.com/forums/img/prev.gif And I see the word "PREVIOUS" over the button, but it's not clickable. And clicking the button still only gives me two "WebServer" in the log, with no payload. But I actually managed to find some of my old code, which is a lot simpler. Unfortunately it doesn't seem to work. In the index.lhtml there are commands like these:
18 (http://www.promixis.com/forums/index.lhtml?PT18)
And to make them work there is an action in Girder which is triggered by /index.lhtml from Event Device 36:
gir.TriggerEvent(pld1,18) That was what I was looking for, and it didn't need any javascript or any other fancy stuff. But it just doesn't work anymore. The only pld1 (payload 1) is the name of the GML, the group and the action that's triggered. Is that because of a change in Girder since I used this function? Here's the full code of that LHTML, if that can accomplish anything:
Girder control Girder control

18 (http://www.promixis.com/forums/index.lhtml?PT18)
This should have sent the code PT18, which triggered an USB-UIRT action to set the Panasonic heat pump to 18 degrees. But all I see is no payload and this in the Lua Console:


[string "D:\Server 2003 G4:\Ved start av Girder\Webs..."]:1: bad argument #1 to `TriggerEvent' (string expected, got nil)
stack traceback:
[C]: in function `TriggerEvent'
[string "D:\Server 2003 G4:\Ved start av Girder\Webs..."]:1: in main chunk


Could it be that I'm only missing a Lua file somewhere to have that working again?

Mastiff
January 12th, 2012, 04:30 AM
Well, I did an experiment and installed Girder 4 in a virtual machine. The code worked there. Then I copied the httpd.dll plugin from Girder 4 to Girder 5, renaming the Girder 5 version httpd.bak. And what do you know - it works! So my next question is: Will this affect stability in Girder 5 in any way? I could have a virtual machine only running Girder 4 and the webserver, but if I can just use the dll from 4 in 5 that would be a lot easier. So what do the experts think?

shaun5
January 12th, 2012, 10:19 AM
If you use a form submital or your href link method, then I see a way to make it work without javascript. I was thinking you would want to keep using Ajax method (I still don't think you can use Ajax without javascript). All the events like onclick, onmousedown, onmouseup are javascript...

Mastiff
January 12th, 2012, 10:37 AM
Thanks for answering! Well, I really only want to do the simplest way possible. The JS-code was from the example pages with Girder, which is why I used that. I didn't find my old code again until this morning. I had it in an old backup.

So is it possible to ask you to write out a line that does that (sends PT18 on the new webserver system)? I have no idea how to use form submittals or anything else, I'm hopeless with stuff that can't be done in Dreamweaver's design mode.

shaun5
January 12th, 2012, 11:07 AM
Yes, I think I can make what you want work with the new web server. Ultimately/ideally, what do you want to be able to do from the page? For just one command, I see the smallest / simplest page possible not even being a page, but instead just a bookmarked link that just replies with something like <html><body>Done.</body></html> (might need a no cache tag too) and all you would see on the client is Done.

I am away from my machine, but I think typing: ajax_sendevent.lhtml?event='PREVIOUS'&device='18' in a browser might work (you would get no response on the client). If you have an event PREVIOUS setup with device 18.....

Mastiff
January 12th, 2012, 11:23 AM
Thanks again! That was close! Really close! :) I put this code in the index.lhtml (which was the equivalent to having your code in the browser):


<a href="ajax_sendevent.lhtml?event='PREVIOUS'&device='18'">PREVIOUS</a><br>


That fired an event in Girder, where Payload 1 was "device='18'" and payload 2 was "event='previous'" I could probably use that with a script that removes the event=' ' part and shots the PREVIOUS as a trigger. Or maybe it can be even better if the synthax is correct? Because the webpage threw an error in the browser:


[string "WebServer"]:7: bad argument #2 to `TriggerEvent' (number expected, got string) stack traceback: [C]: in function `TriggerEvent' [string "WebServer"]:7: in main chunk

Som I'm guessing that there's a small thing there that makes it "throw up", and when that's corrected this will work as it shoud. :D

shaun5
January 13th, 2012, 07:24 PM
The correct code is:

<a href="ajax_sendevent.lhtml?event=PREVIOUS&device=18">PREVIOUS</a><br>

If you need it, there is another thread where I revised the ajax_sendevent.lhtml file to send event, device, pld1, and pld2...

Mastiff
January 14th, 2012, 03:41 AM
Thanks again! Interesting! I'll have to try to find that thread.

This code did not throw an error anywhere, but it gave me a blank page in the browser with this in the address line:


http://192.168.0.1:8080/ajax_sendevent.lhtml?event=PREVIOUS&device=18

Shouldn't it have sent me back to the same index.html page?

shaun5
January 14th, 2012, 07:27 AM
Hopefully you saw the event execute the respective action in Girder. Linking to vs. using ajax to call the functions within the ajax_sendevent.lhtml moves the browser from your index page to ajax_sendevent.lhtml page. ajax_sendevent.lhtml doesn't return or generate any HTML. This behavior can be modified by combing the two pages. So.... to finally answer your initial question, save the following as index.lhtml.

<%
webserver:SetGZIP(false)
webserver:SetHeader("Cache-Control: no-cache, must-revalidate")
webserver:SetHeader("Expires: Fri, 30 Oct 1998 14:19:41 GMT")
local table = webserver:GetCGI()
if ( gir and table['event'] ) then
gir.TriggerEvent( table['event'], table['device'], 0)
end
%>
<HTML><body>
<a href="index.lhtml?event=PREVIOUS&device=1 8">PREVIOUS</a>
</body></HTML>

Mastiff
January 14th, 2012, 08:30 AM
Back to throwing up again, unfortunately. :confused: This is the full HTML page I have now:


<html>
<head>
<title>Girder-styring</title>
<META HTTP-EQUIV="Pragma" CONTENT="no-cache">
</head>
<body>
<h1>Girder-styring</h1>
<%
webserver:SetGZIP(false)
webserver:SetHeader("Cache-Control: no-cache, must-revalidate")
webserver:SetHeader("Expires: Fri, 30 Oct 1998 14:19:41 GMT")
local table = webserver:GetCGI()
if ( gir and table['event'] ) then
gir.TriggerEvent( table['event'], table['device'], 0)
end
%>
<HTML><body>
<a href="index.lhtml?event=PREVIOUS&device=1 8">PREVIOUS</a>
</body></HTML>


But clicking the PREVIUOS I get this in the browser:


Girder-styring [string "WebServer"]:9: bad argument #2 to `TriggerEvent' (number expected, got string) stack traceback: [C]: in function `TriggerEvent' [string "WebServer"]:9: in main chunk

So it seems to have gone back to the correct page (index.lhtml) since the heading is there. And it give me payload device= 1 8 (with a space between) and event=PREVIOUS, as it should. So we're probably getting closer, but not quite there yet. It may of course very well be my fault, in the way I put your code into the full page.

Also is it possible to adjust this so it doesn't get device= and event= but simply the device number and the event? Sorry if I'm nagging...

shaun5
January 14th, 2012, 02:25 PM
You misunderstood my answer. The code was the entire file (I had already combined them). The 18 should never have had a space (just the way the forum formatted my text - the code button doesn't show up in Safari)...

I made a slight improvement to my last post. It will now trigger the event/device and then redirect so the browser URL doesn't have the ?event=PREVIOUS&device=100 string, this keeps it from firing again if you hit refresh in the browser.

The event= and device= do not show up in Girder and will trigger the event/device. Attached is a ma.gml and ma.lhtml file. These work together and will print 'Hello' to your console every time you click PREVIOUS in the browser. Once you understand how it works, you can change things (if you change the name of the lhtml file you have to change it the two places it is used IN the file). The href device and event can be changed to whatever you need and you can add as many of those as you need within the lhtml file. I use device 100 for all my webpage stuff, but you can change it back to 18 (or whatever you need).

Mastiff
January 14th, 2012, 04:49 PM
Thanks! But either I managed to misunderstand again (well, I said I was an idiot with stuff like this...), or there's an error somewhere. I changed the index.lhtml to what you had on the previous side. Still I get the same error:


[string "WebServer"]:7: bad argument #2 to `TriggerEvent' (number expected, got string) stack traceback: [C]: in function `TriggerEvent' [string "WebServer"]:7: in main chunk

I tried to rename your ma.lhtml into index.lthml as well, and that did not change anything either. Sorry if I'm just thick and have made a mistake myself, but I'm still confused.

Edit: Never mind, I suddenly saw what was going on: Even if I had clicked "reload host file" in Grider it needed a full restart before it actually took the changes. Works now. Thanks a lot! :D

shaun5
January 14th, 2012, 05:48 PM
I am glad it is working for you. I don't know your plans for this, but for me (even though I have the same Girder interface whenever and wherever I have an internet browser), I still see a use for the bookmark: The functionality still exists to create a link to a event/device (now the page loads vs. just being blank). I also see a need for some feedback that a command was at least begining to be processesed (depending on what is being done, you may be able to delay the response long enough to give an update that everything was successfully executed). All of this is still 100% server side scripted in Lua without any need or client side JavaScript support...

Mastiff
January 19th, 2012, 05:35 AM
Well, my basic plan is to use this to let network users go to one page on the network where they can control audio, video and whatever else there is to control in the zone (room) they are in (with an identical system being used in our house and our cabin by the sea). And it seems like that will work out. Since everything is audible or viewable it won't be necessary to show any update, they will hear immideatly if anything comes on. And there are LED power diodes for the amps and stuff in all the zones, so it's not a problem to know if that worked out either. Thanks again, this is really something I can build on, I have a very simple page so far, but I'm going to go bananas with this pretty soon.

ajocius
January 19th, 2012, 07:56 AM
It is such a pitty that it is so complicated. Hope there could be Netremote - > Webpage converter, this would be perfect. All this webpage creating seems so complicated, unless you have experience with it, of course...

Mastiff
January 19th, 2012, 08:00 AM
Well, that would of course be ideal, but I'm guessing that it's a bit too complicated to do that, or we would have had it now, that Windows Mobile 6.5 isn't all the rage anymore. I think I and my family are the only ones in Norway still using it, instead of Android and stuff from a company of consumer jailers who has half eaten fruit as their symbol... ;)