(09.07.2015, 11:54)admin Wrote: Nice example, one small improvement: you can use captures inside of regexps like this:
Code:power=string.sub(string.match(response_body,"<Power>%a+</Power>"), 8, -9)
power=string.match(response_body,"<Power>(%a+)</Power>")
Both lines do exactly the same thing, but you don't have to count characters when using captures
You are right, didn't cross my mind to use string.match because the reply is pretty much static but will be helpfull on futher control.
Thank you
For anyone find it usefull below are the complete responce from Yamaha R-N301 on GET command. PUT command replies only the header section.
Headers:
Code:
200 OK
Server: Network_Player/3.1 (R-N301)
Content-Type: text/xml; charset="utf-8"
Content-Length: 480
Body:
Code:
<YAMAHA_AVrsp="GET"RC="0">
<Main_Zone>
<Basic_Status>
<Power_Control>
<Power>On</Power>
</Power_Control>
<Volume>
<Lvl>
<Val>45</Val>
<Exp>0</Exp>
<Unit/>
</Lvl>
<Mute>Off</Mute>
</Volume>
<Input>
<Input_Sel>SERVER</Input_Sel>
<Input_Sel_Item_Info>
<Param>SERVER</Param>
<RW>RW</RW>
<Title/>
<Icon>
<On>/YamahaRemoteControl/Icons/icon067.png</On>
<Off/>
</Icon>
<Src_Name>SERVER</Src_Name>
<Src_Number>1</Src_Number>
</Input_Sel_Item_Info>
</Input>
</Basic_Status>
</Main_Zone>
</YAMAHA_AV>