PDA

View Full Version : Howto - DemoPad to Girder



VicVonDoom
February 15th, 2012, 01:06 PM
This is a howto for using the ipad/iphone app "DemoPad" to send TCP data to Girder to trigger a Girder Event which you can use to trigger anything you like!
(Disclaimer - I am not affiliated in any way with Demopad, Just a happy end user that wants to share an excellent product)

1. Make Girder Listen for a DemoPad connection
Copy the code below (based on the good work by davedave1234) and paste into a scripting action in your gml.
Then drag the appropriate 'triggers' from the girder log to make it run when girder starts up. For example 'Girder Loaded' and 'Script Enable' are nice ones that appear in the log when girder is first started and will make the scripting action trigger.


Girder will now 'listen' on port 12345 for DemoPad, Providing the scripting action was triggered.
You need only run the action once per girder session.



--Absolutely ripped off of the hard work by promixis forum member 'davedave1234' and the work done to get TouchIR working with Girder!
--tiny mods to this script done by VicVonDoom




function mycbserver(p1,p2)
if ( p2 == transport.constants.event.CONNECTIONCLOSED ) then
print("Connection to DemoPad Closed")
return
end

if ( p2 == transport.constants.event.NEWCONNECTION ) then
print("New Incoming Connection from DemoPad")
p1:Callback(transport.constants.parser.TERMINATED, '\r\n', 3000, function (cp1,cp2)
if ( cp2 == transport.constants.event.CONNECTIONCLOSED ) then
print("DemoPad Client Connection Closed")
p1:Close()
clients[p1]=nil
return
end

if ( cp2 == transport.constants.event.CONNECTIONESTABLISHED ) then
if ( cp1 == 0 ) then
print("New DemoPad Client Connection")
clients[p1]=true
else
print("New DemoPad Connection Failed: ")
p1:Close()
clients[p1]=nil
return
end
end
gir.TriggerEvent((cp1), 18, '')
--print(cp1)
end)
return
end
end
if ( clients ) then
for c,v in pairs(clients ) do
c:Close()
end
end
if ( c5 ) then
c5:Close()
end
clients = {}
c5 = transport.New(transport.constants.transport.GIPLIS TEN)
if not c5:Open(nil, 12345) then
print('Could not start listening for DemoPad connections')
c5:Close();
c5 = nil;
end
c5:Callback(transport.constants.parser.TERMINATED, '\r\n', 1000, mycbserver)
print('Listening for connections from DemoPad on port 12345')




VicVonDoom
February 15th, 2012, 01:07 PM
Get yourself an iThingy, the DemoPad app (the lite version is for layout use only - It DOES NOT send any commands!) & the GUI designer from http://www.demopad.com/software.asp

2. The DemoPad Designer Software

Crack the designer open & goto "Create New Project"

6388


Add the info for your project (folder, filename & iThingy device to transfer to once completed)

6389

VicVonDoom
February 15th, 2012, 01:07 PM
Goto "New Device"
rename it to something that will be of use to you later - I'll be using "Girder"...

6390

Adjust the following
IP Address = What ever your Girder PC's IP Address is.
Port = 12345
Type = Generic IP Device
Leave the rest alone!

6391

VicVonDoom
February 15th, 2012, 01:08 PM
Goto Landscape

6392

Goto Objects and expand all the menus
Then drag a button across to the landscape page

6393

Click the new button
This should bring up the action editor of the button. This is where we will send stuff to Girder.

Adjust the following...
Action Type = Send a Command
Device = Girder (or whatever you called your new device earlier!)
Command = Enter command manually
Data = SendSomethingToGirder (this will appear in the Girder Logger - use something unique rather than "Play" as this can come from other places!!)

6394

VicVonDoom
February 15th, 2012, 01:08 PM
SAVE YOUR PROJECT!!!

Then upload to your iThingy using the "Upload to Device" button in the top left of the designer.

On your iThingy, ensure that the settings are correct in the demopad app ("upload file from" and "filename" etc...)

Restart the app to get your latest changes and relax watching the events in the Girder logger as you press your newly designed buttons, these can be dragged from the Girder Logger to trigger any action as usual..!

Happy Days!!

VicVonDoom
February 15th, 2012, 01:09 PM
Coming sometime... Feedback from Girder to Demopad..? (similar to netremote.setvariable)

VicVonDoom
February 15th, 2012, 01:11 PM
placeholder - will delete if not req....

Mike C
February 15th, 2012, 10:13 PM
very cool. is there a link to the tcp/ip protocol... i cannot find it.

VicVonDoom
February 16th, 2012, 11:13 AM
Found this in the manual http://www.demopad.com/demodesignmanual.pdf





SENDING HEX COMMANDS
The command format entered in the pre-defined command screen, or when manually entering commands is standard ASCII text. For those devices which require HEX bytes to be sent, you need some way of entering the hex byte. For this, the software uses \x notation, for example to enter 3 hex bytes 0D 34 2A you would enter \x0D\x34\x2A in the software.
If you have a need to send \x as 2 ASCII characters, then use \\x



And this, which hopefully can be used for feedback...
You can set a flag on receipt of data and have a label or button do something...


USING FLAGS
Flags are Boolean (YES/NO) variables within the software. They can have one of two values: ON, or OFF. Any action can set the status of a flag, and they are used for the following purposes:
1. Flag Dependent Actions – where particular parts of an action list are only executed if a particular flag is set to, say, ‘ON’. (Conditional Logic Statements)
2. Making objects / pages appear – you can have certain objects appear on screen in response to a flag being set to ‘ON’, and have them disappear when the flag is set to ‘OFF’
3. Disabling buttons – you can disable a button by having all actions dependent on a flag
To create a flag, choose ‘Add’ from the ‘Project Flags’ option of the project menu. A flag simply has a name, which must be unique. When the DemoControlHD app is first launched, all flags have a value of ‘OFF’. (Unless you have selected the ‘Remember Last Page’ option in the app settings, in which case all flags have the value they were last set to when the app was running)
A flag can be set by creating an action on a button push/release, page load, or app load event. Whilst in the action editor, select ‘Set a Flag’ as the action type, choose the flag from the drop down list & set the value (either ‘ON’ or ‘OFF’).
It is often useful to use the “App Startup Actions” editor to set the default state of certain flags, so that they are set to “ON” when the app is launched.

VicVonDoom
February 16th, 2012, 11:26 AM
Also just came across this post http://www.avsforum.com/avs-vb/showpost.php?p=21129010&postcount=95

It demonstrates how to configure demopad for feedback - I'm really not sure how to get Girder to send any stuff back via a transport though.
This is my first attempt at a IP type script...

shaun5
February 16th, 2012, 02:24 PM
You just need a script action to implement two way communication. This would send payload one to all the connected clients:

if (pld1 ~= '' ) then
-- might need to append pld1 here with the terminator DemoPad is expecting...
if ( clients ) then
for c,v in pairs(clients ) do
c:Send(pld1)
end
end
end

VicVonDoom
February 16th, 2012, 03:08 PM
thanks shaun5,

I think demopad is expecting the terminator
'\r\n' on the end
Whereabouts would i add that in?

I tried...


if (pld1 ~= 'Hello\r\n' ) then
-- might need to append pld1 here with the terminator DemoPad is expecting...
if ( clients ) then
for c,v in pairs(clients ) do
c:Send(pld1)
end
end
end


I think it would be preferable to have this as a transport & use the 'transport send' action filled out as required, that'll make it usable for everyone.
Not sure that that will work as Girder is more of a listener than a sender in this instance - Or have i got that all wrong..?

shaun5
February 16th, 2012, 04:47 PM
I don't understand what you mean by your last two sentences, because I don't think you are using a transport. Aren't you using the scripting action from your February 8th post? If so (if not show me what you are using), just make another scripting action with the code:

if (pld1 ~= '' ) then
pld1 = pld1 .. '\r\n'
if ( clients ) then
for c,v in pairs(clients ) do
c:Send(pld1)
end
end
end

This would send the first payload variables to all the connected DemoPads. If you just want to do a test, you could make a scripting action like:

if ( clients ) then
for c,v in pairs(clients ) do
c:Send('Hello\r\n')
end
end

When the code is executed, it should send Hello to all the connected DemoPads....

VicVonDoom
February 17th, 2012, 02:34 AM
I'm no longer using the telnet dump code from another thread.
I'm using the code on the first post of this thread in a scripting action that is triggered when girder starts.

all I need is a way to send stuff (not necessarily a response to a received command)

in the old days using the old serial files, I could create a function in the serial file then call it using MySerial:MyFunction from another scripting action - that would be ideal!

Mike C
February 17th, 2012, 02:30 PM
how is demopad different from irule?

shaun5
February 17th, 2012, 03:55 PM
I think what I wrote will work. Let me know.

VicVonDoom
February 17th, 2012, 05:03 PM
how is demopad different from irule?By about $60 in your pocket :-)Also afaik demopad will work with as many devices that are registered to your app store account (all can use different layouts which is handy for restricting the kids options etc) without additional user licences & fees.I can't comment on irule as I've never used it, but from a brief look - it appears to use an online generator/database for your codes or actions (similar to programming a Logitech remote control...Nuff said)Are you a user of irule? Is there already an implementation for use with girder?

VicVonDoom
February 19th, 2012, 09:32 AM
I think what I wrote will work. Let me know.

I've tried both of your scripting actions above to no avail & spent hours searching the forums and manuals...

Why would it be so tough to send?
I'm not sure where to go now, might be a girder fault, might be a demopad fault, might be a firewall/security fault, might even be me!

I'm about ready to throw in the towel!

shaun5
February 19th, 2012, 11:11 AM
It could be mine... Try c:Write('Hello\r\n')

jk2587
February 19th, 2012, 11:22 AM
Hi there,

I've tried the code from the first post as well and am able to trigger events in girder, but the code to send is not working. I think it's a problem in girder somewhere, as the code that should be executed on CONNECTIONESTABLISHED (in the code block below) is not running, so the clients variable is always empty. I could be way off here, but I certainly don't see "New DemoPad Client Connection" in the script console, and using the variable inspector the clients table is empty even with an active connection. Any ideas?



if ( cp2 == transport.constants.event.CONNECTIONESTABLISHED ) then
if ( cp1 == 0 ) then
print("New DemoPad Client Connection")
clients[p1]=true
else
print("New DemoPad Connection Failed: ")
p1:Close()
clients[p1]=nil
return
end
end

VicVonDoom
February 19th, 2012, 02:59 PM
It could be mine... Try c:Write('Hello\r\n')
I've tried this aswell - No cigar to light here either...

VicVonDoom
February 19th, 2012, 03:09 PM
Hi there,

I've tried the code from the first post as well and am able to trigger events in girder, but the code to send is not working. I think it's a problem in girder somewhere, as the code that should be executed on CONNECTIONESTABLISHED (in the code block below) is not running, so the clients variable is always empty. I could be way off here, but I certainly don't see "New DemoPad Client Connection" in the script console, and using the variable inspector the clients table is empty even with an active connection. Any ideas?



if ( cp2 == transport.constants.event.CONNECTIONESTABLISHED ) then
if ( cp1 == 0 ) then
print("New DemoPad Client Connection")
clients[p1]=true
else
print("New DemoPad Connection Failed: ")
p1:Close()
clients[p1]=nil
return
end
end



I think you might be on to something here, '
transport.constants.event.CONNECTIONESTABLISHED' never seems to do anything (I actually removed it from the script to prove it and the rest of the script functioned as before...)

In my VERY limited knowledge it appears that the 'clients' variable will always be 'nil' unless the above kicks in..?

It seems to be set to 'nil' everywhere else in the script aswell..?

I've also tried the original Telnet dump script from per page 295 of the manual, removed the '
transport.constants.event.CONNECTIONESTABLISHED' and that still works without it..?!


Any ideas... Anyone...?

jonrigg68
January 1st, 2013, 07:14 AM
sorry to ressurect and old thread but did anyone get this working?

I am looking to use feedback from Girder to tell multiple demopad clients which devices are turned on. i.e. you start on one demopad and start the Projector, AV reciever and XBMC and then when you log in from another one Girder responds with a message saying each device is on so the second client can respond accordingly.

thanks

VicVonDoom
January 1st, 2013, 12:38 PM
sorry to ressurect and old thread but did anyone get this working?

I am looking to use feedback from Girder to tell multiple demopad clients which devices are turned on. i.e. you start on one demopad and start the Projector, AV reciever and XBMC and then when you log in from another one Girder responds with a message saying each device is on so the second client can respond accordingly.

thanks

only able to send stuff to girder (as per earlier posts) receive data never seemed to work & I gave up.
emailed demopad and their response was the equivalent to "maybe we'll chime in on that idea/thread" - never went anywhere...

jonrigg68
January 3rd, 2013, 10:01 AM
Just one last thing with regard to your first post, Everything works great, except the script does not start after a reboot. If I restart the scripting engine it is fine but not after a full reboot.

shaun5
January 3rd, 2013, 07:55 PM
Add an load event to the script (you probably only have a reset event).

jonrigg68
January 4th, 2013, 04:05 AM
can you point me in the direction of how I do that?

I have added the script as per the first post and then on Script enable the script starts, however I dont get the start script event on start up just restart?

shaun5
January 4th, 2013, 07:15 AM
Right click on the action and add an event. The event is a 'girder event' and is called 'fileloaded'.

sharkvt
January 12th, 2013, 02:03 AM
You can also accomplish this by using the webserver. If you create a file in the httpd directory with the following code



<%
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 ) then
require('json/json')
local json = json.json
local event = table['event'];
gir.TriggerEvent( event, table['device'], table['p1'], table['p2'],table['p3'])
t = {data="true"}
local response = json.encode(t)
webserver:print(response)
end
%>

You can send send requests from DemoPad via http using the "Send data to a website". You'd format your url like this
http://yourserver.com/yourfile.lhtml?device=18&event=do_something&p1=payload1&p2=payload2&p3=payload3

Anything you want to send back, you can just write to the page.