Page 1 of 1

Problem with reading data from device

Posted: Friday 22 November 2019 14:24
by Xfiles
Hi,

I have problem with reading data from device.

I have device:
with state:

5.4;0.0;0.0

and value

0/5.4;0.0;0.0

I try to get this values (I need only first value: 5,4) by script:

Code: Select all

commandArray = {}
if (m % 1 == 0) then
    print "Odczyt bilansu energii:"
    current1, current2, current3=otherdevices_svalues['Pobor_pradu']:match("([^;]+);([^;]+);([^;]+)")

    print(current1)
    print(current2)
    print(current3)
    end
return commandArray
and I received in log only text "Odczyt bilansu energii:"
What is done incorrectly on my side?

Re: Problem with reading data from device

Posted: Friday 22 November 2019 17:56
by waaren
Xfiles wrote: Friday 22 November 2019 14:24 and I received in log only text "Odczyt bilansu energii:"
What is done incorrectly on my side?
this :match should return something so my approach would be to ensure expected raw string is in otherdevices_svalues['Pobor_pradu']

Code: Select all

commandArray = {}
if (m % 1 == 0) then
    print "Odczyt bilansu energii:"
    sValue = otherdevices_svalues['Pobor_pradu']
    print ('Raw sValue: ' .. sValue)	
    current1, current2, current3= sValue:match("([^;]+);([^;]+);([^;]+)")

    print(current1)
    print(current2)
    print(current3)
    end
return commandArray

Re: Problem with reading data from device

Posted: Monday 25 November 2019 23:58
by Xfiles
Thanks a lot! Now it works.