Author Topic: Can I do this?  (Read 4163 times)

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Can I do this?
« on: December 20, 2007, 11:56:32 pm »
I'm trying to store configuration data into my device.

I've added devicedata[56]{string} (Configuration) to my template

I've a lot of information to store... like to store it as XML.


cmd = command.new(blah)
devicedata_[56] = XMLString
SendCommand(cmd)

Which Command (or event) should I use to populate this devicedata string?
Will this push to the database?
Is there a limit on the length of my XMLString?
and is there any problems when I have to CHANGE this information (I don't think so)

Thanks,
Dan

« Last Edit: December 21, 2007, 12:02:49 am by ddamron »
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.

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: Can I do this?
« Reply #1 on: December 21, 2007, 12:33:53 am »
Ok, I think I found something here..

Aaron.B,
Your previous post sparked a possibility...
I had to read it THREE times carefully... lol

 Command:SetDeviceData #765 EDIT: wrong command, it's supposed to be #246

 devdata[2](int)  - the Device to set
 devdata[52](int)  - the devicedata field (56) ## I want to set devicedata(56) in the child.. can I do this without defining it in the template?
 devdata[5](string)  - Value to Assign (my configuration info)

Am I correct in assuming command 765 WILL push the data in devdata[5] into the database as (the value of) devdata[52] which I would set to 56 (Configuration)?

I'm getting frustrated here.. been working on the SAME 3 problem for 5 days now


If this is all OK, can I use this to set the STATE?  I can't figure out the devdata for state, (if it exists)

Thanks, Dan
« Last Edit: December 21, 2007, 05:15:55 am by ddamron »
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.

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: Can I do this?
« Reply #2 on: December 21, 2007, 04:24:56 am »
K, I'm frustrated.
Here's my code for 2 simple routines:
Code: [Select]
def testinit()
  #First, lets try to save configuration information to the child.
  #from me[127], to General Info Plugin[4], priority 1, type=1, ID = 765
  #
  cmd = Command.new(127,4,1,1, 765)
  cmd.params_[2] = '40' # the device to set (40 is my office light)
  cmd.params_[52] = '56' # the devicedata field [56] is Configuration
  cmd.params_[5] = 'Testing' #Value to assign...
  SendCommand(cmd)
end
def testinit2()
  #ok, seems like testinit worked.. lets attempt to read the data back.
  teststring = device_.childdevices_[40].devdata_[56]
  log('Device 40s config:' + teststring)
end
I call testinit, all seems fine.
I call testinit2, and I get an error.
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.

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: Can I do this?
« Reply #3 on: December 21, 2007, 04:37:36 am »
OK, I'm a dummy.
765 is the WRONG command.
it's #246..

I think I got it working... ready to strangle myself.
 ;D ;D ;D ;D
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.

Matthew

  • Douchebag
  • Addicted
  • *
  • Posts: 567
    • View Profile
Re: Can I do this?
« Reply #4 on: December 21, 2007, 04:48:03 pm »
cmd = command.new(blah)
devicedata_[56] = XMLString
SendCommand(cmd)
(...)
Is there a limit on the length of my XMLString?

If you're storing the XMLString in the device as just a blob, you can compress the ASCII XML quite a lot if it's relatively large. (un/compress in LMCE on retreive/store).

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: Can I do this?
« Reply #5 on: December 22, 2007, 12:27:54 am »
Ok, I've run into a 'gotcha'
Hopefully someone can shed some light on this.

I have successfully stored devdata[59] (configuration) to a Light Switch (child of mine)
BUT:
It seems that the data I write is not available until I do a RELOAD..

Here's my routines.. pretty straight forward..

Problem is, I need to be able to WRITE the data and READ it back again..
Code: [Select]
def setdeviceconfig(insteonid, configurestring)
  @deviceid = $children[insteonid]
  @cmdfrom = device_.devid_
  @cmdto = 4 #general info plugin
  @priority = 1
  @type=1 #command
  @cmdid = 246

  #set up command..
  @cmd = Command.new(@cmdfrom, @cmdto, @priority, @type, @cmdid)
  @cmd.params_[2] = @deviceid.to_s
  @cmd.params_[52] = '59' # Configuration
  @cmd.params_[5] = configurestring
  SendCommand(@cmd)
  log('Configuration Saved - will be available on next reload')
end

Code: [Select]
def getdeviceconfig(insteonid)
  @deviceid = $children[insteonid]
  begin
    @configstring = device_.childdevices_[@deviceid].devdata_[59].to_s
    # the above line fails if the data was just written - must do a quick reload first
  rescue
    log('Device ID = ' + @deviceid.to_s)
    log($red + 'Error - Child has no configuration'+ $grey)
    log('Setting initial value of ""')
    setdeviceconfig(insteonid, '')
    @configstring = ''
  end
...
end

I guess the first question is :
  Am I reading the data correctly? using  'device_.childdevices_[@devid].devdata_[59]'

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.

ddamron

  • Alumni
  • wants to work for LinuxMCE
  • *
  • Posts: 962
    • View Profile
    • My LinuxMCE User Page
Re: Can I do this?
« Reply #6 on: December 24, 2007, 10:29:22 am »
I got this figured out.  I'm locking this topic...

That is how you do it.

FYI, when you 'add' a devdata via code, it DOES show up in the child device... just not in the template...

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.