PDA

View Full Version : newbie - help getting girder to start listening



Drabert
January 25th, 2009, 01:41 AM
i am extremely green and been using a resouce from another site to help me get my Phillips Pronto and girder to help me control my Media Center box. Right now though, i am having a problem with the most basic of starting points. I can not get girder to "start listening". I followed the example in pdf (copy and paste) but when i click on test, it comes back with "Could not start listening" I am trying to use sockets to communicate from my pronto to the girder. Is there something that i am missing that i need to "enable" in order for it to start listening?

thanks for the help!

Drabert
January 25th, 2009, 02:00 AM
function clientcb(p1,p2)
if ( p2 == 16384 ) then
print("Client Connection Closed")
return
end

if ( p2 == 32768 ) then
if ( p1 == 0 ) then
print("New Client Connection")
else
print("New Client Connection Failed: ", p1)
end
return
end
start, stop = string.find(p1,"%b[]",1)
eventstring = string.sub(p1, start+1, stop-1)
gir.TriggerEvent(eventstring,18)
end

function mycbserver(p1,p2)
print(p1)
print(p2)
if ( p2 == 16384 ) then
print("Connection Closed")
return
end

if ( p2 == 24576 ) then --in example 8192
print("New Incoming Connection")
p1:Callback(2,'\n', 3000, clientcb)
client =p1
return
end

end

if ( c5 ) then
print ("hi2")
c5:Close()
end

c5 = gip.Listen(5001)
print ("hi")
if ( not c5 ) then
print("Could not start listening")
return
end
c5:Callback(2, '\r\n', 1000, mycbserver)

thought it might help to have the lua code

Drabert
January 25th, 2009, 06:44 PM
well i have tried this on three other systems and im still getting the error so i can only assume that i am missing some step that inables the port for listening. If anyone can help me out i would really appreciate it... i have disabled all firewalls, enabled gip, but still get nothing...

i am just getting a "Could not start" in the Lua Console and the log display is showing
Time Date Source Details Payloads
15:36:49:887 1/25/2009 NetRemote Connection closing 192.168.1.199:1047
15:36:49:886 1/25/2009 Communication Server Close Connection 192.168.1.199 1047


Im not sure why im getting a netremote portion and what looks like the port in the netremote error is wrong, but it keeps changing... everytime i hit the button on my remote (Phillips Pronto) i get those two lines of code and the netremote port number is incremented...

thanks

Rob H
January 26th, 2009, 05:48 AM
Something is blocking access to port 5001 - most likely a software firewall

Drabert
January 26th, 2009, 03:03 PM
I rebuilt the box that i am trying to use this for and i only have xp and girder installed on it. I also have the firewall off on the box. Can i use another application to test if the port is some how getting blocked?

Rob H
January 26th, 2009, 05:38 PM
Have you tried any other ports?

Drabert
January 26th, 2009, 11:08 PM
yes i have tried other ports and even other computers. It seems like im missing some important step in the install/setup process to get GIP to work. I am going to see if i can get the Generic Serial to work for now so i can atleast get the functionality out of it. Such a great product! just wish it would work for me :)

Drabert
January 26th, 2009, 11:11 PM
how do i know if i have girder pro or just girder... i was reading that gip will only work with girder pro... could that be my problem? i downloaded girder 4 from the link in this forum

harleydude
January 26th, 2009, 11:21 PM
Help->About should show you which version you are running. I think that the trial if for Pro. Are you running Girder 4 or 5?

Drabert
January 27th, 2009, 02:13 AM
its the trial and its 4.0.15 but it doesnt say anything about pro... could that be the problem?

Rob H
January 27th, 2009, 04:34 AM
That's possible although I would have expected different error since the gip object shouldn't have been created if gip wasn't available.

I'd recommend you try Girder 5.

Ron
January 27th, 2009, 11:55 AM
Yes there is absolutely no reason to use G4 if you are a new user. Upgrade to 5.

Drabert
January 27th, 2009, 05:46 PM
I will make the update tonight... hey ron... you going to be coming up to the central valley any time soon? :)

Ron
January 27th, 2009, 05:57 PM
The central valley is a big place. Though I don't go there very often.

Drabert
January 28th, 2009, 01:39 AM
ok im officially in Girder 5 now... im going to play with it a little tonight and see if i can get it to talk...

thanks!

Drabert
January 28th, 2009, 03:13 AM
first off, i just want to thank Ron for working with me through this! Now that i am on girder 5, i am not having a problem getting the gml to "start listening"

I think i bit off a bit more than i can chew with this project cuz this just feels like its over my head. I keep looking at the gml file that im using for listening and im trying to use prints in places so i can follow the work flow but i am still not understanding how the callback function works or why im having such a difficult time catching the data that my remote is sending to the girder. I know that the remote is working but i can not get the gml file working.

What does my remote need to send to the open port to get me into the clientcb function? I understand that it is the only place that has the gir.TriggerEvent to actually get the girder to interact but i am never getting into that portion of the function...

i am still using the same code that i put in the second post but now im in girder 5.

so i guess my questions are...
what does p1 and p2 represent?
how does a callback function work?
what kind of data can i send to the girder? (text, hex, bin?)
if i am sending a string does it need to be in this format Send("MP_Play\r\n")

thanks for the help... I cant wait to really start having some fun with this once i can get the remote to talk to girder correctly.

Rob H
January 28th, 2009, 06:52 AM
Please post the scripts that you're using, it's very difficult to debug without seeing the source code.

Drabert
January 28th, 2009, 12:55 PM
this is the code that is running in girder

function clientcb(p1,p2)
if ( p2 == 16384 ) then
print("Client Connection Closed")
return
end

if ( p2 == 32768 ) then
if ( p1 == 0 ) then
print("New Client Connection")
else
print("New Client Connection Failed: ", p1)
end
return
end
start, stop = string.find(p1,"%b[]",1)
eventstring = string.sub(p1, start+1, stop-1)
gir.TriggerEvent(eventstring,18)
end

function mycbserver(p1,p2)
print(p1)
print(p2)
if ( p2 == 16384 ) then
print("Connection Closed")
return
end

if ( p2 == 24576 ) then --in example 8192
print("New Incoming Connection")
p1:Callback(2,'\n', 3000, clientcb)
client =p1
return
end

end

if ( c5 ) then
print ("hi2")
c5:Close()
end

c5 = gip.Listen(5001)
print ("hi")
if ( not c5 ) then
print("Could not start listening")
return
end
c5:Callback(2, '\r\n', 1000, mycbserver)

this is the code that i am using on the remote

var socket = new TCPSocket();
socket.connect("192.168.1.106", 5001, 3000);
socket.write("MP_Up \r\n");
socket.close();

thank you for the help

Rob H
January 28th, 2009, 01:41 PM
Hmm.. that looks okay, but it would help if you posted any code inside the appropriate code tags (if you have the advanced editor open then that's the # button), that will preserve the indentation.

Actually, come to think of it, it looks as though your callback function is embedded inside another function in which case you're effectively passing a nil function to c5:Callback()

Drabert
January 28th, 2009, 02:38 PM
when i was testing, i was putting in a few print commands and i saw that i was passing nil so that could be another problem that i am having. I tried to search through the tutorial and on this site for some info on the callback function but i cant find anything... what does it do? does it restart the script?

if someone could help break down this line of code, i think i can follow the rest
c5:Callback(2, '\r\n', 1000, mycbserver)

i know from the tutorial that this is the second form of a call back function and it needs the ending character, a tolerance window, and the function. I i guess it calls the function but what happens after that? why not just call the function? what is the purpose of Callback :)

Drabert
January 28th, 2009, 02:53 PM
ever do that... where you reread a post that you made and you start to find errors in the code... im telling the lua script to parse the data and grab the info between [] but im not sending it anything with brackets. that could be causing the problem :)

i will try this when i get home tonight...

can someone help though explain the callback part?

harleydude
January 28th, 2009, 04:38 PM
I have looked at the code some more and have a few questions. It looks like the code is based on an example from the manual.

Example - Server Mode

function clientcb(p1, p2)

if (p2 == 16384) then

print("Client Connection Closed")

return

end

if (p2 == 32768) then

if (p1 == 0) then

print("New Client Connection")

else

print("New Client Connection Failed: ", p1)

end

return

end

print(p1)

end

function servercb(p1, p2)

if (p2 == 16384) then

print("Server Connection Closed")

return

end

if (p2 == 8192) then

print("New Incoming Connection")

p1:Callback(2,'\n', 3000, clientcb)

client = p1

return

end

print(p1)

end

c5 = gip.Listen(12345)

c5:Callback(2, '\r\n', 1000, servercb)


Constants defined on same page.

transport.constants.event.NEWCONNECTION (24576)
Socket Object
Incoming connection request to a Listen

transport.constants.event.CONNECTIONESTABLISHED (65536)
Number 0 = OK or error number
Outgoing connection made or failed

transport.constants.event.RXCHAR (1)
String. Rx Data
Incoming data, Connection remains open

transport.constants.event.CONNECTIONCLOSED (32768)
String. Rx Data
Remaining data, Connection closed


Now if you look at the constants that are compared to p2 in the clientcb method, they do not match what the manual specifies. That appears to be causing an error on client connect and maybe some confusion in interpreting the lua output.

Rob H
January 28th, 2009, 06:14 PM
can someone help though explain the callback part?


c5:Callback(2, '\r\n', 1000, mycbserver)
c5 is clearly the connection

2 means we want to look for terminated input

'\r\n' is the terminator ie CRLF

1000 is the timeout - ie 1 second, if you start receiving characters, but you don't see the CRLF within 1 second of the time the last character is received you'll be told about it

mycbserver is your callback function - whenever you receive the terminator (CRLF in this case) then your callback function will be called and the data received (minus the terminator) will be passed as the first parameter. The second parameter is a code that tells you what the data means, this code will be 1 if the data has been received normally so you need to check for that before examining the data.

Drabert
January 28th, 2009, 10:49 PM
ok... i was talking to one of the developers that i work with and he was trying to explain the callback stuff to me so i am slowly getting a grasp of it...

ok so right now with every command that my remote sends, p2 is 32768 and my p1 is 0. So does this mean that my connection is being created as it is being closed? from what i am gathering from how the code works, since p2 is neither 16384 or 8192, my code basically stops after it calls the mycbserver function...

im on the verge of just setting p2 to 8192 someplace in the code just so it will work through all the code

Drabert
January 28th, 2009, 10:49 PM
either ron up for a webx training on this? :)

Drabert
January 28th, 2009, 10:51 PM
i just noticed that i am getting an error about reading the config files

LOG: Component Manager : 4 - Transport Manager Unable to read config file Transport Manager.cfg Config File Open Failed
LOG: Component Manager : 4 - UnitSystem Unable to read config file UnitSystem.cfg Config File Open Failed


is that messing me up?

Rob H
January 29th, 2009, 05:19 AM
ok so right now with every command that my remote sends, p2 is 32768 and my p1 is 0. So does this mean that my connection is being created as it is being closed?

In the example code you posted earlier, you were creating the connection to girder, sending the data and then closing the connection.

Can you post your current code (inside code tags preferably)?

Rob H
January 29th, 2009, 05:20 AM
i just noticed that i am getting an error about reading the config files

LOG: Component Manager : 4 - Transport Manager Unable to read config file Transport Manager.cfg Config File Open Failed
LOG: Component Manager : 4 - UnitSystem Unable to read config file UnitSystem.cfg Config File Open Failed


is that messing me up?

That shouldn't be a problem, both of those will use default values.

Drabert
January 29th, 2009, 02:03 PM
the remote code or the lua script?

Rob H
January 29th, 2009, 03:02 PM
Both would probably be best.

Don't forget the code tags though.

Drabert
January 29th, 2009, 07:44 PM
how do you do code tags?

Drabert
January 30th, 2009, 12:45 AM
Lua Script

function clientcb(p1,p2)
print ("clientcb")
print (p1)
print (p2)
if ( p2 == 16384 ) then
print("Client Connection Closed")
return
end
if ( p2 == 32768 ) then
if ( p1 == 0 ) then
print("New Client Connection")
else
print("New Client Connection Failed: ", p1)
end
return
end
print (p1)
start, stop = string.find(p1," ",1)
eventstring = string.sub(p1, start+1, stop-1)
gir.TriggerEvent(eventstring,18)
end

function mycbserver(p1,p2)
print ("mycbserver")
print(p1)
print(p2)
if ( p2 == 16384 ) then
print("Connection Closed")
return
end

if ( p2 == 8192 ) then --in example 8192
print("New Incoming Connection")
p1:Callback(2,'\r\n', 3000, clientcb)
client =p1
return
end

end

if ( c5 ) then
c5:Close()
end

c5 = gip.Listen(5001)
if ( not c5 ) then
print("Could not start listening")
return
end
c5:Callback(2, '\r\n', 1000, mycbserver)

Pronto Script

var socket = new TCPSocket(true);
socket.connect('192.168.1.106', 5001, 3000);
socket.write("Test\r\n");
socket.close();

I dont know if this is in the correct tags but i am not sure how else to post this information. Thanks for the continued support!

Rob H
January 30th, 2009, 06:28 AM
Can you also post the output of from the Lua console?

To easily add code tags you need to be using the Enhanced Editor (you can make this the default from the User CP link up at the top left, then go to Edit Options)

Drabert
January 30th, 2009, 10:52 PM
It seems like the only thing that my remote is sending to the girder is the new connection. Its not sending the next portion that has the data in it. all that c5 is getting from listen is that p1 is 0 and p2 is 32768. If i understand the girder code correctly, it listens and if it recieves something it goes into mycbserver. my server recieves two variables and as long as p2 is 8192 it then goes to the clientcb function. Once in the clientcb function (which recieves two new variables?) as long as p2 is not 16384 or 32768 then it will finally trigger a girder event.
is this the correct way to look at the logic of this?

as far as the lua output it is

mycbserver
0
32768

and the log is

Time Date Source Details Payloads
19:50:38:321 1/30/2009 Server listen 5001 Lua Success (Nothing Triggered)pronto_org.gml:\Pronto\Server \Server listen 5001
19:50:38:312 1/30/2009 NetRemote Connection closing 192.168.1.199:1027


thanks for the continued support

johanj
January 31st, 2009, 05:18 AM
Hi Drabert

I'm sorry to see that you do not have this functional yet...Back now from the trip in Russia. I was in the same plane from sweden-Russia as the Russian bandy team. Even professional russian sportsmans party hard, a lot of bear cans, vodka- and whisky bottles went back and forth in the plane :D .

I'm the one that gave Drabert the Lua and Pronto file. As someone earlier guessed, I just edited the existing Lua example of how to set up a tcp/ip server in girder. However when I checked the parameter p2 that came in when I sent a string from the pronto, it did not match the one in the script (8192). I just changed this number to what came in, 24576 in my case. Then I was able to sort the string p1 in the function clientcb.

I use brackets around the string from the pronto to be able to sort the command out in clientcb. Here is my code and the result from the Lua panel:

--------------------------------------------------
function clientcb(p1,p2)
print("clientcb")
print(p1)
print(p2)


if ( p2 == 16384 ) then
print("Client Connection Closed")
return
end

if ( p2 == 32768 ) then
if ( p1 == 0 ) then
print("New Client Connection")
else
print("New Client Connection Failed: ", p1)
end
return
end
start, stop = string.find(p1,"%b[]",1)
eventstring = string.sub(p1, start+1, stop-1)
gir.TriggerEvent(eventstring,18)
end

function mycbserver(p1,p2)
print("mycbserver")
print(p1)
print(p2)
if ( p2 == 16384 ) then
print("Connection Closed")
return
end

if ( p2 == 24576 ) then --in example 8192
print("New Incoming Connection")
p1:Callback(2,'\n', 3000, clientcb)
client =p1
return
end

end

if ( c5 ) then
c5:Close()
end

c5 = gip.Listen(5001)
if ( not c5 ) then
print("Could not start listening")
return
end
c5:Callback(2, '\r\n', 1000, mycbserver)
--------------------------------------------------


Lua:

mycbserver
userdata: 06E09298
24576
New Incoming Connection
clientcb
[MP_PLAY]
1
clientcb
nil
32768
New Client Connection Failed: nil

johanj
January 31st, 2009, 05:37 AM
I now realized that you send commands synchronous from the Pronto, in the example I gave you I used asynchronous sockets. Could that be something that change the p2 parameter? Can you go back to test the original files that you got from me with asynchronous sockets?

I'm really surprised that it do not work for you. I have tested this on three computers in my home and are running the same lua script file I gave you on all of them. And I have send the files to others that have it functional.

Rob H
January 31st, 2009, 09:00 AM
24576 is actually two codes in one it's 8192 + 16384, i.e. new connection and connection closed at the same time. It would perhaps be better if you didn't close the connection immediately.

johanj
January 31st, 2009, 10:30 AM
Thanks Rob, that make sense. However, I want to close the connection just after the command is recieved in order to make it simple on the pronto side. The pronto has a limit in the number of open sockets that it can handle. How do I close the socket on the server side?

Johan

Rob H
January 31st, 2009, 10:36 AM
Personally, I'd just keep the socket open unless that has power implications for the Pronto that is - how many devices are you controlling via sockets?

johanj
January 31st, 2009, 11:07 AM
I'm only controlling one device at the time with tcp/ip.

The Pronto go to sleep after some time and I guess that one could loose the socket then and by mistake open a new one the next time a command is sent and in this way reach the limit in the amount of open sockets. That is why I want to close the directly. One can reuse the sockets but I haven't tried that, it is working for me in this way.

But it is working as expected, the command is sent and after that the socket is closed. Why is this not a good approach?

Drabert, have you tried with asynchronous sockets? Open the socket with:
var socket = new TCPSocket(false);

Have you tried to not close the socket directly? Just delete the socket.close(); in the pronto script.

Drabert
February 1st, 2009, 12:07 AM
Today is my wifes birthday so i will have to wait until tomorrow to try this out... as of right now, i have the remote working via serial connection... but tcp/ip is the end goal for my project... thanks for the suggestions! ill get back to you probably tonight :)

glad you had a fun trip...