Author Topic: GSD network connection help  (Read 10868 times)

jspeckman

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
GSD network connection help
« on: January 18, 2008, 03:13:24 pm »
Hi all,
  I'm in the process of rewriting a weather plugin that I had written a while back and need a little help.  The plugin goes out to weather.gov to retrieve the current weather conditions.  Originally I did this by having ruby shell out to a perl script to do the actual work.  The perl script in turn used lynx and grep to get the info, parse it with regex's and the insert the data directly into the database.  I'm now working on redoing the entire thing in ruby.  I wrote a test version as a ruby script (stand alone with no linuxmce functions)  that uses net/http.  This works fine.  Now I'm putting the code into linuxmce and have run into a small snag.  I'm trying to use conn_ to connect to the website, but don't really know how to use it.  I've looked at the panasonic ip camera code, as well as other examples and all of the connect to user defined ip addresses.  Is this the only way?  Can I use additional ruby libraries with the embedded ruby?
  Also, what is the best way to retrieve data from my device.  Here's an example of with I want to do: Weather device retrieves weather conditions once an hour.  If there is any change since last time, an event is fired off.  A respond to event is setup to shut off my outdoor fountain if an event is received from the weather device that it is now raining or there is lightning.  This is working in the old version no problem.  What I want to add is when the timed event to turn the fountain on happens, I would like to check the weather device for if it is currently raining or whatever and not turn the fountain on if the weather is already bad.  Is this possible?

Thanks,
Jason

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: GSD network connection help
« Reply #1 on: January 18, 2008, 04:20:09 pm »
Hi all,
  I'm in the process of rewriting a weather plugin that I had written a while back and need a little help.  The plugin goes out to weather.gov to retrieve the current weather conditions.  Originally I did this by having ruby shell out to a perl script to do the actual work.  The perl script in turn used lynx and grep to get the info, parse it with regex's and the insert the data directly into the database.  I'm now working on redoing the entire thing in ruby.  I wrote a test version as a ruby script (stand alone with no linuxmce functions)  that uses net/http.  This works fine.  Now I'm putting the code into linuxmce and have run into a small snag.  I'm trying to use conn_ to connect to the website, but don't really know how to use it.  I've looked at the panasonic ip camera code, as well as other examples and all of the connect to user defined ip addresses.  Is this the only way?  Can I use additional ruby libraries with the embedded ruby?
  Also, what is the best way to retrieve data from my device.  Here's an example of with I want to do: Weather device retrieves weather conditions once an hour.  If there is any change since last time, an event is fired off.  A respond to event is setup to shut off my outdoor fountain if an event is received from the weather device that it is now raining or there is lightning.  This is working in the old version no problem.  What I want to add is when the timed event to turn the fountain on happens, I would like to check the weather device for if it is currently raining or whatever and not turn the fountain on if the weather is already bad.  Is this possible?

Thanks,
Jason

Hi,

maybe not of much help, but :
1. is there any more info about your work posted somewhere ? It's interesting concept also for all kinds of other "data retrieveing " plugins...

2. retrieving data from device: I also run into this problem - for instance, House Security Mode. We have events to change and notify changes, but AFAIK we don't have convenient way to ask for current state, beside looking directly into sql database...

3. To use state info in Event handler, maybe you could create several devices indication state - for instance one generic I/O device for raining, lightning, etc.. and then include it in event handler... Maybe you could have somekind of parent object with all those children - similar as home automation system is handled. For instance I have home automation controller (interface) as parent device and then all devices as child devices (temperature sensors are already there)... So similar could be done for Weather, with children of temperature, humidity, brightness, etc...

But I'm not sure if this approach is best suited with LMCE's intended architecture, so some opinions from more experienced developers would be also helpful here... It would be nice, if you can make Wiki page for it, and we can discuss this further...

HTH,

Bulek.
 
Thanks in advance,

regards,

Bulek.

jspeckman

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: GSD network connection help
« Reply #2 on: January 18, 2008, 05:15:35 pm »
Thanks for the input.  I had given some thought to child devices, but hadn't gone any further with it.  I wanted to ask first.  All my previous work is over in the plutohome wiki.  I'd be happy to start a page over here.  Retrieving data would also be useful for sunrise/sunset as well.  I have need for knowing when say a half hour before sunrise is.  I know currently those times are calculated in one of the plugins (forget which one) and an event fires off at that time, versus being stored for retrieval at any time.

Jason

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: GSD network connection help
« Reply #3 on: January 18, 2008, 06:22:47 pm »
jspeckman,

Sure, bring that over here and start a new thread with it.

I'll be happy to help.

Dan
The only intuitive interface is the nipple.  After that it's all learned.
My other computer is your windows box.
I'm out of my mind.  Back in 5 minutes.
Q:  What's Red and smells like blue paint?

A:  Red Paint.

jspeckman

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: GSD network connection help
« Reply #4 on: January 19, 2008, 12:46:44 am »
Hi again,
  I answered one of my questions and solved one problem.  You can include libraries and this fixed my connecting to website problem.
Now on to passing data.  Should I post what I have so far here, in a new thread or start a new wiki page for it?  I'm asking 'cause I don't know which is best and where it will benefit the most people.

Thanks,
Jason

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: GSD network connection help
« Reply #5 on: January 19, 2008, 06:39:56 am »
I'd recommend you attach it here first...
I'd rather not put it up on the wiki until it's at least in beta..
Don't embed the code into the message, you'll run out of space..
attach the code as an attachment..

Looking forward to seeing your code!

Regards,

Dan
The only intuitive interface is the nipple.  After that it's all learned.
My other computer is your windows box.
I'm out of my mind.  Back in 5 minutes.
Q:  What's Red and smells like blue paint?

A:  Red Paint.

jspeckman

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: GSD network connection help
« Reply #6 on: January 19, 2008, 06:23:06 pm »
OK, here's what I've got so far.

Jason

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: GSD network connection help
« Reply #7 on: January 19, 2008, 10:31:43 pm »
  75:#cmd = Command.new(devIDfrom, devIDto, priority, type, id)
  76:#cmd.params_
  • = y

  77:#SendCommand(cmd)
  78:
  79:ms = "/usr/pluto/bin/MessageSend dcerouter " + device_.devid_.to_s + " -1000 8 0 5 2 4 10"
  80:system(ms)

Is there a reason you're doing it this way?

The only intuitive interface is the nipple.  After that it's all learned.
My other computer is your windows box.
I'm out of my mind.  Back in 5 minutes.
Q:  What's Red and smells like blue paint?

A:  Red Paint.

jspeckman

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: GSD network connection help
« Reply #8 on: January 20, 2008, 02:30:10 am »
For the shell command to messagesend?  It's the only way I know how at the moment.  I haven't quite figured out how to use the command function yet.  I'm also not entirely sure if the command function supports all the same options as messagesend.  So for now I stuck with what I know to have it working faster.  I would like to do away with as many system calls as possible.

Jason

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: GSD network connection help
« Reply #9 on: January 20, 2008, 07:38:21 am »
Code: [Select]
59:log("Starting NOAA Weather Check")

60:log("Setup message intercept for DCERouter")

61:

62:###

63:# devIDfrom: device_.devid_ = my device id

64:# devIDto: -1000 = dcerouter

65:# priority:

66:# type: 1 = command, 2 = event

67:# id:

68:

69:$devIDfrom = device_.devid_

70:devIDto = -1000

71:priority = ""

72:type = 2

73:id = ""

74:

75:#cmd = Command.new(devIDfrom, devIDto, priority, type, id)

76:#cmd.params_[x] = y

77:#SendCommand(cmd)

78:

79:ms = "/usr/pluto/bin/MessageSend dcerouter " + device_.devid_.to_s + " -1000 8 0 5 2 4 10"

80:system(ms)


Starting on line 63, I assume you're trying to set the params to send the command..
devIDfrom = device_.devid_ This will send a command from YOU (NOT a child device)
(I assume this is correct)

devIDto = -1000 (This is correct for a COMMAND.. if you want to send an event, set it to -1001)

line 66 type, simply set it to 1 for a command, or 2 for an event.

67 id.  this is the ID of the command/event you want to send...

This confuses me a bit...

79:ms = "/usr/pluto/bin/MessageSend dcerouter " + device_.devid_.to_s + " -1000 8 0 5 2 4 10"

MessageSend has this syntax:
MessageSend server [-targetType [device|category|template]] [-r | -o] [-p path] [-bl BroadcastLevel] [-retry value] DeviceFrom DeviceTo MsgType(1=Command, 2=Event) MsgID [parm1id param1value] [parm2id parm2value] ...

Removing all the 'flags' we don't use here, we get:
MessageSend server DeviceFrom DeviceTo MsgType(1=Command, 2=Event) MsgID [parm1id param1value] [parm2id parm2value] ...
Seems to me, the command your sending is missing the MsgType?  8 != 1|2...
is 8 the cmdid you want to send?
If you can explain each variable your sending, that would help.

HTH,

Regards,

Dan
The only intuitive interface is the nipple.  After that it's all learned.
My other computer is your windows box.
I'm out of my mind.  Back in 5 minutes.
Q:  What's Red and smells like blue paint?

A:  Red Paint.

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: GSD network connection help
« Reply #10 on: January 20, 2008, 11:31:15 am »
...

This confuses me a bit...

79:ms = "/usr/pluto/bin/MessageSend dcerouter " + device_.devid_.to_s + " -1000 8 0 5 2 4 10"

MessageSend has this syntax:
MessageSend server [-targetType [device|category|template]] [-r | -o] [-p path] [-bl BroadcastLevel] [-retry value] DeviceFrom DeviceTo MsgType(1=Command, 2=Event) MsgID [parm1id param1value] [parm2id parm2value] ...

Removing all the 'flags' we don't use here, we get:
MessageSend server DeviceFrom DeviceTo MsgType(1=Command, 2=Event) MsgID [parm1id param1value] [parm2id parm2value] ...
Seems to me, the command your sending is missing the MsgType?  8 != 1|2...
is 8 the cmdid you want to send?
If you can explain each variable your sending, that would help.

HTH,

Regards,

Dan


Hi,

I guess he's trying to register message interceptor. You can register either by being device (or parent for its child devices) or as a message interceptor.
But I'm not sure if this can be done on same socket (I wanted device and interceptor, but couldn't get it to work on same socket)....

http://wiki.linuxmce.org/index.php/Message_Interceptors

HTH,

regards,

Bulek.
Thanks in advance,

regards,

Bulek.

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: GSD network connection help
« Reply #11 on: January 20, 2008, 12:33:42 pm »
Even then, the message is still malformatted..

weird..

definately need a bit more explanation on the message is attempting to do.

The only intuitive interface is the nipple.  After that it's all learned.
My other computer is your windows box.
I'm out of my mind.  Back in 5 minutes.
Q:  What's Red and smells like blue paint?

A:  Red Paint.

bulek

  • Administrator
  • wants to work for LinuxMCE
  • *****
  • Posts: 909
  • Living with LMCE
    • View Profile
Re: GSD network connection help
« Reply #12 on: January 20, 2008, 02:21:34 pm »
Even then, the message is still malformatted..

weird..

definately need a bit more explanation on the message is attempting to do.


Hi,

I think you're right... it needs 6 parameters, although formatting of such message is different - there are no parameters ID before parameters, but rather parameters by themselves....

I think that anyone that tries to deal with DCE Router and messages should go through this tutorial :

http://wiki.linuxmce.org/index.php/Plain_Text_DCE_Messages

It's particularly important cause at step 17. you can see proper DCE message for registering message interceptor...

Sorry, for including this a bit offtopic...

Quote
Matthew, are you reading this (regarding Perl integration) ?
One easy way to start is to register message interceptor - it receives all needed messages and with addition of sending events, commands you can get pretty descent event handler in Perl. I have some dirty mockups of LMCE.pm to help in this area. I agree, it's not proper event handler, cause it's totally "external", but it's a good start. I think we need some skeleton object, that anyone should be able to start contributing on, later we can enhance Perl to be properly embedded... if we organize code properly, also MH users will be able to use it...

Regards,

Bulek.
Thanks in advance,

regards,

Bulek.

jspeckman

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: GSD network connection help
« Reply #13 on: January 20, 2008, 10:21:18 pm »
You guys are correct, it's supposed to set up a message interceptor for climate messages.  Honestly I don't really understand it.  I copied the formating from step 14 in the plain text dce messages tutorial  replacing security event (84) with climate event (10).  However after reading your replies and looking in the database again, it appears that security events should be (9).  Like I said I don't really understand what is going on, but I try what I think works and hopefully you guys who've been writing the more complex devices can help me out.

Thanks,
Jason

PS I did find I had incorrect event numbers in the other 2 messagesend commands.  Weather changed  and temperature changed.  I have corrected those to so far.

jspeckman

  • Regular Poster
  • **
  • Posts: 25
    • View Profile
Re: GSD network connection help
« Reply #14 on: January 23, 2008, 11:40:03 pm »
Made a couple of changes.  I'm currently testing the code with the register as message interceptor removed to see how things work.  I also added some code to the idle loop to automaticly get weather updates every 15 past the hour.  I'll post the new code once it's been tested a bit.  I've also run into an odd problem that maybe someone can elighten me with an answer or pointer.  The ruby editor in the admin site is deleting parts of my code when I hit the update button.  Half of the xml tags were missing, I added them back in, clicked update and they were gone again???  They're part of the regex and I really need them to stay.  Does the editor know something I don't?  It seems to think it's smarter than me (maybe it is).  Ideas?

Thanks,
Jason