Jump to content

Welcome to Smart Home Forum by FIBARO

Dear Guest,

 

as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.

 

As a member you can:

  •     Start new topics and reply to others
  •     Follow topics and users to get email updates
  •     Get your own profile page and make new friends
  •     Send personal messages
  •     ... and learn a lot about our system!

 

Regards,

Smart Home Forum by FIBARO Team


Fibaro virtual device Xml read


pepijn
 Share

Recommended Posts

Dear forum readers.

 

I have a virtual device where I wanted to read the XML values from. i know that it is not possible to use external libs to read the XML.

the device wich I wanted to control has a status page which in XML format is.

 

I wanted that my virtual device can read the location ID and from each location id the Preset and the name and at last the type of "room"

I use Lua for the virtual device. hope that someone can help me out with this 

 

Please login or register to see this code.

 

Link to comment
Share on other sites

I made this quick and dirty xml to Lua table converter in the past and it seems to be able to cope with your structure too. It's not standards compliant, does no error checks, and puts tag properties as elements in the Lua table. It's also bit unorthodox in how it handles arrays too. In your example you get {locations={location=[..]}, not the expected {locations=[{location=..},{location=..}]}. In short, you don't know if you have an array or not. However, it's possible to cope with, see use of "array" below. The regexps may need to be modified if you have tags with other chars than lowercase letter and "_".

Please login or register to see this code.

Applied on your structure I get this Lua table

Please login or register to see this code.

and

Please login or register to see this code.

gives

Please login or register to see this code.

 

Edited by jgab
  • Like 1
Link to comment
Share on other sites

  • Topic Author
  • 55 minutes ago, jgab said:

    I made this quick and dirty xml to Lua table converter in the past and it seems to be able to cope with your structure too. It's not standards compliant, does no error checks, and puts tag properties as elements in the Lua table. It's also bit unorthodox in how it handles arrays too. In your example you get {locations={location=[..]}, not the expected {locations=[{location=..},{location=..}]}. In short, you don't know if you have an array or not. However, it's possible to cope with, see use of "array" below. The regexps may need to be modified if you have tags with other chars than lowercase letter and "_".

    Please login or register to see this code.

    Applied on your structure I get this Lua table

    Please login or register to see this code.

    and

    Please login or register to see this code.

    gives

    Please login or register to see this code.

     

    Thanks!  which part do i have to copy and paste in my virtual device (the first code and the function array part??) 

    Link to comment
    Share on other sites

    Yes, I guess you are getting the xml text with some http request, and then it's depend on what you want to do with values...

    Please login or register to see this spoiler.

     

    • Like 1
    Link to comment
    Share on other sites

  • Topic Author
  • So i have this as code right now . 

     

    Please login or register to see this code.

    But when i run the debug it will never say klaar (Done ) or print out the ID and name of the room what do I wrong?  

    i needed the id and the name + the Type  to set the preset of the room and  i wanted to read out wichs preset is already set so i can display that on a label .

    the code is getting stuck in the repeat  part of the function

     

    Kind regards pepijn

    Edited by pepijn
    Link to comment
    Share on other sites

    55 minutes ago, pepijn said:

    So i have this as code right now . 

     

    But when i run the debug it will never say klaar (Done ) or print out the ID and name of the room what do I wrong?  

    i needed the id and the name + the Type  to set the preset of the room and  i wanted to read out wichs preset is already set so i can display that on a label .

    the code is getting stuck in the repeat  part of the function

     

    Kind regards pepijn

     

    Can you print out the locInfo so we can see what you get

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • 8 minutes ago, jgab said:

     

    Can you print out the locInfo so we can see what you get

    Please login or register to see this code.

    this is what I will get nothing of the XML is showing up. but i know that i get the XMl because it was possible to see how many bytes it has

    (when i try to use the locInfo Debug  nothing is printed out.)

    Please login or register to see this image.

    /monthly_2019_02/image.png.61624fa3effb5eb46703904d9368ac14.png" />

    Please login or register to see this code.

    1
    2
    7

     

    Edited by pepijn
    Link to comment
    Share on other sites

    Seems to be an issue with your http requests - or the way that you have structured the code? Do you have the code in the main loop or a button? Who prints the "Get Location" and "Start Function" logs? ...and why do it in a VD?

    11 minutes ago, pepijn said:

     

    move the debug before the conversion as we never see the log otherwise. I expect there are some xml headers,

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • 7 minutes ago, jgab said:

    Seems to be an issue with your http requests - or the way that you have structured the code? Do you have the code in the main loop or a button? Who prints the "Get Location" and "Start Function" logs? ...and why do it in a VD?

    Everything is inside a Virtual Device on a button.

    I have 4 buttons wich all have to read out the xml 

     

    My HTTP request is working i know that because i can get the amount of characters  back from the xml ( and it is exact the same)  

     

    Please login or register to see this image.

    /monthly_2019_02/image.png.fc43368e95c5f7f5232af95c80a94b9a.png" />

    This is what i have right now  as the code :

    Please login or register to see this code.

     

    Edited by pepijn
    Link to comment
    Share on other sites

    4 minutes ago, pepijn said:

    Everything is inside a Virtual Device.

     

    My HTTP request is working i know that because i can get the amount of characters  back from the xml ( and it is exact the same)  

    Yes, just log the xml result before calling the html2lua function so we can see the result, as it doesn't seem to terminate. Probably because some xml schema header...

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • still  nothing getting back when i try to log the locId.

    i can make a picture of the postman request  to show you how it looks? 

    Link to comment
    Share on other sites

    It doesn't log anything on this line? not even "XML:" ?

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

  • Topic Author
  • Just now, jgab said:

    It doesn't log anything on this line? not even "XML:" ?

    Please login or register to see this code.

     

    No nothing ....  i have made a picture of the debug

    Link to comment
    Share on other sites

    Hmm, then we need to see what kind of strange data we get, try this instead

    Please login or register to see this code.

     

    Edited by jgab
    should be str:byte
    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, jgab said:

    Hmm, then we need to see what kind of strange data we get, try this instead

    Please login or register to see this code.

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Sorry, it should have been str:byte, and print out some more chars. You have some headers that was not part of the example in your first post that the code seems to stumble on. Strange though that you don't get any log. Must be that the HC2 console interprets it as html...

    Please login or register to see this code.

     

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • 1 minute ago, jgab said:

    Sorry, it should have been str:byte, and print out some more chars. You have some headers that was not part of the example your first post that the code seems to stumble on. Strange though that you don't get any log. Must be that the HC2 console interprets it as html...

    Please login or register to see this code.

     

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Ok, seems to be a standard xml schema header. Change the beginning of html2lua to this

    Please login or register to see this code.

     

    Guess the name of the function should be xml2lua ;-)

    Edited by jgab
    Link to comment
    Share on other sites

  • Topic Author
  • 5 minutes ago, jgab said:

    Ok, seems to be a standard xml schema header. Change the beginning of html2lua to this

    Please login or register to see this code.

     

    1

    Please login or register to see this code.

    Oke this is what i have right now . but it gives me a error on line 33  wich is 

    Please login or register to see this code.

     

    Edited by pepijn
    Link to comment
    Share on other sites

    What kind of error? It still seems like what you get is not what you had in your first example. 

    Can you do this to print the xml data? 

    Please login or register to see this code.

     

    Link to comment
    Share on other sites

    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.

    Guest
    Reply to this topic...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.

     Share

    ×
    ×
    • Create New...