Author Topic: GSD command question  (Read 838 times)

mkbrown69

  • Guru
  • ****
  • Posts: 192
    • View Profile
GSD command question
« on: July 21, 2013, 02:58:38 pm »
Morning folks!

I have a question about a particular command:  #246 Set Device Data.  I'm trying to use it in a couple of drivers to obtain information and update LMCE.  In this case, I'm grabbing the model information from a thermostat to update Device Data 233 (Model), so that could be used in conditional logic in the driver to use or disable enhanced features, depending on model.

The model info retrieved looks like this "CT80 Rev B2 V1.03" (including the quotes).  The commented out line in the code below strips the quotes, the line below it leaves them intact. 

Code: [Select]
def get_model()
  log("get_model called")
  @data = ""
  @data = get_data("/tstat/model").to_s
  @data = @data.split(":")
  #@model = (@data[1]).to_s.gsub("}","").gsub! /"/, ''
  @model = (@data[1]).to_s.gsub("}","")
  log(@model)
  cmd = Command.new(device_.devid_, -1001, 1, 2, 246)
      cmd.params_[2] = (device_.devid_).to_s
      cmd.params_[52] = '233'
      cmd.params_[5] = @model.to_s
      SendCommand(cmd)
  rescue => e
    log("Error in get_model: " + e.message)
    log(e.backtrace)
    @model
end

The problem is, it's not working for me.  I've worked out any errors, so the routine runs error free.  But it doesn't do anything... Can anyone help me figure out what I'm doing wrong?

Should the cmd.params_[52] = '233' use a constant with a to_s instead? 
Should  cmd.params_[5] = @model.to_s have quoted or non-quoted information in the variable?

Thanks!
/Mike

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5498
  • DOES work for LinuxMCE.
    • View Profile
Re: GSD command question
« Reply #1 on: July 22, 2013, 05:10:17 am »
Why are you sending to -1001?

-Thom

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5498
  • DOES work for LinuxMCE.
    • View Profile
Re: GSD command question
« Reply #2 on: July 22, 2013, 05:14:26 am »

mkbrown69

  • Guru
  • ****
  • Posts: 192
    • View Profile
Re: GSD command question
« Reply #3 on: July 22, 2013, 03:15:00 pm »
Thom,

Thanks for pointing that out.  I'd been looking at pretty much every other GSD template I could find, but missed that one.  DOH!  I'd been sending to -1000 as that's what most of the code templates do, including some others that do work for me.  Now that you've pointed out that code sample, specifically this bit:
Code: [Select]
def setdeviceconfig(insteonid, configurestring)
@deviceid = $children[insteonid]
@cmdfrom = device_.devid_
@cmdto = 4 #general info plugin
@priority = 1
@type=1 #command
@cmdid = 246

Now that I get the messaging aspect a bit better, I'll be reworking that code snippit to look like this (when I get home).
Code: [Select]
def get_model()
  log("get_model called")
  @data = ""
  @data = get_data("/tstat/model").to_s
  @data = @data.split(":")
  #@model = (@data[1]).to_s.gsub("}","").gsub! /"/, ''
  @model = (@data[1]).to_s.gsub("}","")
  log(@model)
  cmd = Command.new(device_.devid_, 4, 1, 1, 246)
      cmd.params_[2] = (device_.devid_).to_s
      cmd.params_[52] = '233'
      cmd.params_[5] = @model.to_s
      SendCommand(cmd)
  rescue => e
    log("Error in get_model: " + e.message)
    log(e.backtrace)
    @model
end

Once I get it all working, I'll write up some more re-usable functions like ddamron did in his drivers.  I've been studying his EZServe and PLM drivers, and using them as the basis for my ISY driver; I'm taking a break from the ISY driver to work on something simpler (like the thermostat) to figure out some of these more complicated LMCE details like modifying other LMCE controlled data, and the whole sqlcvs thing.  

Thanks for getting me back on the right track!  Much appreciated!

/Mike
« Last Edit: July 23, 2013, 03:31:58 am by mkbrown69 »

tschak909

  • LinuxMCE God
  • ****
  • Posts: 5498
  • DOES work for LinuxMCE.
    • View Profile
Re: GSD command question
« Reply #4 on: July 22, 2013, 05:44:01 pm »
No problem, I can also dig into the Generic Serial Device C++ code itself, as it may harbor some much needed information.

As for me, I don't do anything but the simplest of devices in GSD, anymore, everything I do is usually in C++. (Even the Roku device I replaced, is now entirely in C++)

-Thom

mkbrown69

  • Guru
  • ****
  • Posts: 192
    • View Profile
Re: GSD command question
« Reply #5 on: July 22, 2013, 07:40:17 pm »
Thom,

In my case, I don't know that much about C++ programming, but I know enough about shell scripting, and have played with enough other high-level languages like Perl, Visual Basic, and Python that learning Ruby has a lower barrier to playing with LMCE than my trying to learn C++ AND how LMCE internals work.  So, the GSD drivers give me the ability to get my hardware into the LMCE ecosystem, and then I can learn C++ at my leisure for Arduino and LMCE stuff.

Thanks again for the assistance!

/Mike